diff --git a/.gitignore b/.gitignore index a05a65c95c1..21d79becb15 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ tests/*.d.ts scripts/debug.bat scripts/run.bat scripts/word2md.js +scripts/ior.js coverage/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a6ab80a408d..a30b2154133 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ Design changes will not be accepted at this time. If you have a design change pr ## Legal You will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you are granting us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under appropriate copyright. -Please submit a Contributor License Agreement (CLA) before submitting a pull request. Download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190)), sign, scan, and email it back to . Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features. +Please submit a Contributor License Agreement (CLA) before submitting a pull request. Download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190) or [Microsoft Contribution License Agreement.pdf](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=921298)), sign, scan, and email it back to . Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features. ## Housekeeping Your pull request should: @@ -26,6 +26,7 @@ Your pull request should: * Include baseline changes with your change * All changed code must have 100% code coverage * Follow the code conventions descriped in [Coding guidlines](https://github.com/Microsoft/TypeScript/wiki/Coding-guidlines) +* To avoid line ending issues, set `autocrlf = input` and `whitespace = cr-at-eol` in your git configuration ## Running the Tests To run all tests, invoke the runtests target using jake: diff --git a/Jakefile b/Jakefile index da91239d7a5..64394c2d60e 100644 --- a/Jakefile +++ b/Jakefile @@ -10,6 +10,7 @@ var servicesDirectory = "src/services/"; var harnessDirectory = "src/harness/"; var libraryDirectory = "src/lib/"; var scriptsDirectory = "scripts/"; +var unittestsDirectory = "tests/cases/unittests/"; var docDirectory = "doc/"; var builtDirectory = "built/"; @@ -54,6 +55,7 @@ var servicesSources = [ ].map(function (f) { return path.join(compilerDirectory, f); }).concat([ + "breakpoints.ts", "services.ts", "shims.ts", "signatureHelp.ts", @@ -74,13 +76,17 @@ var harnessSources = [ "typeWriter.ts", "fourslashRunner.ts", "projectsRunner.ts", - "unittestrunner.ts", "loggedIO.ts", "rwcRunner.ts", "runner.ts" ].map(function (f) { return path.join(harnessDirectory, f); -}); +}).concat([ + "services/colorization.ts", + "services/documentRegistry.ts" +].map(function (f) { + return path.join(unittestsDirectory, f); +})); var librarySourceMap = [ { target: "lib.core.d.ts", sources: ["core.d.ts"] }, @@ -279,7 +285,6 @@ var word2mdJs = path.join(scriptsDirectory, "word2md.js"); var word2mdTs = path.join(scriptsDirectory, "word2md.ts"); var specWord = path.join(docDirectory, "TypeScript Language Specification.docx"); var specMd = path.join(docDirectory, "spec.md"); -var headerMd = path.join(docDirectory, "header.md"); file(word2mdTs); @@ -292,9 +297,8 @@ compileFile(word2mdJs, // The generated spec.md; built for the 'generate-spec' task file(specMd, [word2mdJs, specWord], function () { - jake.cpR(headerMd, specMd, {silent: true}); var specWordFullPath = path.resolve(specWord); - var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" >>' + specMd; + var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd; console.log(cmd); child_process.exec(cmd, function () { complete(); diff --git a/bin/tsc.js b/bin/tsc.js index 07cccb86d1b..bb432bf9c47 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -19,6 +19,7 @@ var ts; Unterminated_string_literal: { code: 1002, category: 1 /* Error */, key: "Unterminated string literal." }, Identifier_expected: { code: 1003, category: 1 /* Error */, key: "Identifier expected." }, _0_expected: { code: 1005, category: 1 /* Error */, key: "'{0}' expected." }, + A_file_cannot_have_a_reference_to_itself: { code: 1006, category: 1 /* Error */, key: "A file cannot have a reference to itself." }, Trailing_comma_not_allowed: { code: 1009, category: 1 /* Error */, key: "Trailing comma not allowed." }, Asterisk_Slash_expected: { code: 1010, category: 1 /* Error */, key: "'*/' expected." }, Unexpected_token: { code: 1012, category: 1 /* Error */, key: "Unexpected token." }, @@ -127,6 +128,7 @@ var ts; Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: 1 /* Error */, key: "Cannot compile external modules unless the '--module' flag is provided." }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: 1 /* Error */, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: 1 /* Error */, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, + An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: 1 /* Error */, key: "An enum member cannot have a numeric name." }, Duplicate_identifier_0: { code: 2300, category: 1 /* Error */, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1 /* Error */, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: 1 /* Error */, key: "Static members cannot reference class type parameters." }, @@ -193,8 +195,6 @@ var ts; The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: 1 /* Error */, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." }, Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: 1 /* Error */, key: "Invalid left-hand side of assignment expression." }, Operator_0_cannot_be_applied_to_types_1_and_2: { code: 2365, category: 1 /* Error */, key: "Operator '{0}' cannot be applied to types '{1}' and '{2}'." }, - No_best_common_type_exists_between_0_1_and_2: { code: 2366, category: 1 /* Error */, key: "No best common type exists between '{0}', '{1}', and '{2}'." }, - No_best_common_type_exists_between_0_and_1: { code: 2367, category: 1 /* Error */, key: "No best common type exists between '{0}' and '{1}'." }, Type_parameter_name_cannot_be_0: { code: 2368, category: 1 /* Error */, key: "Type parameter name cannot be '{0}'" }, A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2369, category: 1 /* Error */, key: "A parameter property is only allowed in a constructor implementation." }, A_rest_parameter_must_be_of_an_array_type: { code: 2370, category: 1 /* Error */, key: "A rest parameter must be of an array type." }, @@ -274,6 +274,7 @@ var ts; Property_0_is_protected_in_type_1_but_public_in_type_2: { code: 2444, category: 1 /* Error */, key: "Property '{0}' is protected in type '{1}' but public in type '{2}'." }, Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: 1 /* Error */, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." }, Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: 1 /* Error */, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." }, + The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: 1 /* Error */, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1 /* Error */, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, @@ -758,14 +759,14 @@ var ts; return result; } } - function getLeadingComments(text, pos) { + function getLeadingCommentRanges(text, pos) { return getCommentRanges(text, pos, false); } - ts.getLeadingComments = getLeadingComments; - function getTrailingComments(text, pos) { + ts.getLeadingCommentRanges = getLeadingCommentRanges; + function getTrailingCommentRanges(text, pos) { return getCommentRanges(text, pos, true); } - ts.getTrailingComments = getTrailingComments; + ts.getTrailingCommentRanges = getTrailingCommentRanges; function isIdentifierStart(ch, languageVersion) { return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion); } @@ -1492,60 +1493,62 @@ var ts; SyntaxKind[SyntaxKind["TypeLiteral"] = 129] = "TypeLiteral"; SyntaxKind[SyntaxKind["ArrayType"] = 130] = "ArrayType"; SyntaxKind[SyntaxKind["TupleType"] = 131] = "TupleType"; - SyntaxKind[SyntaxKind["ArrayLiteral"] = 132] = "ArrayLiteral"; - SyntaxKind[SyntaxKind["ObjectLiteral"] = 133] = "ObjectLiteral"; - SyntaxKind[SyntaxKind["PropertyAssignment"] = 134] = "PropertyAssignment"; - SyntaxKind[SyntaxKind["PropertyAccess"] = 135] = "PropertyAccess"; - SyntaxKind[SyntaxKind["IndexedAccess"] = 136] = "IndexedAccess"; - SyntaxKind[SyntaxKind["CallExpression"] = 137] = "CallExpression"; - SyntaxKind[SyntaxKind["NewExpression"] = 138] = "NewExpression"; - SyntaxKind[SyntaxKind["TypeAssertion"] = 139] = "TypeAssertion"; - SyntaxKind[SyntaxKind["ParenExpression"] = 140] = "ParenExpression"; - SyntaxKind[SyntaxKind["FunctionExpression"] = 141] = "FunctionExpression"; - SyntaxKind[SyntaxKind["ArrowFunction"] = 142] = "ArrowFunction"; - SyntaxKind[SyntaxKind["PrefixOperator"] = 143] = "PrefixOperator"; - SyntaxKind[SyntaxKind["PostfixOperator"] = 144] = "PostfixOperator"; - SyntaxKind[SyntaxKind["BinaryExpression"] = 145] = "BinaryExpression"; - SyntaxKind[SyntaxKind["ConditionalExpression"] = 146] = "ConditionalExpression"; - SyntaxKind[SyntaxKind["OmittedExpression"] = 147] = "OmittedExpression"; - SyntaxKind[SyntaxKind["Block"] = 148] = "Block"; - SyntaxKind[SyntaxKind["VariableStatement"] = 149] = "VariableStatement"; - SyntaxKind[SyntaxKind["EmptyStatement"] = 150] = "EmptyStatement"; - SyntaxKind[SyntaxKind["ExpressionStatement"] = 151] = "ExpressionStatement"; - SyntaxKind[SyntaxKind["IfStatement"] = 152] = "IfStatement"; - SyntaxKind[SyntaxKind["DoStatement"] = 153] = "DoStatement"; - SyntaxKind[SyntaxKind["WhileStatement"] = 154] = "WhileStatement"; - SyntaxKind[SyntaxKind["ForStatement"] = 155] = "ForStatement"; - SyntaxKind[SyntaxKind["ForInStatement"] = 156] = "ForInStatement"; - SyntaxKind[SyntaxKind["ContinueStatement"] = 157] = "ContinueStatement"; - SyntaxKind[SyntaxKind["BreakStatement"] = 158] = "BreakStatement"; - SyntaxKind[SyntaxKind["ReturnStatement"] = 159] = "ReturnStatement"; - SyntaxKind[SyntaxKind["WithStatement"] = 160] = "WithStatement"; - SyntaxKind[SyntaxKind["SwitchStatement"] = 161] = "SwitchStatement"; - SyntaxKind[SyntaxKind["CaseClause"] = 162] = "CaseClause"; - SyntaxKind[SyntaxKind["DefaultClause"] = 163] = "DefaultClause"; - SyntaxKind[SyntaxKind["LabeledStatement"] = 164] = "LabeledStatement"; - SyntaxKind[SyntaxKind["ThrowStatement"] = 165] = "ThrowStatement"; - SyntaxKind[SyntaxKind["TryStatement"] = 166] = "TryStatement"; - SyntaxKind[SyntaxKind["TryBlock"] = 167] = "TryBlock"; - SyntaxKind[SyntaxKind["CatchBlock"] = 168] = "CatchBlock"; - SyntaxKind[SyntaxKind["FinallyBlock"] = 169] = "FinallyBlock"; - SyntaxKind[SyntaxKind["DebuggerStatement"] = 170] = "DebuggerStatement"; - SyntaxKind[SyntaxKind["VariableDeclaration"] = 171] = "VariableDeclaration"; - SyntaxKind[SyntaxKind["FunctionDeclaration"] = 172] = "FunctionDeclaration"; - SyntaxKind[SyntaxKind["FunctionBlock"] = 173] = "FunctionBlock"; - SyntaxKind[SyntaxKind["ClassDeclaration"] = 174] = "ClassDeclaration"; - SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 175] = "InterfaceDeclaration"; - SyntaxKind[SyntaxKind["EnumDeclaration"] = 176] = "EnumDeclaration"; - SyntaxKind[SyntaxKind["ModuleDeclaration"] = 177] = "ModuleDeclaration"; - SyntaxKind[SyntaxKind["ModuleBlock"] = 178] = "ModuleBlock"; - SyntaxKind[SyntaxKind["ImportDeclaration"] = 179] = "ImportDeclaration"; - SyntaxKind[SyntaxKind["ExportAssignment"] = 180] = "ExportAssignment"; - SyntaxKind[SyntaxKind["EnumMember"] = 181] = "EnumMember"; - SyntaxKind[SyntaxKind["SourceFile"] = 182] = "SourceFile"; - SyntaxKind[SyntaxKind["Program"] = 183] = "Program"; - SyntaxKind[SyntaxKind["SyntaxList"] = 184] = "SyntaxList"; - SyntaxKind[SyntaxKind["Count"] = 185] = "Count"; + SyntaxKind[SyntaxKind["UnionType"] = 132] = "UnionType"; + SyntaxKind[SyntaxKind["ParenType"] = 133] = "ParenType"; + SyntaxKind[SyntaxKind["ArrayLiteral"] = 134] = "ArrayLiteral"; + SyntaxKind[SyntaxKind["ObjectLiteral"] = 135] = "ObjectLiteral"; + SyntaxKind[SyntaxKind["PropertyAssignment"] = 136] = "PropertyAssignment"; + SyntaxKind[SyntaxKind["PropertyAccess"] = 137] = "PropertyAccess"; + SyntaxKind[SyntaxKind["IndexedAccess"] = 138] = "IndexedAccess"; + SyntaxKind[SyntaxKind["CallExpression"] = 139] = "CallExpression"; + SyntaxKind[SyntaxKind["NewExpression"] = 140] = "NewExpression"; + SyntaxKind[SyntaxKind["TypeAssertion"] = 141] = "TypeAssertion"; + SyntaxKind[SyntaxKind["ParenExpression"] = 142] = "ParenExpression"; + SyntaxKind[SyntaxKind["FunctionExpression"] = 143] = "FunctionExpression"; + SyntaxKind[SyntaxKind["ArrowFunction"] = 144] = "ArrowFunction"; + SyntaxKind[SyntaxKind["PrefixOperator"] = 145] = "PrefixOperator"; + SyntaxKind[SyntaxKind["PostfixOperator"] = 146] = "PostfixOperator"; + SyntaxKind[SyntaxKind["BinaryExpression"] = 147] = "BinaryExpression"; + SyntaxKind[SyntaxKind["ConditionalExpression"] = 148] = "ConditionalExpression"; + SyntaxKind[SyntaxKind["OmittedExpression"] = 149] = "OmittedExpression"; + SyntaxKind[SyntaxKind["Block"] = 150] = "Block"; + SyntaxKind[SyntaxKind["VariableStatement"] = 151] = "VariableStatement"; + SyntaxKind[SyntaxKind["EmptyStatement"] = 152] = "EmptyStatement"; + SyntaxKind[SyntaxKind["ExpressionStatement"] = 153] = "ExpressionStatement"; + SyntaxKind[SyntaxKind["IfStatement"] = 154] = "IfStatement"; + SyntaxKind[SyntaxKind["DoStatement"] = 155] = "DoStatement"; + SyntaxKind[SyntaxKind["WhileStatement"] = 156] = "WhileStatement"; + SyntaxKind[SyntaxKind["ForStatement"] = 157] = "ForStatement"; + SyntaxKind[SyntaxKind["ForInStatement"] = 158] = "ForInStatement"; + SyntaxKind[SyntaxKind["ContinueStatement"] = 159] = "ContinueStatement"; + SyntaxKind[SyntaxKind["BreakStatement"] = 160] = "BreakStatement"; + SyntaxKind[SyntaxKind["ReturnStatement"] = 161] = "ReturnStatement"; + SyntaxKind[SyntaxKind["WithStatement"] = 162] = "WithStatement"; + SyntaxKind[SyntaxKind["SwitchStatement"] = 163] = "SwitchStatement"; + SyntaxKind[SyntaxKind["CaseClause"] = 164] = "CaseClause"; + SyntaxKind[SyntaxKind["DefaultClause"] = 165] = "DefaultClause"; + SyntaxKind[SyntaxKind["LabeledStatement"] = 166] = "LabeledStatement"; + SyntaxKind[SyntaxKind["ThrowStatement"] = 167] = "ThrowStatement"; + SyntaxKind[SyntaxKind["TryStatement"] = 168] = "TryStatement"; + SyntaxKind[SyntaxKind["TryBlock"] = 169] = "TryBlock"; + SyntaxKind[SyntaxKind["CatchBlock"] = 170] = "CatchBlock"; + SyntaxKind[SyntaxKind["FinallyBlock"] = 171] = "FinallyBlock"; + SyntaxKind[SyntaxKind["DebuggerStatement"] = 172] = "DebuggerStatement"; + SyntaxKind[SyntaxKind["VariableDeclaration"] = 173] = "VariableDeclaration"; + SyntaxKind[SyntaxKind["FunctionDeclaration"] = 174] = "FunctionDeclaration"; + SyntaxKind[SyntaxKind["FunctionBlock"] = 175] = "FunctionBlock"; + SyntaxKind[SyntaxKind["ClassDeclaration"] = 176] = "ClassDeclaration"; + SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 177] = "InterfaceDeclaration"; + SyntaxKind[SyntaxKind["EnumDeclaration"] = 178] = "EnumDeclaration"; + SyntaxKind[SyntaxKind["ModuleDeclaration"] = 179] = "ModuleDeclaration"; + SyntaxKind[SyntaxKind["ModuleBlock"] = 180] = "ModuleBlock"; + SyntaxKind[SyntaxKind["ImportDeclaration"] = 181] = "ImportDeclaration"; + SyntaxKind[SyntaxKind["ExportAssignment"] = 182] = "ExportAssignment"; + SyntaxKind[SyntaxKind["EnumMember"] = 183] = "EnumMember"; + SyntaxKind[SyntaxKind["SourceFile"] = 184] = "SourceFile"; + SyntaxKind[SyntaxKind["Program"] = 185] = "Program"; + SyntaxKind[SyntaxKind["SyntaxList"] = 186] = "SyntaxList"; + SyntaxKind[SyntaxKind["Count"] = 187] = "Count"; SyntaxKind[SyntaxKind["FirstAssignment"] = SyntaxKind.EqualsToken] = "FirstAssignment"; SyntaxKind[SyntaxKind["LastAssignment"] = SyntaxKind.CaretEqualsToken] = "LastAssignment"; SyntaxKind[SyntaxKind["FirstReservedWord"] = SyntaxKind.BreakKeyword] = "FirstReservedWord"; @@ -1555,11 +1558,13 @@ var ts; SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = SyntaxKind.ImplementsKeyword] = "FirstFutureReservedWord"; SyntaxKind[SyntaxKind["LastFutureReservedWord"] = SyntaxKind.YieldKeyword] = "LastFutureReservedWord"; SyntaxKind[SyntaxKind["FirstTypeNode"] = SyntaxKind.TypeReference] = "FirstTypeNode"; - SyntaxKind[SyntaxKind["LastTypeNode"] = SyntaxKind.TupleType] = "LastTypeNode"; + SyntaxKind[SyntaxKind["LastTypeNode"] = SyntaxKind.ParenType] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = SyntaxKind.OpenBraceToken] = "FirstPunctuation"; SyntaxKind[SyntaxKind["LastPunctuation"] = SyntaxKind.CaretEqualsToken] = "LastPunctuation"; SyntaxKind[SyntaxKind["FirstToken"] = SyntaxKind.EndOfFileToken] = "FirstToken"; SyntaxKind[SyntaxKind["LastToken"] = SyntaxKind.StringKeyword] = "LastToken"; + SyntaxKind[SyntaxKind["FirstTriviaToken"] = SyntaxKind.SingleLineCommentTrivia] = "FirstTriviaToken"; + SyntaxKind[SyntaxKind["LastTriviaToken"] = SyntaxKind.WhitespaceTrivia] = "LastTriviaToken"; })(ts.SyntaxKind || (ts.SyntaxKind = {})); var SyntaxKind = ts.SyntaxKind; (function (NodeFlags) { @@ -1592,8 +1597,18 @@ var ts; TypeFormatFlags[TypeFormatFlags["WriteArrayAsGenericType"] = 0x00000001] = "WriteArrayAsGenericType"; TypeFormatFlags[TypeFormatFlags["UseTypeOfFunction"] = 0x00000002] = "UseTypeOfFunction"; TypeFormatFlags[TypeFormatFlags["NoTruncation"] = 0x00000004] = "NoTruncation"; + TypeFormatFlags[TypeFormatFlags["WriteArrowStyleSignature"] = 0x00000008] = "WriteArrowStyleSignature"; + TypeFormatFlags[TypeFormatFlags["WriteOwnNameForAnyLike"] = 0x00000010] = "WriteOwnNameForAnyLike"; + TypeFormatFlags[TypeFormatFlags["WriteTypeArgumentsOfSignature"] = 0x00000020] = "WriteTypeArgumentsOfSignature"; + TypeFormatFlags[TypeFormatFlags["InElementType"] = 0x00000040] = "InElementType"; })(ts.TypeFormatFlags || (ts.TypeFormatFlags = {})); var TypeFormatFlags = ts.TypeFormatFlags; + (function (SymbolFormatFlags) { + SymbolFormatFlags[SymbolFormatFlags["None"] = 0x00000000] = "None"; + SymbolFormatFlags[SymbolFormatFlags["WriteTypeParametersOrArguments"] = 0x00000001] = "WriteTypeParametersOrArguments"; + SymbolFormatFlags[SymbolFormatFlags["UseOnlyExternalAliasing"] = 0x00000002] = "UseOnlyExternalAliasing"; + })(ts.SymbolFormatFlags || (ts.SymbolFormatFlags = {})); + var SymbolFormatFlags = ts.SymbolFormatFlags; (function (SymbolAccessibility) { SymbolAccessibility[SymbolAccessibility["Accessible"] = 0] = "Accessible"; SymbolAccessibility[SymbolAccessibility["NotAccessible"] = 1] = "NotAccessible"; @@ -1628,6 +1643,7 @@ var ts; SymbolFlags[SymbolFlags["Merged"] = 0x01000000] = "Merged"; SymbolFlags[SymbolFlags["Transient"] = 0x02000000] = "Transient"; SymbolFlags[SymbolFlags["Prototype"] = 0x04000000] = "Prototype"; + SymbolFlags[SymbolFlags["UnionProperty"] = 0x08000000] = "UnionProperty"; SymbolFlags[SymbolFlags["Value"] = SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.EnumMember | SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule | SymbolFlags.Method | SymbolFlags.GetAccessor | SymbolFlags.SetAccessor] = "Value"; SymbolFlags[SymbolFlags["Type"] = SymbolFlags.Class | SymbolFlags.Interface | SymbolFlags.Enum | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral | SymbolFlags.TypeParameter] = "Type"; SymbolFlags[SymbolFlags["Namespace"] = SymbolFlags.ValueModule | SymbolFlags.NamespaceModule] = "Namespace"; @@ -1667,6 +1683,7 @@ var ts; NodeCheckFlags[NodeCheckFlags["SuperInstance"] = 0x00000010] = "SuperInstance"; NodeCheckFlags[NodeCheckFlags["SuperStatic"] = 0x00000020] = "SuperStatic"; NodeCheckFlags[NodeCheckFlags["ContextChecked"] = 0x00000040] = "ContextChecked"; + NodeCheckFlags[NodeCheckFlags["EnumValuesComputed"] = 0x00000080] = "EnumValuesComputed"; })(ts.NodeCheckFlags || (ts.NodeCheckFlags = {})); var NodeCheckFlags = ts.NodeCheckFlags; (function (TypeFlags) { @@ -1684,12 +1701,14 @@ var ts; TypeFlags[TypeFlags["Interface"] = 0x00000800] = "Interface"; TypeFlags[TypeFlags["Reference"] = 0x00001000] = "Reference"; TypeFlags[TypeFlags["Tuple"] = 0x00002000] = "Tuple"; - TypeFlags[TypeFlags["Anonymous"] = 0x00004000] = "Anonymous"; - TypeFlags[TypeFlags["FromSignature"] = 0x00008000] = "FromSignature"; + TypeFlags[TypeFlags["Union"] = 0x00004000] = "Union"; + TypeFlags[TypeFlags["Anonymous"] = 0x00008000] = "Anonymous"; + TypeFlags[TypeFlags["FromSignature"] = 0x00010000] = "FromSignature"; TypeFlags[TypeFlags["Intrinsic"] = TypeFlags.Any | TypeFlags.String | TypeFlags.Number | TypeFlags.Boolean | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null] = "Intrinsic"; TypeFlags[TypeFlags["StringLike"] = TypeFlags.String | TypeFlags.StringLiteral] = "StringLike"; TypeFlags[TypeFlags["NumberLike"] = TypeFlags.Number | TypeFlags.Enum] = "NumberLike"; TypeFlags[TypeFlags["ObjectType"] = TypeFlags.Class | TypeFlags.Interface | TypeFlags.Reference | TypeFlags.Tuple | TypeFlags.Anonymous] = "ObjectType"; + TypeFlags[TypeFlags["Structured"] = TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter] = "Structured"; })(ts.TypeFlags || (ts.TypeFlags = {})); var TypeFlags = ts.TypeFlags; (function (SignatureKind) { @@ -1851,8 +1870,9 @@ var ts; var result; if (array) { for (var i = 0, len = array.length; i < len; i++) { - if (result = callback(array[i])) + if (result = callback(array[i])) { break; + } } } return result; @@ -1880,6 +1900,18 @@ var ts; return -1; } ts.indexOf = indexOf; + function countWhere(array, predicate) { + var count = 0; + if (array) { + for (var i = 0, len = array.length; i < len; i++) { + if (predicate(array[i])) { + count++; + } + } + } + return count; + } + ts.countWhere = countWhere; function filter(array, f) { if (array) { var result = []; @@ -1911,7 +1943,7 @@ var ts; return array1.concat(array2); } ts.concatenate = concatenate; - function uniqueElements(array) { + function deduplicate(array) { if (array) { var result = []; for (var i = 0, len = array.length; i < len; i++) { @@ -1922,7 +1954,7 @@ var ts; } return result; } - ts.uniqueElements = uniqueElements; + ts.deduplicate = deduplicate; function sum(array, prop) { var result = 0; for (var i = 0; i < array.length; i++) { @@ -2020,10 +2052,7 @@ var ts; } ts.localizedDiagnosticMessages = undefined; function getLocaleSpecificMessage(message) { - if (ts.localizedDiagnosticMessages) { - message = ts.localizedDiagnosticMessages[message]; - } - return message; + return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message] ? ts.localizedDiagnosticMessages[message] : message; } ts.getLocaleSpecificMessage = getLocaleSpecificMessage; function createFileDiagnostic(file, start, length, message) { @@ -2244,14 +2273,14 @@ var ts; return getNormalizedPathComponents(pathOrUrl, currentDirectory); } } - function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, isAbsolutePathAnUrl) { + function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, getCanonicalFileName, isAbsolutePathAnUrl) { var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory); var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory); if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") { directoryComponents.length--; } for (var joinStartIndex = 0; joinStartIndex < pathComponents.length && joinStartIndex < directoryComponents.length; joinStartIndex++) { - if (directoryComponents[joinStartIndex] !== pathComponents[joinStartIndex]) { + if (getCanonicalFileName(directoryComponents[joinStartIndex]) !== getCanonicalFileName(pathComponents[joinStartIndex])) { break; } } @@ -2295,6 +2324,37 @@ var ts; return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; } ts.fileExtensionIs = fileExtensionIs; + var supportedExtensions = [".d.ts", ".ts", ".js"]; + function removeFileExtension(path) { + for (var i = 0; i < supportedExtensions.length; i++) { + var ext = supportedExtensions[i]; + if (fileExtensionIs(path, ext)) { + return path.substr(0, path.length - ext.length); + } + } + return path; + } + ts.removeFileExtension = removeFileExtension; + var escapedCharsRegExp = /[\t\v\f\b\0\r\n\"\\\u2028\u2029\u0085]/g; + var escapedCharsMap = { + "\t": "\\t", + "\v": "\\v", + "\f": "\\f", + "\b": "\\b", + "\0": "\\0", + "\r": "\\r", + "\n": "\\n", + "\"": "\\\"", + "\u2028": "\\u2028", + "\u2029": "\\u2029", + "\u0085": "\\u0085" + }; + function escapeString(s) { + return escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, function (c) { + return escapedCharsMap[c] || c; + }) : s; + } + ts.escapeString = escapeString; function Symbol(flags, name) { this.flags = flags; this.name = name; @@ -2383,7 +2443,7 @@ var sys = (function () { return fileStream.ReadText(); } catch (e) { - throw e.number === -2147024809 ? new Error(ts.Diagnostics.Unsupported_file_encoding.key) : e; + throw e; } finally { fileStream.Close(); @@ -2549,7 +2609,7 @@ var sys = (function () { })(); var ts; (function (ts) { - var nodeConstructors = new Array(185 /* Count */); + var nodeConstructors = new Array(187 /* Count */); function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); } @@ -2561,19 +2621,8 @@ var ts; node.flags = flags; return node; } - var moduleExtensions = [".d.ts", ".ts", ".js"]; - function getModuleNameFromFilename(filename) { - for (var i = 0; i < moduleExtensions.length; i++) { - var ext = moduleExtensions[i]; - var len = filename.length - ext.length; - if (len > 0 && filename.substr(len) === ext) - return filename.substr(0, len); - } - return filename; - } - ts.getModuleNameFromFilename = getModuleNameFromFilename; function getSourceFileOfNode(node) { - while (node && node.kind !== 182 /* SourceFile */) + while (node && node.kind !== 184 /* SourceFile */) node = node.parent; return node; } @@ -2592,15 +2641,15 @@ var ts; return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos); } ts.getTokenPosOfNode = getTokenPosOfNode; - function getSourceTextOfNodeFromSourceText(sourceText, node) { + function getTextOfNodeFromSourceText(sourceText, node) { return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end); } - ts.getSourceTextOfNodeFromSourceText = getSourceTextOfNodeFromSourceText; - function getSourceTextOfNode(node) { + ts.getTextOfNodeFromSourceText = getTextOfNodeFromSourceText; + function getTextOfNode(node) { var text = getSourceFileOfNode(node).text; return text.substring(ts.skipTrivia(text, node.pos), node.end); } - ts.getSourceTextOfNode = getSourceTextOfNode; + ts.getTextOfNode = getTextOfNode; function escapeIdentifier(identifier) { return identifier.length >= 2 && identifier.charCodeAt(0) === 95 /* _ */ && identifier.charCodeAt(1) === 95 /* _ */ ? "_" + identifier : identifier; } @@ -2610,7 +2659,7 @@ var ts; } ts.unescapeIdentifier = unescapeIdentifier; function identifierToString(identifier) { - return identifier.kind === 115 /* Missing */ ? "(Missing)" : getSourceTextOfNode(identifier); + return identifier.kind === 115 /* Missing */ ? "(Missing)" : getTextOfNode(identifier); } ts.identifierToString = identifierToString; function createDiagnosticForNode(node, message, arg0, arg1, arg2) { @@ -2632,12 +2681,12 @@ var ts; function getErrorSpanForNode(node) { var errorSpan; switch (node.kind) { - case 171 /* VariableDeclaration */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 177 /* ModuleDeclaration */: - case 176 /* EnumDeclaration */: - case 181 /* EnumMember */: + case 173 /* VariableDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 179 /* ModuleDeclaration */: + case 178 /* EnumDeclaration */: + case 183 /* EnumMember */: errorSpan = node.name; break; } @@ -2648,8 +2697,12 @@ var ts; return file.externalModuleIndicator !== undefined; } ts.isExternalModule = isExternalModule; + function isDeclarationFile(file) { + return (file.flags & 1024 /* DeclarationFile */) !== 0; + } + ts.isDeclarationFile = isDeclarationFile; function isPrologueDirective(node) { - return node.kind === 151 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */; + return node.kind === 153 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */; } ts.isPrologueDirective = isPrologueDirective; function isEvalOrArgumentsIdentifier(node) { @@ -2659,17 +2712,18 @@ var ts; ts.Debug.assert(isPrologueDirective(node)); return node.expression.text === "use strict"; } - function getLeadingCommentsOfNode(node, sourceFileOfNode) { + function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { + sourceFileOfNode = sourceFileOfNode || getSourceFileOfNode(node); if (node.kind === 118 /* Parameter */ || node.kind === 117 /* TypeParameter */) { - return ts.concatenate(ts.getTrailingComments(sourceFileOfNode.text, node.pos), ts.getLeadingComments(sourceFileOfNode.text, node.pos)); + return ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)); } else { - return ts.getLeadingComments(sourceFileOfNode.text, node.pos); + return ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos); } } - ts.getLeadingCommentsOfNode = getLeadingCommentsOfNode; + ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode; function getJsDocComments(node, sourceFileOfNode) { - return ts.filter(getLeadingCommentsOfNode(node, sourceFileOfNode), function (comment) { return isJsDocComment(comment); }); + return ts.filter(getLeadingCommentRangesOfNode(node, sourceFileOfNode), function (comment) { return isJsDocComment(comment); }); function isJsDocComment(comment) { return sourceFileOfNode.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */ && sourceFileOfNode.text.charCodeAt(comment.pos + 2) === 42 /* asterisk */ && sourceFileOfNode.text.charCodeAt(comment.pos + 3) !== 47 /* slash */; } @@ -2703,7 +2757,7 @@ var ts; case 118 /* Parameter */: return child(node.name) || child(node.type) || child(node.initializer); case 119 /* Property */: - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return child(node.name) || child(node.type) || child(node.initializer); case 124 /* CallSignature */: case 125 /* ConstructSignature */: @@ -2713,9 +2767,9 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: return child(node.name) || children(node.typeParameters) || children(node.parameters) || child(node.type) || child(node.body); case 127 /* TypeReference */: return child(node.typeName) || children(node.typeArguments); @@ -2727,84 +2781,88 @@ var ts; return child(node.elementType); case 131 /* TupleType */: return children(node.elementTypes); - case 132 /* ArrayLiteral */: + case 132 /* UnionType */: + return children(node.types); + case 133 /* ParenType */: + return child(node.type); + case 134 /* ArrayLiteral */: return children(node.elements); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return children(node.properties); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return child(node.left) || child(node.right); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return child(node.object) || child(node.index); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return child(node.func) || children(node.typeArguments) || children(node.arguments); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return child(node.type) || child(node.operand); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return child(node.expression); - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: return child(node.operand); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return child(node.left) || child(node.right); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return child(node.condition) || child(node.whenTrue) || child(node.whenFalse); - case 148 /* Block */: - case 167 /* TryBlock */: - case 169 /* FinallyBlock */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 182 /* SourceFile */: + case 150 /* Block */: + case 169 /* TryBlock */: + case 171 /* FinallyBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 184 /* SourceFile */: return children(node.statements); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return children(node.declarations); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return child(node.expression); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return child(node.expression) || child(node.thenStatement) || child(node.elseStatement); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return child(node.statement) || child(node.expression); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return child(node.expression) || child(node.statement); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return children(node.declarations) || child(node.initializer) || child(node.condition) || child(node.iterator) || child(node.statement); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return child(node.declaration) || child(node.variable) || child(node.expression) || child(node.statement); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return child(node.label); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return child(node.expression); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return child(node.expression) || child(node.statement); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return child(node.expression) || children(node.clauses); - case 162 /* CaseClause */: - case 163 /* DefaultClause */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: return child(node.expression) || children(node.statements); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return child(node.label) || child(node.statement); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return child(node.expression); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return child(node.tryBlock) || child(node.catchBlock) || child(node.finallyBlock); - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return child(node.variable) || children(node.statements); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return child(node.name) || child(node.type) || child(node.initializer); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return child(node.name) || children(node.typeParameters) || child(node.baseType) || children(node.implementedTypes) || children(node.members); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return child(node.name) || children(node.typeParameters) || children(node.baseTypes) || children(node.members); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return child(node.name) || children(node.members); - case 181 /* EnumMember */: + case 183 /* EnumMember */: return child(node.name) || child(node.initializer); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return child(node.name) || child(node.body); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return child(node.name) || child(node.entityName) || child(node.externalModuleName); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return child(node.exportName); } } @@ -2813,24 +2871,24 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return visitor(node); - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 160 /* WithStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 163 /* DefaultClause */: - case 164 /* LabeledStatement */: - case 166 /* TryStatement */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: + case 150 /* Block */: + case 175 /* FunctionBlock */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: return forEachChild(node, traverse); } } @@ -2839,9 +2897,9 @@ var ts; function isAnyFunction(node) { if (node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: case 120 /* Method */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: @@ -2868,20 +2926,20 @@ var ts; return undefined; } switch (node.kind) { - case 142 /* ArrowFunction */: + case 144 /* ArrowFunction */: if (!includeArrowFunctions) { continue; } - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 177 /* ModuleDeclaration */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 179 /* ModuleDeclaration */: case 119 /* Property */: case 120 /* Method */: case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 176 /* EnumDeclaration */: - case 182 /* SourceFile */: + case 178 /* EnumDeclaration */: + case 184 /* SourceFile */: return node; } } @@ -2921,19 +2979,19 @@ var ts; switch (node.kind) { case 117 /* TypeParameter */: case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return true; } return false; @@ -2941,24 +2999,24 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 158 /* BreakStatement */: - case 157 /* ContinueStatement */: - case 170 /* DebuggerStatement */: - case 153 /* DoStatement */: - case 151 /* ExpressionStatement */: - case 150 /* EmptyStatement */: - case 156 /* ForInStatement */: - case 155 /* ForStatement */: - case 152 /* IfStatement */: - case 164 /* LabeledStatement */: - case 159 /* ReturnStatement */: - case 161 /* SwitchStatement */: + case 160 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 172 /* DebuggerStatement */: + case 155 /* DoStatement */: + case 153 /* ExpressionStatement */: + case 152 /* EmptyStatement */: + case 158 /* ForInStatement */: + case 157 /* ForStatement */: + case 154 /* IfStatement */: + case 166 /* LabeledStatement */: + case 161 /* ReturnStatement */: + case 163 /* SwitchStatement */: case 88 /* ThrowKeyword */: - case 166 /* TryStatement */: - case 149 /* VariableStatement */: - case 154 /* WhileStatement */: - case 160 /* WithStatement */: - case 180 /* ExportAssignment */: + case 168 /* TryStatement */: + case 151 /* VariableStatement */: + case 156 /* WhileStatement */: + case 162 /* WithStatement */: + case 182 /* ExportAssignment */: return true; default: return false; @@ -2970,10 +3028,10 @@ var ts; return false; } var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 141 /* FunctionExpression */) { + if (isDeclaration(parent) || parent.kind === 143 /* FunctionExpression */) { return parent.name === name; } - if (parent.kind === 168 /* CatchBlock */) { + if (parent.kind === 170 /* CatchBlock */) { return parent.variable === name; } return false; @@ -2981,15 +3039,15 @@ var ts; ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName; function getAncestor(node, kind) { switch (kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: while (node) { switch (node.kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return node; - case 176 /* EnumDeclaration */: - case 175 /* InterfaceDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 178 /* EnumDeclaration */: + case 177 /* InterfaceDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return undefined; default: node = node.parent; @@ -3088,12 +3146,6 @@ var ts; ModifierContext[ModifierContext["ClassMembers"] = 2] = "ClassMembers"; ModifierContext[ModifierContext["Parameters"] = 3] = "Parameters"; })(ModifierContext || (ModifierContext = {})); - var TrailingCommaBehavior; - (function (TrailingCommaBehavior) { - TrailingCommaBehavior[TrailingCommaBehavior["Disallow"] = 0] = "Disallow"; - TrailingCommaBehavior[TrailingCommaBehavior["Allow"] = 1] = "Allow"; - TrailingCommaBehavior[TrailingCommaBehavior["Preserve"] = 2] = "Preserve"; - })(TrailingCommaBehavior || (TrailingCommaBehavior = {})); var ControlBlockContext; (function (ControlBlockContext) { ControlBlockContext[ControlBlockContext["NotNested"] = 0] = "NotNested"; @@ -3104,6 +3156,10 @@ var ts; return ts.SyntaxKind.FirstKeyword <= token && token <= ts.SyntaxKind.LastKeyword; } ts.isKeyword = isKeyword; + function isTrivia(token) { + return ts.SyntaxKind.FirstTriviaToken <= token && token <= ts.SyntaxKind.LastTriviaToken; + } + ts.isTrivia = isTrivia; function isModifier(token) { switch (token) { case 102 /* PublicKeyword */: @@ -3364,7 +3420,9 @@ var ts; return finishNode(node); } error(ts.Diagnostics.Identifier_expected); - return createMissingNode(); + var node = createMissingNode(); + node.text = ""; + return node; } function parseIdentifier() { return createIdentifier(isIdentifier()); @@ -3416,14 +3474,14 @@ var ts; case 14 /* TypeParameters */: return isIdentifier(); case 10 /* ArgumentExpressions */: - return isExpression(); + return token === 18 /* CommaToken */ || isExpression(); case 12 /* ArrayLiteralMembers */: return token === 18 /* CommaToken */ || isExpression(); case 13 /* Parameters */: return isParameter(); case 15 /* TypeArguments */: case 16 /* TupleElementTypes */: - return isType(); + return token === 18 /* CommaToken */ || isType(); } ts.Debug.fail("Non-exhaustive case in 'isListElement'."); } @@ -3516,7 +3574,7 @@ var ts; parsingContext = saveParsingContext; return result; } - function parseDelimitedList(kind, parseElement, trailingCommaBehavior) { + function parseDelimitedList(kind, parseElement, allowTrailingComma) { var saveParsingContext = parsingContext; parsingContext |= 1 << kind; var result = []; @@ -3537,16 +3595,6 @@ var ts; error(ts.Diagnostics._0_expected, ","); } else if (isListTerminator(kind)) { - if (commaStart >= 0) { - if (trailingCommaBehavior === 0 /* Disallow */) { - if (file.syntacticErrors.length === errorCountBeforeParsingList) { - grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, ts.Diagnostics.Trailing_comma_not_allowed); - } - } - else if (trailingCommaBehavior === 2 /* Preserve */) { - result.push(createNode(147 /* OmittedExpression */)); - } - } break; } else { @@ -3557,6 +3605,14 @@ var ts; nextToken(); } } + if (commaStart >= 0) { + if (!allowTrailingComma) { + if (file.syntacticErrors.length === errorCountBeforeParsingList) { + grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, ts.Diagnostics.Trailing_comma_not_allowed); + } + } + result.hasTrailingComma = true; + } result.end = getNodeEnd(); parsingContext = saveParsingContext; return result; @@ -3576,7 +3632,7 @@ var ts; } function parseBracketedList(kind, parseElement, startToken, endToken) { if (parseExpected(startToken)) { - var result = parseDelimitedList(kind, parseElement, 0 /* Disallow */); + var result = parseDelimitedList(kind, parseElement, false); parseExpected(endToken); return result; } @@ -3880,6 +3936,13 @@ var ts; } return finishNode(node); } + function parseParenType() { + var node = createNode(133 /* ParenType */); + parseExpected(11 /* OpenParenToken */); + node.type = parseType(); + parseExpected(12 /* CloseParenToken */); + return finishNode(node); + } function parseFunctionType(signatureKind) { var node = createNode(129 /* TypeLiteral */); var member = createNode(signatureKind); @@ -3911,10 +3974,7 @@ var ts; case 13 /* OpenBracketToken */: return parseTupleType(); case 11 /* OpenParenToken */: - case 19 /* LessThanToken */: - return parseFunctionType(124 /* CallSignature */); - case 82 /* NewKeyword */: - return parseFunctionType(125 /* ConstructSignature */); + return parseParenType(); default: if (isIdentifier()) { return parseTypeReference(); @@ -3939,15 +3999,15 @@ var ts; case 11 /* OpenParenToken */: return lookAhead(function () { nextToken(); - return token === 12 /* CloseParenToken */ || isParameter(); + return token === 12 /* CloseParenToken */ || isParameter() || isType(); }); default: return isIdentifier(); } } - function parseType() { + function parsePrimaryType() { var type = parseNonArrayType(); - while (type && !scanner.hasPrecedingLineBreak() && parseOptional(13 /* OpenBracketToken */)) { + while (!scanner.hasPrecedingLineBreak() && parseOptional(13 /* OpenBracketToken */)) { parseExpected(14 /* CloseBracketToken */); var node = createNode(130 /* ArrayType */, type.pos); node.elementType = type; @@ -3955,6 +4015,51 @@ var ts; } return type; } + function parseUnionType() { + var type = parsePrimaryType(); + if (token === 39 /* BarToken */) { + var types = [type]; + types.pos = type.pos; + while (parseOptional(39 /* BarToken */)) { + types.push(parsePrimaryType()); + } + types.end = getNodeEnd(); + var node = createNode(132 /* UnionType */, type.pos); + node.types = types; + type = finishNode(node); + } + return type; + } + function isFunctionType() { + return token === 19 /* LessThanToken */ || token === 11 /* OpenParenToken */ && lookAhead(function () { + nextToken(); + if (token === 12 /* CloseParenToken */ || token === 16 /* DotDotDotToken */) { + return true; + } + if (isIdentifier() || isModifier(token)) { + nextToken(); + if (token === 46 /* ColonToken */ || token === 18 /* CommaToken */ || token === 45 /* QuestionToken */ || token === 47 /* EqualsToken */ || isIdentifier() || isModifier(token)) { + return true; + } + if (token === 12 /* CloseParenToken */) { + nextToken(); + if (token === 27 /* EqualsGreaterThanToken */) { + return true; + } + } + } + return false; + }); + } + function parseType() { + if (isFunctionType()) { + return parseFunctionType(124 /* CallSignature */); + } + if (token === 82 /* NewKeyword */) { + return parseFunctionType(125 /* ConstructSignature */); + } + return parseUnionType(); + } function parseTypeAnnotation() { return parseOptional(46 /* ColonToken */) ? parseType() : undefined; } @@ -4031,14 +4136,14 @@ var ts; function isLeftHandSideExpression(expr) { if (expr) { switch (expr.kind) { - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 138 /* NewExpression */: - case 137 /* CallExpression */: - case 132 /* ArrayLiteral */: - case 140 /* ParenExpression */: - case 133 /* ObjectLiteral */: - case 141 /* FunctionExpression */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 140 /* NewExpression */: + case 139 /* CallExpression */: + case 134 /* ArrayLiteral */: + case 142 /* ParenExpression */: + case 135 /* ObjectLiteral */: + case 143 /* FunctionExpression */: case 59 /* Identifier */: case 115 /* Missing */: case 8 /* RegularExpressionLiteral */: @@ -4079,7 +4184,7 @@ var ts; return parseArrowExpressionTail(pos, sig, false); } else { - return makeFunctionExpression(142 /* ArrowFunction */, pos, undefined, sig, createMissingNode()); + return makeFunctionExpression(144 /* ArrowFunction */, pos, undefined, sig, createMissingNode()); } } var sig = tryParseSignatureIfArrowOrBraceFollows(); @@ -4153,7 +4258,7 @@ var ts; else { body = parseAssignmentExpression(noIn); } - return makeFunctionExpression(142 /* ArrowFunction */, pos, undefined, sig, body); + return makeFunctionExpression(144 /* ArrowFunction */, pos, undefined, sig, body); } function isAssignmentOperator() { return token >= ts.SyntaxKind.FirstAssignment && token <= ts.SyntaxKind.LastAssignment; @@ -4161,7 +4266,7 @@ var ts; function parseConditionalExpression(noIn) { var expr = parseBinaryExpression(noIn); while (parseOptional(45 /* QuestionToken */)) { - var node = createNode(146 /* ConditionalExpression */, expr.pos); + var node = createNode(148 /* ConditionalExpression */, expr.pos); node.condition = expr; node.whenTrue = parseAssignmentExpression(false); parseExpected(46 /* ColonToken */); @@ -4225,7 +4330,7 @@ var ts; return undefined; } function makeBinaryExpression(left, operator, right) { - var node = createNode(145 /* BinaryExpression */, left.pos); + var node = createNode(147 /* BinaryExpression */, left.pos); node.left = left; node.operator = operator; node.right = right; @@ -4247,14 +4352,14 @@ var ts; nextToken(); var operand = parseUnaryExpression(); if (isInStrictMode) { - if ((token === 33 /* PlusPlusToken */ || token === 34 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(operand)) { + if ((operator === 33 /* PlusPlusToken */ || operator === 34 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(operand)) { reportInvalidUseInStrictMode(operand); } - else if (token === 68 /* DeleteKeyword */ && operand.kind === 59 /* Identifier */) { + else if (operator === 68 /* DeleteKeyword */ && operand.kind === 59 /* Identifier */) { grammarErrorOnNode(operand, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); } } - return makeUnaryExpression(143 /* PrefixOperator */, pos, operator, operand); + return makeUnaryExpression(145 /* PrefixOperator */, pos, operator, operand); case 19 /* LessThanToken */: return parseTypeAssertion(); } @@ -4271,12 +4376,12 @@ var ts; } var operator = token; nextToken(); - expr = makeUnaryExpression(144 /* PostfixOperator */, expr.pos, operator, expr); + expr = makeUnaryExpression(146 /* PostfixOperator */, expr.pos, operator, expr); } return expr; } function parseTypeAssertion() { - var node = createNode(139 /* TypeAssertion */); + var node = createNode(141 /* TypeAssertion */); parseExpected(19 /* LessThanToken */); node.type = parseType(); parseExpected(20 /* GreaterThanToken */); @@ -4293,7 +4398,7 @@ var ts; while (true) { var dotStart = scanner.getTokenPos(); if (parseOptional(15 /* DotToken */)) { - var propertyAccess = createNode(135 /* PropertyAccess */, expr.pos); + var propertyAccess = createNode(137 /* PropertyAccess */, expr.pos); if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord() && lookAhead(function () { return scanner.isReservedWord(); })) { grammarErrorAtPos(dotStart, scanner.getStartPos() - dotStart, ts.Diagnostics.Identifier_expected); var id = createMissingNode(); @@ -4308,7 +4413,7 @@ var ts; } var bracketStart = scanner.getTokenPos(); if (parseOptional(13 /* OpenBracketToken */)) { - var indexedAccess = createNode(136 /* IndexedAccess */, expr.pos); + var indexedAccess = createNode(138 /* IndexedAccess */, expr.pos); indexedAccess.object = expr; if (inNewExpression && parseOptional(14 /* CloseBracketToken */)) { indexedAccess.index = createMissingNode(); @@ -4326,7 +4431,7 @@ var ts; continue; } if ((token === 11 /* OpenParenToken */ || token === 19 /* LessThanToken */) && !inNewExpression) { - var callExpr = createNode(137 /* CallExpression */, expr.pos); + var callExpr = createNode(139 /* CallExpression */, expr.pos); callExpr.func = expr; if (token === 19 /* LessThanToken */) { if (!(callExpr.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) @@ -4335,7 +4440,7 @@ var ts; else { parseExpected(11 /* OpenParenToken */); } - callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseAssignmentExpression, 0 /* Disallow */); + callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false); parseExpected(12 /* CloseParenToken */); expr = finishNode(callExpr); continue; @@ -4351,12 +4456,21 @@ var ts; function parseTypeArguments() { var typeArgumentListStart = scanner.getTokenPos(); var errorCountBeforeTypeParameterList = file.syntacticErrors.length; - var result = parseBracketedList(15 /* TypeArguments */, parseType, 19 /* LessThanToken */, 20 /* GreaterThanToken */); + var result = parseBracketedList(15 /* TypeArguments */, parseSingleTypeArgument, 19 /* LessThanToken */, 20 /* GreaterThanToken */); if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) { grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, ts.Diagnostics.Type_argument_list_cannot_be_empty); } return result; } + function parseSingleTypeArgument() { + if (token === 18 /* CommaToken */) { + var errorStart = scanner.getTokenPos(); + var errorLength = scanner.getTextPos() - errorStart; + grammarErrorAtPos(errorStart, errorLength, ts.Diagnostics.Type_expected); + return createNode(115 /* Missing */); + } + return parseType(); + } function parsePrimaryExpression() { switch (token) { case 87 /* ThisKeyword */: @@ -4393,31 +4507,45 @@ var ts; return createMissingNode(); } function parseParenExpression() { - var node = createNode(140 /* ParenExpression */); + var node = createNode(142 /* ParenExpression */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); parseExpected(12 /* CloseParenToken */); return finishNode(node); } + function parseAssignmentExpressionOrOmittedExpression(omittedExpressionDiagnostic) { + if (token === 18 /* CommaToken */) { + if (omittedExpressionDiagnostic) { + var errorStart = scanner.getTokenPos(); + var errorLength = scanner.getTextPos() - errorStart; + grammarErrorAtPos(errorStart, errorLength, omittedExpressionDiagnostic); + } + return createNode(149 /* OmittedExpression */); + } + return parseAssignmentExpression(); + } function parseArrayLiteralElement() { - return token === 18 /* CommaToken */ ? createNode(147 /* OmittedExpression */) : parseAssignmentExpression(); + return parseAssignmentExpressionOrOmittedExpression(undefined); + } + function parseArgumentExpression() { + return parseAssignmentExpressionOrOmittedExpression(ts.Diagnostics.Argument_expression_expected); } function parseArrayLiteral() { - var node = createNode(132 /* ArrayLiteral */); + var node = createNode(134 /* ArrayLiteral */); parseExpected(13 /* OpenBracketToken */); if (scanner.hasPrecedingLineBreak()) node.flags |= 256 /* MultiLine */; - node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement, 2 /* Preserve */); + node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement, true); parseExpected(14 /* CloseBracketToken */); return finishNode(node); } function parsePropertyAssignment() { - var node = createNode(134 /* PropertyAssignment */); + var node = createNode(136 /* PropertyAssignment */); node.name = parsePropertyName(); if (token === 11 /* OpenParenToken */ || token === 19 /* LessThanToken */) { var sig = parseSignature(124 /* CallSignature */, 46 /* ColonToken */, false); var body = parseBody(false); - node.initializer = makeFunctionExpression(141 /* FunctionExpression */, node.pos, undefined, sig, body); + node.initializer = makeFunctionExpression(143 /* FunctionExpression */, node.pos, undefined, sig, body); } else { parseExpected(46 /* ColonToken */); @@ -4435,13 +4563,12 @@ var ts; return parsePropertyAssignment(); } function parseObjectLiteral() { - var node = createNode(133 /* ObjectLiteral */); + var node = createNode(135 /* ObjectLiteral */); parseExpected(9 /* OpenBraceToken */); if (scanner.hasPrecedingLineBreak()) { node.flags |= 256 /* MultiLine */; } - var trailingCommaBehavior = languageVersion === 0 /* ES3 */ ? 1 /* Allow */ : 2 /* Preserve */; - node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember, trailingCommaBehavior); + node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember, true); parseExpected(10 /* CloseBraceToken */); var seen = {}; var Property = 1; @@ -4449,11 +4576,11 @@ var ts; var SetAccesor = 4; var GetOrSetAccessor = GetAccessor | SetAccesor; ts.forEach(node.properties, function (p) { - if (p.kind === 147 /* OmittedExpression */) { + if (p.kind === 149 /* OmittedExpression */) { return; } var currentKind; - if (p.kind === 134 /* PropertyAssignment */) { + if (p.kind === 136 /* PropertyAssignment */) { currentKind = Property; } else if (p.kind === 122 /* GetAccessor */) { @@ -4499,7 +4626,7 @@ var ts; if (name && isInStrictMode && isEvalOrArgumentsIdentifier(name)) { reportInvalidUseInStrictMode(name); } - return makeFunctionExpression(141 /* FunctionExpression */, pos, name, sig, body); + return makeFunctionExpression(143 /* FunctionExpression */, pos, name, sig, body); } function makeFunctionExpression(kind, pos, name, sig, body) { var node = createNode(kind, pos); @@ -4511,17 +4638,17 @@ var ts; return finishNode(node); } function parseNewExpression() { - var node = createNode(138 /* NewExpression */); + var node = createNode(140 /* NewExpression */); parseExpected(82 /* NewKeyword */); node.func = parseCallAndAccess(parsePrimaryExpression(), true); if (parseOptional(11 /* OpenParenToken */) || token === 19 /* LessThanToken */ && (node.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) { - node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseAssignmentExpression, 0 /* Disallow */); + node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false); parseExpected(12 /* CloseParenToken */); } return finishNode(node); } function parseBlock(ignoreMissingOpenBrace, checkForStrictMode) { - var node = createNode(148 /* Block */); + var node = createNode(150 /* Block */); if (parseExpected(9 /* OpenBraceToken */) || ignoreMissingOpenBrace) { node.statements = parseList(2 /* BlockStatements */, checkForStrictMode, parseStatement); parseExpected(10 /* CloseBraceToken */); @@ -4544,7 +4671,7 @@ var ts; } labelledStatementInfo.pushFunctionBoundary(); var block = parseBlock(ignoreMissingOpenBrace, true); - block.kind = 173 /* FunctionBlock */; + block.kind = 175 /* FunctionBlock */; labelledStatementInfo.pop(); inFunctionBody = saveInFunctionBody; inSwitchStatement = saveInSwitchStatement; @@ -4552,12 +4679,12 @@ var ts; return block; } function parseEmptyStatement() { - var node = createNode(150 /* EmptyStatement */); + var node = createNode(152 /* EmptyStatement */); parseExpected(17 /* SemicolonToken */); return finishNode(node); } function parseIfStatement() { - var node = createNode(152 /* IfStatement */); + var node = createNode(154 /* IfStatement */); parseExpected(78 /* IfKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4567,7 +4694,7 @@ var ts; return finishNode(node); } function parseDoStatement() { - var node = createNode(153 /* DoStatement */); + var node = createNode(155 /* DoStatement */); parseExpected(69 /* DoKeyword */); var saveInIterationStatement = inIterationStatement; inIterationStatement = 1 /* Nested */; @@ -4581,7 +4708,7 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(154 /* WhileStatement */); + var node = createNode(156 /* WhileStatement */); parseExpected(94 /* WhileKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4609,7 +4736,7 @@ var ts; } var forOrForInStatement; if (parseOptional(80 /* InKeyword */)) { - var forInStatement = createNode(156 /* ForInStatement */, pos); + var forInStatement = createNode(158 /* ForInStatement */, pos); if (declarations) { if (declarations.length > 1) { error(ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); @@ -4624,7 +4751,7 @@ var ts; forOrForInStatement = forInStatement; } else { - var forStatement = createNode(155 /* ForStatement */, pos); + var forStatement = createNode(157 /* ForStatement */, pos); if (declarations) forStatement.declarations = declarations; if (varOrInit) @@ -4649,7 +4776,7 @@ var ts; function parseBreakOrContinueStatement(kind) { var node = createNode(kind); var errorCountBeforeStatement = file.syntacticErrors.length; - parseExpected(kind === 158 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */); + parseExpected(kind === 160 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */); if (!canParseSemicolon()) node.label = parseIdentifier(); parseSemicolon(); @@ -4665,7 +4792,7 @@ var ts; return node; } function checkBareBreakOrContinueStatement(node) { - if (node.kind === 158 /* BreakStatement */) { + if (node.kind === 160 /* BreakStatement */) { if (inIterationStatement === 1 /* Nested */ || inSwitchStatement === 1 /* Nested */) { return; } @@ -4674,7 +4801,7 @@ var ts; return; } } - else if (node.kind === 157 /* ContinueStatement */) { + else if (node.kind === 159 /* ContinueStatement */) { if (inIterationStatement === 1 /* Nested */) { return; } @@ -4690,7 +4817,7 @@ var ts; grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } function checkBreakOrContinueStatementWithLabel(node) { - var nodeIsNestedInLabel = labelledStatementInfo.nodeIsNestedInLabel(node.label, node.kind === 157 /* ContinueStatement */, false); + var nodeIsNestedInLabel = labelledStatementInfo.nodeIsNestedInLabel(node.label, node.kind === 159 /* ContinueStatement */, false); if (nodeIsNestedInLabel === 1 /* Nested */) { return; } @@ -4698,10 +4825,10 @@ var ts; grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); return; } - if (node.kind === 157 /* ContinueStatement */) { + if (node.kind === 159 /* ContinueStatement */) { grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); } - else if (node.kind === 158 /* BreakStatement */) { + else if (node.kind === 160 /* BreakStatement */) { grammarErrorOnNode(node, ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement); } else { @@ -4709,7 +4836,7 @@ var ts; } } function parseReturnStatement() { - var node = createNode(159 /* ReturnStatement */); + var node = createNode(161 /* ReturnStatement */); var errorCountBeforeReturnStatement = file.syntacticErrors.length; var returnTokenStart = scanner.getTokenPos(); var returnTokenLength = scanner.getTextPos() - returnTokenStart; @@ -4723,7 +4850,7 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(160 /* WithStatement */); + var node = createNode(162 /* WithStatement */); var startPos = scanner.getTokenPos(); parseExpected(95 /* WithKeyword */); var endPos = scanner.getStartPos(); @@ -4738,7 +4865,7 @@ var ts; return node; } function parseCaseClause() { - var node = createNode(162 /* CaseClause */); + var node = createNode(164 /* CaseClause */); parseExpected(61 /* CaseKeyword */); node.expression = parseExpression(); parseExpected(46 /* ColonToken */); @@ -4746,7 +4873,7 @@ var ts; return finishNode(node); } function parseDefaultClause() { - var node = createNode(163 /* DefaultClause */); + var node = createNode(165 /* DefaultClause */); parseExpected(67 /* DefaultKeyword */); parseExpected(46 /* ColonToken */); node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatement); @@ -4756,7 +4883,7 @@ var ts; return token === 61 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(161 /* SwitchStatement */); + var node = createNode(163 /* SwitchStatement */); parseExpected(86 /* SwitchKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4767,7 +4894,7 @@ var ts; node.clauses = parseList(3 /* SwitchClauses */, false, parseCaseOrDefaultClause); inSwitchStatement = saveInSwitchStatement; parseExpected(10 /* CloseBraceToken */); - var defaultClauses = ts.filter(node.clauses, function (clause) { return clause.kind === 163 /* DefaultClause */; }); + var defaultClauses = ts.filter(node.clauses, function (clause) { return clause.kind === 165 /* DefaultClause */; }); for (var i = 1, n = defaultClauses.length; i < n; i++) { var clause = defaultClauses[i]; var start = ts.skipTrivia(file.text, clause.pos); @@ -4777,7 +4904,7 @@ var ts; return finishNode(node); } function parseThrowStatement() { - var node = createNode(165 /* ThrowStatement */); + var node = createNode(167 /* ThrowStatement */); parseExpected(88 /* ThrowKeyword */); if (scanner.hasPrecedingLineBreak()) { error(ts.Diagnostics.Line_break_not_permitted_here); @@ -4787,13 +4914,13 @@ var ts; return finishNode(node); } function parseTryStatement() { - var node = createNode(166 /* TryStatement */); - node.tryBlock = parseTokenAndBlock(90 /* TryKeyword */, 167 /* TryBlock */); + var node = createNode(168 /* TryStatement */); + node.tryBlock = parseTokenAndBlock(90 /* TryKeyword */, 169 /* TryBlock */); if (token === 62 /* CatchKeyword */) { node.catchBlock = parseCatchBlock(); } if (token === 75 /* FinallyKeyword */) { - node.finallyBlock = parseTokenAndBlock(75 /* FinallyKeyword */, 169 /* FinallyBlock */); + node.finallyBlock = parseTokenAndBlock(75 /* FinallyKeyword */, 171 /* FinallyBlock */); } if (!(node.catchBlock || node.finallyBlock)) { error(ts.Diagnostics.catch_or_finally_expected); @@ -4818,7 +4945,7 @@ var ts; var typeAnnotation = parseTypeAnnotation(); parseExpected(12 /* CloseParenToken */); var result = parseBlock(false, false); - result.kind = 168 /* CatchBlock */; + result.kind = 170 /* CatchBlock */; result.pos = pos; result.variable = variable; if (typeAnnotation) { @@ -4830,7 +4957,7 @@ var ts; return result; } function parseDebuggerStatement() { - var node = createNode(170 /* DebuggerStatement */); + var node = createNode(172 /* DebuggerStatement */); parseExpected(66 /* DebuggerKeyword */); parseSemicolon(); return finishNode(node); @@ -4848,18 +4975,18 @@ var ts; return isIdentifier() && lookAhead(function () { return nextToken() === 46 /* ColonToken */; }); } function parseLabelledStatement() { - var node = createNode(164 /* LabeledStatement */); + var node = createNode(166 /* LabeledStatement */); node.label = parseIdentifier(); parseExpected(46 /* ColonToken */); if (labelledStatementInfo.nodeIsNestedInLabel(node.label, false, true)) { - grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getSourceTextOfNodeFromSourceText(sourceText, node.label)); + grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceText, node.label)); } labelledStatementInfo.addLabel(node.label); node.statement = isLabel() ? parseLabelledStatement() : parseStatementWithLabelSet(); return finishNode(node); } function parseExpressionStatement() { - var node = createNode(151 /* ExpressionStatement */); + var node = createNode(153 /* ExpressionStatement */); node.expression = parseExpression(); parseSemicolon(); return finishNode(node); @@ -4923,9 +5050,9 @@ var ts; case 76 /* ForKeyword */: return parseForOrForInStatement(); case 65 /* ContinueKeyword */: - return parseBreakOrContinueStatement(157 /* ContinueStatement */); + return parseBreakOrContinueStatement(159 /* ContinueStatement */); case 60 /* BreakKeyword */: - return parseBreakOrContinueStatement(158 /* BreakStatement */); + return parseBreakOrContinueStatement(160 /* BreakStatement */); case 84 /* ReturnKeyword */: return parseReturnStatement(); case 95 /* WithKeyword */: @@ -4968,7 +5095,7 @@ var ts; error(ts.Diagnostics.Block_or_expected); } function parseVariableDeclaration(flags, noIn) { - var node = createNode(171 /* VariableDeclaration */); + var node = createNode(173 /* VariableDeclaration */); node.flags = flags; var errorCountBeforeVariableDeclaration = file.syntacticErrors.length; node.name = parseIdentifier(); @@ -4985,10 +5112,10 @@ var ts; return finishNode(node); } function parseVariableDeclarationList(flags, noIn) { - return parseDelimitedList(9 /* VariableDeclarations */, function () { return parseVariableDeclaration(flags, noIn); }, 0 /* Disallow */); + return parseDelimitedList(9 /* VariableDeclarations */, function () { return parseVariableDeclaration(flags, noIn); }, false); } function parseVariableStatement(pos, flags) { - var node = createNode(149 /* VariableStatement */, pos); + var node = createNode(151 /* VariableStatement */, pos); if (flags) node.flags = flags; var errorCountBeforeVarStatement = file.syntacticErrors.length; @@ -5002,7 +5129,7 @@ var ts; return node; } function parseFunctionDeclaration(pos, flags) { - var node = createNode(172 /* FunctionDeclaration */, pos); + var node = createNode(174 /* FunctionDeclaration */, pos); if (flags) node.flags = flags; parseExpected(77 /* FunctionKeyword */); @@ -5313,7 +5440,7 @@ var ts; ts.Debug.fail("Should not have attempted to parse class member declaration."); } function parseClassDeclaration(pos, flags) { - var node = createNode(174 /* ClassDeclaration */, pos); + var node = createNode(176 /* ClassDeclaration */, pos); node.flags = flags; var errorCountBeforeClassDeclaration = file.syntacticErrors.length; parseExpected(63 /* ClassKeyword */); @@ -5324,7 +5451,7 @@ var ts; var implementsKeywordLength; if (parseOptional(96 /* ImplementsKeyword */)) { implementsKeywordLength = scanner.getStartPos() - implementsKeywordStart; - node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, 0 /* Disallow */); + node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false); } var errorCountBeforeClassBody = file.syntacticErrors.length; if (parseExpected(9 /* OpenBraceToken */)) { @@ -5340,7 +5467,7 @@ var ts; return finishNode(node); } function parseInterfaceDeclaration(pos, flags) { - var node = createNode(175 /* InterfaceDeclaration */, pos); + var node = createNode(177 /* InterfaceDeclaration */, pos); node.flags = flags; var errorCountBeforeInterfaceDeclaration = file.syntacticErrors.length; parseExpected(97 /* InterfaceKeyword */); @@ -5350,7 +5477,7 @@ var ts; var extendsKeywordLength; if (parseOptional(73 /* ExtendsKeyword */)) { extendsKeywordLength = scanner.getStartPos() - extendsKeywordStart; - node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, 0 /* Disallow */); + node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false); } var errorCountBeforeInterfaceBody = file.syntacticErrors.length; node.members = parseTypeLiteral().members; @@ -5364,7 +5491,7 @@ var ts; function isInteger(literalExpression) { return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text); } - if (expression.kind === 143 /* PrefixOperator */) { + if (expression.kind === 145 /* PrefixOperator */) { var unaryExpression = expression; if (unaryExpression.operator === 28 /* PlusToken */ || unaryExpression.operator === 29 /* MinusToken */) { expression = unaryExpression.operand; @@ -5377,7 +5504,7 @@ var ts; } var inConstantEnumMemberSection = true; function parseAndCheckEnumMember() { - var node = createNode(181 /* EnumMember */); + var node = createNode(183 /* EnumMember */); var errorCountBeforeEnumMember = file.syntacticErrors.length; node.name = parsePropertyName(); node.initializer = parseInitializer(false); @@ -5394,12 +5521,12 @@ var ts; } return finishNode(node); } - var node = createNode(176 /* EnumDeclaration */, pos); + var node = createNode(178 /* EnumDeclaration */, pos); node.flags = flags; parseExpected(71 /* EnumKeyword */); node.name = parseIdentifier(); if (parseExpected(9 /* OpenBraceToken */)) { - node.members = parseDelimitedList(7 /* EnumMembers */, parseAndCheckEnumMember, 1 /* Allow */); + node.members = parseDelimitedList(7 /* EnumMembers */, parseAndCheckEnumMember, true); parseExpected(10 /* CloseBraceToken */); } else { @@ -5408,7 +5535,7 @@ var ts; return finishNode(node); } function parseModuleBody() { - var node = createNode(178 /* ModuleBlock */); + var node = createNode(180 /* ModuleBlock */); if (parseExpected(9 /* OpenBraceToken */)) { node.statements = parseList(1 /* ModuleElements */, false, parseModuleElement); parseExpected(10 /* CloseBraceToken */); @@ -5419,7 +5546,7 @@ var ts; return finishNode(node); } function parseInternalModuleTail(pos, flags) { - var node = createNode(177 /* ModuleDeclaration */, pos); + var node = createNode(179 /* ModuleDeclaration */, pos); node.flags = flags; node.name = parseIdentifier(); if (parseOptional(15 /* DotToken */)) { @@ -5428,10 +5555,10 @@ var ts; else { node.body = parseModuleBody(); ts.forEach(node.body.statements, function (s) { - if (s.kind === 180 /* ExportAssignment */) { + if (s.kind === 182 /* ExportAssignment */) { grammarErrorOnNode(s, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); } - else if (s.kind === 179 /* ImportDeclaration */ && s.externalModuleName) { + else if (s.kind === 181 /* ImportDeclaration */ && s.externalModuleName) { grammarErrorOnNode(s, ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); } }); @@ -5439,7 +5566,7 @@ var ts; return finishNode(node); } function parseAmbientExternalModuleDeclaration(pos, flags) { - var node = createNode(177 /* ModuleDeclaration */, pos); + var node = createNode(179 /* ModuleDeclaration */, pos); node.flags = flags; node.name = parseStringLiteral(); if (!inAmbientContext) { @@ -5459,7 +5586,7 @@ var ts; return token === 7 /* StringLiteral */ ? parseAmbientExternalModuleDeclaration(pos, flags) : parseInternalModuleTail(pos, flags); } function parseImportDeclaration(pos, flags) { - var node = createNode(179 /* ImportDeclaration */, pos); + var node = createNode(181 /* ImportDeclaration */, pos); node.flags = flags; parseExpected(79 /* ImportKeyword */); node.name = parseIdentifier(); @@ -5476,7 +5603,7 @@ var ts; return finishNode(node); } function parseExportAssignmentTail(pos) { - var node = createNode(180 /* ExportAssignment */, pos); + var node = createNode(182 /* ExportAssignment */, pos); node.exportName = parseIdentifier(); parseSemicolon(); return finishNode(node); @@ -5593,15 +5720,16 @@ var ts; } else { var matchResult = ts.fullTripleSlashReferencePathRegEx.exec(comment); + var start = range.pos; + var end = range.end; + var length = end - start; if (!matchResult) { - var start = range.pos; - var length = range.end - start; errorAtPos(start, length, ts.Diagnostics.Invalid_reference_directive_syntax); } else { referencedFiles.push({ - pos: range.pos, - end: range.end, + pos: start, + end: end, filename: matchResult[3] }); } @@ -5622,7 +5750,7 @@ var ts; }; } function getExternalModuleIndicator() { - return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 179 /* ImportDeclaration */ && node.externalModuleName || node.kind === 180 /* ExportAssignment */ ? node : undefined; }); + return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 181 /* ImportDeclaration */ && node.externalModuleName || node.kind === 182 /* ExportAssignment */ ? node : undefined; }); } scanner = ts.createScanner(languageVersion, true, sourceText, scanError, onComment); var rootNodeFlags = 0; @@ -5630,7 +5758,7 @@ var ts; rootNodeFlags = 1024 /* DeclarationFile */; inAmbientContext = true; } - file = createRootNode(182 /* SourceFile */, 0, sourceText.length, rootNodeFlags); + file = createRootNode(184 /* SourceFile */, 0, sourceText.length, rootNodeFlags); file.filename = ts.normalizePath(filename); file.text = sourceText; file.getLineAndCharacterFromPosition = getLineAndCharacterlFromSourcePosition; @@ -5704,6 +5832,9 @@ var ts; else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) { diagnostic = ts.Diagnostics.File_0_not_found; } + else if (refFile && host.getCanonicalFileName(filename) === host.getCanonicalFileName(refFile.filename)) { + diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself; + } } else { if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) { @@ -5754,12 +5885,13 @@ var ts; } function processReferencedFiles(file, basePath) { ts.forEach(file.referencedFiles, function (ref) { - processSourceFile(ts.normalizePath(ts.combinePaths(basePath, ref.filename)), false, file, ref.pos, ref.end); + var referencedFilename = ts.isRootedDiskPath(ref.filename) ? ref.filename : ts.combinePaths(basePath, ref.filename); + processSourceFile(ts.normalizePath(referencedFilename), false, file, ref.pos, ref.end); }); } function processImportedModules(file, basePath) { ts.forEach(file.statements, function (node) { - if (node.kind === 179 /* ImportDeclaration */ && node.externalModuleName) { + if (node.kind === 181 /* ImportDeclaration */ && node.externalModuleName) { var nameLiteral = node.externalModuleName; var moduleName = nameLiteral.text; if (moduleName) { @@ -5777,9 +5909,9 @@ var ts; } } } - else if (node.kind === 177 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || file.flags & 1024 /* DeclarationFile */)) { + else if (node.kind === 179 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || isDeclarationFile(file))) { forEachChild(node.body, function (node) { - if (node.kind === 179 /* ImportDeclaration */ && node.externalModuleName) { + if (node.kind === 181 /* ImportDeclaration */ && node.externalModuleName) { var nameLiteral = node.externalModuleName; var moduleName = nameLiteral.text; if (moduleName) { @@ -5852,16 +5984,16 @@ var ts; var ts; (function (ts) { function isInstantiated(node) { - if (node.kind === 175 /* InterfaceDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */) { return false; } - else if (node.kind === 179 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) { + else if (node.kind === 181 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) { return false; } - else if (node.kind === 178 /* ModuleBlock */ && !ts.forEachChild(node, isInstantiated)) { + else if (node.kind === 180 /* ModuleBlock */ && !ts.forEachChild(node, isInstantiated)) { return false; } - else if (node.kind === 177 /* ModuleDeclaration */ && !isInstantiated(node.body)) { + else if (node.kind === 179 /* ModuleDeclaration */ && !isInstantiated(node.body)) { return false; } else { @@ -5900,7 +6032,7 @@ var ts; } function getDeclarationName(node) { if (node.name) { - if (node.kind === 177 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) { + if (node.kind === 179 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) { return '"' + node.name.text + '"'; } return node.name.text; @@ -5927,7 +6059,10 @@ var ts; if (node.name) { node.name.parent = node; } - file.semanticErrors.push(ts.createDiagnosticForNode(node.name ? node.name : node, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(node))); + ts.forEach(symbol.declarations, function (declaration) { + file.semanticErrors.push(ts.createDiagnosticForNode(declaration.name, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(declaration))); + }); + file.semanticErrors.push(ts.createDiagnosticForNode(node.name, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(node))); symbol = createSymbol(0, name); } } @@ -5936,7 +6071,7 @@ var ts; } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; - if (node.kind === 174 /* ClassDeclaration */ && symbol.exports) { + if (node.kind === 176 /* ClassDeclaration */ && symbol.exports) { var prototypeSymbol = createSymbol(2 /* Property */ | 67108864 /* Prototype */, "prototype"); if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { if (node.name) { @@ -5968,7 +6103,7 @@ var ts; if (symbolKind & ts.SymbolFlags.Namespace) { exportKind |= 2097152 /* ExportNamespace */; } - if (node.flags & 1 /* Export */ || (node.kind !== 179 /* ImportDeclaration */ && isAmbientContext(container))) { + if (node.flags & 1 /* Export */ || (node.kind !== 181 /* ImportDeclaration */ && isAmbientContext(container))) { if (exportKind) { var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); @@ -6004,10 +6139,10 @@ var ts; } function bindDeclaration(node, symbolKind, symbolExcludes) { switch (container.kind) { - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: declareModuleMember(node, symbolKind, symbolExcludes); break; - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolKind, symbolExcludes); break; @@ -6019,22 +6154,22 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); break; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: if (node.flags & 128 /* Static */) { declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } case 129 /* TypeLiteral */: - case 133 /* ObjectLiteral */: - case 175 /* InterfaceDeclaration */: + case 135 /* ObjectLiteral */: + case 177 /* InterfaceDeclaration */: declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } @@ -6081,14 +6216,14 @@ var ts; case 118 /* Parameter */: bindDeclaration(node, 1 /* Variable */, ts.SymbolFlags.ParameterExcludes); break; - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: bindDeclaration(node, 1 /* Variable */, ts.SymbolFlags.VariableExcludes); break; case 119 /* Property */: - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: bindDeclaration(node, 2 /* Property */, ts.SymbolFlags.PropertyExcludes); break; - case 181 /* EnumMember */: + case 183 /* EnumMember */: bindDeclaration(node, 4 /* EnumMember */, ts.SymbolFlags.EnumMemberExcludes); break; case 124 /* CallSignature */: @@ -6103,7 +6238,7 @@ var ts; case 126 /* IndexSignature */: bindDeclaration(node, 131072 /* IndexSignature */, 0); break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: bindDeclaration(node, 8 /* Function */, ts.SymbolFlags.FunctionExcludes); break; case 121 /* Constructor */: @@ -6118,34 +6253,34 @@ var ts; case 129 /* TypeLiteral */: bindAnonymousDeclaration(node, 512 /* TypeLiteral */, "__type"); break; - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: bindAnonymousDeclaration(node, 1024 /* ObjectLiteral */, "__object"); break; - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: bindAnonymousDeclaration(node, 8 /* Function */, "__function"); break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: bindCatchVariableDeclaration(node); break; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: bindDeclaration(node, 16 /* Class */, ts.SymbolFlags.ClassExcludes); break; - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: bindDeclaration(node, 32 /* Interface */, ts.SymbolFlags.InterfaceExcludes); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: bindDeclaration(node, 64 /* Enum */, ts.SymbolFlags.EnumExcludes); break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: bindModuleDeclaration(node); break; - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: bindDeclaration(node, 4194304 /* Import */, ts.SymbolFlags.ImportExcludes); break; - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (ts.isExternalModule(node)) { - bindAnonymousDeclaration(node, 128 /* ValueModule */, '"' + ts.getModuleNameFromFilename(node.filename) + '"'); + bindAnonymousDeclaration(node, 128 /* ValueModule */, '"' + ts.removeFileExtension(node.filename) + '"'); break; } default: @@ -6167,11 +6302,12 @@ var ts; } return indentStrings[level]; } + ts.getIndentString = getIndentString; function getIndentSize() { return indentStrings[1].length; } function shouldEmitToOwnFile(sourceFile, compilerOptions) { - if (!(sourceFile.flags & 1024 /* DeclarationFile */)) { + if (!ts.isDeclarationFile(sourceFile)) { if ((ts.isExternalModule(sourceFile) || !compilerOptions.out) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { return true; } @@ -6181,7 +6317,7 @@ var ts; } ts.shouldEmitToOwnFile = shouldEmitToOwnFile; function isExternalModuleOrDeclarationFile(sourceFile) { - return ts.isExternalModule(sourceFile) || (sourceFile.flags & 1024 /* DeclarationFile */) !== 0; + return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); } ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; function emitFiles(resolver, targetSourceFile) { @@ -6198,10 +6334,10 @@ var ts; } function getOwnEmitOutputFilePath(sourceFile, extension) { if (compilerOptions.outDir) { - var emitOutputFilePathWithoutExtension = ts.getModuleNameFromFilename(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile)); + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile)); } else { - var emitOutputFilePathWithoutExtension = ts.getModuleNameFromFilename(sourceFile.filename); + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename); } return emitOutputFilePathWithoutExtension + extension; } @@ -6235,7 +6371,7 @@ var ts; setAccessor: setAccessor }; } - function createTextWriter(writeSymbol) { + function createTextWriter() { var output = ""; var indent = 0; var lineStart = true; @@ -6278,7 +6414,6 @@ var ts; } return { write: write, - writeSymbol: writeSymbol, rawWrite: rawWrite, writeLiteral: writeLiteral, writeLine: writeLine, @@ -6387,7 +6522,7 @@ var ts; } } function emitJavaScript(jsFilePath, root) { - var writer = createTextWriter(writeSymbol); + var writer = createTextWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -6417,8 +6552,6 @@ var ts; var scopeEmitEnd = function () { }; var sourceMapData; - function writeSymbol(symbol, enclosingDeclaration, meaning) { - } function initializeEmitterWithSourceMaps() { var sourceMapDir; var sourceMapSourceIndex = -1; @@ -6523,7 +6656,7 @@ var ts; } function recordNewSourceFileStart(node) { var sourcesDirectoryPath = compilerOptions.sourceRoot ? program.getCommonSourceDirectory() : sourceMapDir; - sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, compilerHost.getCurrentDirectory(), true)); + sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, true)); sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; sourceMapData.inputSourceFileNames.push(node.filename); } @@ -6550,7 +6683,7 @@ var ts; if (scopeName) { recordScopeNameStart(scopeName); } - else if (node.kind === 172 /* FunctionDeclaration */ || node.kind === 141 /* FunctionExpression */ || node.kind === 120 /* Method */ || node.kind === 122 /* GetAccessor */ || node.kind === 123 /* SetAccessor */ || node.kind === 177 /* ModuleDeclaration */ || node.kind === 174 /* ClassDeclaration */ || node.kind === 176 /* EnumDeclaration */) { + else if (node.kind === 174 /* FunctionDeclaration */ || node.kind === 143 /* FunctionExpression */ || node.kind === 120 /* Method */ || node.kind === 122 /* GetAccessor */ || node.kind === 123 /* SetAccessor */ || node.kind === 179 /* ModuleDeclaration */ || node.kind === 176 /* ClassDeclaration */ || node.kind === 178 /* EnumDeclaration */) { if (node.name) { scopeName = node.name.text; } @@ -6569,20 +6702,6 @@ var ts; writeCommentRange(comment, writer); recordSourceMapSpan(comment.end); } - var escapedCharsRegExp = /[\t\v\f\b\0\r\n\"\u2028\u2029\u0085]/g; - var escapedCharsMap = { - "\t": "\\t", - "\v": "\\v", - "\f": "\\f", - "\b": "\\b", - "\0": "\\0", - "\r": "\\r", - "\n": "\\n", - "\"": "\\\"", - "\u2028": "\\u2028", - "\u2029": "\\u2029", - "\u0085": "\\u0085" - }; function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings) { if (typeof JSON !== "undefined") { return JSON.stringify({ @@ -6594,19 +6713,14 @@ var ts; mappings: mappings }); } - return "{\"version\":" + version + ",\"file\":\"" + escapeString(file) + "\",\"sourceRoot\":\"" + escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + escapeString(mappings) + "\"}"; - function escapeString(s) { - return escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, function (c) { - return escapedCharsMap[c] || c; - }) : s; - } + return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\"}"; function serializeStringArray(list) { var output = ""; for (var i = 0, n = list.length; i < n; i++) { if (i) { output += ","; } - output += "\"" + escapeString(list[i]) + "\""; + output += "\"" + ts.escapeString(list[i]) + "\""; } return output; } @@ -6640,7 +6754,7 @@ var ts; } if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { sourceMapDir = ts.combinePaths(program.getCommonSourceDirectory(), sourceMapDir); - sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), compilerHost.getCurrentDirectory(), true); + sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, true); } else { sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); @@ -6651,7 +6765,7 @@ var ts; } function emitNodeWithMap(node) { if (node) { - if (node.kind != 182 /* SourceFile */) { + if (node.kind != 184 /* SourceFile */) { recordEmitNodeStartSpan(node); emitNode(node); recordEmitNodeEndSpan(node); @@ -6690,25 +6804,42 @@ var ts; emit(node); } } - function emitCommaList(nodes, count) { - if (!(count >= 0)) - count = nodes.length; - if (nodes) { - for (var i = 0; i < count; i++) { - if (i) - write(", "); - emit(nodes[i]); + function emitTrailingCommaIfPresent(nodeList, isMultiline) { + if (nodeList.hasTrailingComma) { + write(","); + if (isMultiline) { + writeLine(); } } } - function emitMultiLineList(nodes) { + function emitCommaList(nodes, includeTrailingComma, count) { + if (!(count >= 0)) { + count = nodes.length; + } + if (nodes) { + for (var i = 0; i < count; i++) { + if (i) { + write(", "); + } + emit(nodes[i]); + } + if (includeTrailingComma) { + emitTrailingCommaIfPresent(nodes, false); + } + } + } + function emitMultiLineList(nodes, includeTrailingComma) { if (nodes) { for (var i = 0; i < nodes.length; i++) { - if (i) + if (i) { write(","); + } writeLine(); emit(nodes[i]); } + if (includeTrailingComma) { + emitTrailingCommaIfPresent(nodes, true); + } } } function emitLines(nodes) { @@ -6748,28 +6879,28 @@ var ts; var parent = node.parent; switch (parent.kind) { case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 143 /* FunctionExpression */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return parent.name === node; - case 158 /* BreakStatement */: - case 157 /* ContinueStatement */: - case 180 /* ExportAssignment */: + case 160 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 182 /* ExportAssignment */: return false; - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return node.parent.label === node; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return node.parent.variable === node; } } @@ -6807,14 +6938,14 @@ var ts; if (node.flags & 256 /* MultiLine */) { write("["); increaseIndent(); - emitMultiLineList(node.elements); + emitMultiLineList(node.elements, true); decreaseIndent(); writeLine(); write("]"); } else { write("["); - emitCommaList(node.elements); + emitCommaList(node.elements, true); write("]"); } } @@ -6825,14 +6956,14 @@ var ts; else if (node.flags & 256 /* MultiLine */) { write("{"); increaseIndent(); - emitMultiLineList(node.properties); + emitMultiLineList(node.properties, compilerOptions.target >= 1 /* ES5 */); decreaseIndent(); writeLine(); write("}"); } else { write("{ "); - emitCommaList(node.properties); + emitCommaList(node.properties, compilerOptions.target >= 1 /* ES5 */); write(" }"); } } @@ -6844,14 +6975,15 @@ var ts; emitTrailingComments(node); } function emitPropertyAccess(node) { - var text = resolver.getPropertyAccessSubstitution(node); - if (text) { - write(text); - return; + var constantValue = resolver.getConstantValue(node); + if (constantValue !== undefined) { + write(constantValue.toString() + " /* " + ts.identifierToString(node.right) + " */"); + } + else { + emit(node.left); + write("."); + emit(node.right); } - emit(node.left); - write("."); - emit(node.right); } function emitIndexedAccess(node) { emit(node.object); @@ -6867,20 +6999,20 @@ var ts; } else { emit(node.func); - superCall = node.func.kind === 135 /* PropertyAccess */ && node.func.left.kind === 85 /* SuperKeyword */; + superCall = node.func.kind === 137 /* PropertyAccess */ && node.func.left.kind === 85 /* SuperKeyword */; } if (superCall) { write(".call("); emitThis(node.func); if (node.arguments.length) { write(", "); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); } write(")"); } else { write("("); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); write(")"); } } @@ -6889,17 +7021,17 @@ var ts; emit(node.func); if (node.arguments) { write("("); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); write(")"); } } function emitParenExpression(node) { - if (node.expression.kind === 139 /* TypeAssertion */) { + if (node.expression.kind === 141 /* TypeAssertion */) { var operand = node.expression.operand; - while (operand.kind == 139 /* TypeAssertion */) { + while (operand.kind == 141 /* TypeAssertion */) { operand = operand.operand; } - if (operand.kind !== 143 /* PrefixOperator */ && operand.kind !== 144 /* PostfixOperator */ && operand.kind !== 138 /* NewExpression */ && !(operand.kind === 137 /* CallExpression */ && node.parent.kind === 138 /* NewExpression */) && !(operand.kind === 141 /* FunctionExpression */ && node.parent.kind === 137 /* CallExpression */)) { + if (operand.kind !== 145 /* PrefixOperator */ && operand.kind !== 146 /* PostfixOperator */ && operand.kind !== 140 /* NewExpression */ && !(operand.kind === 139 /* CallExpression */ && node.parent.kind === 140 /* NewExpression */) && !(operand.kind === 143 /* FunctionExpression */ && node.parent.kind === 139 /* CallExpression */)) { emit(operand); return; } @@ -6909,13 +7041,13 @@ var ts; write(")"); } function emitUnaryExpression(node) { - if (node.kind === 143 /* PrefixOperator */) { + if (node.kind === 145 /* PrefixOperator */) { write(ts.tokenToString(node.operator)); } if (node.operator >= 59 /* Identifier */) { write(" "); } - else if (node.kind === 143 /* PrefixOperator */ && node.operand.kind === 143 /* PrefixOperator */) { + else if (node.kind === 145 /* PrefixOperator */ && node.operand.kind === 145 /* PrefixOperator */) { var operand = node.operand; if (node.operator === 28 /* PlusToken */ && (operand.operator === 28 /* PlusToken */ || operand.operator === 33 /* PlusPlusToken */)) { write(" "); @@ -6925,7 +7057,7 @@ var ts; } } emit(node.operand); - if (node.kind === 144 /* PostfixOperator */) { + if (node.kind === 146 /* PostfixOperator */) { write(ts.tokenToString(node.operator)); } } @@ -6948,8 +7080,8 @@ var ts; emitToken(9 /* OpenBraceToken */, node.pos); increaseIndent(); scopeEmitStart(node.parent); - if (node.kind === 178 /* ModuleBlock */) { - ts.Debug.assert(node.parent.kind === 177 /* ModuleDeclaration */); + if (node.kind === 180 /* ModuleBlock */) { + ts.Debug.assert(node.parent.kind === 179 /* ModuleDeclaration */); emitCaptureThisForNodeIfNecessary(node.parent); } emitLines(node.statements); @@ -6959,7 +7091,7 @@ var ts; scopeEmitEnd(); } function emitEmbeddedStatement(node) { - if (node.kind === 148 /* Block */) { + if (node.kind === 150 /* Block */) { write(" "); emit(node); } @@ -6971,7 +7103,7 @@ var ts; } } function emitExpressionStatement(node) { - var isArrowExpression = node.expression.kind === 142 /* ArrowFunction */; + var isArrowExpression = node.expression.kind === 144 /* ArrowFunction */; emitLeadingComments(node); if (isArrowExpression) write("("); @@ -6992,7 +7124,7 @@ var ts; if (node.elseStatement) { writeLine(); emitToken(70 /* ElseKeyword */, node.thenStatement.end); - if (node.elseStatement.kind === 152 /* IfStatement */) { + if (node.elseStatement.kind === 154 /* IfStatement */) { write(" "); emit(node.elseStatement); } @@ -7005,7 +7137,7 @@ var ts; function emitDoStatement(node) { write("do"); emitEmbeddedStatement(node.statement); - if (node.statement.kind === 148 /* Block */) { + if (node.statement.kind === 150 /* Block */) { write(" "); } else { @@ -7028,7 +7160,7 @@ var ts; if (node.declarations) { emitToken(92 /* VarKeyword */, endPos); write(" "); - emitCommaList(node.declarations); + emitCommaList(node.declarations, false); } if (node.initializer) { emit(node.initializer); @@ -7058,7 +7190,7 @@ var ts; emitEmbeddedStatement(node.statement); } function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 158 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */, node.pos); + emitToken(node.kind === 160 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */, node.pos); emitOptional(" ", node.label); write(";"); } @@ -7090,7 +7222,7 @@ var ts; emitToken(10 /* CloseBraceToken */, node.clauses.end); } function emitCaseOrDefaultClause(node) { - if (node.kind === 162 /* CaseClause */) { + if (node.kind === 164 /* CaseClause */) { write("case "); emit(node.expression); write(":"); @@ -7139,7 +7271,7 @@ var ts; function getContainingModule(node) { do { node = node.parent; - } while (node && node.kind !== 177 /* ModuleDeclaration */); + } while (node && node.kind !== 179 /* ModuleDeclaration */); return node; } function emitModuleMemberName(node) { @@ -7162,7 +7294,7 @@ var ts; emitLeadingComments(node); if (!(node.flags & 1 /* Export */)) write("var "); - emitCommaList(node.declarations); + emitCommaList(node.declarations, false); write(";"); emitTrailingComments(node); } @@ -7242,7 +7374,7 @@ var ts; emitLeadingComments(node); } write("function "); - if (node.kind === 172 /* FunctionDeclaration */ || (node.kind === 141 /* FunctionExpression */ && node.name)) { + if (node.kind === 174 /* FunctionDeclaration */ || (node.kind === 143 /* FunctionExpression */ && node.name)) { emit(node.name); } emitSignatureAndBody(node); @@ -7262,7 +7394,7 @@ var ts; increaseIndent(); write("("); if (node) { - emitCommaList(node.parameters, node.parameters.length - (ts.hasRestParameters(node) ? 1 : 0)); + emitCommaList(node.parameters, false, node.parameters.length - (ts.hasRestParameters(node) ? 1 : 0)); } write(")"); decreaseIndent(); @@ -7272,16 +7404,16 @@ var ts; write(" {"); scopeEmitStart(node); increaseIndent(); - emitDetachedComments(node.body.kind === 173 /* FunctionBlock */ ? node.body.statements : node.body); + emitDetachedComments(node.body.kind === 175 /* FunctionBlock */ ? node.body.statements : node.body); var startIndex = 0; - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { startIndex = emitDirectivePrologues(node.body.statements, true); } var outPos = writer.getTextPos(); emitCaptureThisForNodeIfNecessary(node); emitDefaultValueAssignments(node); emitRestParameter(node); - if (node.body.kind !== 173 /* FunctionBlock */ && outPos === writer.getTextPos()) { + if (node.body.kind !== 175 /* FunctionBlock */ && outPos === writer.getTextPos()) { decreaseIndent(); write(" "); emitStart(node.body); @@ -7294,7 +7426,7 @@ var ts; emitEnd(node.body); } else { - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { emitLinesStartingAt(node.body.statements, startIndex); } else { @@ -7306,7 +7438,7 @@ var ts; emitTrailingComments(node.body); } writeLine(); - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { emitLeadingCommentsOfPosition(node.body.statements.end); decreaseIndent(); emitToken(10 /* CloseBraceToken */, node.body.statements.end); @@ -7332,9 +7464,9 @@ var ts; function findInitialSuperCall(ctor) { if (ctor.body) { var statement = ctor.body.statements[0]; - if (statement && statement.kind === 151 /* ExpressionStatement */) { + if (statement && statement.kind === 153 /* ExpressionStatement */) { var expr = statement.expression; - if (expr && expr.kind === 137 /* CallExpression */) { + if (expr && expr.kind === 139 /* CallExpression */) { var func = expr.func; if (func && func.kind === 85 /* SuperKeyword */) { return statement; @@ -7648,7 +7780,7 @@ var ts; } } function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 177 /* ModuleDeclaration */) { + if (moduleDeclaration.body.kind === 179 /* ModuleDeclaration */) { var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); return recursiveInnerModule || moduleDeclaration.body; } @@ -7670,7 +7802,7 @@ var ts; write(resolver.getLocalNameOfContainer(node)); emitEnd(node.name); write(") "); - if (node.body.kind === 178 /* ModuleBlock */) { + if (node.body.kind === 180 /* ModuleBlock */) { emit(node.body); } else { @@ -7704,7 +7836,7 @@ var ts; emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportedViaEntityName(node); } if (emitImportDeclaration) { - if (node.externalModuleName && node.parent.kind === 182 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { + if (node.externalModuleName && node.parent.kind === 184 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { if (node.flags & 1 /* Export */) { writeLine(); emitLeadingComments(node); @@ -7744,7 +7876,7 @@ var ts; function getExternalImportDeclarations(node) { var result = []; ts.forEach(node.statements, function (stat) { - if (stat.kind === 179 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) { + if (stat.kind === 181 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) { result.push(stat); } }); @@ -7752,7 +7884,7 @@ var ts; } function getFirstExportAssignment(sourceFile) { return ts.forEach(sourceFile.statements, function (node) { - if (node.kind === 180 /* ExportAssignment */) { + if (node.kind === 182 /* ExportAssignment */) { return node; } }); @@ -7891,94 +8023,94 @@ var ts; return emitLiteral(node); case 116 /* QualifiedName */: return emitPropertyAccess(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return emitArrayLiteral(node); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return emitObjectLiteral(node); - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return emitPropertyAssignment(node); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return emitPropertyAccess(node); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return emitIndexedAccess(node); - case 137 /* CallExpression */: + case 139 /* CallExpression */: return emitCallExpression(node); - case 138 /* NewExpression */: + case 140 /* NewExpression */: return emitNewExpression(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return emit(node.operand); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return emitParenExpression(node); - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return emitFunctionDeclaration(node); - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: return emitUnaryExpression(node); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return emitBinaryExpression(node); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return emitConditionalExpression(node); - case 147 /* OmittedExpression */: + case 149 /* OmittedExpression */: return; - case 148 /* Block */: - case 167 /* TryBlock */: - case 169 /* FinallyBlock */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: + case 150 /* Block */: + case 169 /* TryBlock */: + case 171 /* FinallyBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: return emitBlock(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return emitVariableStatement(node); - case 150 /* EmptyStatement */: + case 152 /* EmptyStatement */: return write(";"); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return emitExpressionStatement(node); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return emitIfStatement(node); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return emitDoStatement(node); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return emitWhileStatement(node); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return emitForStatement(node); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return emitForInStatement(node); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return emitBreakOrContinueStatement(node); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return emitReturnStatement(node); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return emitWithStatement(node); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return emitSwitchStatement(node); - case 162 /* CaseClause */: - case 163 /* DefaultClause */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: return emitCaseOrDefaultClause(node); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return emitLabelledStatement(node); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return emitThrowStatement(node); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return emitTryStatement(node); - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return emitCatchBlock(node); - case 170 /* DebuggerStatement */: + case 172 /* DebuggerStatement */: return emitDebuggerStatement(node); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return emitVariableDeclaration(node); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return emitClassDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return emitInterfaceDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return emitEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return emitModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return emitImportDeclaration(node); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return emitSourceFile(node); } } @@ -7986,7 +8118,7 @@ var ts; return detachedCommentsInfo !== undefined && detachedCommentsInfo[detachedCommentsInfo.length - 1].nodePos === pos; } function getLeadingCommentsWithoutDetachedComments() { - var leadingComments = ts.getLeadingComments(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); if (detachedCommentsInfo.length - 1) { detachedCommentsInfo.pop(); } @@ -7996,13 +8128,13 @@ var ts; return leadingComments; } function getLeadingCommentsToEmit(node) { - if (node.parent.kind === 182 /* SourceFile */ || node.pos !== node.parent.pos) { + if (node.parent.kind === 184 /* SourceFile */ || node.pos !== node.parent.pos) { var leadingComments; if (hasDetachedComments(node.pos)) { leadingComments = getLeadingCommentsWithoutDetachedComments(); } else { - leadingComments = ts.getLeadingCommentsOfNode(node, currentSourceFile); + leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); } return leadingComments; } @@ -8013,8 +8145,8 @@ var ts; emitComments(leadingComments, true, writer, writeComment); } function emitTrailingDeclarationComments(node) { - if (node.parent.kind === 182 /* SourceFile */ || node.end !== node.parent.end) { - var trailingComments = ts.getTrailingComments(currentSourceFile.text, node.end); + if (node.parent.kind === 184 /* SourceFile */ || node.end !== node.parent.end) { + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); emitComments(trailingComments, false, writer, writeComment); } } @@ -8024,13 +8156,13 @@ var ts; leadingComments = getLeadingCommentsWithoutDetachedComments(); } else { - leadingComments = ts.getLeadingComments(currentSourceFile.text, pos); + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); } emitNewLineBeforeLeadingComments({ pos: pos, end: pos }, leadingComments, writer); emitComments(leadingComments, true, writer, writeComment); } function emitDetachedCommentsAtPosition(node) { - var leadingComments = ts.getLeadingComments(currentSourceFile.text, node.pos); + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); if (leadingComments) { var detachedComments = []; var lastComment; @@ -8092,7 +8224,7 @@ var ts; writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); } function emitDeclarations(jsFilePath, root) { - var writer = createTextWriter(writeSymbol); + var writer = createTextWriterWithSymbolWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -8103,11 +8235,23 @@ var ts; } : writeJsDocComments; var aliasDeclarationEmitInfo = []; var getSymbolVisibilityDiagnosticMessage; + function createTextWriterWithSymbolWriter() { + var writer = createTextWriter(); + writer.trackSymbol = trackSymbol; + writer.writeKeyword = writer.write; + writer.writeOperator = writer.write; + writer.writePunctuation = writer.write; + writer.writeSpace = writer.write; + writer.writeStringLiteral = writer.writeLiteral; + writer.writeParameter = writer.write; + writer.writeSymbol = writer.write; + return writer; + } function writeAsychronousImportDeclarations(importDeclarations) { var oldWriter = writer; ts.forEach(importDeclarations, function (aliasToWrite) { var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; }); - writer = createTextWriter(writeSymbol); + writer = createTextWriterWithSymbolWriter(); for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { writer.increaseIndent(); } @@ -8116,10 +8260,9 @@ var ts; }); writer = oldWriter; } - function writeSymbol(symbol, enclosingDeclaration, meaning) { + function trackSymbol(symbol, enclosingDeclaration, meaning) { var symbolAccesibilityResult = resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning); if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) { - resolver.writeSymbol(symbol, enclosingDeclaration, meaning, writer); if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); } @@ -8194,7 +8337,7 @@ var ts; if (node.flags & 1 /* Export */) { write("export "); } - if (node.kind !== 175 /* InterfaceDeclaration */) { + if (node.kind !== 177 /* InterfaceDeclaration */) { write("declare "); } } @@ -8250,7 +8393,7 @@ var ts; emitDeclarationFlags(node); write("module "); emitSourceTextOfNode(node.name); - while (node.body.kind !== 178 /* ModuleBlock */) { + while (node.body.kind !== 180 /* ModuleBlock */) { node = node.body; write("."); emitSourceTextOfNode(node.name); @@ -8298,10 +8441,10 @@ var ts; function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.parent.kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; break; - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; break; case 125 /* ConstructSignature */: @@ -8314,14 +8457,14 @@ var ts; if (node.parent.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -8359,7 +8502,7 @@ var ts; resolver.writeTypeAtLocation(node, enclosingDeclaration, 1 /* WriteArrayAsGenericType */ | 2 /* UseTypeOfFunction */, writer); function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.parent.kind === 174 /* ClassDeclaration */) { + if (node.parent.kind === 176 /* ClassDeclaration */) { if (symbolAccesibilityResult.errorModuleName) { diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2; } @@ -8444,7 +8587,7 @@ var ts; writeLine(); } function emitVariableDeclaration(node) { - if (node.kind !== 171 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { + if (node.kind !== 173 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { emitSourceTextOfNode(node.name); if (node.kind === 119 /* Property */ && (node.flags & 4 /* QuestionMark */)) { write("?"); @@ -8457,14 +8600,14 @@ var ts; } function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.kind === 171 /* VariableDeclaration */) { + if (node.kind === 173 /* VariableDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } else if (node.kind === 119 /* Property */) { if (node.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { @@ -8535,10 +8678,10 @@ var ts; } } function emitFunctionDeclaration(node) { - if ((node.kind !== 172 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { + if ((node.kind !== 174 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); emitDeclarationFlags(node); - if (node.kind === 172 /* FunctionDeclaration */) { + if (node.kind === 174 /* FunctionDeclaration */) { write("function "); emitSourceTextOfNode(node.name); } @@ -8600,14 +8743,14 @@ var ts; if (node.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } - else if (node.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; break; default: @@ -8651,14 +8794,14 @@ var ts; if (node.parent.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -8674,7 +8817,7 @@ var ts; function emitNode(node) { switch (node.kind) { case 121 /* Constructor */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: return emitFunctionDeclaration(node); case 125 /* ConstructSignature */: @@ -8685,44 +8828,44 @@ var ts; case 122 /* GetAccessor */: case 123 /* SetAccessor */: return emitAccessorDeclaration(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return emitVariableStatement(node); case 119 /* Property */: return emitPropertyDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return emitInterfaceDeclaration(node); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return emitClassDeclaration(node); - case 181 /* EnumMember */: + case 183 /* EnumMember */: return emitEnumMemberDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return emitEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return emitModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return emitImportDeclaration(node); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return emitExportAssignment(node); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return emitSourceFile(node); } } - function resolveScriptReference(sourceFile, reference) { + function tryResolveScriptReference(sourceFile, reference) { var referenceFileName = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename)); return program.getSourceFile(referenceFileName); } var referencePathsOutput = ""; function writeReferencePath(referencedFile) { - var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.getModuleNameFromFilename(compilerOptions.out) + ".d.ts"; - declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), false); + var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; + declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, false); referencePathsOutput += "/// " + newLine; } if (root) { if (!compilerOptions.noResolve) { var addedGlobalFileReference = false; ts.forEach(root.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(root, fileReference); - if ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference) { + var referencedFile = tryResolveScriptReference(root, fileReference); + if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { writeReferencePath(referencedFile); if (!isExternalModuleOrDeclarationFile(referencedFile)) { addedGlobalFileReference = true; @@ -8738,8 +8881,8 @@ var ts; if (!isExternalModuleOrDeclarationFile(sourceFile)) { if (!compilerOptions.noResolve) { ts.forEach(sourceFile.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(sourceFile, fileReference); - if (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile)) { + var referencedFile = tryResolveScriptReference(sourceFile, fileReference); + if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) { writeReferencePath(referencedFile); emittedReferencedFiles.push(referencedFile); } @@ -8761,7 +8904,7 @@ var ts; } }); declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos); - writeFile(ts.getModuleNameFromFilename(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); + writeFile(ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); } } var hasSemanticErrors = resolver.hasSemanticErrors(); @@ -8778,13 +8921,18 @@ var ts; emitFile(jsFilePath, sourceFile); } }); + if (compilerOptions.out) { + emitFile(compilerOptions.out); + } } else { - var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js"); - emitFile(jsFilePath, targetSourceFile); - } - if (compilerOptions.out) { - emitFile(compilerOptions.out); + if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { + var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js"); + emitFile(jsFilePath, targetSourceFile); + } + else if (!ts.isDeclarationFile(targetSourceFile) && compilerOptions.out) { + emitFile(compilerOptions.out); + } } diagnostics.sort(ts.compareDiagnostics); diagnostics = ts.deduplicateSortedDiagnostics(diagnostics); @@ -8826,6 +8974,33 @@ var ts; return undefined; } ts.getDeclarationOfKind = getDeclarationOfKind; + var stringWriters = []; + function getSingleLineStringWriter() { + if (stringWriters.length == 0) { + var str = ""; + var writeText = function (text) { return str += text; }; + return { + string: function () { return str; }, + writeKeyword: writeText, + writeOperator: writeText, + writePunctuation: writeText, + writeSpace: writeText, + writeStringLiteral: writeText, + writeParameter: writeText, + writeSymbol: writeText, + writeLine: function () { return str += " "; }, + increaseIndent: function () { + }, + decreaseIndent: function () { + }, + clear: function () { return str = ""; }, + trackSymbol: function () { + } + }; + } + return stringWriters.pop(); + } + ts.getSingleLineStringWriter = getSingleLineStringWriter; function createTypeChecker(program, fullTypeCheck) { var Symbol = ts.objectAllocator.getSymbolConstructor(); var Type = ts.objectAllocator.getTypeConstructor(); @@ -8854,13 +9029,21 @@ var ts; getSymbolsInScope: getSymbolsInScope, getSymbolInfo: getSymbolInfo, getTypeOfNode: getTypeOfNode, - getApparentType: getApparentType, typeToString: typeToString, + getSymbolDisplayBuilder: getSymbolDisplayBuilder, symbolToString: symbolToString, - getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType, - getRootSymbol: getRootSymbol, + getAugmentedPropertiesOfType: getAugmentedPropertiesOfType, + getRootSymbols: getRootSymbols, getContextualType: getContextualType, - getFullyQualifiedName: getFullyQualifiedName + getFullyQualifiedName: getFullyQualifiedName, + getResolvedSignature: getResolvedSignature, + getEnumMemberValue: getEnumMemberValue, + isValidPropertyAccess: isValidPropertyAccess, + getSignatureFromDeclaration: getSignatureFromDeclaration, + isImplementationOfOverload: isImplementationOfOverload, + getAliasedSymbol: resolveImport, + isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; }, + isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; } }; var undefinedSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "undefined"); var argumentsSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "arguments"); @@ -8890,6 +9073,7 @@ var ts; var globalBooleanType; var globalRegExpType; var tupleTypes = {}; + var unionTypes = {}; var stringLiteralTypes = {}; var emitExtends = false; var mergedSymbols = []; @@ -9021,10 +9205,10 @@ var ts; return nodeLinks[node.id] || (nodeLinks[node.id] = {}); } function getSourceFile(node) { - return ts.getAncestor(node, 182 /* SourceFile */); + return ts.getAncestor(node, 184 /* SourceFile */); } function isGlobalSourceFile(node) { - return node.kind === 182 /* SourceFile */ && !ts.isExternalModule(node); + return node.kind === 184 /* SourceFile */ && !ts.isExternalModule(node); } function getSymbol(symbols, name, meaning) { if (meaning && ts.hasProperty(symbols, name)) { @@ -9064,21 +9248,21 @@ var ts; } } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & ts.SymbolFlags.ModuleMember)) { return returnResolvedSymbol(result); } break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 4 /* EnumMember */)) { return returnResolvedSymbol(result); } break; case 119 /* Property */: - if (location.parent.kind === 174 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) { + if (location.parent.kind === 176 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { if (getSymbol(ctor.locals, name, meaning & ts.SymbolFlags.Value)) { @@ -9087,8 +9271,8 @@ var ts; } } break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & ts.SymbolFlags.Type)) { if (lastLocation && lastLocation.flags & 128 /* Static */) { error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters); @@ -9103,13 +9287,13 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: if (name === "arguments") { return returnResolvedSymbol(argumentsSymbol); } break; - case 141 /* FunctionExpression */: + case 143 /* FunctionExpression */: if (name === "arguments") { return returnResolvedSymbol(argumentsSymbol); } @@ -9118,7 +9302,7 @@ var ts; return returnResolvedSymbol(location.symbol); } break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: var id = location.variable; if (name === id.text) { return returnResolvedSymbol(location.symbol); @@ -9138,7 +9322,7 @@ var ts; var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = getDeclarationOfKind(symbol, 179 /* ImportDeclaration */); + var node = getDeclarationOfKind(symbol, 181 /* ImportDeclaration */); var target = node.externalModuleName ? resolveExternalModuleName(node, node.externalModuleName) : getSymbolOfPartOfRightHandSideOfImport(node.entityName, node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; @@ -9154,7 +9338,7 @@ var ts; } function getSymbolOfPartOfRightHandSideOfImport(entityName, importDeclaration) { if (!importDeclaration) { - importDeclaration = ts.getAncestor(entityName, 179 /* ImportDeclaration */); + importDeclaration = ts.getAncestor(entityName, 181 /* ImportDeclaration */); ts.Debug.assert(importDeclaration); } if (entityName.kind === 59 /* Identifier */ && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { @@ -9164,7 +9348,7 @@ var ts; return resolveEntityName(importDeclaration, entityName, ts.SymbolFlags.Namespace); } else { - ts.Debug.assert(entityName.parent.kind === 179 /* ImportDeclaration */); + ts.Debug.assert(entityName.parent.kind === 181 /* ImportDeclaration */); return resolveEntityName(importDeclaration, entityName, ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace); } } @@ -9269,9 +9453,9 @@ var ts; var seenExportedMember = false; var result = []; ts.forEach(symbol.declarations, function (declaration) { - var block = (declaration.kind === 182 /* SourceFile */ ? declaration : declaration.body); + var block = (declaration.kind === 184 /* SourceFile */ ? declaration : declaration.body); ts.forEach(block.statements, function (node) { - if (node.kind === 180 /* ExportAssignment */) { + if (node.kind === 182 /* ExportAssignment */) { result.push(node); } else { @@ -9298,15 +9482,15 @@ var ts; return symbol && (symbol.flags & 524288 /* ExportValue */) !== 0 ? getMergedSymbol(symbol.exportSymbol) : symbol; } function symbolIsValue(symbol) { + if (symbol.flags & 8388608 /* Instantiated */) { + return symbolIsValue(getSymbolLinks(symbol).target); + } if (symbol.flags & ts.SymbolFlags.Value) { return true; } if (symbol.flags & 4194304 /* Import */) { return (resolveImport(symbol).flags & ts.SymbolFlags.Value) !== 0; } - if (symbol.flags & 8388608 /* Instantiated */) { - return (getSymbolLinks(symbol).target.flags & ts.SymbolFlags.Value) !== 0; - } return false; } function findConstructorDeclaration(node) { @@ -9364,7 +9548,7 @@ var ts; return type; } function createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) { - return setObjectTypeMembers(createObjectType(16384 /* Anonymous */, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + return setObjectTypeMembers(createObjectType(32768 /* Anonymous */, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } function isOptionalProperty(propertySymbol) { return propertySymbol.valueDeclaration && propertySymbol.valueDeclaration.flags & 4 /* QuestionMark */ && propertySymbol.valueDeclaration.kind !== 118 /* Parameter */; @@ -9378,17 +9562,17 @@ var ts; } } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) { break; } - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: if (result = callback(getSymbolOfNode(location).exports)) { return result; } break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (result = callback(getSymbolOfNode(location).members)) { return result; } @@ -9400,13 +9584,13 @@ var ts; function getQualifiedLeftMeaning(rightMeaning) { return rightMeaning === ts.SymbolFlags.Value ? ts.SymbolFlags.Value : ts.SymbolFlags.Namespace; } - function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning) { + function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, useOnlyExternalAliasing) { function getAccessibleSymbolChainFromSymbolTable(symbols) { function canQualifySymbol(symbolFromSymbolTable, meaning) { if (!needsQualification(symbolFromSymbolTable, enclosingDeclaration, meaning)) { return true; } - var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning)); + var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing); return !!accessibleParent; } function isAccessible(symbolFromSymbolTable, resolvedAliasSymbol) { @@ -9419,13 +9603,15 @@ var ts; } return ts.forEachValue(symbols, function (symbolFromSymbolTable) { if (symbolFromSymbolTable.flags & 4194304 /* Import */) { - var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); - if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { - return [symbolFromSymbolTable]; - } - var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; - if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { - return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); + if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, function (declaration) { return declaration.kind === 181 /* ImportDeclaration */ && declaration.externalModuleName; })) { + var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); + if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { + return [symbolFromSymbolTable]; + } + var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; + if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { + return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); + } } } }); @@ -9458,7 +9644,7 @@ var ts; var initialSymbol = symbol; var meaningToLook = meaning; while (symbol) { - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook); + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, false); if (accessibleSymbolChain) { var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]); if (!hasAccessibleDeclarations) { @@ -9499,7 +9685,7 @@ var ts; } } function hasExternalModuleSymbol(declaration) { - return (declaration.kind === 177 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 182 /* SourceFile */ && ts.isExternalModule(declaration)); + return (declaration.kind === 179 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 184 /* SourceFile */ && ts.isExternalModule(declaration)); } function hasVisibleDeclarations(symbol) { var aliasesToMakeVisible; @@ -9509,7 +9695,7 @@ var ts; return { aliasesToMakeVisible: aliasesToMakeVisible }; function getIsDeclarationVisible(declaration) { if (!isDeclarationVisible(declaration)) { - if (declaration.kind === 179 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) { + if (declaration.kind === 181 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) { getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { if (!ts.contains(aliasesToMakeVisible, declaration)) { @@ -9533,283 +9719,416 @@ var ts; var hasNamespaceDeclarationsVisibile = hasVisibleDeclarations(symbolOfNameSpace); return hasNamespaceDeclarationsVisibile ? { accessibility: 0 /* Accessible */, aliasesToMakeVisible: hasNamespaceDeclarationsVisibile.aliasesToMakeVisible } : { accessibility: 1 /* NotAccessible */, errorSymbolName: firstIdentifierName }; } + function releaseStringWriter(writer) { + writer.clear(); + stringWriters.push(writer); + } + function writeKeyword(writer, kind) { + writer.writeKeyword(ts.tokenToString(kind)); + } + function writePunctuation(writer, kind) { + writer.writePunctuation(ts.tokenToString(kind)); + } + function writeOperator(writer, kind) { + writer.writeOperator(ts.tokenToString(kind)); + } + function writeSpace(writer) { + writer.writeSpace(" "); + } function symbolToString(symbol, enclosingDeclaration, meaning) { - function getSymbolName(symbol) { + var writer = getSingleLineStringWriter(); + getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning); + var result = writer.string(); + releaseStringWriter(writer); + return result; + } + function typeToString(type, enclosingDeclaration, flags) { + var writer = getSingleLineStringWriter(); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); + var result = writer.string(); + releaseStringWriter(writer); + var maxLength = compilerOptions.noErrorTruncation || flags & 4 /* NoTruncation */ ? undefined : 100; + if (maxLength && result.length >= maxLength) { + result = result.substr(0, maxLength - "...".length) + "..."; + } + return result; + } + var _displayBuilder; + function getSymbolDisplayBuilder() { + function appendSymbolNameOnly(symbol, writer) { if (symbol.declarations && symbol.declarations.length > 0) { var declaration = symbol.declarations[0]; if (declaration.name) { - return ts.identifierToString(declaration.name); - } - } - return symbol.name; - } - if (enclosingDeclaration && !(symbol.flags & 262144 /* TypeParameter */)) { - var symbolName; - while (symbol) { - var isFirstName = !symbolName; - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning); - var currentSymbolName; - if (accessibleSymbolChain) { - currentSymbolName = ts.map(accessibleSymbolChain, function (accessibleSymbol) { return getSymbolName(accessibleSymbol); }).join("."); - } - else { - if (!isFirstName && ts.forEach(symbol.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); })) { - break; - } - currentSymbolName = getSymbolName(symbol); - } - symbolName = currentSymbolName + (isFirstName ? "" : ("." + symbolName)); - if (accessibleSymbolChain && !needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { - break; - } - symbol = getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol); - meaning = getQualifiedLeftMeaning(meaning); - } - return symbolName; - } - return getSymbolName(symbol); - } - function writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, writer) { - writer.write(symbolToString(symbol, enclosingDeclaration, meaning)); - } - function createSingleLineTextWriter(maxLength) { - var result = ""; - var overflow = false; - function write(s) { - if (!overflow) { - result += s; - if (result.length > maxLength) { - result = result.substr(0, maxLength - 3) + "..."; - overflow = true; - } - } - } - return { - write: write, - writeSymbol: function (symbol, enclosingDeclaration, meaning) { - writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this); - }, - writeLine: function () { - write(" "); - }, - increaseIndent: function () { - }, - decreaseIndent: function () { - }, - getText: function () { - return result; - } - }; - } - function typeToString(type, enclosingDeclaration, flags) { - var maxLength = compilerOptions.noErrorTruncation || flags & 4 /* NoTruncation */ ? undefined : 100; - var stringWriter = createSingleLineTextWriter(maxLength); - writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter); - return stringWriter.getText(); - } - function writeTypeToTextWriter(type, enclosingDeclaration, flags, writer) { - var typeStack; - return writeType(type, true); - function writeType(type, allowFunctionOrConstructorTypeLiteral) { - if (type.flags & ts.TypeFlags.Intrinsic) { - writer.write(type.intrinsicName); - } - else if (type.flags & 4096 /* Reference */) { - writeTypeReference(type); - } - else if (type.flags & (1024 /* Class */ | 2048 /* Interface */ | 128 /* Enum */ | 512 /* TypeParameter */)) { - writer.writeSymbol(type.symbol, enclosingDeclaration, ts.SymbolFlags.Type); - } - else if (type.flags & 8192 /* Tuple */) { - writeTupleType(type); - } - else if (type.flags & 16384 /* Anonymous */) { - writeAnonymousType(type, allowFunctionOrConstructorTypeLiteral); - } - else if (type.flags & 256 /* StringLiteral */) { - writer.write(type.text); - } - else { - writer.write("{ ... }"); - } - } - function writeTypeList(types) { - for (var i = 0; i < types.length; i++) { - if (i > 0) { - writer.write(", "); - } - writeType(types[i], true); - } - } - function writeTypeReference(type) { - if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { - writeType(type.typeArguments[0], false); - writer.write("[]"); - } - else { - writer.writeSymbol(type.target.symbol, enclosingDeclaration, ts.SymbolFlags.Type); - writer.write("<"); - writeTypeList(type.typeArguments); - writer.write(">"); - } - } - function writeTupleType(type) { - writer.write("["); - writeTypeList(type.elementTypes); - writer.write("]"); - } - function writeAnonymousType(type, allowFunctionOrConstructorTypeLiteral) { - if (type.symbol && type.symbol.flags & (16 /* Class */ | 64 /* Enum */ | 128 /* ValueModule */)) { - writeTypeofSymbol(type); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type); - } - else if (typeStack && ts.contains(typeStack, type)) { - writer.write("any"); - } - else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); - writeLiteralType(type, allowFunctionOrConstructorTypeLiteral); - typeStack.pop(); - } - function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 2048 /* Method */ && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 8 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 182 /* SourceFile */ || declaration.parent.kind === 178 /* ModuleBlock */; })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - return !!(flags & 2 /* UseTypeOfFunction */) || (typeStack && ts.contains(typeStack, type)); - } - } - } - } - function writeTypeofSymbol(type) { - writer.write("typeof "); - writer.writeSymbol(type.symbol, enclosingDeclaration, ts.SymbolFlags.Value); - } - function writeLiteralType(type, allowFunctionOrConstructorTypeLiteral) { - var resolved = resolveObjectTypeMembers(type); - if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { - if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { - writer.write("{}"); + writer.writeSymbol(ts.identifierToString(declaration.name), symbol); return; } - if (allowFunctionOrConstructorTypeLiteral) { + } + writer.writeSymbol(symbol.name, symbol); + } + function buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags) { + var parentSymbol; + function appendParentTypeArgumentsAndSymbolName(symbol) { + if (parentSymbol) { + if (flags & 1 /* WriteTypeParametersOrArguments */) { + if (symbol.flags & 8388608 /* Instantiated */) { + buildDisplayForTypeArgumentsAndDelimiters(getTypeParametersOfClassOrInterface(parentSymbol), symbol.mapper, writer, enclosingDeclaration); + } + else { + buildTypeParameterDisplayFromSymbol(parentSymbol, writer, enclosingDeclaration); + } + } + writePunctuation(writer, 15 /* DotToken */); + } + parentSymbol = symbol; + appendSymbolNameOnly(symbol, writer); + } + writer.trackSymbol(symbol, enclosingDeclaration, meaning); + function walkSymbol(symbol, meaning) { + if (symbol) { + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & 2 /* UseOnlyExternalAliasing */)); + if (!accessibleSymbolChain || needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { + walkSymbol(getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), getQualifiedLeftMeaning(meaning)); + } + if (accessibleSymbolChain) { + for (var i = 0, n = accessibleSymbolChain.length; i < n; i++) { + appendParentTypeArgumentsAndSymbolName(accessibleSymbolChain[i]); + } + } + else { + if (!parentSymbol && ts.forEach(symbol.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); })) { + return; + } + if (symbol.flags & 512 /* TypeLiteral */ || symbol.flags & 1024 /* ObjectLiteral */) { + return; + } + appendParentTypeArgumentsAndSymbolName(symbol); + } + } + } + if (enclosingDeclaration && !(symbol.flags & 262144 /* TypeParameter */)) { + walkSymbol(symbol, meaning); + return; + } + return appendParentTypeArgumentsAndSymbolName(symbol); + } + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + var globalFlagsToPass = globalFlags & 16 /* WriteOwnNameForAnyLike */; + return writeType(type, globalFlags); + function writeType(type, flags) { + if (type.flags & ts.TypeFlags.Intrinsic) { + writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && (type.flags & 1 /* Any */) ? "any" : type.intrinsicName); + } + else if (type.flags & 4096 /* Reference */) { + writeTypeReference(type, flags); + } + else if (type.flags & (1024 /* Class */ | 2048 /* Interface */ | 128 /* Enum */ | 512 /* TypeParameter */)) { + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Type); + } + else if (type.flags & 8192 /* Tuple */) { + writeTupleType(type); + } + else if (type.flags & 16384 /* Union */) { + writeUnionType(type, flags); + } + else if (type.flags & 32768 /* Anonymous */) { + writeAnonymousType(type, flags); + } + else if (type.flags & 256 /* StringLiteral */) { + writer.writeStringLiteral(type.text); + } + else { + writePunctuation(writer, 9 /* OpenBraceToken */); + writeSpace(writer); + writePunctuation(writer, 16 /* DotDotDotToken */); + writeSpace(writer); + writePunctuation(writer, 10 /* CloseBraceToken */); + } + } + function writeTypeList(types, union) { + for (var i = 0; i < types.length; i++) { + if (i > 0) { + if (union) { + writeSpace(writer); + } + writePunctuation(writer, union ? 39 /* BarToken */ : 18 /* CommaToken */); + writeSpace(writer); + } + writeType(types[i], union ? 64 /* InElementType */ : 0 /* None */); + } + } + function writeTypeReference(type, flags) { + if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { + writeType(type.typeArguments[0], 64 /* InElementType */); + writePunctuation(writer, 13 /* OpenBracketToken */); + writePunctuation(writer, 14 /* CloseBracketToken */); + } + else { + buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Type); + writePunctuation(writer, 19 /* LessThanToken */); + writeTypeList(type.typeArguments, false); + writePunctuation(writer, 20 /* GreaterThanToken */); + } + } + function writeTupleType(type) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writeTypeList(type.elementTypes, false); + writePunctuation(writer, 14 /* CloseBracketToken */); + } + function writeUnionType(type, flags) { + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + writeTypeList(type.types, true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } + } + function writeAnonymousType(type, flags) { + if (type.symbol && type.symbol.flags & (16 /* Class */ | 64 /* Enum */ | 128 /* ValueModule */)) { + writeTypeofSymbol(type); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type); + } + else if (typeStack && ts.contains(typeStack, type)) { + writeKeyword(writer, 105 /* AnyKeyword */); + } + else { + if (!typeStack) { + typeStack = []; + } + typeStack.push(type); + writeLiteralType(type, flags); + typeStack.pop(); + } + function shouldWriteTypeOfFunctionSymbol() { + if (type.symbol) { + var isStaticMethodSymbol = !!(type.symbol.flags & 2048 /* Method */ && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); + var isNonLocalFunctionSymbol = !!(type.symbol.flags & 8 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 184 /* SourceFile */ || declaration.parent.kind === 180 /* ModuleBlock */; })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + return !!(flags & 2 /* UseTypeOfFunction */) || (typeStack && ts.contains(typeStack, type)); + } + } + } + } + function writeTypeofSymbol(type) { + writeKeyword(writer, 91 /* TypeOfKeyword */); + writeSpace(writer); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Value); + } + function writeLiteralType(type, flags) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { + if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { + writePunctuation(writer, 9 /* OpenBraceToken */); + writePunctuation(writer, 10 /* CloseBraceToken */); + return; + } if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) { - writeSignature(resolved.callSignatures[0], true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } return; } if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) { - writer.write("new "); - writeSignature(resolved.constructSignatures[0], true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + writeKeyword(writer, 82 /* NewKeyword */); + writeSpace(writer); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } return; } } - } - writer.write("{"); - writer.writeLine(); - writer.increaseIndent(); - for (var i = 0; i < resolved.callSignatures.length; i++) { - writeSignature(resolved.callSignatures[i]); - writer.write(";"); + writePunctuation(writer, 9 /* OpenBraceToken */); writer.writeLine(); - } - for (var i = 0; i < resolved.constructSignatures.length; i++) { - writer.write("new "); - writeSignature(resolved.constructSignatures[i]); - writer.write(";"); - writer.writeLine(); - } - if (resolved.stringIndexType) { - writer.write("[x: string]: "); - writeType(resolved.stringIndexType, true); - writer.write(";"); - writer.writeLine(); - } - if (resolved.numberIndexType) { - writer.write("[x: number]: "); - writeType(resolved.numberIndexType, true); - writer.write(";"); - writer.writeLine(); - } - for (var i = 0; i < resolved.properties.length; i++) { - var p = resolved.properties[i]; - var t = getTypeOfSymbol(p); - if (p.flags & (8 /* Function */ | 2048 /* Method */) && !getPropertiesOfType(t).length) { - var signatures = getSignaturesOfType(t, 0 /* Call */); - for (var j = 0; j < signatures.length; j++) { - writer.writeSymbol(p); - if (isOptionalProperty(p)) { - writer.write("?"); + writer.increaseIndent(); + for (var i = 0; i < resolved.callSignatures.length; i++) { + buildSignatureDisplay(resolved.callSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + for (var i = 0; i < resolved.constructSignatures.length; i++) { + writeKeyword(writer, 82 /* NewKeyword */); + writeSpace(writer); + buildSignatureDisplay(resolved.constructSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + if (resolved.stringIndexType) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writer.writeParameter("x"); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeKeyword(writer, 114 /* StringKeyword */); + writePunctuation(writer, 14 /* CloseBracketToken */); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(resolved.stringIndexType, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + if (resolved.numberIndexType) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writer.writeParameter("x"); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeKeyword(writer, 112 /* NumberKeyword */); + writePunctuation(writer, 14 /* CloseBracketToken */); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(resolved.numberIndexType, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + for (var i = 0; i < resolved.properties.length; i++) { + var p = resolved.properties[i]; + var t = getTypeOfSymbol(p); + if (p.flags & (8 /* Function */ | 2048 /* Method */) && !getPropertiesOfObjectType(t).length) { + var signatures = getSignaturesOfType(t, 0 /* Call */); + for (var j = 0; j < signatures.length; j++) { + buildSymbolDisplay(p, writer); + if (isOptionalProperty(p)) { + writePunctuation(writer, 45 /* QuestionToken */); + } + buildSignatureDisplay(signatures[j], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); } - writeSignature(signatures[j]); - writer.write(";"); + } + else { + buildSymbolDisplay(p, writer); + if (isOptionalProperty(p)) { + writePunctuation(writer, 45 /* QuestionToken */); + } + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(t, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); writer.writeLine(); } } - else { - writer.writeSymbol(p); - if (isOptionalProperty(p)) { - writer.write("?"); - } - writer.write(": "); - writeType(t, true); - writer.write(";"); - writer.writeLine(); - } + writer.decreaseIndent(); + writePunctuation(writer, 10 /* CloseBraceToken */); } - writer.decreaseIndent(); - writer.write("}"); } - function writeSignature(signature, arrowStyle) { - if (signature.typeParameters) { - writer.write("<"); - for (var i = 0; i < signature.typeParameters.length; i++) { + function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { + var targetSymbol = getTargetSymbol(symbol); + if (targetSymbol.flags & 16 /* Class */ || targetSymbol.flags & 32 /* Interface */) { + buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); + } + } + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + appendSymbolNameOnly(tp.symbol, writer); + var constraint = getConstraintOfTypeParameter(tp); + if (constraint) { + writeSpace(writer); + writeKeyword(writer, 73 /* ExtendsKeyword */); + writeSpace(writer); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + } + } + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + if (getDeclarationFlagsFromSymbol(p) & 8 /* Rest */) { + writePunctuation(writer, 16 /* DotDotDotToken */); + } + appendSymbolNameOnly(p, writer); + if (p.valueDeclaration.flags & 4 /* QuestionMark */ || p.valueDeclaration.initializer) { + writePunctuation(writer, 45 /* QuestionToken */); + } + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + } + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, 19 /* LessThanToken */); + for (var i = 0; i < typeParameters.length; i++) { if (i > 0) { - writer.write(", "); - } - var tp = signature.typeParameters[i]; - writer.writeSymbol(tp.symbol); - var constraint = getConstraintOfTypeParameter(tp); - if (constraint) { - writer.write(" extends "); - writeType(constraint, true); + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); } + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); } - writer.write(">"); + writePunctuation(writer, 20 /* GreaterThanToken */); } - writer.write("("); - for (var i = 0; i < signature.parameters.length; i++) { - if (i > 0) { - writer.write(", "); - } - var p = signature.parameters[i]; - if (getDeclarationFlagsFromSymbol(p) & 8 /* Rest */) { - writer.write("..."); - } - writer.writeSymbol(p); - if (p.valueDeclaration.flags & 4 /* QuestionMark */ || p.valueDeclaration.initializer) { - writer.write("?"); - } - writer.write(": "); - writeType(getTypeOfSymbol(p), true); - } - writer.write(arrowStyle ? ") => " : "): "); - writeType(getReturnTypeOfSignature(signature), true); } + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, 19 /* LessThanToken */); + for (var i = 0; i < typeParameters.length; i++) { + if (i > 0) { + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); + } + buildTypeDisplay(mapper(typeParameters[i]), writer, enclosingDeclaration, 0 /* None */); + } + writePunctuation(writer, 20 /* GreaterThanToken */); + } + } + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + writePunctuation(writer, 11 /* OpenParenToken */); + for (var i = 0; i < parameters.length; i++) { + if (i > 0) { + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); + } + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + } + writePunctuation(writer, 12 /* CloseParenToken */); + } + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + if (flags & 8 /* WriteArrowStyleSignature */) { + writeSpace(writer); + writePunctuation(writer, 27 /* EqualsGreaterThanToken */); + } + else { + writePunctuation(writer, 46 /* ColonToken */); + } + writeSpace(writer); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + } + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + if (signature.target && (flags & 32 /* WriteTypeArgumentsOfSignature */)) { + buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); + } + else { + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + } + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + } + return _displayBuilder || (_displayBuilder = { + symbolToString: symbolToString, + typeToString: typeToString, + buildSymbolDisplay: buildSymbolDisplay, + buildTypeDisplay: buildTypeDisplay, + buildTypeParameterDisplay: buildTypeParameterDisplay, + buildParameterDisplay: buildParameterDisplay, + buildDisplayForParametersAndDelimiters: buildDisplayForParametersAndDelimiters, + buildDisplayForTypeParametersAndDelimiters: buildDisplayForTypeParametersAndDelimiters, + buildDisplayForTypeArgumentsAndDelimiters: buildDisplayForTypeArgumentsAndDelimiters, + buildTypeParameterDisplayFromSymbol: buildTypeParameterDisplayFromSymbol, + buildSignatureDisplay: buildSignatureDisplay, + buildReturnTypeDisplay: buildReturnTypeDisplay + }); } function isDeclarationVisible(node) { function getContainingExternalModule(node) { for (; node; node = node.parent) { - if (node.kind === 177 /* ModuleDeclaration */) { + if (node.kind === 179 /* ModuleDeclaration */) { if (node.name.kind === 7 /* StringLiteral */) { return node; } } - else if (node.kind === 182 /* SourceFile */) { + else if (node.kind === 184 /* SourceFile */) { return ts.isExternalModule(node) ? node : undefined; } } @@ -9851,15 +10170,15 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 171 /* VariableDeclaration */: - case 177 /* ModuleDeclaration */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 172 /* FunctionDeclaration */: - case 176 /* EnumDeclaration */: - case 179 /* ImportDeclaration */: - var parent = node.kind === 171 /* VariableDeclaration */ ? node.parent.parent : node.parent; - if (!(node.flags & 1 /* Export */) && !(node.kind !== 179 /* ImportDeclaration */ && parent.kind !== 182 /* SourceFile */ && ts.isInAmbientContext(parent))) { + case 173 /* VariableDeclaration */: + case 179 /* ModuleDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 174 /* FunctionDeclaration */: + case 178 /* EnumDeclaration */: + case 181 /* ImportDeclaration */: + var parent = node.kind === 173 /* VariableDeclaration */ ? node.parent.parent : node.parent; + if (!(node.flags & 1 /* Export */) && !(node.kind !== 181 /* ImportDeclaration */ && parent.kind !== 184 /* SourceFile */ && ts.isInAmbientContext(parent))) { return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); } return isDeclarationVisible(parent); @@ -9873,9 +10192,9 @@ var ts; case 124 /* CallSignature */: case 126 /* IndexSignature */: case 118 /* Parameter */: - case 178 /* ModuleBlock */: + case 180 /* ModuleBlock */: return isDeclarationVisible(node.parent); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return true; default: ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + ts.SyntaxKind[node.kind]); @@ -9889,31 +10208,12 @@ var ts; return links.isVisible; } } - function getApparentType(type) { - if (type.flags & 512 /* TypeParameter */) { - do { - type = getConstraintOfTypeParameter(type); - } while (type && type.flags & 512 /* TypeParameter */); - if (!type) - type = emptyObjectType; - } - if (type.flags & ts.TypeFlags.StringLike) { - type = globalStringType; - } - else if (type.flags & ts.TypeFlags.NumberLike) { - type = globalNumberType; - } - else if (type.flags & 8 /* Boolean */) { - type = globalBooleanType; - } - return type; - } function getTypeOfPrototypeProperty(prototype) { var classType = getDeclaredTypeOfSymbol(prototype.parent); return classType.typeParameters ? createTypeReference(classType, ts.map(classType.typeParameters, function (_) { return anyType; })) : classType; } function getTypeOfVariableDeclaration(declaration) { - if (declaration.parent.kind === 156 /* ForInStatement */) { + if (declaration.parent.kind === 158 /* ForInStatement */) { return anyType; } if (declaration.type) { @@ -9934,7 +10234,7 @@ var ts; } if (declaration.initializer) { var type = checkAndMarkExpression(declaration.initializer); - if (declaration.kind !== 134 /* PropertyAssignment */) { + if (declaration.kind !== 136 /* PropertyAssignment */) { var unwidenedType = type; type = getWidenedType(type); if (type !== unwidenedType) { @@ -9976,7 +10276,7 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.kind === 168 /* CatchBlock */) { + if (declaration.kind === 170 /* CatchBlock */) { return links.type = anyType; } links.type = resolvingType; @@ -10057,7 +10357,7 @@ var ts; function getTypeOfFuncClassEnumModule(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { - links.type = createObjectType(16384 /* Anonymous */, symbol); + links.type = createObjectType(32768 /* Anonymous */, symbol); } return links.type; } @@ -10083,6 +10383,9 @@ var ts; return links.type; } function getTypeOfSymbol(symbol) { + if (symbol.flags & 8388608 /* Instantiated */) { + return getTypeOfInstantiatedSymbol(symbol); + } if (symbol.flags & (1 /* Variable */ | 2 /* Property */)) { return getTypeOfVariableOrParameterOrProperty(symbol); } @@ -10098,9 +10401,6 @@ var ts; if (symbol.flags & 4194304 /* Import */) { return getTypeOfImport(symbol); } - if (symbol.flags & 8388608 /* Instantiated */) { - return getTypeOfInstantiatedSymbol(symbol); - } return unknownType; } function getTargetType(type) { @@ -10116,7 +10416,7 @@ var ts; function getTypeParametersOfClassOrInterface(symbol) { var result; ts.forEach(symbol.declarations, function (node) { - if (node.kind === 175 /* InterfaceDeclaration */ || node.kind === 174 /* ClassDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */ || node.kind === 176 /* ClassDeclaration */) { var declaration = node; if (declaration.typeParameters && declaration.typeParameters.length) { ts.forEach(declaration.typeParameters, function (node) { @@ -10147,7 +10447,7 @@ var ts; type.typeArguments = type.typeParameters; } type.baseTypes = []; - var declaration = getDeclarationOfKind(symbol, 174 /* ClassDeclaration */); + var declaration = getDeclarationOfKind(symbol, 176 /* ClassDeclaration */); if (declaration.baseType) { var baseType = getTypeFromTypeReferenceNode(declaration.baseType); if (baseType !== unknownType) { @@ -10187,7 +10487,7 @@ var ts; } type.baseTypes = []; ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 175 /* InterfaceDeclaration */ && declaration.baseTypes) { + if (declaration.kind === 177 /* InterfaceDeclaration */ && declaration.baseTypes) { ts.forEach(declaration.baseTypes, function (node) { var baseType = getTypeFromTypeReferenceNode(node); if (baseType !== unknownType) { @@ -10243,6 +10543,7 @@ var ts; return links.declaredType; } function getDeclaredTypeOfSymbol(symbol) { + ts.Debug.assert((symbol.flags & 8388608 /* Instantiated */) === 0); if (symbol.flags & 16 /* Class */) { return getDeclaredTypeOfClass(symbol); } @@ -10258,7 +10559,6 @@ var ts; if (symbol.flags & 4194304 /* Import */) { return getDeclaredTypeOfImport(symbol); } - ts.Debug.assert((symbol.flags & 8388608 /* Instantiated */) === 0); return unknownType; } function createSymbolTable(symbols) { @@ -10301,7 +10601,7 @@ var ts; if (type.baseTypes.length) { members = createSymbolTable(type.declaredProperties); ts.forEach(type.baseTypes, function (baseType) { - addInheritedMembers(members, getPropertiesOfType(baseType)); + addInheritedMembers(members, getPropertiesOfObjectType(baseType)); callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(baseType, 0 /* Call */)); constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(baseType, 1 /* Construct */)); stringIndexType = stringIndexType || getIndexTypeOfType(baseType, 0 /* String */); @@ -10320,7 +10620,7 @@ var ts; var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined; ts.forEach(target.baseTypes, function (baseType) { var instantiatedBaseType = instantiateType(baseType, mapper); - addInheritedMembers(members, getPropertiesOfType(instantiatedBaseType)); + addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0 /* Call */)); constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1 /* Construct */)); stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0 /* String */); @@ -10365,11 +10665,61 @@ var ts; return members; } function resolveTupleTypeMembers(type) { - var arrayType = resolveObjectTypeMembers(createArrayType(getBestCommonType(type.elementTypes))); + var arrayType = resolveObjectOrUnionTypeMembers(createArrayType(getUnionType(type.elementTypes))); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); } + function signatureListsIdentical(s, t) { + if (s.length !== t.length) { + return false; + } + for (var i = 0; i < s.length; i++) { + if (!compareSignatures(s[i], t[i], false, isTypeIdenticalTo)) { + return false; + } + } + return true; + } + function getUnionSignatures(types, kind) { + var signatureLists = ts.map(types, function (t) { return getSignaturesOfType(t, kind); }); + var signatures = signatureLists[0]; + for (var i = 0; i < signatures.length; i++) { + if (signatures[i].typeParameters) { + return emptyArray; + } + } + for (var i = 1; i < signatureLists.length; i++) { + if (!signatureListsIdentical(signatures, signatureLists[i])) { + return emptyArray; + } + } + var result = ts.map(signatures, cloneSignature); + for (var i = 0; i < result.length; i++) { + var s = result[i]; + s.resolvedReturnType = undefined; + s.unionSignatures = ts.map(signatureLists, function (signatures) { return signatures[i]; }); + } + return result; + } + function getUnionIndexType(types, kind) { + var indexTypes = []; + for (var i = 0; i < types.length; i++) { + var indexType = getIndexTypeOfType(types[i], kind); + if (!indexType) { + return undefined; + } + indexTypes.push(indexType); + } + return getUnionType(indexTypes); + } + function resolveUnionTypeMembers(type) { + var callSignatures = getUnionSignatures(type.types, 0 /* Call */); + var constructSignatures = getUnionSignatures(type.types, 1 /* Construct */); + var stringIndexType = getUnionIndexType(type.types, 0 /* String */); + var numberIndexType = getUnionIndexType(type.types, 1 /* Number */); + setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); + } function resolveAnonymousTypeMembers(type) { var symbol = type.symbol; if (symbol.flags & 512 /* TypeLiteral */) { @@ -10397,7 +10747,7 @@ var ts; } if (classType.baseTypes.length) { members = createSymbolTable(getNamedMembers(members)); - addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); + addInheritedMembers(members, getPropertiesOfObjectType(getTypeOfSymbol(classType.baseTypes[0].symbol))); } } var stringIndexType = undefined; @@ -10405,70 +10755,166 @@ var ts; } setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } - function resolveObjectTypeMembers(type) { + function resolveObjectOrUnionTypeMembers(type) { if (!type.members) { if (type.flags & (1024 /* Class */ | 2048 /* Interface */)) { resolveClassOrInterfaceMembers(type); } - else if (type.flags & 16384 /* Anonymous */) { + else if (type.flags & 32768 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.flags & 8192 /* Tuple */) { resolveTupleTypeMembers(type); } + else if (type.flags & 16384 /* Union */) { + resolveUnionTypeMembers(type); + } else { resolveTypeReferenceMembers(type); } } return type; } - function getPropertiesOfType(type) { + function getPropertiesOfObjectType(type) { if (type.flags & ts.TypeFlags.ObjectType) { - return resolveObjectTypeMembers(type).properties; + return resolveObjectOrUnionTypeMembers(type).properties; } return emptyArray; } + function getPropertyOfObjectType(type, name) { + if (type.flags & ts.TypeFlags.ObjectType) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (ts.hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; + } + } + } + } + function getPropertiesOfUnionType(type) { + var result = []; + ts.forEach(getPropertiesOfType(type.types[0]), function (prop) { + var unionProp = getPropertyOfUnionType(type, prop.name); + if (unionProp) { + result.push(unionProp); + } + }); + return result; + } + function getPropertiesOfType(type) { + if (type.flags & 16384 /* Union */) { + return getPropertiesOfUnionType(type); + } + return getPropertiesOfObjectType(getApparentType(type)); + } + function getApparentType(type) { + if (type.flags & 512 /* TypeParameter */) { + do { + type = getConstraintOfTypeParameter(type); + } while (type && type.flags & 512 /* TypeParameter */); + if (!type) { + type = emptyObjectType; + } + } + if (type.flags & ts.TypeFlags.StringLike) { + type = globalStringType; + } + else if (type.flags & ts.TypeFlags.NumberLike) { + type = globalNumberType; + } + else if (type.flags & 8 /* Boolean */) { + type = globalBooleanType; + } + return type; + } + function createUnionProperty(unionType, name) { + var types = unionType.types; + var props; + for (var i = 0; i < types.length; i++) { + var type = getApparentType(types[i]); + if (type !== unknownType) { + var prop = getPropertyOfType(type, name); + if (!prop) { + return undefined; + } + if (!props) { + props = [prop]; + } + else { + props.push(prop); + } + } + } + var propTypes = []; + var declarations = []; + for (var i = 0; i < props.length; i++) { + var prop = props[i]; + if (prop.declarations) { + declarations.push.apply(declarations, prop.declarations); + } + propTypes.push(getTypeOfSymbol(prop)); + } + var result = createSymbol(2 /* Property */ | 33554432 /* Transient */ | 134217728 /* UnionProperty */, name); + result.unionType = unionType; + result.declarations = declarations; + result.type = getUnionType(propTypes); + return result; + } + function getPropertyOfUnionType(type, name) { + var properties = type.resolvedProperties || (type.resolvedProperties = {}); + if (ts.hasProperty(properties, name)) { + return properties[name]; + } + var property = createUnionProperty(type, name); + if (property) { + properties[name] = property; + } + return property; + } function getPropertyOfType(type, name) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (ts.hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + if (type.flags & 16384 /* Union */) { + return getPropertyOfUnionType(type, name); + } + if (!(type.flags & ts.TypeFlags.ObjectType)) { + type = getApparentType(type); + if (!(type.flags & ts.TypeFlags.ObjectType)) { + return undefined; } } - } - function getPropertyOfApparentType(type, name) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (ts.hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + var resolved = resolveObjectOrUnionTypeMembers(type); + if (ts.hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; } - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - var symbol = getPropertyOfType(globalFunctionType, name); - if (symbol) - return symbol; - } - return getPropertyOfType(globalObjectType, name); } + if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { + var symbol = getPropertyOfObjectType(globalFunctionType, name); + if (symbol) + return symbol; + } + return getPropertyOfObjectType(globalObjectType, name); } - function getSignaturesOfType(type, kind) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + function getSignaturesOfObjectOrUnionType(type, kind) { + if (type.flags & (ts.TypeFlags.ObjectType | 16384 /* Union */)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === 0 /* Call */ ? resolved.callSignatures : resolved.constructSignatures; } return emptyArray; } - function getIndexTypeOfType(type, kind) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + function getSignaturesOfType(type, kind) { + return getSignaturesOfObjectOrUnionType(getApparentType(type), kind); + } + function getIndexTypeOfObjectOrUnionType(type, kind) { + if (type.flags & (ts.TypeFlags.ObjectType | 16384 /* Union */)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === 0 /* String */ ? resolved.stringIndexType : resolved.numberIndexType; } } + function getIndexTypeOfType(type, kind) { + return getIndexTypeOfObjectOrUnionType(getApparentType(type), kind); + } function getTypeParametersFromDeclaration(typeParameterDeclarations) { var result = []; ts.forEach(typeParameterDeclarations, function (node) { @@ -10529,7 +10975,7 @@ var ts; for (var i = 0, len = symbol.declarations.length; i < len; i++) { var node = symbol.declarations[i]; switch (node.kind) { - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: case 121 /* Constructor */: case 124 /* CallSignature */: @@ -10537,8 +10983,8 @@ var ts; case 126 /* IndexSignature */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: if (i > 0 && node.body) { var previous = symbol.declarations[i - 1]; if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) { @@ -10556,6 +11002,9 @@ var ts; if (signature.target) { var type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper); } + else if (signature.unionSignatures) { + var type = getUnionType(ts.map(signature.unionSignatures, getReturnTypeOfSignature)); + } else { var type = getReturnTypeFromBody(signature.declaration); } @@ -10605,7 +11054,7 @@ var ts; function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 121 /* Constructor */ || signature.declaration.kind === 125 /* ConstructSignature */; - var type = createObjectType(16384 /* Anonymous */ | 32768 /* FromSignature */); + var type = createObjectType(32768 /* Anonymous */ | 65536 /* FromSignature */); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -10756,9 +11205,9 @@ var ts; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; switch (declaration.kind) { - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: return declaration; } } @@ -10810,10 +11259,98 @@ var ts; } return links.resolvedType; } + function addTypeToSortedSet(sortedSet, type) { + if (type.flags & 16384 /* Union */) { + addTypesToSortedSet(sortedSet, type.types); + } + else { + var i = 0; + var id = type.id; + while (i < sortedSet.length && sortedSet[i].id < id) { + i++; + } + if (i === sortedSet.length || sortedSet[i].id !== id) { + sortedSet.splice(i, 0, type); + } + } + } + function addTypesToSortedSet(sortedTypes, types) { + for (var i = 0, len = types.length; i < len; i++) { + addTypeToSortedSet(sortedTypes, types[i]); + } + } + function isSubtypeOfAny(candidate, types) { + for (var i = 0, len = types.length; i < len; i++) { + if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) { + return true; + } + } + return false; + } + function removeSubtypes(types) { + var i = types.length; + while (i > 0) { + i--; + if (isSubtypeOfAny(types[i], types)) { + types.splice(i, 1); + } + } + } + function containsAnyType(types) { + for (var i = 0; i < types.length; i++) { + if (types[i].flags & 1 /* Any */) { + return true; + } + } + return false; + } + function removeAllButLast(types, typeToRemove) { + var i = types.length; + while (i > 0 && types.length > 1) { + i--; + if (types[i] === typeToRemove) { + types.splice(i, 1); + } + } + } + function getUnionType(types, noSubtypeReduction) { + if (types.length === 0) { + return emptyObjectType; + } + var sortedTypes = []; + addTypesToSortedSet(sortedTypes, types); + if (noSubtypeReduction) { + if (containsAnyType(sortedTypes)) { + return anyType; + } + removeAllButLast(sortedTypes, undefinedType); + removeAllButLast(sortedTypes, nullType); + } + else { + removeSubtypes(sortedTypes); + } + if (sortedTypes.length === 1) { + return sortedTypes[0]; + } + var id = getTypeListId(sortedTypes); + var type = unionTypes[id]; + if (!type) { + type = unionTypes[id] = createObjectType(16384 /* Union */); + type.types = sortedTypes; + } + return type; + } + function getTypeFromUnionTypeNode(node) { + var links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getUnionType(ts.map(node.types, getTypeFromTypeNode), true); + } + return links.resolvedType; + } function getTypeFromTypeLiteralNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = createObjectType(16384 /* Anonymous */, node.symbol); + links.resolvedType = createObjectType(32768 /* Anonymous */, node.symbol); } return links.resolvedType; } @@ -10821,7 +11358,7 @@ var ts; if (ts.hasProperty(stringLiteralTypes, node.text)) return stringLiteralTypes[node.text]; var type = stringLiteralTypes[node.text] = createType(256 /* StringLiteral */); - type.text = ts.getSourceTextOfNode(node); + type.text = ts.getTextOfNode(node); return type; } function getTypeFromStringLiteral(node) { @@ -10853,6 +11390,10 @@ var ts; return getTypeFromArrayTypeNode(node); case 131 /* TupleType */: return getTypeFromTupleTypeNode(node); + case 132 /* UnionType */: + return getTypeFromUnionTypeNode(node); + case 133 /* ParenType */: + return getTypeFromTypeNode(node.type); case 129 /* TypeLiteral */: return getTypeFromTypeLiteralNode(node); case 59 /* Identifier */: @@ -10959,7 +11500,7 @@ var ts; symbol = links.target; mapper = combineTypeMappers(links.mapper, mapper); } - var result = createSymbol(8388608 /* Instantiated */ | 33554432 /* Transient */, symbol.name); + var result = createSymbol(8388608 /* Instantiated */ | 33554432 /* Transient */ | symbol.flags, symbol.name); result.declarations = symbol.declarations; result.parent = symbol.parent; result.target = symbol; @@ -10970,8 +11511,8 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - var result = createObjectType(16384 /* Anonymous */, type.symbol); - result.properties = instantiateList(getPropertiesOfType(type), mapper, instantiateSymbol); + var result = createObjectType(32768 /* Anonymous */, type.symbol); + result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0 /* Call */), mapper, instantiateSignature); result.constructSignatures = instantiateList(getSignaturesOfType(type, 1 /* Construct */), mapper, instantiateSignature); @@ -10988,7 +11529,7 @@ var ts; if (type.flags & 512 /* TypeParameter */) { return mapper(type); } - if (type.flags & 16384 /* Anonymous */) { + if (type.flags & 32768 /* Anonymous */) { return type.symbol && type.symbol.flags & (8 /* Function */ | 2048 /* Method */ | 512 /* TypeLiteral */ | 1024 /* ObjectLiteral */) ? instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096 /* Reference */) { @@ -10997,30 +11538,33 @@ var ts; if (type.flags & 8192 /* Tuple */) { return createTupleType(instantiateList(type.elementTypes, mapper, instantiateType)); } + if (type.flags & 16384 /* Union */) { + return getUnionType(instantiateList(type.types, mapper, instantiateType), true); + } } return type; } function isContextSensitiveExpression(node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return !node.typeParameters && !ts.forEach(node.parameters, function (p) { return p.type; }); - case 133 /* ObjectLiteral */: - return ts.forEach(node.properties, function (p) { return p.kind === 134 /* PropertyAssignment */ && isContextSensitiveExpression(p.initializer); }); - case 132 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + return ts.forEach(node.properties, function (p) { return p.kind === 136 /* PropertyAssignment */ && isContextSensitiveExpression(p.initializer); }); + case 134 /* ArrayLiteral */: return ts.forEach(node.elements, function (e) { return isContextSensitiveExpression(e); }); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return isContextSensitiveExpression(node.whenTrue) || isContextSensitiveExpression(node.whenFalse); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return node.operator === 44 /* BarBarToken */ && (isContextSensitiveExpression(node.left) || isContextSensitiveExpression(node.right)); } return false; } function getTypeWithoutConstructors(type) { if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.constructSignatures.length) { - var result = createObjectType(16384 /* Anonymous */, type.symbol); + var result = createObjectType(32768 /* Anonymous */, type.symbol); result.members = resolved.members; result.properties = resolved.properties; result.callSignatures = resolved.callSignatures; @@ -11070,7 +11614,7 @@ var ts; var ok = true; for (var i = 0, len = type.baseTypes.length; i < len; ++i) { var base = type.baseTypes[i]; - var properties = getPropertiesOfType(base); + var properties = getPropertiesOfObjectType(base); for (var j = 0, proplen = properties.length; j < proplen; ++j) { var prop = properties[j]; if (!ts.hasProperty(seen, prop.name)) { @@ -11155,7 +11699,17 @@ var ts; return true; } } - if (source.flags & 512 /* TypeParameter */ && target.flags & 512 /* TypeParameter */) { + if (source.flags & 16384 /* Union */) { + if (unionTypeRelatedToType(source, target, reportErrors)) { + return true; + } + } + else if (target.flags & 16384 /* Union */) { + if (typeRelatedToUnionType(source, target, reportErrors)) { + return true; + } + } + else if (source.flags & 512 /* TypeParameter */ && target.flags & 512 /* TypeParameter */) { if (typeParameterRelatedTo(source, target, reportErrors)) { return true; } @@ -11183,6 +11737,24 @@ var ts; } return false; } + function typeRelatedToUnionType(source, target, reportErrors) { + var targetTypes = target.types; + for (var i = 0, len = targetTypes.length; i < len; i++) { + if (isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1)) { + return true; + } + } + return false; + } + function unionTypeRelatedToType(source, target, reportErrors) { + var sourceTypes = source.types; + for (var i = 0, len = sourceTypes.length; i < len; i++) { + if (!isRelatedTo(sourceTypes[i], target, reportErrors)) { + return false; + } + } + return true; + } function typesRelatedTo(sources, targets, reportErrors) { for (var i = 0, len = sources.length; i < len; i++) { if (!isRelatedTo(sources[i], targets[i], reportErrors)) @@ -11270,35 +11842,15 @@ var ts; } function propertiesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return propertiesAreIdenticalTo(source, target, reportErrors); + return propertiesIdenticalTo(source, target, reportErrors); } - else { - return propertiesAreSubtypeOrAssignableTo(source, target, reportErrors); - } - } - function propertiesAreIdenticalTo(source, target, reportErrors) { - var sourceProperties = getPropertiesOfType(source); - var targetProperties = getPropertiesOfType(target); - if (sourceProperties.length !== targetProperties.length) { - return false; - } - for (var i = 0, len = sourceProperties.length; i < len; ++i) { - var sourceProp = sourceProperties[i]; - var targetProp = getPropertyOfType(target, sourceProp.name); - if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { - return false; - } - } - return true; - } - function propertiesAreSubtypeOrAssignableTo(source, target, reportErrors) { - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfApparentType(source, targetProp.name); + var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { - if (!isOptionalProperty(targetProp)) { + if (relation === subtypeRelation || !isOptionalProperty(targetProp)) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } @@ -11355,67 +11907,25 @@ var ts; } return true; } - function signaturesRelatedTo(source, target, kind, reportErrors) { - if (relation === identityRelation) { - return areSignaturesIdenticalTo(source, target, kind, reportErrors); - } - else { - return areSignaturesSubtypeOrAssignableTo(source, target, kind, reportErrors); - } - } - function areSignaturesIdenticalTo(source, target, kind, reportErrors) { - var sourceSignatures = getSignaturesOfType(source, kind); - var targetSignatures = getSignaturesOfType(target, kind); - if (sourceSignatures.length !== targetSignatures.length) { + function propertiesIdenticalTo(source, target, reportErrors) { + var sourceProperties = getPropertiesOfObjectType(source); + var targetProperties = getPropertiesOfObjectType(target); + if (sourceProperties.length !== targetProperties.length) { return false; } - for (var i = 0, len = sourceSignatures.length; i < len; ++i) { - if (!isSignatureIdenticalTo(sourceSignatures[i], targetSignatures[i], reportErrors)) { + for (var i = 0, len = sourceProperties.length; i < len; ++i) { + var sourceProp = sourceProperties[i]; + var targetProp = getPropertyOfObjectType(target, sourceProp.name); + if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { return false; } } return true; } - function isSignatureIdenticalTo(source, target, reportErrors) { - if (source === target) { - return true; + function signaturesRelatedTo(source, target, kind, reportErrors) { + if (relation === identityRelation) { + return signaturesIdenticalTo(source, target, kind, reportErrors); } - if (source.hasRestParameter !== target.hasRestParameter) { - return false; - } - if (source.parameters.length !== target.parameters.length) { - return false; - } - if (source.minArgumentCount !== target.minArgumentCount) { - return false; - } - if (source.typeParameters && target.typeParameters) { - if (source.typeParameters.length !== target.typeParameters.length) { - return false; - } - for (var i = 0, len = source.typeParameters.length; i < len; ++i) { - if (!isRelatedTo(source.typeParameters[i], target.typeParameters[i], reportErrors)) { - return false; - } - } - } - else if (source.typeParameters || source.typeParameters) { - return false; - } - source = getErasedSignature(source); - target = getErasedSignature(target); - for (var i = 0, len = source.parameters.length; i < len; i++) { - var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); - var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); - if (!isRelatedTo(s, t, reportErrors)) { - return false; - } - } - var t = getReturnTypeOfSignature(target); - var s = getReturnTypeOfSignature(source); - return isRelatedTo(s, t, reportErrors); - } - function areSignaturesSubtypeOrAssignableTo(source, target, kind, reportErrors) { if (target === anyFunctionType || source === anyFunctionType) return true; var sourceSignatures = getSignaturesOfType(source, kind); @@ -11423,12 +11933,12 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var i = 0; i < targetSignatures.length; i++) { var t = targetSignatures[i]; - if (!t.hasStringLiterals || target.flags & 32768 /* FromSignature */) { + if (!t.hasStringLiterals || target.flags & 65536 /* FromSignature */) { var localErrors = reportErrors; for (var j = 0; j < sourceSignatures.length; j++) { var s = sourceSignatures[j]; - if (!s.hasStringLiterals || source.flags & 32768 /* FromSignature */) { - if (isSignatureSubtypeOrAssignableTo(s, t, localErrors)) { + if (!s.hasStringLiterals || source.flags & 65536 /* FromSignature */) { + if (signatureRelatedTo(s, t, localErrors)) { errorInfo = saveErrorInfo; continue outer; } @@ -11440,7 +11950,7 @@ var ts; } return true; } - function isSignatureSubtypeOrAssignableTo(source, target, reportErrors) { + function signatureRelatedTo(source, target, reportErrors) { if (source === target) { return true; } @@ -11488,67 +11998,107 @@ var ts; var s = getReturnTypeOfSignature(source); return isRelatedTo(s, t, reportErrors); } + function signaturesIdenticalTo(source, target, kind, reportErrors) { + var sourceSignatures = getSignaturesOfType(source, kind); + var targetSignatures = getSignaturesOfType(target, kind); + if (sourceSignatures.length !== targetSignatures.length) { + return false; + } + for (var i = 0, len = sourceSignatures.length; i < len; ++i) { + if (!compareSignatures(sourceSignatures[i], targetSignatures[i], true, isRelatedTo)) { + return false; + } + } + return true; + } function stringIndexTypesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(0 /* String */, source, target, reportErrors); + return indexTypesIdenticalTo(0 /* String */, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, 0 /* String */); - if (targetType) { - var sourceType = getIndexTypeOfType(source, 0 /* String */); - if (!sourceType) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return false; - } - if (!isRelatedTo(sourceType, targetType, reportErrors)) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, 0 /* String */); + if (targetType) { + var sourceType = getIndexTypeOfType(source, 0 /* String */); + if (!sourceType) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return false; + } + if (!isRelatedTo(sourceType, targetType, reportErrors)) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } function numberIndexTypesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(1 /* Number */, source, target, reportErrors); + return indexTypesIdenticalTo(1 /* Number */, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, 1 /* Number */); - if (targetType) { - var sourceStringType = getIndexTypeOfType(source, 0 /* String */); - var sourceNumberType = getIndexTypeOfType(source, 1 /* Number */); - if (!(sourceStringType || sourceNumberType)) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return false; - } - if (sourceStringType && sourceNumberType) { - var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); - } - else { - var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); - } - if (!compatible) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, 1 /* Number */); + if (targetType) { + var sourceStringType = getIndexTypeOfType(source, 0 /* String */); + var sourceNumberType = getIndexTypeOfType(source, 1 /* Number */); + if (!(sourceStringType || sourceNumberType)) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return false; + } + if (sourceStringType && sourceNumberType) { + var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); + } + else { + var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); + } + if (!compatible) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } - function areIndexTypesIdenticalTo(indexKind, source, target, reportErrors) { + function indexTypesIdenticalTo(indexKind, source, target, reportErrors) { var targetType = getIndexTypeOfType(target, indexKind); var sourceType = getIndexTypeOfType(source, indexKind); return (!sourceType && !targetType) || (sourceType && targetType && isRelatedTo(sourceType, targetType, reportErrors)); } } + function compareSignatures(source, target, compareReturnTypes, compareTypes) { + if (source === target) { + return true; + } + if (source.parameters.length !== target.parameters.length || source.minArgumentCount !== target.minArgumentCount || source.hasRestParameter !== target.hasRestParameter) { + return false; + } + if (source.typeParameters && target.typeParameters) { + if (source.typeParameters.length !== target.typeParameters.length) { + return false; + } + for (var i = 0, len = source.typeParameters.length; i < len; ++i) { + if (!compareTypes(source.typeParameters[i], target.typeParameters[i])) { + return false; + } + } + } + else if (source.typeParameters || source.typeParameters) { + return false; + } + source = getErasedSignature(source); + target = getErasedSignature(target); + for (var i = 0, len = source.parameters.length; i < len; i++) { + var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); + var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); + if (!compareTypes(s, t)) { + return false; + } + } + return !compareReturnTypes || compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + } function isSupertypeOfEach(candidate, types) { for (var i = 0, len = types.length; i < len; i++) { if (candidate !== types[i] && !isTypeSubtypeOf(types[i], candidate)) @@ -11556,13 +12106,11 @@ var ts; } return true; } - function getBestCommonType(types, contextualType, candidatesOnly) { - if (contextualType && isSupertypeOfEach(contextualType, types)) - return contextualType; - return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; }) || (candidatesOnly ? undefined : emptyObjectType); + function getCommonSupertype(types) { + return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; }); } function isTypeOfObjectLiteral(type) { - return (type.flags & 16384 /* Anonymous */) && type.symbol && (type.symbol.flags & 1024 /* ObjectLiteral */) ? true : false; + return (type.flags & 32768 /* Anonymous */) && type.symbol && (type.symbol.flags & 1024 /* ObjectLiteral */) ? true : false; } function isArrayType(type) { return type.flags & 4096 /* Reference */ && type.target === globalArrayType; @@ -11573,10 +12121,13 @@ var ts; } return type; } - function getWidenedType(type, supressNoImplicitAnyErrors) { + function getWidenedType(type, suppressNoImplicitAnyErrors) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } + if (type.flags & 16384 /* Union */) { + return getWidenedTypeOfUnion(type); + } if (isTypeOfObjectLiteral(type)) { return getWidenedTypeOfObjectLiteral(type); } @@ -11584,8 +12135,11 @@ var ts; return getWidenedTypeOfArrayLiteral(type); } return type; + function getWidenedTypeOfUnion(type) { + return getUnionType(ts.map(type.types, function (t) { return getWidenedType(t, suppressNoImplicitAnyErrors); })); + } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfType(type); + var properties = getPropertiesOfObjectType(type); if (properties.length) { var widenedTypes = []; var propTypeWasWidened = false; @@ -11594,7 +12148,7 @@ var ts; var widenedType = getWidenedType(propType); if (propType !== widenedType) { propTypeWasWidened = true; - if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (!suppressNoImplicitAnyErrors && compilerOptions.noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); } } @@ -11604,7 +12158,7 @@ var ts; var members = {}; var index = 0; ts.forEach(properties, function (p) { - var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, p.name); + var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */ | p.flags, p.name); symbol.declarations = p.declarations; symbol.parent = p.parent; symbol.type = widenedTypes[index++]; @@ -11626,7 +12180,7 @@ var ts; } function getWidenedTypeOfArrayLiteral(type) { var elementType = type.typeArguments[0]; - var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors); + var widenedType = getWidenedType(elementType, suppressNoImplicitAnyErrors); type = elementType !== widenedType ? createArrayType(widenedType) : type; return type; } @@ -11657,12 +12211,14 @@ var ts; callback(s, t); } } - function createInferenceContext(typeParameters) { + function createInferenceContext(typeParameters, inferUnionTypes) { var inferences = []; for (var i = 0; i < typeParameters.length; i++) inferences.push([]); return { typeParameters: typeParameters, + inferUnionTypes: inferUnionTypes, + inferenceCount: 0, inferences: inferences, inferredTypes: new Array(typeParameters.length) }; @@ -11697,6 +12253,7 @@ var ts; var typeParameters = context.typeParameters; for (var i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { + context.inferenceCount++; var inferences = context.inferences[i]; if (!ts.contains(inferences, source)) inferences.push(source); @@ -11711,7 +12268,32 @@ var ts; inferFromTypes(sourceTypes[i], targetTypes[i]); } } - else if (source.flags & ts.TypeFlags.ObjectType && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || (target.flags & 16384 /* Anonymous */) && target.symbol && target.symbol.flags & (2048 /* Method */ | 512 /* TypeLiteral */))) { + else if (target.flags & 16384 /* Union */) { + var targetTypes = target.types; + var startCount = context.inferenceCount; + var typeParameterCount = 0; + var typeParameter; + for (var i = 0; i < targetTypes.length; i++) { + var t = targetTypes[i]; + if (t.flags & 512 /* TypeParameter */ && ts.contains(context.typeParameters, t)) { + typeParameter = t; + typeParameterCount++; + } + else { + inferFromTypes(source, t); + } + } + if (context.inferenceCount === startCount && typeParameterCount === 1) { + inferFromTypes(source, typeParameter); + } + } + else if (source.flags & 16384 /* Union */) { + var sourceTypes = source.types; + for (var i = 0; i < sourceTypes.length; i++) { + inferFromTypes(sourceTypes[i], target); + } + } + else if (source.flags & ts.TypeFlags.ObjectType && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || (target.flags & 32768 /* Anonymous */) && target.symbol && target.symbol.flags & (2048 /* Method */ | 512 /* TypeLiteral */))) { if (!isInProcess(source, target) && isWithinDepthLimit(source, sourceStack) && isWithinDepthLimit(target, targetStack)) { if (depth === 0) { sourceStack = []; @@ -11731,10 +12313,10 @@ var ts; } } function inferFromProperties(source, target) { - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfType(source, targetProp.name); + var sourceProp = getPropertyOfObjectType(source, targetProp.name); if (sourceProp) { inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } @@ -11767,9 +12349,16 @@ var ts; function getInferredType(context, index) { var result = context.inferredTypes[index]; if (!result) { - var commonType = getWidenedType(getBestCommonType(context.inferences[index])); + var inferences = context.inferences[index]; + if (inferences.length) { + var unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences); + var inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : undefinedType; + } + else { + inferredType = emptyObjectType; + } var constraint = getConstraintOfTypeParameter(context.typeParameters[index]); - var result = constraint && !isTypeAssignableTo(commonType, constraint) ? constraint : commonType; + var result = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType; context.inferredTypes[index] = result; } return result; @@ -11784,37 +12373,244 @@ var ts; function hasAncestor(node, kind) { return ts.getAncestor(node, kind) !== undefined; } - function checkIdentifier(node) { - function isInTypeQuery(node) { - while (node) { - switch (node.kind) { - case 128 /* TypeQuery */: - return true; - case 59 /* Identifier */: - case 116 /* QualifiedName */: - node = node.parent; - continue; - default: - return false; + function getResolvedSymbol(node) { + var links = getNodeLinks(node); + if (!links.resolvedSymbol) { + links.resolvedSymbol = resolveName(node, node.text, ts.SymbolFlags.Value | 524288 /* ExportValue */, ts.Diagnostics.Cannot_find_name_0, ts.identifierToString(node)) || unknownSymbol; + } + return links.resolvedSymbol; + } + function isInTypeQuery(node) { + while (node) { + switch (node.kind) { + case 128 /* TypeQuery */: + return true; + case 59 /* Identifier */: + case 116 /* QualifiedName */: + node = node.parent; + continue; + default: + return false; + } + } + ts.Debug.fail("should not get here"); + } + function subtractPrimitiveTypes(type, subtractMask) { + if (type.flags & 16384 /* Union */) { + var types = type.types; + if (ts.forEach(types, function (t) { return t.flags & subtractMask; })) { + return getUnionType(ts.filter(types, function (t) { return !(t.flags & subtractMask); })); + } + } + return type; + } + function isVariableAssignedWithin(symbol, node) { + var links = getNodeLinks(node); + if (links.assignmentChecks) { + var cachedResult = links.assignmentChecks[symbol.id]; + if (cachedResult !== undefined) { + return cachedResult; + } + } + else { + links.assignmentChecks = {}; + } + return links.assignmentChecks[symbol.id] = isAssignedIn(node); + function isAssignedInBinaryExpression(node) { + if (node.operator >= ts.SyntaxKind.FirstAssignment && node.operator <= ts.SyntaxKind.LastAssignment) { + var n = node.left; + while (n.kind === 142 /* ParenExpression */) { + n = n.expression; + } + if (n.kind === 59 /* Identifier */ && getResolvedSymbol(n) === symbol) { + return true; } } - ts.Debug.fail("should not get here"); + return ts.forEachChild(node, isAssignedIn); } - var symbol = resolveName(node, node.text, ts.SymbolFlags.Value | 524288 /* ExportValue */, ts.Diagnostics.Cannot_find_name_0, ts.identifierToString(node)); - if (!symbol) { - symbol = unknownSymbol; + function isAssignedInVariableDeclaration(node) { + if (getSymbolOfNode(node) === symbol && node.initializer) { + return true; + } + return ts.forEachChild(node, isAssignedIn); } + function isAssignedIn(node) { + switch (node.kind) { + case 147 /* BinaryExpression */: + return isAssignedInBinaryExpression(node); + case 173 /* VariableDeclaration */: + return isAssignedInVariableDeclaration(node); + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 148 /* ConditionalExpression */: + case 150 /* Block */: + case 151 /* VariableStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 161 /* ReturnStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 167 /* ThrowStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + return ts.forEachChild(node, isAssignedIn); + } + return false; + } + } + function getNarrowedTypeOfSymbol(symbol, node) { + var type = getTypeOfSymbol(symbol); + if (symbol.flags & 1 /* Variable */ && type.flags & ts.TypeFlags.Structured) { + while (true) { + var child = node; + node = node.parent; + if (!node || node.kind === 175 /* FunctionBlock */ || node.kind === 180 /* ModuleBlock */) { + break; + } + var narrowedType = type; + switch (node.kind) { + case 154 /* IfStatement */: + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); + } + break; + case 148 /* ConditionalExpression */: + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); + } + break; + case 147 /* BinaryExpression */: + if (child === node.right) { + if (node.operator === 43 /* AmpersandAmpersandToken */) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operator === 44 /* BarBarToken */) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + } + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; + } + } + } + return type; + function narrowTypeByEquality(type, expr, assumeTrue) { + var left = expr.left; + var right = expr.right; + if (left.kind !== 145 /* PrefixOperator */ || left.operator !== 91 /* TypeOfKeyword */ || left.operand.kind !== 59 /* Identifier */ || right.kind !== 7 /* StringLiteral */ || getResolvedSymbol(left.operand) !== symbol) { + return type; + } + var t = right.text; + var checkType = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType; + if (expr.operator === 26 /* ExclamationEqualsEqualsToken */) { + assumeTrue = !assumeTrue; + } + if (assumeTrue) { + return checkType === emptyObjectType ? subtractPrimitiveTypes(type, 2 /* String */ | 4 /* Number */ | 8 /* Boolean */) : checkType; + } + else { + return checkType === emptyObjectType ? type : subtractPrimitiveTypes(type, checkType.flags); + } + } + function narrowTypeByAnd(type, expr, assumeTrue) { + if (assumeTrue) { + return narrowType(narrowType(type, expr.left, true), expr.right, true); + } + else { + return getUnionType([ + narrowType(type, expr.left, false), + narrowType(narrowType(type, expr.left, true), expr.right, false) + ]); + } + } + function narrowTypeByOr(type, expr, assumeTrue) { + if (assumeTrue) { + return getUnionType([ + narrowType(type, expr.left, true), + narrowType(narrowType(type, expr.left, false), expr.right, true) + ]); + } + else { + return narrowType(narrowType(type, expr.left, false), expr.right, false); + } + } + function narrowTypeByInstanceof(type, expr, assumeTrue) { + if (!assumeTrue || expr.left.kind !== 59 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + return type; + } + var rightType = checkExpression(expr.right); + if (!isTypeSubtypeOf(rightType, globalFunctionType)) { + return type; + } + var prototypeProperty = getPropertyOfType(rightType, "prototype"); + if (!prototypeProperty) { + return type; + } + var prototypeType = getTypeOfSymbol(prototypeProperty); + return isTypeSubtypeOf(prototypeType, type) ? prototypeType : type; + } + function narrowType(type, expr, assumeTrue) { + switch (expr.kind) { + case 142 /* ParenExpression */: + return narrowType(type, expr.expression, assumeTrue); + case 147 /* BinaryExpression */: + var operator = expr.operator; + if (operator === 25 /* EqualsEqualsEqualsToken */ || operator === 26 /* ExclamationEqualsEqualsToken */) { + return narrowTypeByEquality(type, expr, assumeTrue); + } + else if (operator === 43 /* AmpersandAmpersandToken */) { + return narrowTypeByAnd(type, expr, assumeTrue); + } + else if (operator === 44 /* BarBarToken */) { + return narrowTypeByOr(type, expr, assumeTrue); + } + else if (operator === 81 /* InstanceOfKeyword */) { + return narrowTypeByInstanceof(type, expr, assumeTrue); + } + break; + case 145 /* PrefixOperator */: + if (expr.operator === 41 /* ExclamationToken */) { + return narrowType(type, expr.operand, !assumeTrue); + } + break; + } + return type; + } + } + function checkIdentifier(node) { + var symbol = getResolvedSymbol(node); if (symbol.flags & 4194304 /* Import */) { getSymbolLinks(symbol).referenced = !isInTypeQuery(node); } - getNodeLinks(node).resolvedSymbol = symbol; checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); checkCollisionWithIndexVariableInGeneratedCode(node, node); - return getTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol)); + return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } function captureLexicalThis(node, container) { - var classNode = container.parent && container.parent.kind === 174 /* ClassDeclaration */ ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 176 /* ClassDeclaration */ ? container.parent : undefined; getNodeLinks(node).flags |= 2 /* LexicalThis */; if (container.kind === 119 /* Property */ || container.kind === 121 /* Constructor */) { getNodeLinks(classNode).flags |= 4 /* CaptureThis */; @@ -11826,15 +12622,15 @@ var ts; function checkThisExpression(node) { var container = ts.getThisContainer(node, true); var needToCaptureLexicalThis = false; - if (container.kind === 142 /* ArrowFunction */) { + if (container.kind === 144 /* ArrowFunction */) { container = ts.getThisContainer(container, false); needToCaptureLexicalThis = true; } switch (container.kind) { - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_body); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location); break; case 121 /* Constructor */: @@ -11851,7 +12647,7 @@ var ts; if (needToCaptureLexicalThis) { captureLexicalThis(node, container); } - var classNode = container.parent && container.parent.kind === 174 /* ClassDeclaration */ ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 176 /* ClassDeclaration */ ? container.parent : undefined; if (classNode) { var symbol = getSymbolOfNode(classNode); return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); @@ -11864,9 +12660,9 @@ var ts; if (!node) return node; switch (node.kind) { - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: case 119 /* Property */: case 120 /* Method */: case 121 /* Constructor */: @@ -11885,8 +12681,8 @@ var ts; return false; } function checkSuperExpression(node) { - var isCallExpression = node.parent.kind === 137 /* CallExpression */ && node.parent.func === node; - var enclosingClass = ts.getAncestor(node, 174 /* ClassDeclaration */); + var isCallExpression = node.parent.kind === 139 /* CallExpression */ && node.parent.func === node; + var enclosingClass = ts.getAncestor(node, 176 /* ClassDeclaration */); var baseClass; if (enclosingClass && enclosingClass.baseType) { var classType = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass)); @@ -11904,11 +12700,11 @@ var ts; } else { var needToCaptureLexicalThis = false; - while (container && container.kind === 142 /* ArrowFunction */) { + while (container && container.kind === 144 /* ArrowFunction */) { container = getSuperContainer(container); needToCaptureLexicalThis = true; } - if (container && container.parent && container.parent.kind === 174 /* ClassDeclaration */) { + if (container && container.parent && container.parent.kind === 176 /* ClassDeclaration */) { if (container.flags & 128 /* Static */) { canUseSuperExpression = container.kind === 120 /* Method */ || container.kind === 122 /* GetAccessor */ || container.kind === 123 /* SetAccessor */; } @@ -11947,11 +12743,19 @@ var ts; } function getContextuallyTypedParameterType(parameter) { var func = parameter.parent; - if (func.kind === 141 /* FunctionExpression */ || func.kind === 142 /* ArrowFunction */) { + if (func.kind === 143 /* FunctionExpression */ || func.kind === 144 /* ArrowFunction */) { if (isContextSensitiveExpression(func)) { - var signature = getContextualSignature(func); - if (signature) { - return getTypeAtPosition(signature, ts.indexOf(func.parameters, parameter)); + var contextualSignature = getContextualSignature(func); + if (contextualSignature) { + var funcHasRestParameters = ts.hasRestParameters(func); + var len = func.parameters.length - (funcHasRestParameters ? 1 : 0); + var indexOfParameter = ts.indexOf(func.parameters, parameter); + if (indexOfParameter < len) { + return getTypeAtPosition(contextualSignature, indexOfParameter); + } + if (indexOfParameter === (func.parameters.length - 1) && funcHasRestParameters && contextualSignature.hasRestParameter && func.parameters.length >= contextualSignature.parameters.length) { + return getTypeOfSymbol(contextualSignature.parameters[contextualSignature.parameters.length - 1]); + } } } } @@ -12008,17 +12812,51 @@ var ts; } return undefined; } + function applyToContextualType(type, mapper) { + if (!(type.flags & 16384 /* Union */)) { + return mapper(type); + } + var types = type.types; + var mappedType; + var mappedTypes; + for (var i = 0; i < types.length; i++) { + var t = mapper(types[i]); + if (t) { + if (!mappedType) { + mappedType = t; + } + else if (!mappedTypes) { + mappedTypes = [mappedType, t]; + } + else { + mappedTypes.push(t); + } + } + } + return mappedTypes ? getUnionType(mappedTypes) : mappedType; + } + function getTypeOfPropertyOfContextualType(type, name) { + return applyToContextualType(type, function (t) { + var prop = getPropertyOfObjectType(t, name); + return prop ? getTypeOfSymbol(prop) : undefined; + }); + } + function getIndexTypeOfContextualType(type, kind) { + return applyToContextualType(type, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }); + } + function contextualTypeIsTupleType(type) { + return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return getPropertyOfObjectType(t, "0"); }) : getPropertyOfObjectType(type, "0")); + } + function contextualTypeHasIndexSignature(type, kind) { + return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }) : getIndexTypeOfObjectOrUnionType(type, kind)); + } function getContextualTypeForPropertyExpression(node) { var declaration = node.parent; var objectLiteral = declaration.parent; var type = getContextualType(objectLiteral); var name = declaration.name.text; if (type && name) { - var prop = getPropertyOfType(type, name); - if (prop) { - return getTypeOfSymbol(prop); - } - return isNumericName(name) && getIndexTypeOfType(type, 1 /* Number */) || getIndexTypeOfType(type, 0 /* String */); + return getTypeOfPropertyOfContextualType(type, name) || isNumericName(name) && getIndexTypeOfContextualType(type, 1 /* Number */) || getIndexTypeOfContextualType(type, 0 /* String */); } return undefined; } @@ -12027,11 +12865,7 @@ var ts; var type = getContextualType(arrayLiteral); if (type) { var index = ts.indexOf(arrayLiteral.elements, node); - var prop = getPropertyOfType(type, "" + index); - if (prop) { - return getTypeOfSymbol(prop); - } - return getIndexTypeOfType(type, 1 /* Number */); + return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1 /* Number */); } return undefined; } @@ -12048,70 +12882,78 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 118 /* Parameter */: case 119 /* Property */: return getContextualTypeForInitializerExpression(node); - case 142 /* ArrowFunction */: - case 159 /* ReturnStatement */: + case 144 /* ArrowFunction */: + case 161 /* ReturnStatement */: return getContextualTypeForReturnExpression(node); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return getContextualTypeForArgument(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return getTypeFromTypeNode(parent.type); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return getContextualTypeForBinaryOperand(node); - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return getContextualTypeForPropertyExpression(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return getContextualTypeForElementExpression(node); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return getContextualTypeForConditionalOperand(node); } return undefined; } + function getNonGenericSignature(type) { + var signatures = getSignaturesOfObjectOrUnionType(type, 0 /* Call */); + if (signatures.length === 1) { + var signature = signatures[0]; + if (!signature.typeParameters) { + return signature; + } + } + } function getContextualSignature(node) { var type = getContextualType(node); - if (type) { - var signatures = getSignaturesOfType(type, 0 /* Call */); - if (signatures.length === 1) { - var signature = signatures[0]; - if (!signature.typeParameters) { - return signature; + if (!type) { + return undefined; + } + if (!(type.flags & 16384 /* Union */)) { + return getNonGenericSignature(type); + } + var result; + var types = type.types; + for (var i = 0; i < types.length; i++) { + var signature = getNonGenericSignature(types[i]); + if (signature) { + if (!result) { + result = signature; + } + else if (!compareSignatures(result, signature, true, isTypeIdenticalTo)) { + return undefined; } } } - return undefined; + return result; } function isInferentialContext(mapper) { return mapper && mapper !== identityMapper; } function checkArrayLiteral(node, contextualMapper) { - var contextualType = getContextualType(node); var elements = node.elements; - var elementTypes = []; - var isTupleLiteral = false; - for (var i = 0; i < elements.length; i++) { - if (contextualType && getPropertyOfType(contextualType, "" + i)) { - isTupleLiteral = true; - } - var element = elements[i]; - var type = element.kind !== 147 /* OmittedExpression */ ? checkExpression(element, contextualMapper) : undefinedType; - elementTypes.push(type); + if (!elements.length) { + return createArrayType(undefinedType); } - if (isTupleLiteral) { + var elementTypes = ts.map(elements, function (e) { return checkExpression(e, contextualMapper); }); + var contextualType = getContextualType(node); + if (contextualType && contextualTypeIsTupleType(contextualType)) { return createTupleType(elementTypes); } - var contextualElementType = contextualType && !isInferentialContext(contextualMapper) ? getIndexTypeOfType(contextualType, 1 /* Number */) : undefined; - var elementType = getBestCommonType(ts.uniqueElements(elementTypes), contextualElementType, true); - if (!elementType) { - elementType = elements.length ? emptyObjectType : undefinedType; - } - return createArrayType(elementType); + return createArrayType(getUnionType(elementTypes)); } function isNumericName(name) { - return !isNaN(name); + return (+name).toString() === name; } function checkObjectLiteral(node, contextualMapper) { var members = node.symbol.members; @@ -12122,7 +12964,7 @@ var ts; var member = members[id]; if (member.flags & 2 /* Property */) { var type = checkExpression(member.declarations[0].initializer, contextualMapper); - var prop = createSymbol(2 /* Property */ | 33554432 /* Transient */, member.name); + var prop = createSymbol(2 /* Property */ | 33554432 /* Transient */ | member.flags, member.name); prop.declarations = member.declarations; prop.parent = member.parent; if (member.valueDeclaration) @@ -12148,22 +12990,21 @@ var ts; var numberIndexType = getIndexType(1 /* Number */); return createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); function getIndexType(kind) { - if (contextualType) { - var indexType = getIndexTypeOfType(contextualType, kind); - if (indexType) { - var propTypes = []; - for (var id in properties) { - if (ts.hasProperty(properties, id)) { - if (kind === 0 /* String */ || isNumericName(id)) { - var type = getTypeOfSymbol(properties[id]); - if (!ts.contains(propTypes, type)) - propTypes.push(type); + if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { + var propTypes = []; + for (var id in properties) { + if (ts.hasProperty(properties, id)) { + if (kind === 0 /* String */ || isNumericName(id)) { + var type = getTypeOfSymbol(properties[id]); + if (!ts.contains(propTypes, type)) { + propTypes.push(type); } } } - return getBestCommonType(propTypes, isInferentialContext(contextualMapper) ? undefined : indexType); } + return propTypes.length ? getUnionType(propTypes) : undefinedType; } + return undefined; } } function getDeclarationKindFromSymbol(s) { @@ -12177,7 +13018,7 @@ var ts; if (!(flags & (32 /* Private */ | 64 /* Protected */))) { return; } - var enclosingClassDeclaration = ts.getAncestor(node, 174 /* ClassDeclaration */); + var enclosingClassDeclaration = ts.getAncestor(node, 176 /* ClassDeclaration */); var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; var declaringClass = getDeclaredTypeOfSymbol(prop.parent); if (flags & 32 /* Private */) { @@ -12209,7 +13050,7 @@ var ts; if (apparentType === unknownType) { return unknownType; } - var prop = getPropertyOfApparentType(apparentType, node.right.text); + var prop = getPropertyOfType(apparentType, node.right.text); if (!prop) { if (node.right.text) { error(node.right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.identifierToString(node.right), typeToString(type)); @@ -12229,30 +13070,43 @@ var ts; } return anyType; } + function isValidPropertyAccess(node, propertyName) { + var type = checkExpression(node.left); + if (type !== unknownType && type !== anyType) { + var prop = getPropertyOfType(getWidenedType(type), propertyName); + if (prop && prop.parent && prop.parent.flags & 16 /* Class */) { + if (node.left.kind === 85 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 120 /* Method */) { + return false; + } + else { + var diagnosticsCount = diagnostics.length; + checkClassPropertyAccess(node, type, prop); + return diagnostics.length === diagnosticsCount; + } + } + } + return true; + } function checkIndexedAccess(node) { - var objectType = checkExpression(node.object); + var objectType = getApparentType(checkExpression(node.object)); var indexType = checkExpression(node.index); if (objectType === unknownType) return unknownType; - var apparentType = getApparentType(objectType); - if (apparentType === unknownType) { - return unknownType; - } if (node.index.kind === 7 /* StringLiteral */ || node.index.kind === 6 /* NumericLiteral */) { var name = node.index.text; - var prop = getPropertyOfApparentType(apparentType, name); + var prop = getPropertyOfType(objectType, name); if (prop) { return getTypeOfSymbol(prop); } } if (indexType.flags & (1 /* Any */ | ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike)) { if (indexType.flags & (1 /* Any */ | ts.TypeFlags.NumberLike)) { - var numberIndexType = getIndexTypeOfType(apparentType, 1 /* Number */); + var numberIndexType = getIndexTypeOfType(objectType, 1 /* Number */); if (numberIndexType) { return numberIndexType; } } - var stringIndexType = getIndexTypeOfType(apparentType, 0 /* String */); + var stringIndexType = getIndexTypeOfType(objectType, 0 /* String */); if (stringIndexType) { return stringIndexType; } @@ -12274,46 +13128,24 @@ var ts; resolveUntypedCall(node); return unknownSignature; } - function isCandidateSignature(node, signature) { - var args = node.arguments || emptyArray; - return args.length >= signature.minArgumentCount && (signature.hasRestParameter || args.length <= signature.parameters.length) && (!node.typeArguments || signature.typeParameters && node.typeArguments.length === signature.typeParameters.length); - } - function collectCandidates(node, signatures) { - var result = []; - var lastParent; - var lastSymbol; - var cutoffPos = 0; - var pos; - for (var i = 0; i < signatures.length; i++) { - var signature = signatures[i]; - if (isCandidateSignature(node, signature)) { - var symbol = signature.declaration && getSymbolOfNode(signature.declaration); - var parent = signature.declaration && signature.declaration.parent; - if (!lastSymbol || symbol === lastSymbol) { - if (lastParent && parent === lastParent) { - pos++; - } - else { - lastParent = parent; - pos = cutoffPos; - } - } - else { - pos = cutoffPos = result.length; - lastParent = parent; - } - lastSymbol = symbol; - for (var j = result.length; j > pos; j--) { - result[j] = result[j - 1]; - } - result[pos] = signature; - } + function signatureHasCorrectArity(node, signature) { + if (!node.arguments) { + return signature.minArgumentCount === 0; } - return result; + var args = node.arguments; + var numberOfArgs = args.hasTrailingComma ? args.length + 1 : args.length; + var hasTooManyArguments = !signature.hasRestParameter && numberOfArgs > signature.parameters.length; + var hasRightNumberOfTypeArguments = !node.typeArguments || (signature.typeParameters && node.typeArguments.length === signature.typeParameters.length); + if (hasTooManyArguments || !hasRightNumberOfTypeArguments) { + return false; + } + var callIsIncomplete = args.end === node.end; + var hasEnoughArguments = numberOfArgs >= signature.minArgumentCount; + return callIsIncomplete || hasEnoughArguments; } function getSingleCallSignature(type) { if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 && resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) { return resolved.callSignatures[0]; } @@ -12321,7 +13153,7 @@ var ts; return undefined; } function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper) { - var context = createInferenceContext(signature.typeParameters); + var context = createInferenceContext(signature.typeParameters, true); forEachMatchingParameterType(contextualSignature, signature, function (source, target) { inferTypes(context, instantiateType(source, contextualMapper), target); }); @@ -12329,9 +13161,12 @@ var ts; } function inferTypeArguments(signature, args, excludeArgument) { var typeParameters = signature.typeParameters; - var context = createInferenceContext(typeParameters); + var context = createInferenceContext(typeParameters, false); var mapper = createInferenceMapper(context); for (var i = 0; i < args.length; i++) { + if (args[i].kind === 149 /* OmittedExpression */) { + continue; + } if (!excludeArgument || excludeArgument[i] === undefined) { var parameterType = getTypeAtPosition(signature, i); inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); @@ -12339,13 +13174,17 @@ var ts; } if (excludeArgument) { for (var i = 0; i < args.length; i++) { + if (args[i].kind === 149 /* OmittedExpression */) { + continue; + } if (excludeArgument[i] === false) { var parameterType = getTypeAtPosition(signature, i); inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); } } } - return getInferredTypes(context); + var inferredTypes = getInferredTypes(context); + return ts.contains(inferredTypes, undefinedType) ? undefined : inferredTypes; } function checkTypeArguments(signature, typeArguments) { var typeParameters = signature.typeParameters; @@ -12365,6 +13204,9 @@ var ts; if (node.arguments) { for (var i = 0; i < node.arguments.length; i++) { var arg = node.arguments[i]; + if (arg.kind === 149 /* OmittedExpression */) { + continue; + } var paramType = getTypeAtPosition(signature, i); var argType = arg.kind === 7 /* StringLiteral */ && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); var isValidArgument = checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1); @@ -12375,9 +13217,10 @@ var ts; } return true; } - function resolveCall(node, signatures) { + function resolveCall(node, signatures, candidatesOutArray) { ts.forEach(node.typeArguments, checkSourceElement); - var candidates = collectCandidates(node, signatures); + var candidates = candidatesOutArray || []; + collectCandidates(); if (!candidates.length) { error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); return resolveErrorCall(node); @@ -12392,14 +13235,22 @@ var ts; } } var relation = candidates.length === 1 ? assignableRelation : subtypeRelation; + var lastCandidate; while (true) { for (var i = 0; i < candidates.length; i++) { + if (!signatureHasCorrectArity(node, candidates[i])) { + continue; + } while (true) { var candidate = candidates[i]; if (candidate.typeParameters) { var typeArguments = node.typeArguments ? checkTypeArguments(candidate, node.typeArguments) : inferTypeArguments(candidate, args, excludeArgument); + if (!typeArguments) { + break; + } candidate = getSignatureInstantiation(candidate, typeArguments); } + lastCandidate = candidate; if (!checkApplicableSignature(node, candidate, relation, excludeArgument, false)) { break; } @@ -12415,28 +13266,70 @@ var ts; } relation = assignableRelation; } - checkApplicableSignature(node, candidate, relation, undefined, true); + if (lastCandidate) { + checkApplicableSignature(node, lastCandidate, relation, undefined, true); + } + else { + error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + } + if (!fullTypeCheck) { + for (var i = 0, n = candidates.length; i < n; i++) { + if (signatureHasCorrectArity(node, candidates[i])) { + return candidates[i]; + } + } + } return resolveErrorCall(node); + function collectCandidates() { + var result = candidates; + var lastParent; + var lastSymbol; + var cutoffPos = 0; + var pos; + ts.Debug.assert(!result.length); + for (var i = 0; i < signatures.length; i++) { + var signature = signatures[i]; + if (true) { + var symbol = signature.declaration && getSymbolOfNode(signature.declaration); + var parent = signature.declaration && signature.declaration.parent; + if (!lastSymbol || symbol === lastSymbol) { + if (lastParent && parent === lastParent) { + pos++; + } + else { + lastParent = parent; + pos = cutoffPos; + } + } + else { + pos = cutoffPos = result.length; + lastParent = parent; + } + lastSymbol = symbol; + for (var j = result.length; j > pos; j--) { + result[j] = result[j - 1]; + } + result[pos] = signature; + } + } + } } - function resolveCallExpression(node) { + function resolveCallExpression(node, candidatesOutArray) { if (node.func.kind === 85 /* SuperKeyword */) { var superType = checkSuperExpression(node.func); if (superType !== unknownType) { - return resolveCall(node, getSignaturesOfType(superType, 1 /* Construct */)); + return resolveCall(node, getSignaturesOfType(superType, 1 /* Construct */), candidatesOutArray); } return resolveUntypedCall(node); } var funcType = checkExpression(node.func); - if (funcType === unknownType) { - return resolveErrorCall(node); - } var apparentType = getApparentType(funcType); if (apparentType === unknownType) { return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); var constructSignatures = getSignaturesOfType(apparentType, 1 /* Construct */); - if ((funcType === anyType) || (!callSignatures.length && !constructSignatures.length && isTypeAssignableTo(funcType, globalFunctionType))) { + if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } @@ -12451,13 +13344,10 @@ var ts; } return resolveErrorCall(node); } - return resolveCall(node, callSignatures); + return resolveCall(node, callSignatures, candidatesOutArray); } - function resolveNewExpression(node) { + function resolveNewExpression(node, candidatesOutArray) { var expressionType = checkExpression(node.func); - if (expressionType === unknownType) { - return resolveErrorCall(node); - } if (expressionType === anyType) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); @@ -12470,11 +13360,11 @@ var ts; } var constructSignatures = getSignaturesOfType(expressionType, 1 /* Construct */); if (constructSignatures.length) { - return resolveCall(node, constructSignatures); + return resolveCall(node, constructSignatures, candidatesOutArray); } var callSignatures = getSignaturesOfType(expressionType, 0 /* Call */); if (callSignatures.length) { - var signature = resolveCall(node, callSignatures); + var signature = resolveCall(node, callSignatures, candidatesOutArray); if (getReturnTypeOfSignature(signature) !== voidType) { error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } @@ -12483,11 +13373,11 @@ var ts; error(node, ts.Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature); return resolveErrorCall(node); } - function getResolvedSignature(node) { + function getResolvedSignature(node, candidatesOutArray) { var links = getNodeLinks(node); - if (!links.resolvedSignature) { + if (!links.resolvedSignature || candidatesOutArray) { links.resolvedSignature = anySignature; - links.resolvedSignature = node.kind === 137 /* CallExpression */ ? resolveCallExpression(node) : resolveNewExpression(node); + links.resolvedSignature = node.kind === 139 /* CallExpression */ ? resolveCallExpression(node, candidatesOutArray) : resolveNewExpression(node, candidatesOutArray); } return links.resolvedSignature; } @@ -12496,7 +13386,7 @@ var ts; if (node.func.kind === 85 /* SuperKeyword */) { return voidType; } - if (node.kind === 138 /* NewExpression */) { + if (node.kind === 140 /* NewExpression */) { var declaration = signature.declaration; if (declaration && (declaration.kind !== 121 /* Constructor */ && declaration.kind !== 125 /* ConstructSignature */)) { if (compilerOptions.noImplicitAny) { @@ -12535,23 +13425,24 @@ var ts; } } function getReturnTypeFromBody(func, contextualMapper) { - if (func.body.kind !== 173 /* FunctionBlock */) { + var contextualSignature = getContextualSignature(func); + if (func.body.kind !== 175 /* FunctionBlock */) { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); var widenedType = getWidenedType(unwidenedType); - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(func, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeToString(widenedType)); } return widenedType; } var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); if (types.length > 0) { - var commonType = getBestCommonType(types, undefined, true); + var commonType = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!commonType) { error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); return unknownType; } var widenedType = getWidenedType(commonType); - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { var typeName = typeToString(widenedType); if (func.name) { error(func, ts.Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type, ts.identifierToString(func.name), typeName); @@ -12583,7 +13474,7 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 165 /* ThrowStatement */); + return (body.statements.length === 1) && (body.statements[0].kind === 167 /* ThrowStatement */); } function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) { if (!fullTypeCheck) { @@ -12592,7 +13483,7 @@ var ts; if (returnType === voidType || returnType === anyType) { return; } - if (!func.body || func.body.kind !== 173 /* FunctionBlock */) { + if (!func.body || func.body.kind !== 175 /* FunctionBlock */) { return; } var bodyBlock = func.body; @@ -12636,7 +13527,7 @@ var ts; if (node.type) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { checkSourceElement(node.body); } else { @@ -12664,12 +13555,12 @@ var ts; case 59 /* Identifier */: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 1 /* Variable */) !== 0; - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || (symbol.flags & ~4 /* EnumMember */) !== 0; - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return true; - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return isReferenceOrErrorExpression(n.expression); default: return false; @@ -12713,14 +13604,17 @@ var ts; } return numberType; } - function isTypeAnyTypeObjectTypeOrTypeParameter(type) { - return type === anyType || ((type.flags & (ts.TypeFlags.ObjectType | 512 /* TypeParameter */)) !== 0); + function isStructuredType(type) { + if (type.flags & 16384 /* Union */) { + return !ts.forEach(type.types, function (t) { return !isStructuredType(t); }); + } + return (type.flags & ts.TypeFlags.Structured) !== 0; } function checkInstanceOfExpression(node, leftType, rightType) { - if (!isTypeAnyTypeObjectTypeOrTypeParameter(leftType)) { + if (leftType !== unknownType && !isStructuredType(leftType)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } - if (rightType !== anyType && !isTypeSubtypeOf(rightType, globalFunctionType)) { + if (rightType !== unknownType && rightType !== anyType && !isTypeSubtypeOf(rightType, globalFunctionType)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; @@ -12729,7 +13623,7 @@ var ts; if (leftType !== anyType && leftType !== stringType && leftType !== numberType) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number); } - if (!isTypeAnyTypeObjectTypeOrTypeParameter(rightType)) { + if (!isStructuredType(rightType)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -12763,10 +13657,16 @@ var ts; leftType = rightType; if (rightType.flags & (32 /* Undefined */ | 64 /* Null */)) rightType = leftType; - var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - if (leftOk && rightOk) { - checkAssignmentOperator(numberType); + var suggestedOperator; + if ((leftType.flags & 8 /* Boolean */) && (rightType.flags & 8 /* Boolean */) && (suggestedOperator = getSuggestedBooleanOperator(node.operator)) !== undefined) { + error(node, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(node.operator), ts.tokenToString(suggestedOperator)); + } + else { + var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + if (leftOk && rightOk) { + checkAssignmentOperator(numberType); + } } return numberType; case 28 /* PlusToken */: @@ -12801,7 +13701,7 @@ var ts; case 20 /* GreaterThanToken */: case 21 /* LessThanEqualsToken */: case 22 /* GreaterThanEqualsToken */: - if (!isTypeSubtypeOf(leftType, rightType) && !isTypeSubtypeOf(rightType, leftType)) { + if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) { reportOperatorError(); } return booleanType; @@ -12812,13 +13712,28 @@ var ts; case 43 /* AmpersandAmpersandToken */: return rightType; case 44 /* BarBarToken */: - return getBestCommonType([leftType, rightType], isInferentialContext(contextualMapper) ? undefined : getContextualType(node)); + return getUnionType([leftType, rightType]); case 47 /* EqualsToken */: checkAssignmentOperator(rightType); return rightType; case 18 /* CommaToken */: return rightType; } + function getSuggestedBooleanOperator(operator) { + switch (operator) { + case 39 /* BarToken */: + case 57 /* BarEqualsToken */: + return 44 /* BarBarToken */; + case 40 /* CaretToken */: + case 58 /* CaretEqualsToken */: + return 26 /* ExclamationEqualsEqualsToken */; + case 38 /* AmpersandToken */: + case 56 /* AmpersandEqualsToken */: + return 43 /* AmpersandAmpersandToken */; + default: + return undefined; + } + } function checkAssignmentOperator(valueType) { if (fullTypeCheck && operator >= ts.SyntaxKind.FirstAssignment && operator <= ts.SyntaxKind.LastAssignment) { var ok = checkReferenceExpression(node.left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression); @@ -12835,18 +13750,7 @@ var ts; checkExpression(node.condition); var type1 = checkExpression(node.whenTrue, contextualMapper); var type2 = checkExpression(node.whenFalse, contextualMapper); - var contextualType = isInferentialContext(contextualMapper) ? undefined : getContextualType(node); - var resultType = getBestCommonType([type1, type2], contextualType, true); - if (!resultType) { - if (contextualType) { - error(node, ts.Diagnostics.No_best_common_type_exists_between_0_1_and_2, typeToString(contextualType), typeToString(type1), typeToString(type2)); - } - else { - error(node, ts.Diagnostics.No_best_common_type_exists_between_0_and_1, typeToString(type1), typeToString(type2)); - } - resultType = emptyObjectType; - } - return resultType; + return getUnionType([type1, type2]); } function checkExpressionWithContextualType(node, contextualType, contextualMapper) { var saveContextualType = node.contextualType; @@ -12897,32 +13801,34 @@ var ts; return globalRegExpType; case 116 /* QualifiedName */: return checkPropertyAccess(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return checkArrayLiteral(node, contextualMapper); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return checkObjectLiteral(node, contextualMapper); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return checkPropertyAccess(node); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return checkIndexedAccess(node); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return checkCallExpression(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return checkTypeAssertion(node); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return checkExpression(node.expression); - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return checkFunctionExpression(node, contextualMapper); - case 143 /* PrefixOperator */: + case 145 /* PrefixOperator */: return checkPrefixExpression(node); - case 144 /* PostfixOperator */: + case 146 /* PostfixOperator */: return checkPostfixExpression(node); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return checkBinaryExpression(node, contextualMapper); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return checkConditionalExpression(node, contextualMapper); + case 149 /* OmittedExpression */: + return undefinedType; } return unknownType; } @@ -12985,7 +13891,7 @@ var ts; if (fullTypeCheck) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { @@ -13001,7 +13907,7 @@ var ts; checkSpecializedSignatureDeclaration(node); } function checkTypeForDuplicateIndexSignatures(node) { - if (node.kind === 175 /* InterfaceDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */) { var nodeSymbol = getSymbolOfNode(node); if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) { return; @@ -13057,17 +13963,17 @@ var ts; return; } function isSuperCallExpression(n) { - return n.kind === 137 /* CallExpression */ && n.func.kind === 85 /* SuperKeyword */; + return n.kind === 139 /* CallExpression */ && n.func.kind === 85 /* SuperKeyword */; } function containsSuperCall(n) { if (isSuperCallExpression(n)) { return true; } switch (n.kind) { - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: - case 133 /* ObjectLiteral */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: + case 135 /* ObjectLiteral */: return false; default: return ts.forEachChild(n, containsSuperCall); @@ -13077,7 +13983,7 @@ var ts; if (n.kind === 87 /* ThisKeyword */) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } - else if (n.kind !== 141 /* FunctionExpression */ && n.kind !== 172 /* FunctionDeclaration */) { + else if (n.kind !== 143 /* FunctionExpression */ && n.kind !== 174 /* FunctionDeclaration */) { ts.forEachChild(n, markThisReferencesAsErrors); } } @@ -13089,7 +13995,7 @@ var ts; var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) || ts.forEach(node.parameters, function (p) { return p.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */); }); if (superCallShouldBeFirst) { var statements = node.body.statements; - if (!statements.length || statements[0].kind !== 151 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) { + if (!statements.length || statements[0].kind !== 153 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) { error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } else { @@ -13158,6 +14064,9 @@ var ts; function checkTupleType(node) { ts.forEach(node.elementTypes, checkSourceElement); } + function checkUnionType(node) { + ts.forEach(node.types, checkSourceElement); + } function isPrivateWithinAmbient(node) { return (node.flags & 32 /* Private */) && ts.isInAmbientContext(node); } @@ -13175,7 +14084,7 @@ var ts; } var symbol = getSymbolOfNode(signatureDeclarationNode); var signaturesToCheck; - if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 175 /* InterfaceDeclaration */) { + if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 177 /* InterfaceDeclaration */) { ts.Debug.assert(signatureDeclarationNode.kind === 124 /* CallSignature */ || signatureDeclarationNode.kind === 125 /* ConstructSignature */); var signatureKind = signatureDeclarationNode.kind === 124 /* CallSignature */ ? 0 /* Call */ : 1 /* Construct */; var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent); @@ -13195,7 +14104,7 @@ var ts; } function getEffectiveDeclarationFlags(n, flagsToCheck) { var flags = n.flags; - if (n.parent.kind !== 175 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { + if (n.parent.kind !== 177 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { if (!(flags & 2 /* Ambient */)) { flags |= 1 /* Export */; } @@ -13239,6 +14148,9 @@ var ts; var declarations = symbol.declarations; var isConstructor = (symbol.flags & 4096 /* Constructor */) !== 0; function reportImplementationExpectedError(node) { + if (node.name && node.name.kind === 115 /* Missing */) { + return; + } var seen = false; var subsequentNode = ts.forEachChild(node.parent, function (c) { if (seen) { @@ -13273,23 +14185,25 @@ var ts; } } var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & ts.SymbolFlags.Module; + var duplicateFunctionDeclaration = false; + var multipleConstructorImplementation = false; for (var i = 0; i < declarations.length; i++) { var node = declarations[i]; var inAmbientContext = ts.isInAmbientContext(node); - var inAmbientContextOrInterface = node.parent.kind === 175 /* InterfaceDeclaration */ || node.parent.kind === 129 /* TypeLiteral */ || inAmbientContext; + var inAmbientContextOrInterface = node.parent.kind === 177 /* InterfaceDeclaration */ || node.parent.kind === 129 /* TypeLiteral */ || inAmbientContext; if (inAmbientContextOrInterface) { previousDeclaration = undefined; } - if (node.kind === 172 /* FunctionDeclaration */ || node.kind === 120 /* Method */ || node.kind === 121 /* Constructor */) { + if (node.kind === 174 /* FunctionDeclaration */ || node.kind === 120 /* Method */ || node.kind === 121 /* Constructor */) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; if (node.body && bodyDeclaration) { if (isConstructor) { - error(node, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed); + multipleConstructorImplementation = true; } else { - error(node, ts.Diagnostics.Duplicate_function_implementation); + duplicateFunctionDeclaration = true; } } else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) { @@ -13309,6 +14223,16 @@ var ts; } } } + if (multipleConstructorImplementation) { + ts.forEach(declarations, function (declaration) { + error(declaration, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed); + }); + } + if (duplicateFunctionDeclaration) { + ts.forEach(declarations, function (declaration) { + error(declaration.name, ts.Diagnostics.Duplicate_function_implementation); + }); + } if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) { reportImplementationExpectedError(lastSeenNonAmbientDeclaration); } @@ -13364,14 +14288,14 @@ var ts; } function getDeclarationSpaces(d) { switch (d.kind) { - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return 1048576 /* ExportType */; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return d.name.kind === 7 /* StringLiteral */ || ts.isInstantiated(d) ? 2097152 /* ExportNamespace */ | 524288 /* ExportValue */ : 2097152 /* ExportNamespace */; - case 174 /* ClassDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: return 1048576 /* ExportType */ | 524288 /* ExportValue */; - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: var result = 0; var target = resolveImport(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { @@ -13446,10 +14370,10 @@ var ts; return; } switch (current.kind) { - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: case 120 /* Method */: - case 142 /* ArrowFunction */: + case 144 /* ArrowFunction */: case 121 /* Constructor */: if (ts.hasRestParameters(current)) { error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_i_that_compiler_uses_to_initialize_rest_parameter); @@ -13501,7 +14425,7 @@ var ts; if (!needCollisionCheckForIdentifier(node, name, "_super")) { return; } - var enclosingClass = ts.getAncestor(node, 174 /* ClassDeclaration */); + var enclosingClass = ts.getAncestor(node, 176 /* ClassDeclaration */); if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) { return; } @@ -13515,15 +14439,15 @@ var ts; } } } - function checkCollistionWithRequireExportsInGeneratedCode(node, name) { + function checkCollisionWithRequireExportsInGeneratedCode(node, name) { if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { return; } - if (node.kind === 177 /* ModuleDeclaration */ && !ts.isInstantiated(node)) { + if (node.kind === 179 /* ModuleDeclaration */ && !ts.isInstantiated(node)) { return; } - var parent = node.kind === 171 /* VariableDeclaration */ ? node.parent.parent : node.parent; - if (parent.kind === 182 /* SourceFile */ && ts.isExternalModule(parent)) { + var parent = node.kind === 173 /* VariableDeclaration */ ? node.parent.parent : node.parent; + if (parent.kind === 184 /* SourceFile */ && ts.isExternalModule(parent)) { error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module, name.text, name.text); } } @@ -13548,7 +14472,7 @@ var ts; } checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); if (!useTypeFromValueDeclaration) { if (typeOfValueDeclaration !== unknownType && type !== unknownType && !isTypeIdenticalTo(typeOfValueDeclaration, type)) { error(node.name, ts.Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, ts.identifierToString(node.name), typeToString(typeOfValueDeclaration), typeToString(type)); @@ -13603,7 +14527,7 @@ var ts; } } var exprType = checkExpression(node.expression); - if (!isTypeAnyTypeObjectTypeOrTypeParameter(exprType) && exprType !== unknownType) { + if (!isStructuredType(exprType) && exprType !== unknownType) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -13679,7 +14603,7 @@ var ts; errorNode = indexDeclaration; } else if (type.flags & 2048 /* Interface */) { - var someBaseClassHasBothPropertyAndIndexer = ts.forEach(type.baseTypes, function (base) { return getPropertyOfType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); + var someBaseClassHasBothPropertyAndIndexer = ts.forEach(type.baseTypes, function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : type.symbol.declarations[0]; } if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { @@ -13692,7 +14616,7 @@ var ts; var stringIndexType = getIndexTypeOfType(type, 0 /* String */); var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); if (stringIndexType || numberIndexType) { - ts.forEach(getPropertiesOfType(type), function (prop) { + ts.forEach(getPropertiesOfObjectType(type), function (prop) { var propType = getTypeOfSymbol(prop); checkIndexConstraintForProperty(prop, propType, declaredStringIndexer, stringIndexType, 0 /* String */); checkIndexConstraintForProperty(prop, propType, declaredNumberIndexer, numberIndexType, 1 /* Number */); @@ -13739,7 +14663,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); checkTypeParameters(node.typeParameters); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -13788,13 +14712,13 @@ var ts; return s.flags & 8388608 /* Instantiated */ ? getSymbolLinks(s).target : s; } function checkKindsOfPropertyMemberOverrides(type, baseType) { - var baseProperties = getPropertiesOfType(baseType); + var baseProperties = getPropertiesOfObjectType(baseType); for (var i = 0, len = baseProperties.length; i < len; ++i) { var base = getTargetSymbol(baseProperties[i]); if (base.flags & 67108864 /* Prototype */) { continue; } - var derived = getTargetSymbol(getPropertyOfType(type, base.name)); + var derived = getTargetSymbol(getPropertyOfObjectType(type, base.name)); if (derived) { var baseDeclarationFlags = getDeclarationFlagsFromSymbol(base); var derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived); @@ -13864,7 +14788,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - var firstInterfaceDecl = getDeclarationOfKind(symbol, 175 /* InterfaceDeclaration */); + var firstInterfaceDecl = getDeclarationOfKind(symbol, 177 /* InterfaceDeclaration */); if (symbol.declarations.length > 1) { if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) { error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters); @@ -13886,9 +14810,9 @@ var ts; checkTypeForDuplicateIndexSignatures(node); } } - function getConstantValue(node) { + function getConstantValueForExpression(node) { var isNegative = false; - if (node.kind === 143 /* PrefixOperator */) { + if (node.kind === 145 /* PrefixOperator */) { var unaryExpression = node; if (unaryExpression.operator === 29 /* MinusToken */ || unaryExpression.operator === 28 /* PlusToken */) { node = unaryExpression.operand; @@ -13901,38 +14825,49 @@ var ts; } return undefined; } + function computeEnumMemberValues(node) { + var nodeLinks = getNodeLinks(node); + if (!(nodeLinks.flags & 128 /* EnumValuesComputed */)) { + var enumSymbol = getSymbolOfNode(node); + var enumType = getDeclaredTypeOfSymbol(enumSymbol); + var autoValue = 0; + var ambient = ts.isInAmbientContext(node); + ts.forEach(node.members, function (member) { + if (isNumericName(member.name.text)) { + error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); + } + var initializer = member.initializer; + if (initializer) { + autoValue = getConstantValueForExpression(initializer); + if (autoValue === undefined && !ambient) { + checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined, undefined); + } + } + else if (ambient) { + autoValue = undefined; + } + if (autoValue !== undefined) { + getNodeLinks(member).enumMemberValue = autoValue++; + } + }); + nodeLinks.flags |= 128 /* EnumValuesComputed */; + } + } function checkEnumDeclaration(node) { if (!fullTypeCheck) { return; } checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); + computeEnumMemberValues(node); var enumSymbol = getSymbolOfNode(node); - var enumType = getDeclaredTypeOfSymbol(enumSymbol); - var autoValue = 0; - var ambient = ts.isInAmbientContext(node); - ts.forEach(node.members, function (member) { - var initializer = member.initializer; - if (initializer) { - autoValue = getConstantValue(initializer); - if (autoValue === undefined && !ambient) { - checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined, undefined); - } - } - else if (ambient) { - autoValue = undefined; - } - if (autoValue !== undefined) { - getNodeLinks(member).enumMemberValue = autoValue++; - } - }); var firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind); if (node === firstDeclaration) { var seenEnumMissingInitialInitializer = false; ts.forEach(enumSymbol.declarations, function (declaration) { - if (declaration.kind !== 176 /* EnumDeclaration */) { + if (declaration.kind !== 178 /* EnumDeclaration */) { return false; } var enumDeclaration = declaration; @@ -13955,7 +14890,7 @@ var ts; var declarations = symbol.declarations; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; - if ((declaration.kind === 174 /* ClassDeclaration */ || (declaration.kind === 172 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) { + if ((declaration.kind === 176 /* ClassDeclaration */ || (declaration.kind === 174 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) { return declaration; } } @@ -13964,7 +14899,7 @@ var ts; function checkModuleDeclaration(node) { if (fullTypeCheck) { checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); if (symbol.flags & 128 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node)) { @@ -13997,7 +14932,7 @@ var ts; } function checkImportDeclaration(node) { checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); var symbol = getSymbolOfNode(node); var target; if (node.entityName) { @@ -14018,10 +14953,10 @@ var ts; } } else { - if (node.parent.kind === 182 /* SourceFile */) { + if (node.parent.kind === 184 /* SourceFile */) { target = resolveImport(symbol); } - else if (node.parent.kind === 178 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) { + else if (node.parent.kind === 180 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) { if (isExternalModuleNameRelative(node.externalModuleName.text)) { error(node, ts.Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); target = unknownSymbol; @@ -14043,7 +14978,7 @@ var ts; } function checkExportAssignment(node) { var container = node.parent; - if (container.kind !== 182 /* SourceFile */) { + if (container.kind !== 184 /* SourceFile */) { container = container.parent; } checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container)); @@ -14079,62 +15014,66 @@ var ts; return checkArrayType(node); case 131 /* TupleType */: return checkTupleType(node); - case 172 /* FunctionDeclaration */: + case 132 /* UnionType */: + return checkUnionType(node); + case 133 /* ParenType */: + return checkSourceElement(node.type); + case 174 /* FunctionDeclaration */: return checkFunctionDeclaration(node); - case 148 /* Block */: + case 150 /* Block */: return checkBlock(node); - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: return checkBody(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return checkVariableStatement(node); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return checkExpressionStatement(node); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return checkIfStatement(node); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return checkDoStatement(node); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return checkWhileStatement(node); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return checkForStatement(node); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return checkForInStatement(node); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return checkBreakOrContinueStatement(node); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return checkReturnStatement(node); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return checkWithStatement(node); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return checkSwitchStatement(node); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return checkLabeledStatement(node); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return checkThrowStatement(node); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return checkTryStatement(node); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return ts.Debug.fail("Checker encountered variable declaration"); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return checkClassDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return checkEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return checkModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return checkImportDeclaration(node); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return checkExportAssignment(node); } } function checkFunctionExpressionBodies(node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: ts.forEach(node.parameters, checkFunctionExpressionBodies); checkFunctionExpressionBody(node); break; @@ -14142,54 +15081,54 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: ts.forEach(node.parameters, checkFunctionExpressionBodies); break; - case 160 /* WithStatement */: + case 162 /* WithStatement */: checkFunctionExpressionBodies(node.expression); break; case 118 /* Parameter */: case 119 /* Property */: - case 132 /* ArrayLiteral */: - case 133 /* ObjectLiteral */: - case 134 /* PropertyAssignment */: - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 137 /* CallExpression */: - case 138 /* NewExpression */: - case 139 /* TypeAssertion */: - case 140 /* ParenExpression */: - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: - case 145 /* BinaryExpression */: - case 146 /* ConditionalExpression */: - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 149 /* VariableStatement */: - case 151 /* ExpressionStatement */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: - case 159 /* ReturnStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 163 /* DefaultClause */: - case 164 /* LabeledStatement */: - case 165 /* ThrowStatement */: - case 166 /* TryStatement */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: - case 171 /* VariableDeclaration */: - case 174 /* ClassDeclaration */: - case 176 /* EnumDeclaration */: - case 181 /* EnumMember */: - case 182 /* SourceFile */: + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 136 /* PropertyAssignment */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 147 /* BinaryExpression */: + case 148 /* ConditionalExpression */: + case 150 /* Block */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 151 /* VariableStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: + case 161 /* ReturnStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 167 /* ThrowStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + case 173 /* VariableDeclaration */: + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: + case 183 /* EnumMember */: + case 184 /* SourceFile */: ts.forEachChild(node, checkFunctionExpressionBodies); break; } @@ -14260,7 +15199,7 @@ var ts; function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 160 /* WithStatement */ && node.parent.statement === node) { + if (node.parent.kind === 162 /* WithStatement */ && node.parent.statement === node) { return true; } node = node.parent; @@ -14296,27 +15235,27 @@ var ts; copySymbols(location.locals, meaning); } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & ts.SymbolFlags.ModuleMember); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & 4 /* EnumMember */); break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (!(memberFlags & 128 /* Static */)) { copySymbols(getSymbolOfNode(location).members, meaning & ts.SymbolFlags.Type); } break; - case 141 /* FunctionExpression */: + case 143 /* FunctionExpression */: if (location.name) { copySymbol(location.symbol, meaning); } break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: if (location.variable.text) { copySymbol(location.symbol, meaning); } @@ -14334,9 +15273,9 @@ var ts; function isTypeDeclaration(node) { switch (node.kind) { case 117 /* TypeParameter */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: return true; } } @@ -14354,21 +15293,21 @@ var ts; case 89 /* TrueKeyword */: case 74 /* FalseKeyword */: case 8 /* RegularExpressionLiteral */: - case 132 /* ArrayLiteral */: - case 133 /* ObjectLiteral */: - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 137 /* CallExpression */: - case 138 /* NewExpression */: - case 139 /* TypeAssertion */: - case 140 /* ParenExpression */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: - case 145 /* BinaryExpression */: - case 146 /* ConditionalExpression */: - case 147 /* OmittedExpression */: + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 147 /* BinaryExpression */: + case 148 /* ConditionalExpression */: + case 149 /* OmittedExpression */: return true; case 116 /* QualifiedName */: while (node.parent.kind === 116 /* QualifiedName */) @@ -14382,28 +15321,28 @@ var ts; case 7 /* StringLiteral */: var parent = node.parent; switch (parent.kind) { - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 118 /* Parameter */: case 119 /* Property */: - case 181 /* EnumMember */: - case 134 /* PropertyAssignment */: + case 183 /* EnumMember */: + case 136 /* PropertyAssignment */: return parent.initializer === node; - case 151 /* ExpressionStatement */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 159 /* ReturnStatement */: - case 160 /* WithStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 165 /* ThrowStatement */: - case 161 /* SwitchStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 161 /* ReturnStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 167 /* ThrowStatement */: + case 163 /* SwitchStatement */: return parent.expression === node; - case 155 /* ForStatement */: + case 157 /* ForStatement */: return parent.initializer === node || parent.condition === node || parent.iterator === node; - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return parent.variable === node || parent.expression === node; - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return node === parent.operand; default: if (isExpression(parent)) { @@ -14414,7 +15353,7 @@ var ts; return false; } function isTypeNode(node) { - if (node.kind >= ts.SyntaxKind.FirstTypeNode && node.kind <= ts.SyntaxKind.LastTypeNode) { + if (ts.SyntaxKind.FirstTypeNode <= node.kind && node.kind <= ts.SyntaxKind.LastTypeNode) { return true; } switch (node.kind) { @@ -14424,7 +15363,7 @@ var ts; case 106 /* BooleanKeyword */: return true; case 93 /* VoidKeyword */: - return node.parent.kind !== 143 /* PrefixOperator */; + return node.parent.kind !== 145 /* PrefixOperator */; case 7 /* StringLiteral */: return node.parent.kind === 118 /* Parameter */; case 59 /* Identifier */: @@ -14432,11 +15371,12 @@ var ts; node = node.parent; } case 116 /* QualifiedName */: + ts.Debug.assert(node.kind === 59 /* Identifier */ || node.kind === 116 /* QualifiedName */, "'node' was expected to be a qualified name or identifier in 'isTypeNode'."); var parent = node.parent; if (parent.kind === 128 /* TypeQuery */) { return false; } - if (parent.kind >= ts.SyntaxKind.FirstTypeNode && parent.kind <= ts.SyntaxKind.LastTypeNode) { + if (ts.SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= ts.SyntaxKind.LastTypeNode) { return true; } switch (parent.kind) { @@ -14444,11 +15384,11 @@ var ts; return node === parent.constraint; case 119 /* Property */: case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return node === parent.type; - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: case 121 /* Constructor */: case 120 /* Method */: case 122 /* GetAccessor */: @@ -14458,11 +15398,11 @@ var ts; case 125 /* ConstructSignature */: case 126 /* IndexSignature */: return node === parent.type; - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return node === parent.type; - case 137 /* CallExpression */: - case 138 /* NewExpression */: - return parent.typeArguments.indexOf(node) >= 0; + case 139 /* CallExpression */: + case 140 /* NewExpression */: + return parent.typeArguments && parent.typeArguments.indexOf(node) >= 0; } } return false; @@ -14471,22 +15411,22 @@ var ts; while (node.parent.kind === 116 /* QualifiedName */) { node = node.parent; } - if (node.parent.kind === 179 /* ImportDeclaration */) { + if (node.parent.kind === 181 /* ImportDeclaration */) { return node.parent.entityName === node; } - if (node.parent.kind === 180 /* ExportAssignment */) { + if (node.parent.kind === 182 /* ExportAssignment */) { return node.parent.exportName === node; } return false; } function isRightSideOfQualifiedNameOrPropertyAccess(node) { - return (node.parent.kind === 116 /* QualifiedName */ || node.parent.kind === 135 /* PropertyAccess */) && node.parent.right === node; + return (node.parent.kind === 116 /* QualifiedName */ || node.parent.kind === 137 /* PropertyAccess */) && node.parent.right === node; } function getSymbolOfEntityName(entityName) { if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { return getSymbolOfNode(entityName.parent); } - if (entityName.parent.kind === 180 /* ExportAssignment */) { + if (entityName.parent.kind === 182 /* ExportAssignment */) { return resolveEntityName(entityName.parent.parent, entityName, ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace | 4194304 /* Import */); } if (isInRightSideOfImportOrExportAssignment(entityName)) { @@ -14500,7 +15440,7 @@ var ts; var meaning = ts.SymbolFlags.Value | 4194304 /* Import */; return resolveEntityName(entityName, entityName, meaning); } - else if (entityName.kind === 116 /* QualifiedName */ || entityName.kind === 135 /* PropertyAccess */) { + else if (entityName.kind === 116 /* QualifiedName */ || entityName.kind === 137 /* PropertyAccess */) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkPropertyAccess(entityName); @@ -14526,11 +15466,11 @@ var ts; return getSymbolOfNode(node.parent); } if (node.kind === 59 /* Identifier */ && isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 180 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node); + return node.parent.kind === 182 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node); } switch (node.kind) { case 59 /* Identifier */: - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: case 116 /* QualifiedName */: return getSymbolOfEntityName(node); case 87 /* ThisKeyword */: @@ -14544,20 +15484,20 @@ var ts; } return undefined; case 7 /* StringLiteral */: - if (node.parent.kind === 179 /* ImportDeclaration */ && node.parent.externalModuleName === node) { + if (node.parent.kind === 181 /* ImportDeclaration */ && node.parent.externalModuleName === node) { var importSymbol = getSymbolOfNode(node.parent); var moduleType = getTypeOfSymbol(importSymbol); return moduleType ? moduleType.symbol : undefined; } case 6 /* NumericLiteral */: - if (node.parent.kind == 136 /* IndexedAccess */ && node.parent.index === node) { + if (node.parent.kind == 138 /* IndexedAccess */ && node.parent.index === node) { var objectType = checkExpression(node.parent.object); if (objectType === unknownType) return undefined; var apparentType = getApparentType(objectType); if (apparentType === unknownType) return undefined; - return getPropertyOfApparentType(apparentType, node.text); + return getPropertyOfType(apparentType, node.text); } break; } @@ -14602,41 +15542,37 @@ var ts; } return checkExpression(expr); } - function getAugmentedPropertiesOfApparentType(type) { - var apparentType = getApparentType(type); - if (apparentType.flags & ts.TypeFlags.ObjectType) { - var propertiesByName = {}; - var results = []; - ts.forEach(getPropertiesOfType(apparentType), function (s) { - propertiesByName[s.name] = s; - results.push(s); - }); - var resolved = resolveObjectTypeMembers(type); - ts.forEachValue(resolved.members, function (s) { - if (symbolIsValue(s) && !propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); + function getAugmentedPropertiesOfType(type) { + var type = getApparentType(type); + var propsByName = createSymbolTable(getPropertiesOfType(type)); + if (getSignaturesOfType(type, 0 /* Call */).length || getSignaturesOfType(type, 1 /* Construct */).length) { + ts.forEach(getPropertiesOfType(globalFunctionType), function (p) { + if (!ts.hasProperty(propsByName, p.name)) { + propsByName[p.name] = p; } }); - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - ts.forEach(getPropertiesOfType(globalFunctionType), function (s) { - if (!propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); - } - }); - } - return results; - } - else { - return getPropertiesOfType(apparentType); } + return getNamedMembers(propsByName); } - function getRootSymbol(symbol) { - return ((symbol.flags & 33554432 /* Transient */) && getSymbolLinks(symbol).target) || symbol; + function getRootSymbols(symbol) { + if (symbol.flags & 134217728 /* UnionProperty */) { + var symbols = []; + var name = symbol.name; + ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { + symbols.push(getPropertyOfType(t, name)); + }); + return symbols; + } + else if (symbol.flags & 33554432 /* Transient */) { + var target = getSymbolLinks(symbol).target; + if (target) { + return [target]; + } + } + return [symbol]; } function isExternalModuleSymbol(symbol) { - return symbol.flags & 128 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 182 /* SourceFile */; + return symbol.flags & 128 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 184 /* SourceFile */; } function isNodeDescendentOf(node, ancestor) { while (node) { @@ -14662,14 +15598,14 @@ var ts; while (!isUniqueLocalName(ts.escapeIdentifier(prefix + name), container)) { prefix += "_"; } - links.localModuleName = prefix + ts.getSourceTextOfNode(container.name); + links.localModuleName = prefix + ts.getTextOfNode(container.name); } return links.localModuleName; } function getLocalNameForSymbol(symbol, location) { var node = location; while (node) { - if ((node.kind === 177 /* ModuleDeclaration */ || node.kind === 176 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) { + if ((node.kind === 179 /* ModuleDeclaration */ || node.kind === 178 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) { return getLocalNameOfContainer(node); } node = node.parent; @@ -14688,22 +15624,12 @@ var ts; } } } - function getPropertyAccessSubstitution(node) { - var symbol = getNodeLinks(node).resolvedSymbol; - if (symbol && (symbol.flags & 4 /* EnumMember */)) { - var declaration = symbol.valueDeclaration; - var constantValue; - if (declaration.kind === 181 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) { - return constantValue.toString() + " /* " + ts.identifierToString(declaration.name) + " */"; - } - } - } function getExportAssignmentName(node) { var symbol = getExportAssignmentSymbol(getSymbolOfNode(node)); return symbol && symbolIsValue(symbol) ? symbolToString(symbol) : undefined; } function isTopLevelValueImportedViaEntityName(node) { - if (node.parent.kind !== 182 /* SourceFile */ || !node.entityName) { + if (node.parent.kind !== 184 /* SourceFile */ || !node.entityName) { return false; } var symbol = getSymbolOfNode(node); @@ -14738,23 +15664,34 @@ var ts; return getNodeLinks(node).flags; } function getEnumMemberValue(node) { + computeEnumMemberValues(node.parent); return getNodeLinks(node).enumMemberValue; } + function getConstantValue(node) { + var symbol = getNodeLinks(node).resolvedSymbol; + if (symbol && (symbol.flags & 4 /* EnumMember */)) { + var declaration = symbol.valueDeclaration; + var constantValue; + if (declaration.kind === 183 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) { + return constantValue; + } + } + return undefined; + } function writeTypeAtLocation(location, enclosingDeclaration, flags, writer) { var symbol = getSymbolOfNode(location); var type = symbol && !(symbol.flags & 512 /* TypeLiteral */) ? getTypeOfSymbol(symbol) : getTypeFromTypeNode(location); - writeTypeToTextWriter(type, enclosingDeclaration, flags, writer); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } function writeReturnTypeOfSignatureDeclaration(signatureDeclaration, enclosingDeclaration, flags, writer) { var signature = getSignatureFromDeclaration(signatureDeclaration); - writeTypeToTextWriter(getReturnTypeOfSignature(signature), enclosingDeclaration, flags, writer); + getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); } function invokeEmitter(targetSourceFile) { var resolver = { getProgram: function () { return program; }, getLocalNameOfContainer: getLocalNameOfContainer, getExpressionNamePrefix: getExpressionNamePrefix, - getPropertyAccessSubstitution: getPropertyAccessSubstitution, getExportAssignmentName: getExportAssignmentName, isReferencedImportDeclaration: isReferencedImportDeclaration, getNodeCheckFlags: getNodeCheckFlags, @@ -14765,9 +15702,9 @@ var ts; isImplementationOfOverload: isImplementationOfOverload, writeTypeAtLocation: writeTypeAtLocation, writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration, - writeSymbol: writeSymbolToTextWriter, isSymbolAccessible: isSymbolAccessible, - isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile + isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile, + getConstantValue: getConstantValue }; checkProgram(); return ts.emitFiles(resolver, targetSourceFile); @@ -15024,7 +15961,7 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { - var version = "1.1.0.0"; + var version = "1.3.0.0"; function validateLocaleAndSetLanguage(locale, errors) { var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase()); if (!matchResult) { @@ -15123,13 +16060,14 @@ var ts; function getCanonicalFileName(fileName) { return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); } + var unsupportedFileEncodingErrorCode = -2147024809; function getSourceFile(filename, languageVersion, onError) { try { var text = sys.readFile(filename, options.charset); } catch (e) { if (onError) { - onError(e.message); + onError(e.number === unsupportedFileEncodingErrorCode ? getDiagnosticText(ts.Diagnostics.Unsupported_file_encoding) : e.message); } text = ""; } @@ -15326,7 +16264,7 @@ var ts; output += sys.newLine + sys.newLine; var padding = makePadding(marginLength); output += getDiagnosticText(ts.Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine; - output += padding + "tsc --out foo.js foo.ts" + sys.newLine; + output += padding + "tsc --out file.js file.ts" + sys.newLine; output += padding + "tsc @args.txt" + sys.newLine; output += sys.newLine; output += getDiagnosticText(ts.Diagnostics.Options_Colon) + sys.newLine; diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 38f2d4e1ecf..6bd9677a26a 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -19,6 +19,7 @@ var ts; Unterminated_string_literal: { code: 1002, category: 1 /* Error */, key: "Unterminated string literal." }, Identifier_expected: { code: 1003, category: 1 /* Error */, key: "Identifier expected." }, _0_expected: { code: 1005, category: 1 /* Error */, key: "'{0}' expected." }, + A_file_cannot_have_a_reference_to_itself: { code: 1006, category: 1 /* Error */, key: "A file cannot have a reference to itself." }, Trailing_comma_not_allowed: { code: 1009, category: 1 /* Error */, key: "Trailing comma not allowed." }, Asterisk_Slash_expected: { code: 1010, category: 1 /* Error */, key: "'*/' expected." }, Unexpected_token: { code: 1012, category: 1 /* Error */, key: "Unexpected token." }, @@ -127,6 +128,7 @@ var ts; Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: 1 /* Error */, key: "Cannot compile external modules unless the '--module' flag is provided." }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: 1 /* Error */, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: 1 /* Error */, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, + An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: 1 /* Error */, key: "An enum member cannot have a numeric name." }, Duplicate_identifier_0: { code: 2300, category: 1 /* Error */, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1 /* Error */, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: 1 /* Error */, key: "Static members cannot reference class type parameters." }, @@ -193,8 +195,6 @@ var ts; The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: 1 /* Error */, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." }, Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: 1 /* Error */, key: "Invalid left-hand side of assignment expression." }, Operator_0_cannot_be_applied_to_types_1_and_2: { code: 2365, category: 1 /* Error */, key: "Operator '{0}' cannot be applied to types '{1}' and '{2}'." }, - No_best_common_type_exists_between_0_1_and_2: { code: 2366, category: 1 /* Error */, key: "No best common type exists between '{0}', '{1}', and '{2}'." }, - No_best_common_type_exists_between_0_and_1: { code: 2367, category: 1 /* Error */, key: "No best common type exists between '{0}' and '{1}'." }, Type_parameter_name_cannot_be_0: { code: 2368, category: 1 /* Error */, key: "Type parameter name cannot be '{0}'" }, A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2369, category: 1 /* Error */, key: "A parameter property is only allowed in a constructor implementation." }, A_rest_parameter_must_be_of_an_array_type: { code: 2370, category: 1 /* Error */, key: "A rest parameter must be of an array type." }, @@ -274,6 +274,7 @@ var ts; Property_0_is_protected_in_type_1_but_public_in_type_2: { code: 2444, category: 1 /* Error */, key: "Property '{0}' is protected in type '{1}' but public in type '{2}'." }, Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: 1 /* Error */, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." }, Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: 1 /* Error */, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." }, + The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: 1 /* Error */, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1 /* Error */, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, @@ -526,10 +527,10 @@ var ts; "|=": 57 /* BarEqualsToken */, "^=": 58 /* CaretEqualsToken */ }; - var unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - var unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - var unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - var unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; + var unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + var unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + var unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + var unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; function lookupInUnicodeMap(code, map) { if (code < map[0]) { return false; @@ -758,14 +759,14 @@ var ts; return result; } } - function getLeadingComments(text, pos) { + function getLeadingCommentRanges(text, pos) { return getCommentRanges(text, pos, false); } - ts.getLeadingComments = getLeadingComments; - function getTrailingComments(text, pos) { + ts.getLeadingCommentRanges = getLeadingCommentRanges; + function getTrailingCommentRanges(text, pos) { return getCommentRanges(text, pos, true); } - ts.getTrailingComments = getTrailingComments; + ts.getTrailingCommentRanges = getTrailingCommentRanges; function isIdentifierStart(ch, languageVersion) { return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion); } @@ -1492,60 +1493,62 @@ var ts; SyntaxKind[SyntaxKind["TypeLiteral"] = 129] = "TypeLiteral"; SyntaxKind[SyntaxKind["ArrayType"] = 130] = "ArrayType"; SyntaxKind[SyntaxKind["TupleType"] = 131] = "TupleType"; - SyntaxKind[SyntaxKind["ArrayLiteral"] = 132] = "ArrayLiteral"; - SyntaxKind[SyntaxKind["ObjectLiteral"] = 133] = "ObjectLiteral"; - SyntaxKind[SyntaxKind["PropertyAssignment"] = 134] = "PropertyAssignment"; - SyntaxKind[SyntaxKind["PropertyAccess"] = 135] = "PropertyAccess"; - SyntaxKind[SyntaxKind["IndexedAccess"] = 136] = "IndexedAccess"; - SyntaxKind[SyntaxKind["CallExpression"] = 137] = "CallExpression"; - SyntaxKind[SyntaxKind["NewExpression"] = 138] = "NewExpression"; - SyntaxKind[SyntaxKind["TypeAssertion"] = 139] = "TypeAssertion"; - SyntaxKind[SyntaxKind["ParenExpression"] = 140] = "ParenExpression"; - SyntaxKind[SyntaxKind["FunctionExpression"] = 141] = "FunctionExpression"; - SyntaxKind[SyntaxKind["ArrowFunction"] = 142] = "ArrowFunction"; - SyntaxKind[SyntaxKind["PrefixOperator"] = 143] = "PrefixOperator"; - SyntaxKind[SyntaxKind["PostfixOperator"] = 144] = "PostfixOperator"; - SyntaxKind[SyntaxKind["BinaryExpression"] = 145] = "BinaryExpression"; - SyntaxKind[SyntaxKind["ConditionalExpression"] = 146] = "ConditionalExpression"; - SyntaxKind[SyntaxKind["OmittedExpression"] = 147] = "OmittedExpression"; - SyntaxKind[SyntaxKind["Block"] = 148] = "Block"; - SyntaxKind[SyntaxKind["VariableStatement"] = 149] = "VariableStatement"; - SyntaxKind[SyntaxKind["EmptyStatement"] = 150] = "EmptyStatement"; - SyntaxKind[SyntaxKind["ExpressionStatement"] = 151] = "ExpressionStatement"; - SyntaxKind[SyntaxKind["IfStatement"] = 152] = "IfStatement"; - SyntaxKind[SyntaxKind["DoStatement"] = 153] = "DoStatement"; - SyntaxKind[SyntaxKind["WhileStatement"] = 154] = "WhileStatement"; - SyntaxKind[SyntaxKind["ForStatement"] = 155] = "ForStatement"; - SyntaxKind[SyntaxKind["ForInStatement"] = 156] = "ForInStatement"; - SyntaxKind[SyntaxKind["ContinueStatement"] = 157] = "ContinueStatement"; - SyntaxKind[SyntaxKind["BreakStatement"] = 158] = "BreakStatement"; - SyntaxKind[SyntaxKind["ReturnStatement"] = 159] = "ReturnStatement"; - SyntaxKind[SyntaxKind["WithStatement"] = 160] = "WithStatement"; - SyntaxKind[SyntaxKind["SwitchStatement"] = 161] = "SwitchStatement"; - SyntaxKind[SyntaxKind["CaseClause"] = 162] = "CaseClause"; - SyntaxKind[SyntaxKind["DefaultClause"] = 163] = "DefaultClause"; - SyntaxKind[SyntaxKind["LabeledStatement"] = 164] = "LabeledStatement"; - SyntaxKind[SyntaxKind["ThrowStatement"] = 165] = "ThrowStatement"; - SyntaxKind[SyntaxKind["TryStatement"] = 166] = "TryStatement"; - SyntaxKind[SyntaxKind["TryBlock"] = 167] = "TryBlock"; - SyntaxKind[SyntaxKind["CatchBlock"] = 168] = "CatchBlock"; - SyntaxKind[SyntaxKind["FinallyBlock"] = 169] = "FinallyBlock"; - SyntaxKind[SyntaxKind["DebuggerStatement"] = 170] = "DebuggerStatement"; - SyntaxKind[SyntaxKind["VariableDeclaration"] = 171] = "VariableDeclaration"; - SyntaxKind[SyntaxKind["FunctionDeclaration"] = 172] = "FunctionDeclaration"; - SyntaxKind[SyntaxKind["FunctionBlock"] = 173] = "FunctionBlock"; - SyntaxKind[SyntaxKind["ClassDeclaration"] = 174] = "ClassDeclaration"; - SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 175] = "InterfaceDeclaration"; - SyntaxKind[SyntaxKind["EnumDeclaration"] = 176] = "EnumDeclaration"; - SyntaxKind[SyntaxKind["ModuleDeclaration"] = 177] = "ModuleDeclaration"; - SyntaxKind[SyntaxKind["ModuleBlock"] = 178] = "ModuleBlock"; - SyntaxKind[SyntaxKind["ImportDeclaration"] = 179] = "ImportDeclaration"; - SyntaxKind[SyntaxKind["ExportAssignment"] = 180] = "ExportAssignment"; - SyntaxKind[SyntaxKind["EnumMember"] = 181] = "EnumMember"; - SyntaxKind[SyntaxKind["SourceFile"] = 182] = "SourceFile"; - SyntaxKind[SyntaxKind["Program"] = 183] = "Program"; - SyntaxKind[SyntaxKind["SyntaxList"] = 184] = "SyntaxList"; - SyntaxKind[SyntaxKind["Count"] = 185] = "Count"; + SyntaxKind[SyntaxKind["UnionType"] = 132] = "UnionType"; + SyntaxKind[SyntaxKind["ParenType"] = 133] = "ParenType"; + SyntaxKind[SyntaxKind["ArrayLiteral"] = 134] = "ArrayLiteral"; + SyntaxKind[SyntaxKind["ObjectLiteral"] = 135] = "ObjectLiteral"; + SyntaxKind[SyntaxKind["PropertyAssignment"] = 136] = "PropertyAssignment"; + SyntaxKind[SyntaxKind["PropertyAccess"] = 137] = "PropertyAccess"; + SyntaxKind[SyntaxKind["IndexedAccess"] = 138] = "IndexedAccess"; + SyntaxKind[SyntaxKind["CallExpression"] = 139] = "CallExpression"; + SyntaxKind[SyntaxKind["NewExpression"] = 140] = "NewExpression"; + SyntaxKind[SyntaxKind["TypeAssertion"] = 141] = "TypeAssertion"; + SyntaxKind[SyntaxKind["ParenExpression"] = 142] = "ParenExpression"; + SyntaxKind[SyntaxKind["FunctionExpression"] = 143] = "FunctionExpression"; + SyntaxKind[SyntaxKind["ArrowFunction"] = 144] = "ArrowFunction"; + SyntaxKind[SyntaxKind["PrefixOperator"] = 145] = "PrefixOperator"; + SyntaxKind[SyntaxKind["PostfixOperator"] = 146] = "PostfixOperator"; + SyntaxKind[SyntaxKind["BinaryExpression"] = 147] = "BinaryExpression"; + SyntaxKind[SyntaxKind["ConditionalExpression"] = 148] = "ConditionalExpression"; + SyntaxKind[SyntaxKind["OmittedExpression"] = 149] = "OmittedExpression"; + SyntaxKind[SyntaxKind["Block"] = 150] = "Block"; + SyntaxKind[SyntaxKind["VariableStatement"] = 151] = "VariableStatement"; + SyntaxKind[SyntaxKind["EmptyStatement"] = 152] = "EmptyStatement"; + SyntaxKind[SyntaxKind["ExpressionStatement"] = 153] = "ExpressionStatement"; + SyntaxKind[SyntaxKind["IfStatement"] = 154] = "IfStatement"; + SyntaxKind[SyntaxKind["DoStatement"] = 155] = "DoStatement"; + SyntaxKind[SyntaxKind["WhileStatement"] = 156] = "WhileStatement"; + SyntaxKind[SyntaxKind["ForStatement"] = 157] = "ForStatement"; + SyntaxKind[SyntaxKind["ForInStatement"] = 158] = "ForInStatement"; + SyntaxKind[SyntaxKind["ContinueStatement"] = 159] = "ContinueStatement"; + SyntaxKind[SyntaxKind["BreakStatement"] = 160] = "BreakStatement"; + SyntaxKind[SyntaxKind["ReturnStatement"] = 161] = "ReturnStatement"; + SyntaxKind[SyntaxKind["WithStatement"] = 162] = "WithStatement"; + SyntaxKind[SyntaxKind["SwitchStatement"] = 163] = "SwitchStatement"; + SyntaxKind[SyntaxKind["CaseClause"] = 164] = "CaseClause"; + SyntaxKind[SyntaxKind["DefaultClause"] = 165] = "DefaultClause"; + SyntaxKind[SyntaxKind["LabeledStatement"] = 166] = "LabeledStatement"; + SyntaxKind[SyntaxKind["ThrowStatement"] = 167] = "ThrowStatement"; + SyntaxKind[SyntaxKind["TryStatement"] = 168] = "TryStatement"; + SyntaxKind[SyntaxKind["TryBlock"] = 169] = "TryBlock"; + SyntaxKind[SyntaxKind["CatchBlock"] = 170] = "CatchBlock"; + SyntaxKind[SyntaxKind["FinallyBlock"] = 171] = "FinallyBlock"; + SyntaxKind[SyntaxKind["DebuggerStatement"] = 172] = "DebuggerStatement"; + SyntaxKind[SyntaxKind["VariableDeclaration"] = 173] = "VariableDeclaration"; + SyntaxKind[SyntaxKind["FunctionDeclaration"] = 174] = "FunctionDeclaration"; + SyntaxKind[SyntaxKind["FunctionBlock"] = 175] = "FunctionBlock"; + SyntaxKind[SyntaxKind["ClassDeclaration"] = 176] = "ClassDeclaration"; + SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 177] = "InterfaceDeclaration"; + SyntaxKind[SyntaxKind["EnumDeclaration"] = 178] = "EnumDeclaration"; + SyntaxKind[SyntaxKind["ModuleDeclaration"] = 179] = "ModuleDeclaration"; + SyntaxKind[SyntaxKind["ModuleBlock"] = 180] = "ModuleBlock"; + SyntaxKind[SyntaxKind["ImportDeclaration"] = 181] = "ImportDeclaration"; + SyntaxKind[SyntaxKind["ExportAssignment"] = 182] = "ExportAssignment"; + SyntaxKind[SyntaxKind["EnumMember"] = 183] = "EnumMember"; + SyntaxKind[SyntaxKind["SourceFile"] = 184] = "SourceFile"; + SyntaxKind[SyntaxKind["Program"] = 185] = "Program"; + SyntaxKind[SyntaxKind["SyntaxList"] = 186] = "SyntaxList"; + SyntaxKind[SyntaxKind["Count"] = 187] = "Count"; SyntaxKind[SyntaxKind["FirstAssignment"] = SyntaxKind.EqualsToken] = "FirstAssignment"; SyntaxKind[SyntaxKind["LastAssignment"] = SyntaxKind.CaretEqualsToken] = "LastAssignment"; SyntaxKind[SyntaxKind["FirstReservedWord"] = SyntaxKind.BreakKeyword] = "FirstReservedWord"; @@ -1555,11 +1558,13 @@ var ts; SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = SyntaxKind.ImplementsKeyword] = "FirstFutureReservedWord"; SyntaxKind[SyntaxKind["LastFutureReservedWord"] = SyntaxKind.YieldKeyword] = "LastFutureReservedWord"; SyntaxKind[SyntaxKind["FirstTypeNode"] = SyntaxKind.TypeReference] = "FirstTypeNode"; - SyntaxKind[SyntaxKind["LastTypeNode"] = SyntaxKind.TupleType] = "LastTypeNode"; + SyntaxKind[SyntaxKind["LastTypeNode"] = SyntaxKind.ParenType] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = SyntaxKind.OpenBraceToken] = "FirstPunctuation"; SyntaxKind[SyntaxKind["LastPunctuation"] = SyntaxKind.CaretEqualsToken] = "LastPunctuation"; SyntaxKind[SyntaxKind["FirstToken"] = SyntaxKind.EndOfFileToken] = "FirstToken"; SyntaxKind[SyntaxKind["LastToken"] = SyntaxKind.StringKeyword] = "LastToken"; + SyntaxKind[SyntaxKind["FirstTriviaToken"] = SyntaxKind.SingleLineCommentTrivia] = "FirstTriviaToken"; + SyntaxKind[SyntaxKind["LastTriviaToken"] = SyntaxKind.WhitespaceTrivia] = "LastTriviaToken"; })(ts.SyntaxKind || (ts.SyntaxKind = {})); var SyntaxKind = ts.SyntaxKind; (function (NodeFlags) { @@ -1592,8 +1597,18 @@ var ts; TypeFormatFlags[TypeFormatFlags["WriteArrayAsGenericType"] = 0x00000001] = "WriteArrayAsGenericType"; TypeFormatFlags[TypeFormatFlags["UseTypeOfFunction"] = 0x00000002] = "UseTypeOfFunction"; TypeFormatFlags[TypeFormatFlags["NoTruncation"] = 0x00000004] = "NoTruncation"; + TypeFormatFlags[TypeFormatFlags["WriteArrowStyleSignature"] = 0x00000008] = "WriteArrowStyleSignature"; + TypeFormatFlags[TypeFormatFlags["WriteOwnNameForAnyLike"] = 0x00000010] = "WriteOwnNameForAnyLike"; + TypeFormatFlags[TypeFormatFlags["WriteTypeArgumentsOfSignature"] = 0x00000020] = "WriteTypeArgumentsOfSignature"; + TypeFormatFlags[TypeFormatFlags["InElementType"] = 0x00000040] = "InElementType"; })(ts.TypeFormatFlags || (ts.TypeFormatFlags = {})); var TypeFormatFlags = ts.TypeFormatFlags; + (function (SymbolFormatFlags) { + SymbolFormatFlags[SymbolFormatFlags["None"] = 0x00000000] = "None"; + SymbolFormatFlags[SymbolFormatFlags["WriteTypeParametersOrArguments"] = 0x00000001] = "WriteTypeParametersOrArguments"; + SymbolFormatFlags[SymbolFormatFlags["UseOnlyExternalAliasing"] = 0x00000002] = "UseOnlyExternalAliasing"; + })(ts.SymbolFormatFlags || (ts.SymbolFormatFlags = {})); + var SymbolFormatFlags = ts.SymbolFormatFlags; (function (SymbolAccessibility) { SymbolAccessibility[SymbolAccessibility["Accessible"] = 0] = "Accessible"; SymbolAccessibility[SymbolAccessibility["NotAccessible"] = 1] = "NotAccessible"; @@ -1628,6 +1643,7 @@ var ts; SymbolFlags[SymbolFlags["Merged"] = 0x01000000] = "Merged"; SymbolFlags[SymbolFlags["Transient"] = 0x02000000] = "Transient"; SymbolFlags[SymbolFlags["Prototype"] = 0x04000000] = "Prototype"; + SymbolFlags[SymbolFlags["UnionProperty"] = 0x08000000] = "UnionProperty"; SymbolFlags[SymbolFlags["Value"] = SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.EnumMember | SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule | SymbolFlags.Method | SymbolFlags.GetAccessor | SymbolFlags.SetAccessor] = "Value"; SymbolFlags[SymbolFlags["Type"] = SymbolFlags.Class | SymbolFlags.Interface | SymbolFlags.Enum | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral | SymbolFlags.TypeParameter] = "Type"; SymbolFlags[SymbolFlags["Namespace"] = SymbolFlags.ValueModule | SymbolFlags.NamespaceModule] = "Namespace"; @@ -1667,6 +1683,7 @@ var ts; NodeCheckFlags[NodeCheckFlags["SuperInstance"] = 0x00000010] = "SuperInstance"; NodeCheckFlags[NodeCheckFlags["SuperStatic"] = 0x00000020] = "SuperStatic"; NodeCheckFlags[NodeCheckFlags["ContextChecked"] = 0x00000040] = "ContextChecked"; + NodeCheckFlags[NodeCheckFlags["EnumValuesComputed"] = 0x00000080] = "EnumValuesComputed"; })(ts.NodeCheckFlags || (ts.NodeCheckFlags = {})); var NodeCheckFlags = ts.NodeCheckFlags; (function (TypeFlags) { @@ -1684,12 +1701,14 @@ var ts; TypeFlags[TypeFlags["Interface"] = 0x00000800] = "Interface"; TypeFlags[TypeFlags["Reference"] = 0x00001000] = "Reference"; TypeFlags[TypeFlags["Tuple"] = 0x00002000] = "Tuple"; - TypeFlags[TypeFlags["Anonymous"] = 0x00004000] = "Anonymous"; - TypeFlags[TypeFlags["FromSignature"] = 0x00008000] = "FromSignature"; + TypeFlags[TypeFlags["Union"] = 0x00004000] = "Union"; + TypeFlags[TypeFlags["Anonymous"] = 0x00008000] = "Anonymous"; + TypeFlags[TypeFlags["FromSignature"] = 0x00010000] = "FromSignature"; TypeFlags[TypeFlags["Intrinsic"] = TypeFlags.Any | TypeFlags.String | TypeFlags.Number | TypeFlags.Boolean | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null] = "Intrinsic"; TypeFlags[TypeFlags["StringLike"] = TypeFlags.String | TypeFlags.StringLiteral] = "StringLike"; TypeFlags[TypeFlags["NumberLike"] = TypeFlags.Number | TypeFlags.Enum] = "NumberLike"; TypeFlags[TypeFlags["ObjectType"] = TypeFlags.Class | TypeFlags.Interface | TypeFlags.Reference | TypeFlags.Tuple | TypeFlags.Anonymous] = "ObjectType"; + TypeFlags[TypeFlags["Structured"] = TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter] = "Structured"; })(ts.TypeFlags || (ts.TypeFlags = {})); var TypeFlags = ts.TypeFlags; (function (SignatureKind) { @@ -1851,8 +1870,9 @@ var ts; var result; if (array) { for (var i = 0, len = array.length; i < len; i++) { - if (result = callback(array[i])) + if (result = callback(array[i])) { break; + } } } return result; @@ -1880,6 +1900,18 @@ var ts; return -1; } ts.indexOf = indexOf; + function countWhere(array, predicate) { + var count = 0; + if (array) { + for (var i = 0, len = array.length; i < len; i++) { + if (predicate(array[i])) { + count++; + } + } + } + return count; + } + ts.countWhere = countWhere; function filter(array, f) { if (array) { var result = []; @@ -1911,7 +1943,7 @@ var ts; return array1.concat(array2); } ts.concatenate = concatenate; - function uniqueElements(array) { + function deduplicate(array) { if (array) { var result = []; for (var i = 0, len = array.length; i < len; i++) { @@ -1922,7 +1954,7 @@ var ts; } return result; } - ts.uniqueElements = uniqueElements; + ts.deduplicate = deduplicate; function sum(array, prop) { var result = 0; for (var i = 0; i < array.length; i++) { @@ -2020,10 +2052,7 @@ var ts; } ts.localizedDiagnosticMessages = undefined; function getLocaleSpecificMessage(message) { - if (ts.localizedDiagnosticMessages) { - message = ts.localizedDiagnosticMessages[message]; - } - return message; + return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message] ? ts.localizedDiagnosticMessages[message] : message; } ts.getLocaleSpecificMessage = getLocaleSpecificMessage; function createFileDiagnostic(file, start, length, message) { @@ -2244,14 +2273,14 @@ var ts; return getNormalizedPathComponents(pathOrUrl, currentDirectory); } } - function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, isAbsolutePathAnUrl) { + function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, getCanonicalFileName, isAbsolutePathAnUrl) { var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory); var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory); if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") { directoryComponents.length--; } for (var joinStartIndex = 0; joinStartIndex < pathComponents.length && joinStartIndex < directoryComponents.length; joinStartIndex++) { - if (directoryComponents[joinStartIndex] !== pathComponents[joinStartIndex]) { + if (getCanonicalFileName(directoryComponents[joinStartIndex]) !== getCanonicalFileName(pathComponents[joinStartIndex])) { break; } } @@ -2295,6 +2324,37 @@ var ts; return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; } ts.fileExtensionIs = fileExtensionIs; + var supportedExtensions = [".d.ts", ".ts", ".js"]; + function removeFileExtension(path) { + for (var i = 0; i < supportedExtensions.length; i++) { + var ext = supportedExtensions[i]; + if (fileExtensionIs(path, ext)) { + return path.substr(0, path.length - ext.length); + } + } + return path; + } + ts.removeFileExtension = removeFileExtension; + var escapedCharsRegExp = /[\t\v\f\b\0\r\n\"\\\u2028\u2029\u0085]/g; + var escapedCharsMap = { + "\t": "\\t", + "\v": "\\v", + "\f": "\\f", + "\b": "\\b", + "\0": "\\0", + "\r": "\\r", + "\n": "\\n", + "\"": "\\\"", + "\u2028": "\\u2028", + "\u2029": "\\u2029", + "\u0085": "\\u0085" + }; + function escapeString(s) { + return escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, function (c) { + return escapedCharsMap[c] || c; + }) : s; + } + ts.escapeString = escapeString; function Symbol(flags, name) { this.flags = flags; this.name = name; @@ -2354,7 +2414,7 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { - var nodeConstructors = new Array(185 /* Count */); + var nodeConstructors = new Array(187 /* Count */); function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); } @@ -2366,19 +2426,8 @@ var ts; node.flags = flags; return node; } - var moduleExtensions = [".d.ts", ".ts", ".js"]; - function getModuleNameFromFilename(filename) { - for (var i = 0; i < moduleExtensions.length; i++) { - var ext = moduleExtensions[i]; - var len = filename.length - ext.length; - if (len > 0 && filename.substr(len) === ext) - return filename.substr(0, len); - } - return filename; - } - ts.getModuleNameFromFilename = getModuleNameFromFilename; function getSourceFileOfNode(node) { - while (node && node.kind !== 182 /* SourceFile */) + while (node && node.kind !== 184 /* SourceFile */) node = node.parent; return node; } @@ -2397,15 +2446,15 @@ var ts; return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos); } ts.getTokenPosOfNode = getTokenPosOfNode; - function getSourceTextOfNodeFromSourceText(sourceText, node) { + function getTextOfNodeFromSourceText(sourceText, node) { return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end); } - ts.getSourceTextOfNodeFromSourceText = getSourceTextOfNodeFromSourceText; - function getSourceTextOfNode(node) { + ts.getTextOfNodeFromSourceText = getTextOfNodeFromSourceText; + function getTextOfNode(node) { var text = getSourceFileOfNode(node).text; return text.substring(ts.skipTrivia(text, node.pos), node.end); } - ts.getSourceTextOfNode = getSourceTextOfNode; + ts.getTextOfNode = getTextOfNode; function escapeIdentifier(identifier) { return identifier.length >= 2 && identifier.charCodeAt(0) === 95 /* _ */ && identifier.charCodeAt(1) === 95 /* _ */ ? "_" + identifier : identifier; } @@ -2415,7 +2464,7 @@ var ts; } ts.unescapeIdentifier = unescapeIdentifier; function identifierToString(identifier) { - return identifier.kind === 115 /* Missing */ ? "(Missing)" : getSourceTextOfNode(identifier); + return identifier.kind === 115 /* Missing */ ? "(Missing)" : getTextOfNode(identifier); } ts.identifierToString = identifierToString; function createDiagnosticForNode(node, message, arg0, arg1, arg2) { @@ -2437,12 +2486,12 @@ var ts; function getErrorSpanForNode(node) { var errorSpan; switch (node.kind) { - case 171 /* VariableDeclaration */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 177 /* ModuleDeclaration */: - case 176 /* EnumDeclaration */: - case 181 /* EnumMember */: + case 173 /* VariableDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 179 /* ModuleDeclaration */: + case 178 /* EnumDeclaration */: + case 183 /* EnumMember */: errorSpan = node.name; break; } @@ -2453,8 +2502,12 @@ var ts; return file.externalModuleIndicator !== undefined; } ts.isExternalModule = isExternalModule; + function isDeclarationFile(file) { + return (file.flags & 1024 /* DeclarationFile */) !== 0; + } + ts.isDeclarationFile = isDeclarationFile; function isPrologueDirective(node) { - return node.kind === 151 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */; + return node.kind === 153 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */; } ts.isPrologueDirective = isPrologueDirective; function isEvalOrArgumentsIdentifier(node) { @@ -2464,17 +2517,18 @@ var ts; ts.Debug.assert(isPrologueDirective(node)); return node.expression.text === "use strict"; } - function getLeadingCommentsOfNode(node, sourceFileOfNode) { + function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { + sourceFileOfNode = sourceFileOfNode || getSourceFileOfNode(node); if (node.kind === 118 /* Parameter */ || node.kind === 117 /* TypeParameter */) { - return ts.concatenate(ts.getTrailingComments(sourceFileOfNode.text, node.pos), ts.getLeadingComments(sourceFileOfNode.text, node.pos)); + return ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)); } else { - return ts.getLeadingComments(sourceFileOfNode.text, node.pos); + return ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos); } } - ts.getLeadingCommentsOfNode = getLeadingCommentsOfNode; + ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode; function getJsDocComments(node, sourceFileOfNode) { - return ts.filter(getLeadingCommentsOfNode(node, sourceFileOfNode), function (comment) { return isJsDocComment(comment); }); + return ts.filter(getLeadingCommentRangesOfNode(node, sourceFileOfNode), function (comment) { return isJsDocComment(comment); }); function isJsDocComment(comment) { return sourceFileOfNode.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */ && sourceFileOfNode.text.charCodeAt(comment.pos + 2) === 42 /* asterisk */ && sourceFileOfNode.text.charCodeAt(comment.pos + 3) !== 47 /* slash */; } @@ -2508,7 +2562,7 @@ var ts; case 118 /* Parameter */: return child(node.name) || child(node.type) || child(node.initializer); case 119 /* Property */: - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return child(node.name) || child(node.type) || child(node.initializer); case 124 /* CallSignature */: case 125 /* ConstructSignature */: @@ -2518,9 +2572,9 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: return child(node.name) || children(node.typeParameters) || children(node.parameters) || child(node.type) || child(node.body); case 127 /* TypeReference */: return child(node.typeName) || children(node.typeArguments); @@ -2532,84 +2586,88 @@ var ts; return child(node.elementType); case 131 /* TupleType */: return children(node.elementTypes); - case 132 /* ArrayLiteral */: + case 132 /* UnionType */: + return children(node.types); + case 133 /* ParenType */: + return child(node.type); + case 134 /* ArrayLiteral */: return children(node.elements); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return children(node.properties); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return child(node.left) || child(node.right); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return child(node.object) || child(node.index); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return child(node.func) || children(node.typeArguments) || children(node.arguments); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return child(node.type) || child(node.operand); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return child(node.expression); - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: return child(node.operand); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return child(node.left) || child(node.right); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return child(node.condition) || child(node.whenTrue) || child(node.whenFalse); - case 148 /* Block */: - case 167 /* TryBlock */: - case 169 /* FinallyBlock */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 182 /* SourceFile */: + case 150 /* Block */: + case 169 /* TryBlock */: + case 171 /* FinallyBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 184 /* SourceFile */: return children(node.statements); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return children(node.declarations); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return child(node.expression); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return child(node.expression) || child(node.thenStatement) || child(node.elseStatement); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return child(node.statement) || child(node.expression); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return child(node.expression) || child(node.statement); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return children(node.declarations) || child(node.initializer) || child(node.condition) || child(node.iterator) || child(node.statement); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return child(node.declaration) || child(node.variable) || child(node.expression) || child(node.statement); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return child(node.label); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return child(node.expression); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return child(node.expression) || child(node.statement); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return child(node.expression) || children(node.clauses); - case 162 /* CaseClause */: - case 163 /* DefaultClause */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: return child(node.expression) || children(node.statements); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return child(node.label) || child(node.statement); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return child(node.expression); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return child(node.tryBlock) || child(node.catchBlock) || child(node.finallyBlock); - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return child(node.variable) || children(node.statements); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return child(node.name) || child(node.type) || child(node.initializer); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return child(node.name) || children(node.typeParameters) || child(node.baseType) || children(node.implementedTypes) || children(node.members); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return child(node.name) || children(node.typeParameters) || children(node.baseTypes) || children(node.members); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return child(node.name) || children(node.members); - case 181 /* EnumMember */: + case 183 /* EnumMember */: return child(node.name) || child(node.initializer); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return child(node.name) || child(node.body); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return child(node.name) || child(node.entityName) || child(node.externalModuleName); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return child(node.exportName); } } @@ -2618,24 +2676,24 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return visitor(node); - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 160 /* WithStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 163 /* DefaultClause */: - case 164 /* LabeledStatement */: - case 166 /* TryStatement */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: + case 150 /* Block */: + case 175 /* FunctionBlock */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: return forEachChild(node, traverse); } } @@ -2644,9 +2702,9 @@ var ts; function isAnyFunction(node) { if (node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: case 120 /* Method */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: @@ -2673,20 +2731,20 @@ var ts; return undefined; } switch (node.kind) { - case 142 /* ArrowFunction */: + case 144 /* ArrowFunction */: if (!includeArrowFunctions) { continue; } - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 177 /* ModuleDeclaration */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 179 /* ModuleDeclaration */: case 119 /* Property */: case 120 /* Method */: case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 176 /* EnumDeclaration */: - case 182 /* SourceFile */: + case 178 /* EnumDeclaration */: + case 184 /* SourceFile */: return node; } } @@ -2726,19 +2784,19 @@ var ts; switch (node.kind) { case 117 /* TypeParameter */: case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return true; } return false; @@ -2746,24 +2804,24 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 158 /* BreakStatement */: - case 157 /* ContinueStatement */: - case 170 /* DebuggerStatement */: - case 153 /* DoStatement */: - case 151 /* ExpressionStatement */: - case 150 /* EmptyStatement */: - case 156 /* ForInStatement */: - case 155 /* ForStatement */: - case 152 /* IfStatement */: - case 164 /* LabeledStatement */: - case 159 /* ReturnStatement */: - case 161 /* SwitchStatement */: + case 160 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 172 /* DebuggerStatement */: + case 155 /* DoStatement */: + case 153 /* ExpressionStatement */: + case 152 /* EmptyStatement */: + case 158 /* ForInStatement */: + case 157 /* ForStatement */: + case 154 /* IfStatement */: + case 166 /* LabeledStatement */: + case 161 /* ReturnStatement */: + case 163 /* SwitchStatement */: case 88 /* ThrowKeyword */: - case 166 /* TryStatement */: - case 149 /* VariableStatement */: - case 154 /* WhileStatement */: - case 160 /* WithStatement */: - case 180 /* ExportAssignment */: + case 168 /* TryStatement */: + case 151 /* VariableStatement */: + case 156 /* WhileStatement */: + case 162 /* WithStatement */: + case 182 /* ExportAssignment */: return true; default: return false; @@ -2775,10 +2833,10 @@ var ts; return false; } var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 141 /* FunctionExpression */) { + if (isDeclaration(parent) || parent.kind === 143 /* FunctionExpression */) { return parent.name === name; } - if (parent.kind === 168 /* CatchBlock */) { + if (parent.kind === 170 /* CatchBlock */) { return parent.variable === name; } return false; @@ -2786,15 +2844,15 @@ var ts; ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName; function getAncestor(node, kind) { switch (kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: while (node) { switch (node.kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return node; - case 176 /* EnumDeclaration */: - case 175 /* InterfaceDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 178 /* EnumDeclaration */: + case 177 /* InterfaceDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return undefined; default: node = node.parent; @@ -2893,12 +2951,6 @@ var ts; ModifierContext[ModifierContext["ClassMembers"] = 2] = "ClassMembers"; ModifierContext[ModifierContext["Parameters"] = 3] = "Parameters"; })(ModifierContext || (ModifierContext = {})); - var TrailingCommaBehavior; - (function (TrailingCommaBehavior) { - TrailingCommaBehavior[TrailingCommaBehavior["Disallow"] = 0] = "Disallow"; - TrailingCommaBehavior[TrailingCommaBehavior["Allow"] = 1] = "Allow"; - TrailingCommaBehavior[TrailingCommaBehavior["Preserve"] = 2] = "Preserve"; - })(TrailingCommaBehavior || (TrailingCommaBehavior = {})); var ControlBlockContext; (function (ControlBlockContext) { ControlBlockContext[ControlBlockContext["NotNested"] = 0] = "NotNested"; @@ -2909,6 +2961,10 @@ var ts; return ts.SyntaxKind.FirstKeyword <= token && token <= ts.SyntaxKind.LastKeyword; } ts.isKeyword = isKeyword; + function isTrivia(token) { + return ts.SyntaxKind.FirstTriviaToken <= token && token <= ts.SyntaxKind.LastTriviaToken; + } + ts.isTrivia = isTrivia; function isModifier(token) { switch (token) { case 102 /* PublicKeyword */: @@ -3169,7 +3225,9 @@ var ts; return finishNode(node); } error(ts.Diagnostics.Identifier_expected); - return createMissingNode(); + var node = createMissingNode(); + node.text = ""; + return node; } function parseIdentifier() { return createIdentifier(isIdentifier()); @@ -3221,14 +3279,14 @@ var ts; case 14 /* TypeParameters */: return isIdentifier(); case 10 /* ArgumentExpressions */: - return isExpression(); + return token === 18 /* CommaToken */ || isExpression(); case 12 /* ArrayLiteralMembers */: return token === 18 /* CommaToken */ || isExpression(); case 13 /* Parameters */: return isParameter(); case 15 /* TypeArguments */: case 16 /* TupleElementTypes */: - return isType(); + return token === 18 /* CommaToken */ || isType(); } ts.Debug.fail("Non-exhaustive case in 'isListElement'."); } @@ -3321,7 +3379,7 @@ var ts; parsingContext = saveParsingContext; return result; } - function parseDelimitedList(kind, parseElement, trailingCommaBehavior) { + function parseDelimitedList(kind, parseElement, allowTrailingComma) { var saveParsingContext = parsingContext; parsingContext |= 1 << kind; var result = []; @@ -3342,16 +3400,6 @@ var ts; error(ts.Diagnostics._0_expected, ","); } else if (isListTerminator(kind)) { - if (commaStart >= 0) { - if (trailingCommaBehavior === 0 /* Disallow */) { - if (file.syntacticErrors.length === errorCountBeforeParsingList) { - grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, ts.Diagnostics.Trailing_comma_not_allowed); - } - } - else if (trailingCommaBehavior === 2 /* Preserve */) { - result.push(createNode(147 /* OmittedExpression */)); - } - } break; } else { @@ -3362,6 +3410,14 @@ var ts; nextToken(); } } + if (commaStart >= 0) { + if (!allowTrailingComma) { + if (file.syntacticErrors.length === errorCountBeforeParsingList) { + grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, ts.Diagnostics.Trailing_comma_not_allowed); + } + } + result.hasTrailingComma = true; + } result.end = getNodeEnd(); parsingContext = saveParsingContext; return result; @@ -3381,7 +3437,7 @@ var ts; } function parseBracketedList(kind, parseElement, startToken, endToken) { if (parseExpected(startToken)) { - var result = parseDelimitedList(kind, parseElement, 0 /* Disallow */); + var result = parseDelimitedList(kind, parseElement, false); parseExpected(endToken); return result; } @@ -3685,6 +3741,13 @@ var ts; } return finishNode(node); } + function parseParenType() { + var node = createNode(133 /* ParenType */); + parseExpected(11 /* OpenParenToken */); + node.type = parseType(); + parseExpected(12 /* CloseParenToken */); + return finishNode(node); + } function parseFunctionType(signatureKind) { var node = createNode(129 /* TypeLiteral */); var member = createNode(signatureKind); @@ -3716,10 +3779,7 @@ var ts; case 13 /* OpenBracketToken */: return parseTupleType(); case 11 /* OpenParenToken */: - case 19 /* LessThanToken */: - return parseFunctionType(124 /* CallSignature */); - case 82 /* NewKeyword */: - return parseFunctionType(125 /* ConstructSignature */); + return parseParenType(); default: if (isIdentifier()) { return parseTypeReference(); @@ -3744,15 +3804,15 @@ var ts; case 11 /* OpenParenToken */: return lookAhead(function () { nextToken(); - return token === 12 /* CloseParenToken */ || isParameter(); + return token === 12 /* CloseParenToken */ || isParameter() || isType(); }); default: return isIdentifier(); } } - function parseType() { + function parsePrimaryType() { var type = parseNonArrayType(); - while (type && !scanner.hasPrecedingLineBreak() && parseOptional(13 /* OpenBracketToken */)) { + while (!scanner.hasPrecedingLineBreak() && parseOptional(13 /* OpenBracketToken */)) { parseExpected(14 /* CloseBracketToken */); var node = createNode(130 /* ArrayType */, type.pos); node.elementType = type; @@ -3760,6 +3820,51 @@ var ts; } return type; } + function parseUnionType() { + var type = parsePrimaryType(); + if (token === 39 /* BarToken */) { + var types = [type]; + types.pos = type.pos; + while (parseOptional(39 /* BarToken */)) { + types.push(parsePrimaryType()); + } + types.end = getNodeEnd(); + var node = createNode(132 /* UnionType */, type.pos); + node.types = types; + type = finishNode(node); + } + return type; + } + function isFunctionType() { + return token === 19 /* LessThanToken */ || token === 11 /* OpenParenToken */ && lookAhead(function () { + nextToken(); + if (token === 12 /* CloseParenToken */ || token === 16 /* DotDotDotToken */) { + return true; + } + if (isIdentifier() || isModifier(token)) { + nextToken(); + if (token === 46 /* ColonToken */ || token === 18 /* CommaToken */ || token === 45 /* QuestionToken */ || token === 47 /* EqualsToken */ || isIdentifier() || isModifier(token)) { + return true; + } + if (token === 12 /* CloseParenToken */) { + nextToken(); + if (token === 27 /* EqualsGreaterThanToken */) { + return true; + } + } + } + return false; + }); + } + function parseType() { + if (isFunctionType()) { + return parseFunctionType(124 /* CallSignature */); + } + if (token === 82 /* NewKeyword */) { + return parseFunctionType(125 /* ConstructSignature */); + } + return parseUnionType(); + } function parseTypeAnnotation() { return parseOptional(46 /* ColonToken */) ? parseType() : undefined; } @@ -3836,14 +3941,14 @@ var ts; function isLeftHandSideExpression(expr) { if (expr) { switch (expr.kind) { - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 138 /* NewExpression */: - case 137 /* CallExpression */: - case 132 /* ArrayLiteral */: - case 140 /* ParenExpression */: - case 133 /* ObjectLiteral */: - case 141 /* FunctionExpression */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 140 /* NewExpression */: + case 139 /* CallExpression */: + case 134 /* ArrayLiteral */: + case 142 /* ParenExpression */: + case 135 /* ObjectLiteral */: + case 143 /* FunctionExpression */: case 59 /* Identifier */: case 115 /* Missing */: case 8 /* RegularExpressionLiteral */: @@ -3884,7 +3989,7 @@ var ts; return parseArrowExpressionTail(pos, sig, false); } else { - return makeFunctionExpression(142 /* ArrowFunction */, pos, undefined, sig, createMissingNode()); + return makeFunctionExpression(144 /* ArrowFunction */, pos, undefined, sig, createMissingNode()); } } var sig = tryParseSignatureIfArrowOrBraceFollows(); @@ -3958,7 +4063,7 @@ var ts; else { body = parseAssignmentExpression(noIn); } - return makeFunctionExpression(142 /* ArrowFunction */, pos, undefined, sig, body); + return makeFunctionExpression(144 /* ArrowFunction */, pos, undefined, sig, body); } function isAssignmentOperator() { return token >= ts.SyntaxKind.FirstAssignment && token <= ts.SyntaxKind.LastAssignment; @@ -3966,7 +4071,7 @@ var ts; function parseConditionalExpression(noIn) { var expr = parseBinaryExpression(noIn); while (parseOptional(45 /* QuestionToken */)) { - var node = createNode(146 /* ConditionalExpression */, expr.pos); + var node = createNode(148 /* ConditionalExpression */, expr.pos); node.condition = expr; node.whenTrue = parseAssignmentExpression(false); parseExpected(46 /* ColonToken */); @@ -4030,7 +4135,7 @@ var ts; return undefined; } function makeBinaryExpression(left, operator, right) { - var node = createNode(145 /* BinaryExpression */, left.pos); + var node = createNode(147 /* BinaryExpression */, left.pos); node.left = left; node.operator = operator; node.right = right; @@ -4052,14 +4157,14 @@ var ts; nextToken(); var operand = parseUnaryExpression(); if (isInStrictMode) { - if ((token === 33 /* PlusPlusToken */ || token === 34 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(operand)) { + if ((operator === 33 /* PlusPlusToken */ || operator === 34 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(operand)) { reportInvalidUseInStrictMode(operand); } - else if (token === 68 /* DeleteKeyword */ && operand.kind === 59 /* Identifier */) { + else if (operator === 68 /* DeleteKeyword */ && operand.kind === 59 /* Identifier */) { grammarErrorOnNode(operand, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); } } - return makeUnaryExpression(143 /* PrefixOperator */, pos, operator, operand); + return makeUnaryExpression(145 /* PrefixOperator */, pos, operator, operand); case 19 /* LessThanToken */: return parseTypeAssertion(); } @@ -4076,12 +4181,12 @@ var ts; } var operator = token; nextToken(); - expr = makeUnaryExpression(144 /* PostfixOperator */, expr.pos, operator, expr); + expr = makeUnaryExpression(146 /* PostfixOperator */, expr.pos, operator, expr); } return expr; } function parseTypeAssertion() { - var node = createNode(139 /* TypeAssertion */); + var node = createNode(141 /* TypeAssertion */); parseExpected(19 /* LessThanToken */); node.type = parseType(); parseExpected(20 /* GreaterThanToken */); @@ -4098,7 +4203,7 @@ var ts; while (true) { var dotStart = scanner.getTokenPos(); if (parseOptional(15 /* DotToken */)) { - var propertyAccess = createNode(135 /* PropertyAccess */, expr.pos); + var propertyAccess = createNode(137 /* PropertyAccess */, expr.pos); if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord() && lookAhead(function () { return scanner.isReservedWord(); })) { grammarErrorAtPos(dotStart, scanner.getStartPos() - dotStart, ts.Diagnostics.Identifier_expected); var id = createMissingNode(); @@ -4113,7 +4218,7 @@ var ts; } var bracketStart = scanner.getTokenPos(); if (parseOptional(13 /* OpenBracketToken */)) { - var indexedAccess = createNode(136 /* IndexedAccess */, expr.pos); + var indexedAccess = createNode(138 /* IndexedAccess */, expr.pos); indexedAccess.object = expr; if (inNewExpression && parseOptional(14 /* CloseBracketToken */)) { indexedAccess.index = createMissingNode(); @@ -4131,7 +4236,7 @@ var ts; continue; } if ((token === 11 /* OpenParenToken */ || token === 19 /* LessThanToken */) && !inNewExpression) { - var callExpr = createNode(137 /* CallExpression */, expr.pos); + var callExpr = createNode(139 /* CallExpression */, expr.pos); callExpr.func = expr; if (token === 19 /* LessThanToken */) { if (!(callExpr.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) @@ -4140,7 +4245,7 @@ var ts; else { parseExpected(11 /* OpenParenToken */); } - callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseAssignmentExpression, 0 /* Disallow */); + callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false); parseExpected(12 /* CloseParenToken */); expr = finishNode(callExpr); continue; @@ -4156,12 +4261,21 @@ var ts; function parseTypeArguments() { var typeArgumentListStart = scanner.getTokenPos(); var errorCountBeforeTypeParameterList = file.syntacticErrors.length; - var result = parseBracketedList(15 /* TypeArguments */, parseType, 19 /* LessThanToken */, 20 /* GreaterThanToken */); + var result = parseBracketedList(15 /* TypeArguments */, parseSingleTypeArgument, 19 /* LessThanToken */, 20 /* GreaterThanToken */); if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) { grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, ts.Diagnostics.Type_argument_list_cannot_be_empty); } return result; } + function parseSingleTypeArgument() { + if (token === 18 /* CommaToken */) { + var errorStart = scanner.getTokenPos(); + var errorLength = scanner.getTextPos() - errorStart; + grammarErrorAtPos(errorStart, errorLength, ts.Diagnostics.Type_expected); + return createNode(115 /* Missing */); + } + return parseType(); + } function parsePrimaryExpression() { switch (token) { case 87 /* ThisKeyword */: @@ -4198,31 +4312,45 @@ var ts; return createMissingNode(); } function parseParenExpression() { - var node = createNode(140 /* ParenExpression */); + var node = createNode(142 /* ParenExpression */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); parseExpected(12 /* CloseParenToken */); return finishNode(node); } + function parseAssignmentExpressionOrOmittedExpression(omittedExpressionDiagnostic) { + if (token === 18 /* CommaToken */) { + if (omittedExpressionDiagnostic) { + var errorStart = scanner.getTokenPos(); + var errorLength = scanner.getTextPos() - errorStart; + grammarErrorAtPos(errorStart, errorLength, omittedExpressionDiagnostic); + } + return createNode(149 /* OmittedExpression */); + } + return parseAssignmentExpression(); + } function parseArrayLiteralElement() { - return token === 18 /* CommaToken */ ? createNode(147 /* OmittedExpression */) : parseAssignmentExpression(); + return parseAssignmentExpressionOrOmittedExpression(undefined); + } + function parseArgumentExpression() { + return parseAssignmentExpressionOrOmittedExpression(ts.Diagnostics.Argument_expression_expected); } function parseArrayLiteral() { - var node = createNode(132 /* ArrayLiteral */); + var node = createNode(134 /* ArrayLiteral */); parseExpected(13 /* OpenBracketToken */); if (scanner.hasPrecedingLineBreak()) node.flags |= 256 /* MultiLine */; - node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement, 2 /* Preserve */); + node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement, true); parseExpected(14 /* CloseBracketToken */); return finishNode(node); } function parsePropertyAssignment() { - var node = createNode(134 /* PropertyAssignment */); + var node = createNode(136 /* PropertyAssignment */); node.name = parsePropertyName(); if (token === 11 /* OpenParenToken */ || token === 19 /* LessThanToken */) { var sig = parseSignature(124 /* CallSignature */, 46 /* ColonToken */, false); var body = parseBody(false); - node.initializer = makeFunctionExpression(141 /* FunctionExpression */, node.pos, undefined, sig, body); + node.initializer = makeFunctionExpression(143 /* FunctionExpression */, node.pos, undefined, sig, body); } else { parseExpected(46 /* ColonToken */); @@ -4240,13 +4368,12 @@ var ts; return parsePropertyAssignment(); } function parseObjectLiteral() { - var node = createNode(133 /* ObjectLiteral */); + var node = createNode(135 /* ObjectLiteral */); parseExpected(9 /* OpenBraceToken */); if (scanner.hasPrecedingLineBreak()) { node.flags |= 256 /* MultiLine */; } - var trailingCommaBehavior = languageVersion === 0 /* ES3 */ ? 1 /* Allow */ : 2 /* Preserve */; - node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember, trailingCommaBehavior); + node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember, true); parseExpected(10 /* CloseBraceToken */); var seen = {}; var Property = 1; @@ -4254,11 +4381,11 @@ var ts; var SetAccesor = 4; var GetOrSetAccessor = GetAccessor | SetAccesor; ts.forEach(node.properties, function (p) { - if (p.kind === 147 /* OmittedExpression */) { + if (p.kind === 149 /* OmittedExpression */) { return; } var currentKind; - if (p.kind === 134 /* PropertyAssignment */) { + if (p.kind === 136 /* PropertyAssignment */) { currentKind = Property; } else if (p.kind === 122 /* GetAccessor */) { @@ -4304,7 +4431,7 @@ var ts; if (name && isInStrictMode && isEvalOrArgumentsIdentifier(name)) { reportInvalidUseInStrictMode(name); } - return makeFunctionExpression(141 /* FunctionExpression */, pos, name, sig, body); + return makeFunctionExpression(143 /* FunctionExpression */, pos, name, sig, body); } function makeFunctionExpression(kind, pos, name, sig, body) { var node = createNode(kind, pos); @@ -4316,17 +4443,17 @@ var ts; return finishNode(node); } function parseNewExpression() { - var node = createNode(138 /* NewExpression */); + var node = createNode(140 /* NewExpression */); parseExpected(82 /* NewKeyword */); node.func = parseCallAndAccess(parsePrimaryExpression(), true); if (parseOptional(11 /* OpenParenToken */) || token === 19 /* LessThanToken */ && (node.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) { - node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseAssignmentExpression, 0 /* Disallow */); + node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false); parseExpected(12 /* CloseParenToken */); } return finishNode(node); } function parseBlock(ignoreMissingOpenBrace, checkForStrictMode) { - var node = createNode(148 /* Block */); + var node = createNode(150 /* Block */); if (parseExpected(9 /* OpenBraceToken */) || ignoreMissingOpenBrace) { node.statements = parseList(2 /* BlockStatements */, checkForStrictMode, parseStatement); parseExpected(10 /* CloseBraceToken */); @@ -4349,7 +4476,7 @@ var ts; } labelledStatementInfo.pushFunctionBoundary(); var block = parseBlock(ignoreMissingOpenBrace, true); - block.kind = 173 /* FunctionBlock */; + block.kind = 175 /* FunctionBlock */; labelledStatementInfo.pop(); inFunctionBody = saveInFunctionBody; inSwitchStatement = saveInSwitchStatement; @@ -4357,12 +4484,12 @@ var ts; return block; } function parseEmptyStatement() { - var node = createNode(150 /* EmptyStatement */); + var node = createNode(152 /* EmptyStatement */); parseExpected(17 /* SemicolonToken */); return finishNode(node); } function parseIfStatement() { - var node = createNode(152 /* IfStatement */); + var node = createNode(154 /* IfStatement */); parseExpected(78 /* IfKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4372,7 +4499,7 @@ var ts; return finishNode(node); } function parseDoStatement() { - var node = createNode(153 /* DoStatement */); + var node = createNode(155 /* DoStatement */); parseExpected(69 /* DoKeyword */); var saveInIterationStatement = inIterationStatement; inIterationStatement = 1 /* Nested */; @@ -4386,7 +4513,7 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(154 /* WhileStatement */); + var node = createNode(156 /* WhileStatement */); parseExpected(94 /* WhileKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4414,7 +4541,7 @@ var ts; } var forOrForInStatement; if (parseOptional(80 /* InKeyword */)) { - var forInStatement = createNode(156 /* ForInStatement */, pos); + var forInStatement = createNode(158 /* ForInStatement */, pos); if (declarations) { if (declarations.length > 1) { error(ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); @@ -4429,7 +4556,7 @@ var ts; forOrForInStatement = forInStatement; } else { - var forStatement = createNode(155 /* ForStatement */, pos); + var forStatement = createNode(157 /* ForStatement */, pos); if (declarations) forStatement.declarations = declarations; if (varOrInit) @@ -4454,7 +4581,7 @@ var ts; function parseBreakOrContinueStatement(kind) { var node = createNode(kind); var errorCountBeforeStatement = file.syntacticErrors.length; - parseExpected(kind === 158 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */); + parseExpected(kind === 160 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */); if (!canParseSemicolon()) node.label = parseIdentifier(); parseSemicolon(); @@ -4470,7 +4597,7 @@ var ts; return node; } function checkBareBreakOrContinueStatement(node) { - if (node.kind === 158 /* BreakStatement */) { + if (node.kind === 160 /* BreakStatement */) { if (inIterationStatement === 1 /* Nested */ || inSwitchStatement === 1 /* Nested */) { return; } @@ -4479,7 +4606,7 @@ var ts; return; } } - else if (node.kind === 157 /* ContinueStatement */) { + else if (node.kind === 159 /* ContinueStatement */) { if (inIterationStatement === 1 /* Nested */) { return; } @@ -4495,7 +4622,7 @@ var ts; grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } function checkBreakOrContinueStatementWithLabel(node) { - var nodeIsNestedInLabel = labelledStatementInfo.nodeIsNestedInLabel(node.label, node.kind === 157 /* ContinueStatement */, false); + var nodeIsNestedInLabel = labelledStatementInfo.nodeIsNestedInLabel(node.label, node.kind === 159 /* ContinueStatement */, false); if (nodeIsNestedInLabel === 1 /* Nested */) { return; } @@ -4503,10 +4630,10 @@ var ts; grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); return; } - if (node.kind === 157 /* ContinueStatement */) { + if (node.kind === 159 /* ContinueStatement */) { grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); } - else if (node.kind === 158 /* BreakStatement */) { + else if (node.kind === 160 /* BreakStatement */) { grammarErrorOnNode(node, ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement); } else { @@ -4514,7 +4641,7 @@ var ts; } } function parseReturnStatement() { - var node = createNode(159 /* ReturnStatement */); + var node = createNode(161 /* ReturnStatement */); var errorCountBeforeReturnStatement = file.syntacticErrors.length; var returnTokenStart = scanner.getTokenPos(); var returnTokenLength = scanner.getTextPos() - returnTokenStart; @@ -4528,7 +4655,7 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(160 /* WithStatement */); + var node = createNode(162 /* WithStatement */); var startPos = scanner.getTokenPos(); parseExpected(95 /* WithKeyword */); var endPos = scanner.getStartPos(); @@ -4543,7 +4670,7 @@ var ts; return node; } function parseCaseClause() { - var node = createNode(162 /* CaseClause */); + var node = createNode(164 /* CaseClause */); parseExpected(61 /* CaseKeyword */); node.expression = parseExpression(); parseExpected(46 /* ColonToken */); @@ -4551,7 +4678,7 @@ var ts; return finishNode(node); } function parseDefaultClause() { - var node = createNode(163 /* DefaultClause */); + var node = createNode(165 /* DefaultClause */); parseExpected(67 /* DefaultKeyword */); parseExpected(46 /* ColonToken */); node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatement); @@ -4561,7 +4688,7 @@ var ts; return token === 61 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(161 /* SwitchStatement */); + var node = createNode(163 /* SwitchStatement */); parseExpected(86 /* SwitchKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4572,7 +4699,7 @@ var ts; node.clauses = parseList(3 /* SwitchClauses */, false, parseCaseOrDefaultClause); inSwitchStatement = saveInSwitchStatement; parseExpected(10 /* CloseBraceToken */); - var defaultClauses = ts.filter(node.clauses, function (clause) { return clause.kind === 163 /* DefaultClause */; }); + var defaultClauses = ts.filter(node.clauses, function (clause) { return clause.kind === 165 /* DefaultClause */; }); for (var i = 1, n = defaultClauses.length; i < n; i++) { var clause = defaultClauses[i]; var start = ts.skipTrivia(file.text, clause.pos); @@ -4582,7 +4709,7 @@ var ts; return finishNode(node); } function parseThrowStatement() { - var node = createNode(165 /* ThrowStatement */); + var node = createNode(167 /* ThrowStatement */); parseExpected(88 /* ThrowKeyword */); if (scanner.hasPrecedingLineBreak()) { error(ts.Diagnostics.Line_break_not_permitted_here); @@ -4592,13 +4719,13 @@ var ts; return finishNode(node); } function parseTryStatement() { - var node = createNode(166 /* TryStatement */); - node.tryBlock = parseTokenAndBlock(90 /* TryKeyword */, 167 /* TryBlock */); + var node = createNode(168 /* TryStatement */); + node.tryBlock = parseTokenAndBlock(90 /* TryKeyword */, 169 /* TryBlock */); if (token === 62 /* CatchKeyword */) { node.catchBlock = parseCatchBlock(); } if (token === 75 /* FinallyKeyword */) { - node.finallyBlock = parseTokenAndBlock(75 /* FinallyKeyword */, 169 /* FinallyBlock */); + node.finallyBlock = parseTokenAndBlock(75 /* FinallyKeyword */, 171 /* FinallyBlock */); } if (!(node.catchBlock || node.finallyBlock)) { error(ts.Diagnostics.catch_or_finally_expected); @@ -4623,7 +4750,7 @@ var ts; var typeAnnotation = parseTypeAnnotation(); parseExpected(12 /* CloseParenToken */); var result = parseBlock(false, false); - result.kind = 168 /* CatchBlock */; + result.kind = 170 /* CatchBlock */; result.pos = pos; result.variable = variable; if (typeAnnotation) { @@ -4635,7 +4762,7 @@ var ts; return result; } function parseDebuggerStatement() { - var node = createNode(170 /* DebuggerStatement */); + var node = createNode(172 /* DebuggerStatement */); parseExpected(66 /* DebuggerKeyword */); parseSemicolon(); return finishNode(node); @@ -4653,18 +4780,18 @@ var ts; return isIdentifier() && lookAhead(function () { return nextToken() === 46 /* ColonToken */; }); } function parseLabelledStatement() { - var node = createNode(164 /* LabeledStatement */); + var node = createNode(166 /* LabeledStatement */); node.label = parseIdentifier(); parseExpected(46 /* ColonToken */); if (labelledStatementInfo.nodeIsNestedInLabel(node.label, false, true)) { - grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getSourceTextOfNodeFromSourceText(sourceText, node.label)); + grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceText, node.label)); } labelledStatementInfo.addLabel(node.label); node.statement = isLabel() ? parseLabelledStatement() : parseStatementWithLabelSet(); return finishNode(node); } function parseExpressionStatement() { - var node = createNode(151 /* ExpressionStatement */); + var node = createNode(153 /* ExpressionStatement */); node.expression = parseExpression(); parseSemicolon(); return finishNode(node); @@ -4728,9 +4855,9 @@ var ts; case 76 /* ForKeyword */: return parseForOrForInStatement(); case 65 /* ContinueKeyword */: - return parseBreakOrContinueStatement(157 /* ContinueStatement */); + return parseBreakOrContinueStatement(159 /* ContinueStatement */); case 60 /* BreakKeyword */: - return parseBreakOrContinueStatement(158 /* BreakStatement */); + return parseBreakOrContinueStatement(160 /* BreakStatement */); case 84 /* ReturnKeyword */: return parseReturnStatement(); case 95 /* WithKeyword */: @@ -4773,7 +4900,7 @@ var ts; error(ts.Diagnostics.Block_or_expected); } function parseVariableDeclaration(flags, noIn) { - var node = createNode(171 /* VariableDeclaration */); + var node = createNode(173 /* VariableDeclaration */); node.flags = flags; var errorCountBeforeVariableDeclaration = file.syntacticErrors.length; node.name = parseIdentifier(); @@ -4790,10 +4917,10 @@ var ts; return finishNode(node); } function parseVariableDeclarationList(flags, noIn) { - return parseDelimitedList(9 /* VariableDeclarations */, function () { return parseVariableDeclaration(flags, noIn); }, 0 /* Disallow */); + return parseDelimitedList(9 /* VariableDeclarations */, function () { return parseVariableDeclaration(flags, noIn); }, false); } function parseVariableStatement(pos, flags) { - var node = createNode(149 /* VariableStatement */, pos); + var node = createNode(151 /* VariableStatement */, pos); if (flags) node.flags = flags; var errorCountBeforeVarStatement = file.syntacticErrors.length; @@ -4807,7 +4934,7 @@ var ts; return node; } function parseFunctionDeclaration(pos, flags) { - var node = createNode(172 /* FunctionDeclaration */, pos); + var node = createNode(174 /* FunctionDeclaration */, pos); if (flags) node.flags = flags; parseExpected(77 /* FunctionKeyword */); @@ -5118,7 +5245,7 @@ var ts; ts.Debug.fail("Should not have attempted to parse class member declaration."); } function parseClassDeclaration(pos, flags) { - var node = createNode(174 /* ClassDeclaration */, pos); + var node = createNode(176 /* ClassDeclaration */, pos); node.flags = flags; var errorCountBeforeClassDeclaration = file.syntacticErrors.length; parseExpected(63 /* ClassKeyword */); @@ -5129,7 +5256,7 @@ var ts; var implementsKeywordLength; if (parseOptional(96 /* ImplementsKeyword */)) { implementsKeywordLength = scanner.getStartPos() - implementsKeywordStart; - node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, 0 /* Disallow */); + node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false); } var errorCountBeforeClassBody = file.syntacticErrors.length; if (parseExpected(9 /* OpenBraceToken */)) { @@ -5145,7 +5272,7 @@ var ts; return finishNode(node); } function parseInterfaceDeclaration(pos, flags) { - var node = createNode(175 /* InterfaceDeclaration */, pos); + var node = createNode(177 /* InterfaceDeclaration */, pos); node.flags = flags; var errorCountBeforeInterfaceDeclaration = file.syntacticErrors.length; parseExpected(97 /* InterfaceKeyword */); @@ -5155,7 +5282,7 @@ var ts; var extendsKeywordLength; if (parseOptional(73 /* ExtendsKeyword */)) { extendsKeywordLength = scanner.getStartPos() - extendsKeywordStart; - node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, 0 /* Disallow */); + node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false); } var errorCountBeforeInterfaceBody = file.syntacticErrors.length; node.members = parseTypeLiteral().members; @@ -5169,7 +5296,7 @@ var ts; function isInteger(literalExpression) { return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text); } - if (expression.kind === 143 /* PrefixOperator */) { + if (expression.kind === 145 /* PrefixOperator */) { var unaryExpression = expression; if (unaryExpression.operator === 28 /* PlusToken */ || unaryExpression.operator === 29 /* MinusToken */) { expression = unaryExpression.operand; @@ -5182,7 +5309,7 @@ var ts; } var inConstantEnumMemberSection = true; function parseAndCheckEnumMember() { - var node = createNode(181 /* EnumMember */); + var node = createNode(183 /* EnumMember */); var errorCountBeforeEnumMember = file.syntacticErrors.length; node.name = parsePropertyName(); node.initializer = parseInitializer(false); @@ -5199,12 +5326,12 @@ var ts; } return finishNode(node); } - var node = createNode(176 /* EnumDeclaration */, pos); + var node = createNode(178 /* EnumDeclaration */, pos); node.flags = flags; parseExpected(71 /* EnumKeyword */); node.name = parseIdentifier(); if (parseExpected(9 /* OpenBraceToken */)) { - node.members = parseDelimitedList(7 /* EnumMembers */, parseAndCheckEnumMember, 1 /* Allow */); + node.members = parseDelimitedList(7 /* EnumMembers */, parseAndCheckEnumMember, true); parseExpected(10 /* CloseBraceToken */); } else { @@ -5213,7 +5340,7 @@ var ts; return finishNode(node); } function parseModuleBody() { - var node = createNode(178 /* ModuleBlock */); + var node = createNode(180 /* ModuleBlock */); if (parseExpected(9 /* OpenBraceToken */)) { node.statements = parseList(1 /* ModuleElements */, false, parseModuleElement); parseExpected(10 /* CloseBraceToken */); @@ -5224,7 +5351,7 @@ var ts; return finishNode(node); } function parseInternalModuleTail(pos, flags) { - var node = createNode(177 /* ModuleDeclaration */, pos); + var node = createNode(179 /* ModuleDeclaration */, pos); node.flags = flags; node.name = parseIdentifier(); if (parseOptional(15 /* DotToken */)) { @@ -5233,10 +5360,10 @@ var ts; else { node.body = parseModuleBody(); ts.forEach(node.body.statements, function (s) { - if (s.kind === 180 /* ExportAssignment */) { + if (s.kind === 182 /* ExportAssignment */) { grammarErrorOnNode(s, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); } - else if (s.kind === 179 /* ImportDeclaration */ && s.externalModuleName) { + else if (s.kind === 181 /* ImportDeclaration */ && s.externalModuleName) { grammarErrorOnNode(s, ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); } }); @@ -5244,7 +5371,7 @@ var ts; return finishNode(node); } function parseAmbientExternalModuleDeclaration(pos, flags) { - var node = createNode(177 /* ModuleDeclaration */, pos); + var node = createNode(179 /* ModuleDeclaration */, pos); node.flags = flags; node.name = parseStringLiteral(); if (!inAmbientContext) { @@ -5264,7 +5391,7 @@ var ts; return token === 7 /* StringLiteral */ ? parseAmbientExternalModuleDeclaration(pos, flags) : parseInternalModuleTail(pos, flags); } function parseImportDeclaration(pos, flags) { - var node = createNode(179 /* ImportDeclaration */, pos); + var node = createNode(181 /* ImportDeclaration */, pos); node.flags = flags; parseExpected(79 /* ImportKeyword */); node.name = parseIdentifier(); @@ -5281,7 +5408,7 @@ var ts; return finishNode(node); } function parseExportAssignmentTail(pos) { - var node = createNode(180 /* ExportAssignment */, pos); + var node = createNode(182 /* ExportAssignment */, pos); node.exportName = parseIdentifier(); parseSemicolon(); return finishNode(node); @@ -5398,15 +5525,16 @@ var ts; } else { var matchResult = ts.fullTripleSlashReferencePathRegEx.exec(comment); + var start = range.pos; + var end = range.end; + var length = end - start; if (!matchResult) { - var start = range.pos; - var length = range.end - start; errorAtPos(start, length, ts.Diagnostics.Invalid_reference_directive_syntax); } else { referencedFiles.push({ - pos: range.pos, - end: range.end, + pos: start, + end: end, filename: matchResult[3] }); } @@ -5427,7 +5555,7 @@ var ts; }; } function getExternalModuleIndicator() { - return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 179 /* ImportDeclaration */ && node.externalModuleName || node.kind === 180 /* ExportAssignment */ ? node : undefined; }); + return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 181 /* ImportDeclaration */ && node.externalModuleName || node.kind === 182 /* ExportAssignment */ ? node : undefined; }); } scanner = ts.createScanner(languageVersion, true, sourceText, scanError, onComment); var rootNodeFlags = 0; @@ -5435,7 +5563,7 @@ var ts; rootNodeFlags = 1024 /* DeclarationFile */; inAmbientContext = true; } - file = createRootNode(182 /* SourceFile */, 0, sourceText.length, rootNodeFlags); + file = createRootNode(184 /* SourceFile */, 0, sourceText.length, rootNodeFlags); file.filename = ts.normalizePath(filename); file.text = sourceText; file.getLineAndCharacterFromPosition = getLineAndCharacterlFromSourcePosition; @@ -5509,6 +5637,9 @@ var ts; else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) { diagnostic = ts.Diagnostics.File_0_not_found; } + else if (refFile && host.getCanonicalFileName(filename) === host.getCanonicalFileName(refFile.filename)) { + diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself; + } } else { if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) { @@ -5559,12 +5690,13 @@ var ts; } function processReferencedFiles(file, basePath) { ts.forEach(file.referencedFiles, function (ref) { - processSourceFile(ts.normalizePath(ts.combinePaths(basePath, ref.filename)), false, file, ref.pos, ref.end); + var referencedFilename = ts.isRootedDiskPath(ref.filename) ? ref.filename : ts.combinePaths(basePath, ref.filename); + processSourceFile(ts.normalizePath(referencedFilename), false, file, ref.pos, ref.end); }); } function processImportedModules(file, basePath) { ts.forEach(file.statements, function (node) { - if (node.kind === 179 /* ImportDeclaration */ && node.externalModuleName) { + if (node.kind === 181 /* ImportDeclaration */ && node.externalModuleName) { var nameLiteral = node.externalModuleName; var moduleName = nameLiteral.text; if (moduleName) { @@ -5582,9 +5714,9 @@ var ts; } } } - else if (node.kind === 177 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || file.flags & 1024 /* DeclarationFile */)) { + else if (node.kind === 179 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || isDeclarationFile(file))) { forEachChild(node.body, function (node) { - if (node.kind === 179 /* ImportDeclaration */ && node.externalModuleName) { + if (node.kind === 181 /* ImportDeclaration */ && node.externalModuleName) { var nameLiteral = node.externalModuleName; var moduleName = nameLiteral.text; if (moduleName) { @@ -5657,16 +5789,16 @@ var ts; var ts; (function (ts) { function isInstantiated(node) { - if (node.kind === 175 /* InterfaceDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */) { return false; } - else if (node.kind === 179 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) { + else if (node.kind === 181 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) { return false; } - else if (node.kind === 178 /* ModuleBlock */ && !ts.forEachChild(node, isInstantiated)) { + else if (node.kind === 180 /* ModuleBlock */ && !ts.forEachChild(node, isInstantiated)) { return false; } - else if (node.kind === 177 /* ModuleDeclaration */ && !isInstantiated(node.body)) { + else if (node.kind === 179 /* ModuleDeclaration */ && !isInstantiated(node.body)) { return false; } else { @@ -5705,7 +5837,7 @@ var ts; } function getDeclarationName(node) { if (node.name) { - if (node.kind === 177 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) { + if (node.kind === 179 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) { return '"' + node.name.text + '"'; } return node.name.text; @@ -5732,7 +5864,10 @@ var ts; if (node.name) { node.name.parent = node; } - file.semanticErrors.push(ts.createDiagnosticForNode(node.name ? node.name : node, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(node))); + ts.forEach(symbol.declarations, function (declaration) { + file.semanticErrors.push(ts.createDiagnosticForNode(declaration.name, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(declaration))); + }); + file.semanticErrors.push(ts.createDiagnosticForNode(node.name, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(node))); symbol = createSymbol(0, name); } } @@ -5741,7 +5876,7 @@ var ts; } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; - if (node.kind === 174 /* ClassDeclaration */ && symbol.exports) { + if (node.kind === 176 /* ClassDeclaration */ && symbol.exports) { var prototypeSymbol = createSymbol(2 /* Property */ | 67108864 /* Prototype */, "prototype"); if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { if (node.name) { @@ -5773,7 +5908,7 @@ var ts; if (symbolKind & ts.SymbolFlags.Namespace) { exportKind |= 2097152 /* ExportNamespace */; } - if (node.flags & 1 /* Export */ || (node.kind !== 179 /* ImportDeclaration */ && isAmbientContext(container))) { + if (node.flags & 1 /* Export */ || (node.kind !== 181 /* ImportDeclaration */ && isAmbientContext(container))) { if (exportKind) { var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); @@ -5809,10 +5944,10 @@ var ts; } function bindDeclaration(node, symbolKind, symbolExcludes) { switch (container.kind) { - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: declareModuleMember(node, symbolKind, symbolExcludes); break; - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolKind, symbolExcludes); break; @@ -5824,22 +5959,22 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); break; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: if (node.flags & 128 /* Static */) { declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } case 129 /* TypeLiteral */: - case 133 /* ObjectLiteral */: - case 175 /* InterfaceDeclaration */: + case 135 /* ObjectLiteral */: + case 177 /* InterfaceDeclaration */: declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } @@ -5886,14 +6021,14 @@ var ts; case 118 /* Parameter */: bindDeclaration(node, 1 /* Variable */, ts.SymbolFlags.ParameterExcludes); break; - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: bindDeclaration(node, 1 /* Variable */, ts.SymbolFlags.VariableExcludes); break; case 119 /* Property */: - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: bindDeclaration(node, 2 /* Property */, ts.SymbolFlags.PropertyExcludes); break; - case 181 /* EnumMember */: + case 183 /* EnumMember */: bindDeclaration(node, 4 /* EnumMember */, ts.SymbolFlags.EnumMemberExcludes); break; case 124 /* CallSignature */: @@ -5908,7 +6043,7 @@ var ts; case 126 /* IndexSignature */: bindDeclaration(node, 131072 /* IndexSignature */, 0); break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: bindDeclaration(node, 8 /* Function */, ts.SymbolFlags.FunctionExcludes); break; case 121 /* Constructor */: @@ -5923,34 +6058,34 @@ var ts; case 129 /* TypeLiteral */: bindAnonymousDeclaration(node, 512 /* TypeLiteral */, "__type"); break; - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: bindAnonymousDeclaration(node, 1024 /* ObjectLiteral */, "__object"); break; - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: bindAnonymousDeclaration(node, 8 /* Function */, "__function"); break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: bindCatchVariableDeclaration(node); break; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: bindDeclaration(node, 16 /* Class */, ts.SymbolFlags.ClassExcludes); break; - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: bindDeclaration(node, 32 /* Interface */, ts.SymbolFlags.InterfaceExcludes); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: bindDeclaration(node, 64 /* Enum */, ts.SymbolFlags.EnumExcludes); break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: bindModuleDeclaration(node); break; - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: bindDeclaration(node, 4194304 /* Import */, ts.SymbolFlags.ImportExcludes); break; - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (ts.isExternalModule(node)) { - bindAnonymousDeclaration(node, 128 /* ValueModule */, '"' + ts.getModuleNameFromFilename(node.filename) + '"'); + bindAnonymousDeclaration(node, 128 /* ValueModule */, '"' + ts.removeFileExtension(node.filename) + '"'); break; } default: @@ -5972,11 +6107,12 @@ var ts; } return indentStrings[level]; } + ts.getIndentString = getIndentString; function getIndentSize() { return indentStrings[1].length; } function shouldEmitToOwnFile(sourceFile, compilerOptions) { - if (!(sourceFile.flags & 1024 /* DeclarationFile */)) { + if (!ts.isDeclarationFile(sourceFile)) { if ((ts.isExternalModule(sourceFile) || !compilerOptions.out) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { return true; } @@ -5986,7 +6122,7 @@ var ts; } ts.shouldEmitToOwnFile = shouldEmitToOwnFile; function isExternalModuleOrDeclarationFile(sourceFile) { - return ts.isExternalModule(sourceFile) || (sourceFile.flags & 1024 /* DeclarationFile */) !== 0; + return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); } ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; function emitFiles(resolver, targetSourceFile) { @@ -6003,10 +6139,10 @@ var ts; } function getOwnEmitOutputFilePath(sourceFile, extension) { if (compilerOptions.outDir) { - var emitOutputFilePathWithoutExtension = ts.getModuleNameFromFilename(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile)); + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile)); } else { - var emitOutputFilePathWithoutExtension = ts.getModuleNameFromFilename(sourceFile.filename); + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename); } return emitOutputFilePathWithoutExtension + extension; } @@ -6040,7 +6176,7 @@ var ts; setAccessor: setAccessor }; } - function createTextWriter(writeSymbol) { + function createTextWriter() { var output = ""; var indent = 0; var lineStart = true; @@ -6083,7 +6219,6 @@ var ts; } return { write: write, - writeSymbol: writeSymbol, rawWrite: rawWrite, writeLiteral: writeLiteral, writeLine: writeLine, @@ -6192,7 +6327,7 @@ var ts; } } function emitJavaScript(jsFilePath, root) { - var writer = createTextWriter(writeSymbol); + var writer = createTextWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -6222,8 +6357,6 @@ var ts; var scopeEmitEnd = function () { }; var sourceMapData; - function writeSymbol(symbol, enclosingDeclaration, meaning) { - } function initializeEmitterWithSourceMaps() { var sourceMapDir; var sourceMapSourceIndex = -1; @@ -6328,7 +6461,7 @@ var ts; } function recordNewSourceFileStart(node) { var sourcesDirectoryPath = compilerOptions.sourceRoot ? program.getCommonSourceDirectory() : sourceMapDir; - sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, compilerHost.getCurrentDirectory(), true)); + sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, true)); sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; sourceMapData.inputSourceFileNames.push(node.filename); } @@ -6355,7 +6488,7 @@ var ts; if (scopeName) { recordScopeNameStart(scopeName); } - else if (node.kind === 172 /* FunctionDeclaration */ || node.kind === 141 /* FunctionExpression */ || node.kind === 120 /* Method */ || node.kind === 122 /* GetAccessor */ || node.kind === 123 /* SetAccessor */ || node.kind === 177 /* ModuleDeclaration */ || node.kind === 174 /* ClassDeclaration */ || node.kind === 176 /* EnumDeclaration */) { + else if (node.kind === 174 /* FunctionDeclaration */ || node.kind === 143 /* FunctionExpression */ || node.kind === 120 /* Method */ || node.kind === 122 /* GetAccessor */ || node.kind === 123 /* SetAccessor */ || node.kind === 179 /* ModuleDeclaration */ || node.kind === 176 /* ClassDeclaration */ || node.kind === 178 /* EnumDeclaration */) { if (node.name) { scopeName = node.name.text; } @@ -6374,20 +6507,6 @@ var ts; writeCommentRange(comment, writer); recordSourceMapSpan(comment.end); } - var escapedCharsRegExp = /[\t\v\f\b\0\r\n\"\u2028\u2029\u0085]/g; - var escapedCharsMap = { - "\t": "\\t", - "\v": "\\v", - "\f": "\\f", - "\b": "\\b", - "\0": "\\0", - "\r": "\\r", - "\n": "\\n", - "\"": "\\\"", - "\u2028": "\\u2028", - "\u2029": "\\u2029", - "\u0085": "\\u0085" - }; function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings) { if (typeof JSON !== "undefined") { return JSON.stringify({ @@ -6399,19 +6518,14 @@ var ts; mappings: mappings }); } - return "{\"version\":" + version + ",\"file\":\"" + escapeString(file) + "\",\"sourceRoot\":\"" + escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + escapeString(mappings) + "\"}"; - function escapeString(s) { - return escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, function (c) { - return escapedCharsMap[c] || c; - }) : s; - } + return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\"}"; function serializeStringArray(list) { var output = ""; for (var i = 0, n = list.length; i < n; i++) { if (i) { output += ","; } - output += "\"" + escapeString(list[i]) + "\""; + output += "\"" + ts.escapeString(list[i]) + "\""; } return output; } @@ -6445,7 +6559,7 @@ var ts; } if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { sourceMapDir = ts.combinePaths(program.getCommonSourceDirectory(), sourceMapDir); - sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), compilerHost.getCurrentDirectory(), true); + sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, true); } else { sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); @@ -6456,7 +6570,7 @@ var ts; } function emitNodeWithMap(node) { if (node) { - if (node.kind != 182 /* SourceFile */) { + if (node.kind != 184 /* SourceFile */) { recordEmitNodeStartSpan(node); emitNode(node); recordEmitNodeEndSpan(node); @@ -6495,25 +6609,42 @@ var ts; emit(node); } } - function emitCommaList(nodes, count) { - if (!(count >= 0)) - count = nodes.length; - if (nodes) { - for (var i = 0; i < count; i++) { - if (i) - write(", "); - emit(nodes[i]); + function emitTrailingCommaIfPresent(nodeList, isMultiline) { + if (nodeList.hasTrailingComma) { + write(","); + if (isMultiline) { + writeLine(); } } } - function emitMultiLineList(nodes) { + function emitCommaList(nodes, includeTrailingComma, count) { + if (!(count >= 0)) { + count = nodes.length; + } + if (nodes) { + for (var i = 0; i < count; i++) { + if (i) { + write(", "); + } + emit(nodes[i]); + } + if (includeTrailingComma) { + emitTrailingCommaIfPresent(nodes, false); + } + } + } + function emitMultiLineList(nodes, includeTrailingComma) { if (nodes) { for (var i = 0; i < nodes.length; i++) { - if (i) + if (i) { write(","); + } writeLine(); emit(nodes[i]); } + if (includeTrailingComma) { + emitTrailingCommaIfPresent(nodes, true); + } } } function emitLines(nodes) { @@ -6553,28 +6684,28 @@ var ts; var parent = node.parent; switch (parent.kind) { case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 143 /* FunctionExpression */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return parent.name === node; - case 158 /* BreakStatement */: - case 157 /* ContinueStatement */: - case 180 /* ExportAssignment */: + case 160 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 182 /* ExportAssignment */: return false; - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return node.parent.label === node; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return node.parent.variable === node; } } @@ -6612,14 +6743,14 @@ var ts; if (node.flags & 256 /* MultiLine */) { write("["); increaseIndent(); - emitMultiLineList(node.elements); + emitMultiLineList(node.elements, true); decreaseIndent(); writeLine(); write("]"); } else { write("["); - emitCommaList(node.elements); + emitCommaList(node.elements, true); write("]"); } } @@ -6630,14 +6761,14 @@ var ts; else if (node.flags & 256 /* MultiLine */) { write("{"); increaseIndent(); - emitMultiLineList(node.properties); + emitMultiLineList(node.properties, compilerOptions.target >= 1 /* ES5 */); decreaseIndent(); writeLine(); write("}"); } else { write("{ "); - emitCommaList(node.properties); + emitCommaList(node.properties, compilerOptions.target >= 1 /* ES5 */); write(" }"); } } @@ -6649,14 +6780,15 @@ var ts; emitTrailingComments(node); } function emitPropertyAccess(node) { - var text = resolver.getPropertyAccessSubstitution(node); - if (text) { - write(text); - return; + var constantValue = resolver.getConstantValue(node); + if (constantValue !== undefined) { + write(constantValue.toString() + " /* " + ts.identifierToString(node.right) + " */"); + } + else { + emit(node.left); + write("."); + emit(node.right); } - emit(node.left); - write("."); - emit(node.right); } function emitIndexedAccess(node) { emit(node.object); @@ -6672,20 +6804,20 @@ var ts; } else { emit(node.func); - superCall = node.func.kind === 135 /* PropertyAccess */ && node.func.left.kind === 85 /* SuperKeyword */; + superCall = node.func.kind === 137 /* PropertyAccess */ && node.func.left.kind === 85 /* SuperKeyword */; } if (superCall) { write(".call("); emitThis(node.func); if (node.arguments.length) { write(", "); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); } write(")"); } else { write("("); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); write(")"); } } @@ -6694,17 +6826,17 @@ var ts; emit(node.func); if (node.arguments) { write("("); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); write(")"); } } function emitParenExpression(node) { - if (node.expression.kind === 139 /* TypeAssertion */) { + if (node.expression.kind === 141 /* TypeAssertion */) { var operand = node.expression.operand; - while (operand.kind == 139 /* TypeAssertion */) { + while (operand.kind == 141 /* TypeAssertion */) { operand = operand.operand; } - if (operand.kind !== 143 /* PrefixOperator */ && operand.kind !== 144 /* PostfixOperator */ && operand.kind !== 138 /* NewExpression */ && !(operand.kind === 137 /* CallExpression */ && node.parent.kind === 138 /* NewExpression */) && !(operand.kind === 141 /* FunctionExpression */ && node.parent.kind === 137 /* CallExpression */)) { + if (operand.kind !== 145 /* PrefixOperator */ && operand.kind !== 146 /* PostfixOperator */ && operand.kind !== 140 /* NewExpression */ && !(operand.kind === 139 /* CallExpression */ && node.parent.kind === 140 /* NewExpression */) && !(operand.kind === 143 /* FunctionExpression */ && node.parent.kind === 139 /* CallExpression */)) { emit(operand); return; } @@ -6714,13 +6846,13 @@ var ts; write(")"); } function emitUnaryExpression(node) { - if (node.kind === 143 /* PrefixOperator */) { + if (node.kind === 145 /* PrefixOperator */) { write(ts.tokenToString(node.operator)); } if (node.operator >= 59 /* Identifier */) { write(" "); } - else if (node.kind === 143 /* PrefixOperator */ && node.operand.kind === 143 /* PrefixOperator */) { + else if (node.kind === 145 /* PrefixOperator */ && node.operand.kind === 145 /* PrefixOperator */) { var operand = node.operand; if (node.operator === 28 /* PlusToken */ && (operand.operator === 28 /* PlusToken */ || operand.operator === 33 /* PlusPlusToken */)) { write(" "); @@ -6730,7 +6862,7 @@ var ts; } } emit(node.operand); - if (node.kind === 144 /* PostfixOperator */) { + if (node.kind === 146 /* PostfixOperator */) { write(ts.tokenToString(node.operator)); } } @@ -6753,8 +6885,8 @@ var ts; emitToken(9 /* OpenBraceToken */, node.pos); increaseIndent(); scopeEmitStart(node.parent); - if (node.kind === 178 /* ModuleBlock */) { - ts.Debug.assert(node.parent.kind === 177 /* ModuleDeclaration */); + if (node.kind === 180 /* ModuleBlock */) { + ts.Debug.assert(node.parent.kind === 179 /* ModuleDeclaration */); emitCaptureThisForNodeIfNecessary(node.parent); } emitLines(node.statements); @@ -6764,7 +6896,7 @@ var ts; scopeEmitEnd(); } function emitEmbeddedStatement(node) { - if (node.kind === 148 /* Block */) { + if (node.kind === 150 /* Block */) { write(" "); emit(node); } @@ -6776,7 +6908,7 @@ var ts; } } function emitExpressionStatement(node) { - var isArrowExpression = node.expression.kind === 142 /* ArrowFunction */; + var isArrowExpression = node.expression.kind === 144 /* ArrowFunction */; emitLeadingComments(node); if (isArrowExpression) write("("); @@ -6797,7 +6929,7 @@ var ts; if (node.elseStatement) { writeLine(); emitToken(70 /* ElseKeyword */, node.thenStatement.end); - if (node.elseStatement.kind === 152 /* IfStatement */) { + if (node.elseStatement.kind === 154 /* IfStatement */) { write(" "); emit(node.elseStatement); } @@ -6810,7 +6942,7 @@ var ts; function emitDoStatement(node) { write("do"); emitEmbeddedStatement(node.statement); - if (node.statement.kind === 148 /* Block */) { + if (node.statement.kind === 150 /* Block */) { write(" "); } else { @@ -6833,7 +6965,7 @@ var ts; if (node.declarations) { emitToken(92 /* VarKeyword */, endPos); write(" "); - emitCommaList(node.declarations); + emitCommaList(node.declarations, false); } if (node.initializer) { emit(node.initializer); @@ -6863,7 +6995,7 @@ var ts; emitEmbeddedStatement(node.statement); } function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 158 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */, node.pos); + emitToken(node.kind === 160 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */, node.pos); emitOptional(" ", node.label); write(";"); } @@ -6895,7 +7027,7 @@ var ts; emitToken(10 /* CloseBraceToken */, node.clauses.end); } function emitCaseOrDefaultClause(node) { - if (node.kind === 162 /* CaseClause */) { + if (node.kind === 164 /* CaseClause */) { write("case "); emit(node.expression); write(":"); @@ -6944,7 +7076,7 @@ var ts; function getContainingModule(node) { do { node = node.parent; - } while (node && node.kind !== 177 /* ModuleDeclaration */); + } while (node && node.kind !== 179 /* ModuleDeclaration */); return node; } function emitModuleMemberName(node) { @@ -6967,7 +7099,7 @@ var ts; emitLeadingComments(node); if (!(node.flags & 1 /* Export */)) write("var "); - emitCommaList(node.declarations); + emitCommaList(node.declarations, false); write(";"); emitTrailingComments(node); } @@ -7047,7 +7179,7 @@ var ts; emitLeadingComments(node); } write("function "); - if (node.kind === 172 /* FunctionDeclaration */ || (node.kind === 141 /* FunctionExpression */ && node.name)) { + if (node.kind === 174 /* FunctionDeclaration */ || (node.kind === 143 /* FunctionExpression */ && node.name)) { emit(node.name); } emitSignatureAndBody(node); @@ -7067,7 +7199,7 @@ var ts; increaseIndent(); write("("); if (node) { - emitCommaList(node.parameters, node.parameters.length - (ts.hasRestParameters(node) ? 1 : 0)); + emitCommaList(node.parameters, false, node.parameters.length - (ts.hasRestParameters(node) ? 1 : 0)); } write(")"); decreaseIndent(); @@ -7077,16 +7209,16 @@ var ts; write(" {"); scopeEmitStart(node); increaseIndent(); - emitDetachedComments(node.body.kind === 173 /* FunctionBlock */ ? node.body.statements : node.body); + emitDetachedComments(node.body.kind === 175 /* FunctionBlock */ ? node.body.statements : node.body); var startIndex = 0; - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { startIndex = emitDirectivePrologues(node.body.statements, true); } var outPos = writer.getTextPos(); emitCaptureThisForNodeIfNecessary(node); emitDefaultValueAssignments(node); emitRestParameter(node); - if (node.body.kind !== 173 /* FunctionBlock */ && outPos === writer.getTextPos()) { + if (node.body.kind !== 175 /* FunctionBlock */ && outPos === writer.getTextPos()) { decreaseIndent(); write(" "); emitStart(node.body); @@ -7099,7 +7231,7 @@ var ts; emitEnd(node.body); } else { - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { emitLinesStartingAt(node.body.statements, startIndex); } else { @@ -7111,7 +7243,7 @@ var ts; emitTrailingComments(node.body); } writeLine(); - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { emitLeadingCommentsOfPosition(node.body.statements.end); decreaseIndent(); emitToken(10 /* CloseBraceToken */, node.body.statements.end); @@ -7137,9 +7269,9 @@ var ts; function findInitialSuperCall(ctor) { if (ctor.body) { var statement = ctor.body.statements[0]; - if (statement && statement.kind === 151 /* ExpressionStatement */) { + if (statement && statement.kind === 153 /* ExpressionStatement */) { var expr = statement.expression; - if (expr && expr.kind === 137 /* CallExpression */) { + if (expr && expr.kind === 139 /* CallExpression */) { var func = expr.func; if (func && func.kind === 85 /* SuperKeyword */) { return statement; @@ -7453,7 +7585,7 @@ var ts; } } function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 177 /* ModuleDeclaration */) { + if (moduleDeclaration.body.kind === 179 /* ModuleDeclaration */) { var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); return recursiveInnerModule || moduleDeclaration.body; } @@ -7475,7 +7607,7 @@ var ts; write(resolver.getLocalNameOfContainer(node)); emitEnd(node.name); write(") "); - if (node.body.kind === 178 /* ModuleBlock */) { + if (node.body.kind === 180 /* ModuleBlock */) { emit(node.body); } else { @@ -7509,7 +7641,7 @@ var ts; emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportedViaEntityName(node); } if (emitImportDeclaration) { - if (node.externalModuleName && node.parent.kind === 182 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { + if (node.externalModuleName && node.parent.kind === 184 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { if (node.flags & 1 /* Export */) { writeLine(); emitLeadingComments(node); @@ -7549,7 +7681,7 @@ var ts; function getExternalImportDeclarations(node) { var result = []; ts.forEach(node.statements, function (stat) { - if (stat.kind === 179 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) { + if (stat.kind === 181 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) { result.push(stat); } }); @@ -7557,7 +7689,7 @@ var ts; } function getFirstExportAssignment(sourceFile) { return ts.forEach(sourceFile.statements, function (node) { - if (node.kind === 180 /* ExportAssignment */) { + if (node.kind === 182 /* ExportAssignment */) { return node; } }); @@ -7696,94 +7828,94 @@ var ts; return emitLiteral(node); case 116 /* QualifiedName */: return emitPropertyAccess(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return emitArrayLiteral(node); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return emitObjectLiteral(node); - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return emitPropertyAssignment(node); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return emitPropertyAccess(node); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return emitIndexedAccess(node); - case 137 /* CallExpression */: + case 139 /* CallExpression */: return emitCallExpression(node); - case 138 /* NewExpression */: + case 140 /* NewExpression */: return emitNewExpression(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return emit(node.operand); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return emitParenExpression(node); - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return emitFunctionDeclaration(node); - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: return emitUnaryExpression(node); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return emitBinaryExpression(node); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return emitConditionalExpression(node); - case 147 /* OmittedExpression */: + case 149 /* OmittedExpression */: return; - case 148 /* Block */: - case 167 /* TryBlock */: - case 169 /* FinallyBlock */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: + case 150 /* Block */: + case 169 /* TryBlock */: + case 171 /* FinallyBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: return emitBlock(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return emitVariableStatement(node); - case 150 /* EmptyStatement */: + case 152 /* EmptyStatement */: return write(";"); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return emitExpressionStatement(node); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return emitIfStatement(node); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return emitDoStatement(node); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return emitWhileStatement(node); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return emitForStatement(node); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return emitForInStatement(node); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return emitBreakOrContinueStatement(node); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return emitReturnStatement(node); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return emitWithStatement(node); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return emitSwitchStatement(node); - case 162 /* CaseClause */: - case 163 /* DefaultClause */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: return emitCaseOrDefaultClause(node); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return emitLabelledStatement(node); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return emitThrowStatement(node); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return emitTryStatement(node); - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return emitCatchBlock(node); - case 170 /* DebuggerStatement */: + case 172 /* DebuggerStatement */: return emitDebuggerStatement(node); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return emitVariableDeclaration(node); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return emitClassDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return emitInterfaceDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return emitEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return emitModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return emitImportDeclaration(node); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return emitSourceFile(node); } } @@ -7791,7 +7923,7 @@ var ts; return detachedCommentsInfo !== undefined && detachedCommentsInfo[detachedCommentsInfo.length - 1].nodePos === pos; } function getLeadingCommentsWithoutDetachedComments() { - var leadingComments = ts.getLeadingComments(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); if (detachedCommentsInfo.length - 1) { detachedCommentsInfo.pop(); } @@ -7801,13 +7933,13 @@ var ts; return leadingComments; } function getLeadingCommentsToEmit(node) { - if (node.parent.kind === 182 /* SourceFile */ || node.pos !== node.parent.pos) { + if (node.parent.kind === 184 /* SourceFile */ || node.pos !== node.parent.pos) { var leadingComments; if (hasDetachedComments(node.pos)) { leadingComments = getLeadingCommentsWithoutDetachedComments(); } else { - leadingComments = ts.getLeadingCommentsOfNode(node, currentSourceFile); + leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); } return leadingComments; } @@ -7818,8 +7950,8 @@ var ts; emitComments(leadingComments, true, writer, writeComment); } function emitTrailingDeclarationComments(node) { - if (node.parent.kind === 182 /* SourceFile */ || node.end !== node.parent.end) { - var trailingComments = ts.getTrailingComments(currentSourceFile.text, node.end); + if (node.parent.kind === 184 /* SourceFile */ || node.end !== node.parent.end) { + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); emitComments(trailingComments, false, writer, writeComment); } } @@ -7829,13 +7961,13 @@ var ts; leadingComments = getLeadingCommentsWithoutDetachedComments(); } else { - leadingComments = ts.getLeadingComments(currentSourceFile.text, pos); + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); } emitNewLineBeforeLeadingComments({ pos: pos, end: pos }, leadingComments, writer); emitComments(leadingComments, true, writer, writeComment); } function emitDetachedCommentsAtPosition(node) { - var leadingComments = ts.getLeadingComments(currentSourceFile.text, node.pos); + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); if (leadingComments) { var detachedComments = []; var lastComment; @@ -7897,7 +8029,7 @@ var ts; writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); } function emitDeclarations(jsFilePath, root) { - var writer = createTextWriter(writeSymbol); + var writer = createTextWriterWithSymbolWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -7908,11 +8040,23 @@ var ts; } : writeJsDocComments; var aliasDeclarationEmitInfo = []; var getSymbolVisibilityDiagnosticMessage; + function createTextWriterWithSymbolWriter() { + var writer = createTextWriter(); + writer.trackSymbol = trackSymbol; + writer.writeKeyword = writer.write; + writer.writeOperator = writer.write; + writer.writePunctuation = writer.write; + writer.writeSpace = writer.write; + writer.writeStringLiteral = writer.writeLiteral; + writer.writeParameter = writer.write; + writer.writeSymbol = writer.write; + return writer; + } function writeAsychronousImportDeclarations(importDeclarations) { var oldWriter = writer; ts.forEach(importDeclarations, function (aliasToWrite) { var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; }); - writer = createTextWriter(writeSymbol); + writer = createTextWriterWithSymbolWriter(); for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { writer.increaseIndent(); } @@ -7921,10 +8065,9 @@ var ts; }); writer = oldWriter; } - function writeSymbol(symbol, enclosingDeclaration, meaning) { + function trackSymbol(symbol, enclosingDeclaration, meaning) { var symbolAccesibilityResult = resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning); if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) { - resolver.writeSymbol(symbol, enclosingDeclaration, meaning, writer); if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); } @@ -7999,7 +8142,7 @@ var ts; if (node.flags & 1 /* Export */) { write("export "); } - if (node.kind !== 175 /* InterfaceDeclaration */) { + if (node.kind !== 177 /* InterfaceDeclaration */) { write("declare "); } } @@ -8055,7 +8198,7 @@ var ts; emitDeclarationFlags(node); write("module "); emitSourceTextOfNode(node.name); - while (node.body.kind !== 178 /* ModuleBlock */) { + while (node.body.kind !== 180 /* ModuleBlock */) { node = node.body; write("."); emitSourceTextOfNode(node.name); @@ -8103,10 +8246,10 @@ var ts; function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.parent.kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; break; - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; break; case 125 /* ConstructSignature */: @@ -8119,14 +8262,14 @@ var ts; if (node.parent.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -8164,7 +8307,7 @@ var ts; resolver.writeTypeAtLocation(node, enclosingDeclaration, 1 /* WriteArrayAsGenericType */ | 2 /* UseTypeOfFunction */, writer); function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.parent.kind === 174 /* ClassDeclaration */) { + if (node.parent.kind === 176 /* ClassDeclaration */) { if (symbolAccesibilityResult.errorModuleName) { diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2; } @@ -8249,7 +8392,7 @@ var ts; writeLine(); } function emitVariableDeclaration(node) { - if (node.kind !== 171 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { + if (node.kind !== 173 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { emitSourceTextOfNode(node.name); if (node.kind === 119 /* Property */ && (node.flags & 4 /* QuestionMark */)) { write("?"); @@ -8262,14 +8405,14 @@ var ts; } function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.kind === 171 /* VariableDeclaration */) { + if (node.kind === 173 /* VariableDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } else if (node.kind === 119 /* Property */) { if (node.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { @@ -8340,10 +8483,10 @@ var ts; } } function emitFunctionDeclaration(node) { - if ((node.kind !== 172 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { + if ((node.kind !== 174 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); emitDeclarationFlags(node); - if (node.kind === 172 /* FunctionDeclaration */) { + if (node.kind === 174 /* FunctionDeclaration */) { write("function "); emitSourceTextOfNode(node.name); } @@ -8405,14 +8548,14 @@ var ts; if (node.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } - else if (node.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; break; default: @@ -8456,14 +8599,14 @@ var ts; if (node.parent.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -8479,7 +8622,7 @@ var ts; function emitNode(node) { switch (node.kind) { case 121 /* Constructor */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: return emitFunctionDeclaration(node); case 125 /* ConstructSignature */: @@ -8490,44 +8633,44 @@ var ts; case 122 /* GetAccessor */: case 123 /* SetAccessor */: return emitAccessorDeclaration(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return emitVariableStatement(node); case 119 /* Property */: return emitPropertyDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return emitInterfaceDeclaration(node); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return emitClassDeclaration(node); - case 181 /* EnumMember */: + case 183 /* EnumMember */: return emitEnumMemberDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return emitEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return emitModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return emitImportDeclaration(node); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return emitExportAssignment(node); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return emitSourceFile(node); } } - function resolveScriptReference(sourceFile, reference) { + function tryResolveScriptReference(sourceFile, reference) { var referenceFileName = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename)); return program.getSourceFile(referenceFileName); } var referencePathsOutput = ""; function writeReferencePath(referencedFile) { - var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.getModuleNameFromFilename(compilerOptions.out) + ".d.ts"; - declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), false); + var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; + declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, false); referencePathsOutput += "/// " + newLine; } if (root) { if (!compilerOptions.noResolve) { var addedGlobalFileReference = false; ts.forEach(root.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(root, fileReference); - if ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference) { + var referencedFile = tryResolveScriptReference(root, fileReference); + if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { writeReferencePath(referencedFile); if (!isExternalModuleOrDeclarationFile(referencedFile)) { addedGlobalFileReference = true; @@ -8543,8 +8686,8 @@ var ts; if (!isExternalModuleOrDeclarationFile(sourceFile)) { if (!compilerOptions.noResolve) { ts.forEach(sourceFile.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(sourceFile, fileReference); - if (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile)) { + var referencedFile = tryResolveScriptReference(sourceFile, fileReference); + if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) { writeReferencePath(referencedFile); emittedReferencedFiles.push(referencedFile); } @@ -8566,7 +8709,7 @@ var ts; } }); declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos); - writeFile(ts.getModuleNameFromFilename(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); + writeFile(ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); } } var hasSemanticErrors = resolver.hasSemanticErrors(); @@ -8583,13 +8726,18 @@ var ts; emitFile(jsFilePath, sourceFile); } }); + if (compilerOptions.out) { + emitFile(compilerOptions.out); + } } else { - var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js"); - emitFile(jsFilePath, targetSourceFile); - } - if (compilerOptions.out) { - emitFile(compilerOptions.out); + if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { + var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js"); + emitFile(jsFilePath, targetSourceFile); + } + else if (!ts.isDeclarationFile(targetSourceFile) && compilerOptions.out) { + emitFile(compilerOptions.out); + } } diagnostics.sort(ts.compareDiagnostics); diagnostics = ts.deduplicateSortedDiagnostics(diagnostics); @@ -8631,6 +8779,33 @@ var ts; return undefined; } ts.getDeclarationOfKind = getDeclarationOfKind; + var stringWriters = []; + function getSingleLineStringWriter() { + if (stringWriters.length == 0) { + var str = ""; + var writeText = function (text) { return str += text; }; + return { + string: function () { return str; }, + writeKeyword: writeText, + writeOperator: writeText, + writePunctuation: writeText, + writeSpace: writeText, + writeStringLiteral: writeText, + writeParameter: writeText, + writeSymbol: writeText, + writeLine: function () { return str += " "; }, + increaseIndent: function () { + }, + decreaseIndent: function () { + }, + clear: function () { return str = ""; }, + trackSymbol: function () { + } + }; + } + return stringWriters.pop(); + } + ts.getSingleLineStringWriter = getSingleLineStringWriter; function createTypeChecker(program, fullTypeCheck) { var Symbol = ts.objectAllocator.getSymbolConstructor(); var Type = ts.objectAllocator.getTypeConstructor(); @@ -8659,13 +8834,21 @@ var ts; getSymbolsInScope: getSymbolsInScope, getSymbolInfo: getSymbolInfo, getTypeOfNode: getTypeOfNode, - getApparentType: getApparentType, typeToString: typeToString, + getSymbolDisplayBuilder: getSymbolDisplayBuilder, symbolToString: symbolToString, - getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType, - getRootSymbol: getRootSymbol, + getAugmentedPropertiesOfType: getAugmentedPropertiesOfType, + getRootSymbols: getRootSymbols, getContextualType: getContextualType, - getFullyQualifiedName: getFullyQualifiedName + getFullyQualifiedName: getFullyQualifiedName, + getResolvedSignature: getResolvedSignature, + getEnumMemberValue: getEnumMemberValue, + isValidPropertyAccess: isValidPropertyAccess, + getSignatureFromDeclaration: getSignatureFromDeclaration, + isImplementationOfOverload: isImplementationOfOverload, + getAliasedSymbol: resolveImport, + isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; }, + isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; } }; var undefinedSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "undefined"); var argumentsSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "arguments"); @@ -8695,6 +8878,7 @@ var ts; var globalBooleanType; var globalRegExpType; var tupleTypes = {}; + var unionTypes = {}; var stringLiteralTypes = {}; var emitExtends = false; var mergedSymbols = []; @@ -8826,10 +9010,10 @@ var ts; return nodeLinks[node.id] || (nodeLinks[node.id] = {}); } function getSourceFile(node) { - return ts.getAncestor(node, 182 /* SourceFile */); + return ts.getAncestor(node, 184 /* SourceFile */); } function isGlobalSourceFile(node) { - return node.kind === 182 /* SourceFile */ && !ts.isExternalModule(node); + return node.kind === 184 /* SourceFile */ && !ts.isExternalModule(node); } function getSymbol(symbols, name, meaning) { if (meaning && ts.hasProperty(symbols, name)) { @@ -8869,21 +9053,21 @@ var ts; } } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & ts.SymbolFlags.ModuleMember)) { return returnResolvedSymbol(result); } break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 4 /* EnumMember */)) { return returnResolvedSymbol(result); } break; case 119 /* Property */: - if (location.parent.kind === 174 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) { + if (location.parent.kind === 176 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { if (getSymbol(ctor.locals, name, meaning & ts.SymbolFlags.Value)) { @@ -8892,8 +9076,8 @@ var ts; } } break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & ts.SymbolFlags.Type)) { if (lastLocation && lastLocation.flags & 128 /* Static */) { error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters); @@ -8908,13 +9092,13 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: if (name === "arguments") { return returnResolvedSymbol(argumentsSymbol); } break; - case 141 /* FunctionExpression */: + case 143 /* FunctionExpression */: if (name === "arguments") { return returnResolvedSymbol(argumentsSymbol); } @@ -8923,7 +9107,7 @@ var ts; return returnResolvedSymbol(location.symbol); } break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: var id = location.variable; if (name === id.text) { return returnResolvedSymbol(location.symbol); @@ -8943,7 +9127,7 @@ var ts; var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = getDeclarationOfKind(symbol, 179 /* ImportDeclaration */); + var node = getDeclarationOfKind(symbol, 181 /* ImportDeclaration */); var target = node.externalModuleName ? resolveExternalModuleName(node, node.externalModuleName) : getSymbolOfPartOfRightHandSideOfImport(node.entityName, node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; @@ -8959,7 +9143,7 @@ var ts; } function getSymbolOfPartOfRightHandSideOfImport(entityName, importDeclaration) { if (!importDeclaration) { - importDeclaration = ts.getAncestor(entityName, 179 /* ImportDeclaration */); + importDeclaration = ts.getAncestor(entityName, 181 /* ImportDeclaration */); ts.Debug.assert(importDeclaration); } if (entityName.kind === 59 /* Identifier */ && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { @@ -8969,7 +9153,7 @@ var ts; return resolveEntityName(importDeclaration, entityName, ts.SymbolFlags.Namespace); } else { - ts.Debug.assert(entityName.parent.kind === 179 /* ImportDeclaration */); + ts.Debug.assert(entityName.parent.kind === 181 /* ImportDeclaration */); return resolveEntityName(importDeclaration, entityName, ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace); } } @@ -9074,9 +9258,9 @@ var ts; var seenExportedMember = false; var result = []; ts.forEach(symbol.declarations, function (declaration) { - var block = (declaration.kind === 182 /* SourceFile */ ? declaration : declaration.body); + var block = (declaration.kind === 184 /* SourceFile */ ? declaration : declaration.body); ts.forEach(block.statements, function (node) { - if (node.kind === 180 /* ExportAssignment */) { + if (node.kind === 182 /* ExportAssignment */) { result.push(node); } else { @@ -9103,15 +9287,15 @@ var ts; return symbol && (symbol.flags & 524288 /* ExportValue */) !== 0 ? getMergedSymbol(symbol.exportSymbol) : symbol; } function symbolIsValue(symbol) { + if (symbol.flags & 8388608 /* Instantiated */) { + return symbolIsValue(getSymbolLinks(symbol).target); + } if (symbol.flags & ts.SymbolFlags.Value) { return true; } if (symbol.flags & 4194304 /* Import */) { return (resolveImport(symbol).flags & ts.SymbolFlags.Value) !== 0; } - if (symbol.flags & 8388608 /* Instantiated */) { - return (getSymbolLinks(symbol).target.flags & ts.SymbolFlags.Value) !== 0; - } return false; } function findConstructorDeclaration(node) { @@ -9169,7 +9353,7 @@ var ts; return type; } function createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) { - return setObjectTypeMembers(createObjectType(16384 /* Anonymous */, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + return setObjectTypeMembers(createObjectType(32768 /* Anonymous */, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } function isOptionalProperty(propertySymbol) { return propertySymbol.valueDeclaration && propertySymbol.valueDeclaration.flags & 4 /* QuestionMark */ && propertySymbol.valueDeclaration.kind !== 118 /* Parameter */; @@ -9183,17 +9367,17 @@ var ts; } } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) { break; } - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: if (result = callback(getSymbolOfNode(location).exports)) { return result; } break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (result = callback(getSymbolOfNode(location).members)) { return result; } @@ -9205,13 +9389,13 @@ var ts; function getQualifiedLeftMeaning(rightMeaning) { return rightMeaning === ts.SymbolFlags.Value ? ts.SymbolFlags.Value : ts.SymbolFlags.Namespace; } - function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning) { + function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, useOnlyExternalAliasing) { function getAccessibleSymbolChainFromSymbolTable(symbols) { function canQualifySymbol(symbolFromSymbolTable, meaning) { if (!needsQualification(symbolFromSymbolTable, enclosingDeclaration, meaning)) { return true; } - var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning)); + var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing); return !!accessibleParent; } function isAccessible(symbolFromSymbolTable, resolvedAliasSymbol) { @@ -9224,13 +9408,15 @@ var ts; } return ts.forEachValue(symbols, function (symbolFromSymbolTable) { if (symbolFromSymbolTable.flags & 4194304 /* Import */) { - var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); - if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { - return [symbolFromSymbolTable]; - } - var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; - if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { - return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); + if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, function (declaration) { return declaration.kind === 181 /* ImportDeclaration */ && declaration.externalModuleName; })) { + var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); + if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { + return [symbolFromSymbolTable]; + } + var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; + if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { + return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); + } } } }); @@ -9263,7 +9449,7 @@ var ts; var initialSymbol = symbol; var meaningToLook = meaning; while (symbol) { - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook); + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, false); if (accessibleSymbolChain) { var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]); if (!hasAccessibleDeclarations) { @@ -9304,7 +9490,7 @@ var ts; } } function hasExternalModuleSymbol(declaration) { - return (declaration.kind === 177 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 182 /* SourceFile */ && ts.isExternalModule(declaration)); + return (declaration.kind === 179 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 184 /* SourceFile */ && ts.isExternalModule(declaration)); } function hasVisibleDeclarations(symbol) { var aliasesToMakeVisible; @@ -9314,7 +9500,7 @@ var ts; return { aliasesToMakeVisible: aliasesToMakeVisible }; function getIsDeclarationVisible(declaration) { if (!isDeclarationVisible(declaration)) { - if (declaration.kind === 179 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) { + if (declaration.kind === 181 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) { getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { if (!ts.contains(aliasesToMakeVisible, declaration)) { @@ -9338,283 +9524,416 @@ var ts; var hasNamespaceDeclarationsVisibile = hasVisibleDeclarations(symbolOfNameSpace); return hasNamespaceDeclarationsVisibile ? { accessibility: 0 /* Accessible */, aliasesToMakeVisible: hasNamespaceDeclarationsVisibile.aliasesToMakeVisible } : { accessibility: 1 /* NotAccessible */, errorSymbolName: firstIdentifierName }; } + function releaseStringWriter(writer) { + writer.clear(); + stringWriters.push(writer); + } + function writeKeyword(writer, kind) { + writer.writeKeyword(ts.tokenToString(kind)); + } + function writePunctuation(writer, kind) { + writer.writePunctuation(ts.tokenToString(kind)); + } + function writeOperator(writer, kind) { + writer.writeOperator(ts.tokenToString(kind)); + } + function writeSpace(writer) { + writer.writeSpace(" "); + } function symbolToString(symbol, enclosingDeclaration, meaning) { - function getSymbolName(symbol) { + var writer = getSingleLineStringWriter(); + getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning); + var result = writer.string(); + releaseStringWriter(writer); + return result; + } + function typeToString(type, enclosingDeclaration, flags) { + var writer = getSingleLineStringWriter(); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); + var result = writer.string(); + releaseStringWriter(writer); + var maxLength = compilerOptions.noErrorTruncation || flags & 4 /* NoTruncation */ ? undefined : 100; + if (maxLength && result.length >= maxLength) { + result = result.substr(0, maxLength - "...".length) + "..."; + } + return result; + } + var _displayBuilder; + function getSymbolDisplayBuilder() { + function appendSymbolNameOnly(symbol, writer) { if (symbol.declarations && symbol.declarations.length > 0) { var declaration = symbol.declarations[0]; if (declaration.name) { - return ts.identifierToString(declaration.name); - } - } - return symbol.name; - } - if (enclosingDeclaration && !(symbol.flags & 262144 /* TypeParameter */)) { - var symbolName; - while (symbol) { - var isFirstName = !symbolName; - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning); - var currentSymbolName; - if (accessibleSymbolChain) { - currentSymbolName = ts.map(accessibleSymbolChain, function (accessibleSymbol) { return getSymbolName(accessibleSymbol); }).join("."); - } - else { - if (!isFirstName && ts.forEach(symbol.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); })) { - break; - } - currentSymbolName = getSymbolName(symbol); - } - symbolName = currentSymbolName + (isFirstName ? "" : ("." + symbolName)); - if (accessibleSymbolChain && !needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { - break; - } - symbol = getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol); - meaning = getQualifiedLeftMeaning(meaning); - } - return symbolName; - } - return getSymbolName(symbol); - } - function writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, writer) { - writer.write(symbolToString(symbol, enclosingDeclaration, meaning)); - } - function createSingleLineTextWriter(maxLength) { - var result = ""; - var overflow = false; - function write(s) { - if (!overflow) { - result += s; - if (result.length > maxLength) { - result = result.substr(0, maxLength - 3) + "..."; - overflow = true; - } - } - } - return { - write: write, - writeSymbol: function (symbol, enclosingDeclaration, meaning) { - writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this); - }, - writeLine: function () { - write(" "); - }, - increaseIndent: function () { - }, - decreaseIndent: function () { - }, - getText: function () { - return result; - } - }; - } - function typeToString(type, enclosingDeclaration, flags) { - var maxLength = compilerOptions.noErrorTruncation || flags & 4 /* NoTruncation */ ? undefined : 100; - var stringWriter = createSingleLineTextWriter(maxLength); - writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter); - return stringWriter.getText(); - } - function writeTypeToTextWriter(type, enclosingDeclaration, flags, writer) { - var typeStack; - return writeType(type, true); - function writeType(type, allowFunctionOrConstructorTypeLiteral) { - if (type.flags & ts.TypeFlags.Intrinsic) { - writer.write(type.intrinsicName); - } - else if (type.flags & 4096 /* Reference */) { - writeTypeReference(type); - } - else if (type.flags & (1024 /* Class */ | 2048 /* Interface */ | 128 /* Enum */ | 512 /* TypeParameter */)) { - writer.writeSymbol(type.symbol, enclosingDeclaration, ts.SymbolFlags.Type); - } - else if (type.flags & 8192 /* Tuple */) { - writeTupleType(type); - } - else if (type.flags & 16384 /* Anonymous */) { - writeAnonymousType(type, allowFunctionOrConstructorTypeLiteral); - } - else if (type.flags & 256 /* StringLiteral */) { - writer.write(type.text); - } - else { - writer.write("{ ... }"); - } - } - function writeTypeList(types) { - for (var i = 0; i < types.length; i++) { - if (i > 0) { - writer.write(", "); - } - writeType(types[i], true); - } - } - function writeTypeReference(type) { - if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { - writeType(type.typeArguments[0], false); - writer.write("[]"); - } - else { - writer.writeSymbol(type.target.symbol, enclosingDeclaration, ts.SymbolFlags.Type); - writer.write("<"); - writeTypeList(type.typeArguments); - writer.write(">"); - } - } - function writeTupleType(type) { - writer.write("["); - writeTypeList(type.elementTypes); - writer.write("]"); - } - function writeAnonymousType(type, allowFunctionOrConstructorTypeLiteral) { - if (type.symbol && type.symbol.flags & (16 /* Class */ | 64 /* Enum */ | 128 /* ValueModule */)) { - writeTypeofSymbol(type); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type); - } - else if (typeStack && ts.contains(typeStack, type)) { - writer.write("any"); - } - else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); - writeLiteralType(type, allowFunctionOrConstructorTypeLiteral); - typeStack.pop(); - } - function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 2048 /* Method */ && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 8 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 182 /* SourceFile */ || declaration.parent.kind === 178 /* ModuleBlock */; })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - return !!(flags & 2 /* UseTypeOfFunction */) || (typeStack && ts.contains(typeStack, type)); - } - } - } - } - function writeTypeofSymbol(type) { - writer.write("typeof "); - writer.writeSymbol(type.symbol, enclosingDeclaration, ts.SymbolFlags.Value); - } - function writeLiteralType(type, allowFunctionOrConstructorTypeLiteral) { - var resolved = resolveObjectTypeMembers(type); - if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { - if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { - writer.write("{}"); + writer.writeSymbol(ts.identifierToString(declaration.name), symbol); return; } - if (allowFunctionOrConstructorTypeLiteral) { + } + writer.writeSymbol(symbol.name, symbol); + } + function buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags) { + var parentSymbol; + function appendParentTypeArgumentsAndSymbolName(symbol) { + if (parentSymbol) { + if (flags & 1 /* WriteTypeParametersOrArguments */) { + if (symbol.flags & 8388608 /* Instantiated */) { + buildDisplayForTypeArgumentsAndDelimiters(getTypeParametersOfClassOrInterface(parentSymbol), symbol.mapper, writer, enclosingDeclaration); + } + else { + buildTypeParameterDisplayFromSymbol(parentSymbol, writer, enclosingDeclaration); + } + } + writePunctuation(writer, 15 /* DotToken */); + } + parentSymbol = symbol; + appendSymbolNameOnly(symbol, writer); + } + writer.trackSymbol(symbol, enclosingDeclaration, meaning); + function walkSymbol(symbol, meaning) { + if (symbol) { + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & 2 /* UseOnlyExternalAliasing */)); + if (!accessibleSymbolChain || needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { + walkSymbol(getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), getQualifiedLeftMeaning(meaning)); + } + if (accessibleSymbolChain) { + for (var i = 0, n = accessibleSymbolChain.length; i < n; i++) { + appendParentTypeArgumentsAndSymbolName(accessibleSymbolChain[i]); + } + } + else { + if (!parentSymbol && ts.forEach(symbol.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); })) { + return; + } + if (symbol.flags & 512 /* TypeLiteral */ || symbol.flags & 1024 /* ObjectLiteral */) { + return; + } + appendParentTypeArgumentsAndSymbolName(symbol); + } + } + } + if (enclosingDeclaration && !(symbol.flags & 262144 /* TypeParameter */)) { + walkSymbol(symbol, meaning); + return; + } + return appendParentTypeArgumentsAndSymbolName(symbol); + } + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + var globalFlagsToPass = globalFlags & 16 /* WriteOwnNameForAnyLike */; + return writeType(type, globalFlags); + function writeType(type, flags) { + if (type.flags & ts.TypeFlags.Intrinsic) { + writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && (type.flags & 1 /* Any */) ? "any" : type.intrinsicName); + } + else if (type.flags & 4096 /* Reference */) { + writeTypeReference(type, flags); + } + else if (type.flags & (1024 /* Class */ | 2048 /* Interface */ | 128 /* Enum */ | 512 /* TypeParameter */)) { + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Type); + } + else if (type.flags & 8192 /* Tuple */) { + writeTupleType(type); + } + else if (type.flags & 16384 /* Union */) { + writeUnionType(type, flags); + } + else if (type.flags & 32768 /* Anonymous */) { + writeAnonymousType(type, flags); + } + else if (type.flags & 256 /* StringLiteral */) { + writer.writeStringLiteral(type.text); + } + else { + writePunctuation(writer, 9 /* OpenBraceToken */); + writeSpace(writer); + writePunctuation(writer, 16 /* DotDotDotToken */); + writeSpace(writer); + writePunctuation(writer, 10 /* CloseBraceToken */); + } + } + function writeTypeList(types, union) { + for (var i = 0; i < types.length; i++) { + if (i > 0) { + if (union) { + writeSpace(writer); + } + writePunctuation(writer, union ? 39 /* BarToken */ : 18 /* CommaToken */); + writeSpace(writer); + } + writeType(types[i], union ? 64 /* InElementType */ : 0 /* None */); + } + } + function writeTypeReference(type, flags) { + if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { + writeType(type.typeArguments[0], 64 /* InElementType */); + writePunctuation(writer, 13 /* OpenBracketToken */); + writePunctuation(writer, 14 /* CloseBracketToken */); + } + else { + buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Type); + writePunctuation(writer, 19 /* LessThanToken */); + writeTypeList(type.typeArguments, false); + writePunctuation(writer, 20 /* GreaterThanToken */); + } + } + function writeTupleType(type) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writeTypeList(type.elementTypes, false); + writePunctuation(writer, 14 /* CloseBracketToken */); + } + function writeUnionType(type, flags) { + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + writeTypeList(type.types, true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } + } + function writeAnonymousType(type, flags) { + if (type.symbol && type.symbol.flags & (16 /* Class */ | 64 /* Enum */ | 128 /* ValueModule */)) { + writeTypeofSymbol(type); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type); + } + else if (typeStack && ts.contains(typeStack, type)) { + writeKeyword(writer, 105 /* AnyKeyword */); + } + else { + if (!typeStack) { + typeStack = []; + } + typeStack.push(type); + writeLiteralType(type, flags); + typeStack.pop(); + } + function shouldWriteTypeOfFunctionSymbol() { + if (type.symbol) { + var isStaticMethodSymbol = !!(type.symbol.flags & 2048 /* Method */ && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); + var isNonLocalFunctionSymbol = !!(type.symbol.flags & 8 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 184 /* SourceFile */ || declaration.parent.kind === 180 /* ModuleBlock */; })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + return !!(flags & 2 /* UseTypeOfFunction */) || (typeStack && ts.contains(typeStack, type)); + } + } + } + } + function writeTypeofSymbol(type) { + writeKeyword(writer, 91 /* TypeOfKeyword */); + writeSpace(writer); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Value); + } + function writeLiteralType(type, flags) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { + if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { + writePunctuation(writer, 9 /* OpenBraceToken */); + writePunctuation(writer, 10 /* CloseBraceToken */); + return; + } if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) { - writeSignature(resolved.callSignatures[0], true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } return; } if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) { - writer.write("new "); - writeSignature(resolved.constructSignatures[0], true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + writeKeyword(writer, 82 /* NewKeyword */); + writeSpace(writer); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } return; } } - } - writer.write("{"); - writer.writeLine(); - writer.increaseIndent(); - for (var i = 0; i < resolved.callSignatures.length; i++) { - writeSignature(resolved.callSignatures[i]); - writer.write(";"); + writePunctuation(writer, 9 /* OpenBraceToken */); writer.writeLine(); - } - for (var i = 0; i < resolved.constructSignatures.length; i++) { - writer.write("new "); - writeSignature(resolved.constructSignatures[i]); - writer.write(";"); - writer.writeLine(); - } - if (resolved.stringIndexType) { - writer.write("[x: string]: "); - writeType(resolved.stringIndexType, true); - writer.write(";"); - writer.writeLine(); - } - if (resolved.numberIndexType) { - writer.write("[x: number]: "); - writeType(resolved.numberIndexType, true); - writer.write(";"); - writer.writeLine(); - } - for (var i = 0; i < resolved.properties.length; i++) { - var p = resolved.properties[i]; - var t = getTypeOfSymbol(p); - if (p.flags & (8 /* Function */ | 2048 /* Method */) && !getPropertiesOfType(t).length) { - var signatures = getSignaturesOfType(t, 0 /* Call */); - for (var j = 0; j < signatures.length; j++) { - writer.writeSymbol(p); - if (isOptionalProperty(p)) { - writer.write("?"); + writer.increaseIndent(); + for (var i = 0; i < resolved.callSignatures.length; i++) { + buildSignatureDisplay(resolved.callSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + for (var i = 0; i < resolved.constructSignatures.length; i++) { + writeKeyword(writer, 82 /* NewKeyword */); + writeSpace(writer); + buildSignatureDisplay(resolved.constructSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + if (resolved.stringIndexType) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writer.writeParameter("x"); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeKeyword(writer, 114 /* StringKeyword */); + writePunctuation(writer, 14 /* CloseBracketToken */); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(resolved.stringIndexType, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + if (resolved.numberIndexType) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writer.writeParameter("x"); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeKeyword(writer, 112 /* NumberKeyword */); + writePunctuation(writer, 14 /* CloseBracketToken */); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(resolved.numberIndexType, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + for (var i = 0; i < resolved.properties.length; i++) { + var p = resolved.properties[i]; + var t = getTypeOfSymbol(p); + if (p.flags & (8 /* Function */ | 2048 /* Method */) && !getPropertiesOfObjectType(t).length) { + var signatures = getSignaturesOfType(t, 0 /* Call */); + for (var j = 0; j < signatures.length; j++) { + buildSymbolDisplay(p, writer); + if (isOptionalProperty(p)) { + writePunctuation(writer, 45 /* QuestionToken */); + } + buildSignatureDisplay(signatures[j], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); } - writeSignature(signatures[j]); - writer.write(";"); + } + else { + buildSymbolDisplay(p, writer); + if (isOptionalProperty(p)) { + writePunctuation(writer, 45 /* QuestionToken */); + } + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(t, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); writer.writeLine(); } } - else { - writer.writeSymbol(p); - if (isOptionalProperty(p)) { - writer.write("?"); - } - writer.write(": "); - writeType(t, true); - writer.write(";"); - writer.writeLine(); - } + writer.decreaseIndent(); + writePunctuation(writer, 10 /* CloseBraceToken */); } - writer.decreaseIndent(); - writer.write("}"); } - function writeSignature(signature, arrowStyle) { - if (signature.typeParameters) { - writer.write("<"); - for (var i = 0; i < signature.typeParameters.length; i++) { + function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { + var targetSymbol = getTargetSymbol(symbol); + if (targetSymbol.flags & 16 /* Class */ || targetSymbol.flags & 32 /* Interface */) { + buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); + } + } + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + appendSymbolNameOnly(tp.symbol, writer); + var constraint = getConstraintOfTypeParameter(tp); + if (constraint) { + writeSpace(writer); + writeKeyword(writer, 73 /* ExtendsKeyword */); + writeSpace(writer); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + } + } + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + if (getDeclarationFlagsFromSymbol(p) & 8 /* Rest */) { + writePunctuation(writer, 16 /* DotDotDotToken */); + } + appendSymbolNameOnly(p, writer); + if (p.valueDeclaration.flags & 4 /* QuestionMark */ || p.valueDeclaration.initializer) { + writePunctuation(writer, 45 /* QuestionToken */); + } + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + } + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, 19 /* LessThanToken */); + for (var i = 0; i < typeParameters.length; i++) { if (i > 0) { - writer.write(", "); - } - var tp = signature.typeParameters[i]; - writer.writeSymbol(tp.symbol); - var constraint = getConstraintOfTypeParameter(tp); - if (constraint) { - writer.write(" extends "); - writeType(constraint, true); + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); } + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); } - writer.write(">"); + writePunctuation(writer, 20 /* GreaterThanToken */); } - writer.write("("); - for (var i = 0; i < signature.parameters.length; i++) { - if (i > 0) { - writer.write(", "); - } - var p = signature.parameters[i]; - if (getDeclarationFlagsFromSymbol(p) & 8 /* Rest */) { - writer.write("..."); - } - writer.writeSymbol(p); - if (p.valueDeclaration.flags & 4 /* QuestionMark */ || p.valueDeclaration.initializer) { - writer.write("?"); - } - writer.write(": "); - writeType(getTypeOfSymbol(p), true); - } - writer.write(arrowStyle ? ") => " : "): "); - writeType(getReturnTypeOfSignature(signature), true); } + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, 19 /* LessThanToken */); + for (var i = 0; i < typeParameters.length; i++) { + if (i > 0) { + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); + } + buildTypeDisplay(mapper(typeParameters[i]), writer, enclosingDeclaration, 0 /* None */); + } + writePunctuation(writer, 20 /* GreaterThanToken */); + } + } + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + writePunctuation(writer, 11 /* OpenParenToken */); + for (var i = 0; i < parameters.length; i++) { + if (i > 0) { + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); + } + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + } + writePunctuation(writer, 12 /* CloseParenToken */); + } + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + if (flags & 8 /* WriteArrowStyleSignature */) { + writeSpace(writer); + writePunctuation(writer, 27 /* EqualsGreaterThanToken */); + } + else { + writePunctuation(writer, 46 /* ColonToken */); + } + writeSpace(writer); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + } + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + if (signature.target && (flags & 32 /* WriteTypeArgumentsOfSignature */)) { + buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); + } + else { + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + } + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + } + return _displayBuilder || (_displayBuilder = { + symbolToString: symbolToString, + typeToString: typeToString, + buildSymbolDisplay: buildSymbolDisplay, + buildTypeDisplay: buildTypeDisplay, + buildTypeParameterDisplay: buildTypeParameterDisplay, + buildParameterDisplay: buildParameterDisplay, + buildDisplayForParametersAndDelimiters: buildDisplayForParametersAndDelimiters, + buildDisplayForTypeParametersAndDelimiters: buildDisplayForTypeParametersAndDelimiters, + buildDisplayForTypeArgumentsAndDelimiters: buildDisplayForTypeArgumentsAndDelimiters, + buildTypeParameterDisplayFromSymbol: buildTypeParameterDisplayFromSymbol, + buildSignatureDisplay: buildSignatureDisplay, + buildReturnTypeDisplay: buildReturnTypeDisplay + }); } function isDeclarationVisible(node) { function getContainingExternalModule(node) { for (; node; node = node.parent) { - if (node.kind === 177 /* ModuleDeclaration */) { + if (node.kind === 179 /* ModuleDeclaration */) { if (node.name.kind === 7 /* StringLiteral */) { return node; } } - else if (node.kind === 182 /* SourceFile */) { + else if (node.kind === 184 /* SourceFile */) { return ts.isExternalModule(node) ? node : undefined; } } @@ -9656,15 +9975,15 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 171 /* VariableDeclaration */: - case 177 /* ModuleDeclaration */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 172 /* FunctionDeclaration */: - case 176 /* EnumDeclaration */: - case 179 /* ImportDeclaration */: - var parent = node.kind === 171 /* VariableDeclaration */ ? node.parent.parent : node.parent; - if (!(node.flags & 1 /* Export */) && !(node.kind !== 179 /* ImportDeclaration */ && parent.kind !== 182 /* SourceFile */ && ts.isInAmbientContext(parent))) { + case 173 /* VariableDeclaration */: + case 179 /* ModuleDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 174 /* FunctionDeclaration */: + case 178 /* EnumDeclaration */: + case 181 /* ImportDeclaration */: + var parent = node.kind === 173 /* VariableDeclaration */ ? node.parent.parent : node.parent; + if (!(node.flags & 1 /* Export */) && !(node.kind !== 181 /* ImportDeclaration */ && parent.kind !== 184 /* SourceFile */ && ts.isInAmbientContext(parent))) { return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); } return isDeclarationVisible(parent); @@ -9678,9 +9997,9 @@ var ts; case 124 /* CallSignature */: case 126 /* IndexSignature */: case 118 /* Parameter */: - case 178 /* ModuleBlock */: + case 180 /* ModuleBlock */: return isDeclarationVisible(node.parent); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return true; default: ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + ts.SyntaxKind[node.kind]); @@ -9694,31 +10013,12 @@ var ts; return links.isVisible; } } - function getApparentType(type) { - if (type.flags & 512 /* TypeParameter */) { - do { - type = getConstraintOfTypeParameter(type); - } while (type && type.flags & 512 /* TypeParameter */); - if (!type) - type = emptyObjectType; - } - if (type.flags & ts.TypeFlags.StringLike) { - type = globalStringType; - } - else if (type.flags & ts.TypeFlags.NumberLike) { - type = globalNumberType; - } - else if (type.flags & 8 /* Boolean */) { - type = globalBooleanType; - } - return type; - } function getTypeOfPrototypeProperty(prototype) { var classType = getDeclaredTypeOfSymbol(prototype.parent); return classType.typeParameters ? createTypeReference(classType, ts.map(classType.typeParameters, function (_) { return anyType; })) : classType; } function getTypeOfVariableDeclaration(declaration) { - if (declaration.parent.kind === 156 /* ForInStatement */) { + if (declaration.parent.kind === 158 /* ForInStatement */) { return anyType; } if (declaration.type) { @@ -9739,7 +10039,7 @@ var ts; } if (declaration.initializer) { var type = checkAndMarkExpression(declaration.initializer); - if (declaration.kind !== 134 /* PropertyAssignment */) { + if (declaration.kind !== 136 /* PropertyAssignment */) { var unwidenedType = type; type = getWidenedType(type); if (type !== unwidenedType) { @@ -9781,7 +10081,7 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.kind === 168 /* CatchBlock */) { + if (declaration.kind === 170 /* CatchBlock */) { return links.type = anyType; } links.type = resolvingType; @@ -9862,7 +10162,7 @@ var ts; function getTypeOfFuncClassEnumModule(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { - links.type = createObjectType(16384 /* Anonymous */, symbol); + links.type = createObjectType(32768 /* Anonymous */, symbol); } return links.type; } @@ -9888,6 +10188,9 @@ var ts; return links.type; } function getTypeOfSymbol(symbol) { + if (symbol.flags & 8388608 /* Instantiated */) { + return getTypeOfInstantiatedSymbol(symbol); + } if (symbol.flags & (1 /* Variable */ | 2 /* Property */)) { return getTypeOfVariableOrParameterOrProperty(symbol); } @@ -9903,9 +10206,6 @@ var ts; if (symbol.flags & 4194304 /* Import */) { return getTypeOfImport(symbol); } - if (symbol.flags & 8388608 /* Instantiated */) { - return getTypeOfInstantiatedSymbol(symbol); - } return unknownType; } function getTargetType(type) { @@ -9921,7 +10221,7 @@ var ts; function getTypeParametersOfClassOrInterface(symbol) { var result; ts.forEach(symbol.declarations, function (node) { - if (node.kind === 175 /* InterfaceDeclaration */ || node.kind === 174 /* ClassDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */ || node.kind === 176 /* ClassDeclaration */) { var declaration = node; if (declaration.typeParameters && declaration.typeParameters.length) { ts.forEach(declaration.typeParameters, function (node) { @@ -9952,7 +10252,7 @@ var ts; type.typeArguments = type.typeParameters; } type.baseTypes = []; - var declaration = getDeclarationOfKind(symbol, 174 /* ClassDeclaration */); + var declaration = getDeclarationOfKind(symbol, 176 /* ClassDeclaration */); if (declaration.baseType) { var baseType = getTypeFromTypeReferenceNode(declaration.baseType); if (baseType !== unknownType) { @@ -9992,7 +10292,7 @@ var ts; } type.baseTypes = []; ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 175 /* InterfaceDeclaration */ && declaration.baseTypes) { + if (declaration.kind === 177 /* InterfaceDeclaration */ && declaration.baseTypes) { ts.forEach(declaration.baseTypes, function (node) { var baseType = getTypeFromTypeReferenceNode(node); if (baseType !== unknownType) { @@ -10048,6 +10348,7 @@ var ts; return links.declaredType; } function getDeclaredTypeOfSymbol(symbol) { + ts.Debug.assert((symbol.flags & 8388608 /* Instantiated */) === 0); if (symbol.flags & 16 /* Class */) { return getDeclaredTypeOfClass(symbol); } @@ -10063,7 +10364,6 @@ var ts; if (symbol.flags & 4194304 /* Import */) { return getDeclaredTypeOfImport(symbol); } - ts.Debug.assert((symbol.flags & 8388608 /* Instantiated */) === 0); return unknownType; } function createSymbolTable(symbols) { @@ -10106,7 +10406,7 @@ var ts; if (type.baseTypes.length) { members = createSymbolTable(type.declaredProperties); ts.forEach(type.baseTypes, function (baseType) { - addInheritedMembers(members, getPropertiesOfType(baseType)); + addInheritedMembers(members, getPropertiesOfObjectType(baseType)); callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(baseType, 0 /* Call */)); constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(baseType, 1 /* Construct */)); stringIndexType = stringIndexType || getIndexTypeOfType(baseType, 0 /* String */); @@ -10125,7 +10425,7 @@ var ts; var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined; ts.forEach(target.baseTypes, function (baseType) { var instantiatedBaseType = instantiateType(baseType, mapper); - addInheritedMembers(members, getPropertiesOfType(instantiatedBaseType)); + addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0 /* Call */)); constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1 /* Construct */)); stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0 /* String */); @@ -10170,11 +10470,61 @@ var ts; return members; } function resolveTupleTypeMembers(type) { - var arrayType = resolveObjectTypeMembers(createArrayType(getBestCommonType(type.elementTypes))); + var arrayType = resolveObjectOrUnionTypeMembers(createArrayType(getUnionType(type.elementTypes))); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); } + function signatureListsIdentical(s, t) { + if (s.length !== t.length) { + return false; + } + for (var i = 0; i < s.length; i++) { + if (!compareSignatures(s[i], t[i], false, isTypeIdenticalTo)) { + return false; + } + } + return true; + } + function getUnionSignatures(types, kind) { + var signatureLists = ts.map(types, function (t) { return getSignaturesOfType(t, kind); }); + var signatures = signatureLists[0]; + for (var i = 0; i < signatures.length; i++) { + if (signatures[i].typeParameters) { + return emptyArray; + } + } + for (var i = 1; i < signatureLists.length; i++) { + if (!signatureListsIdentical(signatures, signatureLists[i])) { + return emptyArray; + } + } + var result = ts.map(signatures, cloneSignature); + for (var i = 0; i < result.length; i++) { + var s = result[i]; + s.resolvedReturnType = undefined; + s.unionSignatures = ts.map(signatureLists, function (signatures) { return signatures[i]; }); + } + return result; + } + function getUnionIndexType(types, kind) { + var indexTypes = []; + for (var i = 0; i < types.length; i++) { + var indexType = getIndexTypeOfType(types[i], kind); + if (!indexType) { + return undefined; + } + indexTypes.push(indexType); + } + return getUnionType(indexTypes); + } + function resolveUnionTypeMembers(type) { + var callSignatures = getUnionSignatures(type.types, 0 /* Call */); + var constructSignatures = getUnionSignatures(type.types, 1 /* Construct */); + var stringIndexType = getUnionIndexType(type.types, 0 /* String */); + var numberIndexType = getUnionIndexType(type.types, 1 /* Number */); + setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); + } function resolveAnonymousTypeMembers(type) { var symbol = type.symbol; if (symbol.flags & 512 /* TypeLiteral */) { @@ -10202,7 +10552,7 @@ var ts; } if (classType.baseTypes.length) { members = createSymbolTable(getNamedMembers(members)); - addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); + addInheritedMembers(members, getPropertiesOfObjectType(getTypeOfSymbol(classType.baseTypes[0].symbol))); } } var stringIndexType = undefined; @@ -10210,70 +10560,166 @@ var ts; } setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } - function resolveObjectTypeMembers(type) { + function resolveObjectOrUnionTypeMembers(type) { if (!type.members) { if (type.flags & (1024 /* Class */ | 2048 /* Interface */)) { resolveClassOrInterfaceMembers(type); } - else if (type.flags & 16384 /* Anonymous */) { + else if (type.flags & 32768 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.flags & 8192 /* Tuple */) { resolveTupleTypeMembers(type); } + else if (type.flags & 16384 /* Union */) { + resolveUnionTypeMembers(type); + } else { resolveTypeReferenceMembers(type); } } return type; } - function getPropertiesOfType(type) { + function getPropertiesOfObjectType(type) { if (type.flags & ts.TypeFlags.ObjectType) { - return resolveObjectTypeMembers(type).properties; + return resolveObjectOrUnionTypeMembers(type).properties; } return emptyArray; } + function getPropertyOfObjectType(type, name) { + if (type.flags & ts.TypeFlags.ObjectType) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (ts.hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; + } + } + } + } + function getPropertiesOfUnionType(type) { + var result = []; + ts.forEach(getPropertiesOfType(type.types[0]), function (prop) { + var unionProp = getPropertyOfUnionType(type, prop.name); + if (unionProp) { + result.push(unionProp); + } + }); + return result; + } + function getPropertiesOfType(type) { + if (type.flags & 16384 /* Union */) { + return getPropertiesOfUnionType(type); + } + return getPropertiesOfObjectType(getApparentType(type)); + } + function getApparentType(type) { + if (type.flags & 512 /* TypeParameter */) { + do { + type = getConstraintOfTypeParameter(type); + } while (type && type.flags & 512 /* TypeParameter */); + if (!type) { + type = emptyObjectType; + } + } + if (type.flags & ts.TypeFlags.StringLike) { + type = globalStringType; + } + else if (type.flags & ts.TypeFlags.NumberLike) { + type = globalNumberType; + } + else if (type.flags & 8 /* Boolean */) { + type = globalBooleanType; + } + return type; + } + function createUnionProperty(unionType, name) { + var types = unionType.types; + var props; + for (var i = 0; i < types.length; i++) { + var type = getApparentType(types[i]); + if (type !== unknownType) { + var prop = getPropertyOfType(type, name); + if (!prop) { + return undefined; + } + if (!props) { + props = [prop]; + } + else { + props.push(prop); + } + } + } + var propTypes = []; + var declarations = []; + for (var i = 0; i < props.length; i++) { + var prop = props[i]; + if (prop.declarations) { + declarations.push.apply(declarations, prop.declarations); + } + propTypes.push(getTypeOfSymbol(prop)); + } + var result = createSymbol(2 /* Property */ | 33554432 /* Transient */ | 134217728 /* UnionProperty */, name); + result.unionType = unionType; + result.declarations = declarations; + result.type = getUnionType(propTypes); + return result; + } + function getPropertyOfUnionType(type, name) { + var properties = type.resolvedProperties || (type.resolvedProperties = {}); + if (ts.hasProperty(properties, name)) { + return properties[name]; + } + var property = createUnionProperty(type, name); + if (property) { + properties[name] = property; + } + return property; + } function getPropertyOfType(type, name) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (ts.hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + if (type.flags & 16384 /* Union */) { + return getPropertyOfUnionType(type, name); + } + if (!(type.flags & ts.TypeFlags.ObjectType)) { + type = getApparentType(type); + if (!(type.flags & ts.TypeFlags.ObjectType)) { + return undefined; } } - } - function getPropertyOfApparentType(type, name) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (ts.hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + var resolved = resolveObjectOrUnionTypeMembers(type); + if (ts.hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; } - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - var symbol = getPropertyOfType(globalFunctionType, name); - if (symbol) - return symbol; - } - return getPropertyOfType(globalObjectType, name); } + if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { + var symbol = getPropertyOfObjectType(globalFunctionType, name); + if (symbol) + return symbol; + } + return getPropertyOfObjectType(globalObjectType, name); } - function getSignaturesOfType(type, kind) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + function getSignaturesOfObjectOrUnionType(type, kind) { + if (type.flags & (ts.TypeFlags.ObjectType | 16384 /* Union */)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === 0 /* Call */ ? resolved.callSignatures : resolved.constructSignatures; } return emptyArray; } - function getIndexTypeOfType(type, kind) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + function getSignaturesOfType(type, kind) { + return getSignaturesOfObjectOrUnionType(getApparentType(type), kind); + } + function getIndexTypeOfObjectOrUnionType(type, kind) { + if (type.flags & (ts.TypeFlags.ObjectType | 16384 /* Union */)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === 0 /* String */ ? resolved.stringIndexType : resolved.numberIndexType; } } + function getIndexTypeOfType(type, kind) { + return getIndexTypeOfObjectOrUnionType(getApparentType(type), kind); + } function getTypeParametersFromDeclaration(typeParameterDeclarations) { var result = []; ts.forEach(typeParameterDeclarations, function (node) { @@ -10334,7 +10780,7 @@ var ts; for (var i = 0, len = symbol.declarations.length; i < len; i++) { var node = symbol.declarations[i]; switch (node.kind) { - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: case 121 /* Constructor */: case 124 /* CallSignature */: @@ -10342,8 +10788,8 @@ var ts; case 126 /* IndexSignature */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: if (i > 0 && node.body) { var previous = symbol.declarations[i - 1]; if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) { @@ -10361,6 +10807,9 @@ var ts; if (signature.target) { var type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper); } + else if (signature.unionSignatures) { + var type = getUnionType(ts.map(signature.unionSignatures, getReturnTypeOfSignature)); + } else { var type = getReturnTypeFromBody(signature.declaration); } @@ -10410,7 +10859,7 @@ var ts; function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 121 /* Constructor */ || signature.declaration.kind === 125 /* ConstructSignature */; - var type = createObjectType(16384 /* Anonymous */ | 32768 /* FromSignature */); + var type = createObjectType(32768 /* Anonymous */ | 65536 /* FromSignature */); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -10561,9 +11010,9 @@ var ts; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; switch (declaration.kind) { - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: return declaration; } } @@ -10615,10 +11064,98 @@ var ts; } return links.resolvedType; } + function addTypeToSortedSet(sortedSet, type) { + if (type.flags & 16384 /* Union */) { + addTypesToSortedSet(sortedSet, type.types); + } + else { + var i = 0; + var id = type.id; + while (i < sortedSet.length && sortedSet[i].id < id) { + i++; + } + if (i === sortedSet.length || sortedSet[i].id !== id) { + sortedSet.splice(i, 0, type); + } + } + } + function addTypesToSortedSet(sortedTypes, types) { + for (var i = 0, len = types.length; i < len; i++) { + addTypeToSortedSet(sortedTypes, types[i]); + } + } + function isSubtypeOfAny(candidate, types) { + for (var i = 0, len = types.length; i < len; i++) { + if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) { + return true; + } + } + return false; + } + function removeSubtypes(types) { + var i = types.length; + while (i > 0) { + i--; + if (isSubtypeOfAny(types[i], types)) { + types.splice(i, 1); + } + } + } + function containsAnyType(types) { + for (var i = 0; i < types.length; i++) { + if (types[i].flags & 1 /* Any */) { + return true; + } + } + return false; + } + function removeAllButLast(types, typeToRemove) { + var i = types.length; + while (i > 0 && types.length > 1) { + i--; + if (types[i] === typeToRemove) { + types.splice(i, 1); + } + } + } + function getUnionType(types, noSubtypeReduction) { + if (types.length === 0) { + return emptyObjectType; + } + var sortedTypes = []; + addTypesToSortedSet(sortedTypes, types); + if (noSubtypeReduction) { + if (containsAnyType(sortedTypes)) { + return anyType; + } + removeAllButLast(sortedTypes, undefinedType); + removeAllButLast(sortedTypes, nullType); + } + else { + removeSubtypes(sortedTypes); + } + if (sortedTypes.length === 1) { + return sortedTypes[0]; + } + var id = getTypeListId(sortedTypes); + var type = unionTypes[id]; + if (!type) { + type = unionTypes[id] = createObjectType(16384 /* Union */); + type.types = sortedTypes; + } + return type; + } + function getTypeFromUnionTypeNode(node) { + var links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getUnionType(ts.map(node.types, getTypeFromTypeNode), true); + } + return links.resolvedType; + } function getTypeFromTypeLiteralNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = createObjectType(16384 /* Anonymous */, node.symbol); + links.resolvedType = createObjectType(32768 /* Anonymous */, node.symbol); } return links.resolvedType; } @@ -10626,7 +11163,7 @@ var ts; if (ts.hasProperty(stringLiteralTypes, node.text)) return stringLiteralTypes[node.text]; var type = stringLiteralTypes[node.text] = createType(256 /* StringLiteral */); - type.text = ts.getSourceTextOfNode(node); + type.text = ts.getTextOfNode(node); return type; } function getTypeFromStringLiteral(node) { @@ -10658,6 +11195,10 @@ var ts; return getTypeFromArrayTypeNode(node); case 131 /* TupleType */: return getTypeFromTupleTypeNode(node); + case 132 /* UnionType */: + return getTypeFromUnionTypeNode(node); + case 133 /* ParenType */: + return getTypeFromTypeNode(node.type); case 129 /* TypeLiteral */: return getTypeFromTypeLiteralNode(node); case 59 /* Identifier */: @@ -10764,7 +11305,7 @@ var ts; symbol = links.target; mapper = combineTypeMappers(links.mapper, mapper); } - var result = createSymbol(8388608 /* Instantiated */ | 33554432 /* Transient */, symbol.name); + var result = createSymbol(8388608 /* Instantiated */ | 33554432 /* Transient */ | symbol.flags, symbol.name); result.declarations = symbol.declarations; result.parent = symbol.parent; result.target = symbol; @@ -10775,8 +11316,8 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - var result = createObjectType(16384 /* Anonymous */, type.symbol); - result.properties = instantiateList(getPropertiesOfType(type), mapper, instantiateSymbol); + var result = createObjectType(32768 /* Anonymous */, type.symbol); + result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0 /* Call */), mapper, instantiateSignature); result.constructSignatures = instantiateList(getSignaturesOfType(type, 1 /* Construct */), mapper, instantiateSignature); @@ -10793,7 +11334,7 @@ var ts; if (type.flags & 512 /* TypeParameter */) { return mapper(type); } - if (type.flags & 16384 /* Anonymous */) { + if (type.flags & 32768 /* Anonymous */) { return type.symbol && type.symbol.flags & (8 /* Function */ | 2048 /* Method */ | 512 /* TypeLiteral */ | 1024 /* ObjectLiteral */) ? instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096 /* Reference */) { @@ -10802,30 +11343,33 @@ var ts; if (type.flags & 8192 /* Tuple */) { return createTupleType(instantiateList(type.elementTypes, mapper, instantiateType)); } + if (type.flags & 16384 /* Union */) { + return getUnionType(instantiateList(type.types, mapper, instantiateType), true); + } } return type; } function isContextSensitiveExpression(node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return !node.typeParameters && !ts.forEach(node.parameters, function (p) { return p.type; }); - case 133 /* ObjectLiteral */: - return ts.forEach(node.properties, function (p) { return p.kind === 134 /* PropertyAssignment */ && isContextSensitiveExpression(p.initializer); }); - case 132 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + return ts.forEach(node.properties, function (p) { return p.kind === 136 /* PropertyAssignment */ && isContextSensitiveExpression(p.initializer); }); + case 134 /* ArrayLiteral */: return ts.forEach(node.elements, function (e) { return isContextSensitiveExpression(e); }); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return isContextSensitiveExpression(node.whenTrue) || isContextSensitiveExpression(node.whenFalse); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return node.operator === 44 /* BarBarToken */ && (isContextSensitiveExpression(node.left) || isContextSensitiveExpression(node.right)); } return false; } function getTypeWithoutConstructors(type) { if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.constructSignatures.length) { - var result = createObjectType(16384 /* Anonymous */, type.symbol); + var result = createObjectType(32768 /* Anonymous */, type.symbol); result.members = resolved.members; result.properties = resolved.properties; result.callSignatures = resolved.callSignatures; @@ -10875,7 +11419,7 @@ var ts; var ok = true; for (var i = 0, len = type.baseTypes.length; i < len; ++i) { var base = type.baseTypes[i]; - var properties = getPropertiesOfType(base); + var properties = getPropertiesOfObjectType(base); for (var j = 0, proplen = properties.length; j < proplen; ++j) { var prop = properties[j]; if (!ts.hasProperty(seen, prop.name)) { @@ -10960,7 +11504,17 @@ var ts; return true; } } - if (source.flags & 512 /* TypeParameter */ && target.flags & 512 /* TypeParameter */) { + if (source.flags & 16384 /* Union */) { + if (unionTypeRelatedToType(source, target, reportErrors)) { + return true; + } + } + else if (target.flags & 16384 /* Union */) { + if (typeRelatedToUnionType(source, target, reportErrors)) { + return true; + } + } + else if (source.flags & 512 /* TypeParameter */ && target.flags & 512 /* TypeParameter */) { if (typeParameterRelatedTo(source, target, reportErrors)) { return true; } @@ -10988,6 +11542,24 @@ var ts; } return false; } + function typeRelatedToUnionType(source, target, reportErrors) { + var targetTypes = target.types; + for (var i = 0, len = targetTypes.length; i < len; i++) { + if (isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1)) { + return true; + } + } + return false; + } + function unionTypeRelatedToType(source, target, reportErrors) { + var sourceTypes = source.types; + for (var i = 0, len = sourceTypes.length; i < len; i++) { + if (!isRelatedTo(sourceTypes[i], target, reportErrors)) { + return false; + } + } + return true; + } function typesRelatedTo(sources, targets, reportErrors) { for (var i = 0, len = sources.length; i < len; i++) { if (!isRelatedTo(sources[i], targets[i], reportErrors)) @@ -11075,35 +11647,15 @@ var ts; } function propertiesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return propertiesAreIdenticalTo(source, target, reportErrors); + return propertiesIdenticalTo(source, target, reportErrors); } - else { - return propertiesAreSubtypeOrAssignableTo(source, target, reportErrors); - } - } - function propertiesAreIdenticalTo(source, target, reportErrors) { - var sourceProperties = getPropertiesOfType(source); - var targetProperties = getPropertiesOfType(target); - if (sourceProperties.length !== targetProperties.length) { - return false; - } - for (var i = 0, len = sourceProperties.length; i < len; ++i) { - var sourceProp = sourceProperties[i]; - var targetProp = getPropertyOfType(target, sourceProp.name); - if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { - return false; - } - } - return true; - } - function propertiesAreSubtypeOrAssignableTo(source, target, reportErrors) { - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfApparentType(source, targetProp.name); + var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { - if (!isOptionalProperty(targetProp)) { + if (relation === subtypeRelation || !isOptionalProperty(targetProp)) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } @@ -11160,67 +11712,25 @@ var ts; } return true; } - function signaturesRelatedTo(source, target, kind, reportErrors) { - if (relation === identityRelation) { - return areSignaturesIdenticalTo(source, target, kind, reportErrors); - } - else { - return areSignaturesSubtypeOrAssignableTo(source, target, kind, reportErrors); - } - } - function areSignaturesIdenticalTo(source, target, kind, reportErrors) { - var sourceSignatures = getSignaturesOfType(source, kind); - var targetSignatures = getSignaturesOfType(target, kind); - if (sourceSignatures.length !== targetSignatures.length) { + function propertiesIdenticalTo(source, target, reportErrors) { + var sourceProperties = getPropertiesOfObjectType(source); + var targetProperties = getPropertiesOfObjectType(target); + if (sourceProperties.length !== targetProperties.length) { return false; } - for (var i = 0, len = sourceSignatures.length; i < len; ++i) { - if (!isSignatureIdenticalTo(sourceSignatures[i], targetSignatures[i], reportErrors)) { + for (var i = 0, len = sourceProperties.length; i < len; ++i) { + var sourceProp = sourceProperties[i]; + var targetProp = getPropertyOfObjectType(target, sourceProp.name); + if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { return false; } } return true; } - function isSignatureIdenticalTo(source, target, reportErrors) { - if (source === target) { - return true; + function signaturesRelatedTo(source, target, kind, reportErrors) { + if (relation === identityRelation) { + return signaturesIdenticalTo(source, target, kind, reportErrors); } - if (source.hasRestParameter !== target.hasRestParameter) { - return false; - } - if (source.parameters.length !== target.parameters.length) { - return false; - } - if (source.minArgumentCount !== target.minArgumentCount) { - return false; - } - if (source.typeParameters && target.typeParameters) { - if (source.typeParameters.length !== target.typeParameters.length) { - return false; - } - for (var i = 0, len = source.typeParameters.length; i < len; ++i) { - if (!isRelatedTo(source.typeParameters[i], target.typeParameters[i], reportErrors)) { - return false; - } - } - } - else if (source.typeParameters || source.typeParameters) { - return false; - } - source = getErasedSignature(source); - target = getErasedSignature(target); - for (var i = 0, len = source.parameters.length; i < len; i++) { - var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); - var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); - if (!isRelatedTo(s, t, reportErrors)) { - return false; - } - } - var t = getReturnTypeOfSignature(target); - var s = getReturnTypeOfSignature(source); - return isRelatedTo(s, t, reportErrors); - } - function areSignaturesSubtypeOrAssignableTo(source, target, kind, reportErrors) { if (target === anyFunctionType || source === anyFunctionType) return true; var sourceSignatures = getSignaturesOfType(source, kind); @@ -11228,12 +11738,12 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var i = 0; i < targetSignatures.length; i++) { var t = targetSignatures[i]; - if (!t.hasStringLiterals || target.flags & 32768 /* FromSignature */) { + if (!t.hasStringLiterals || target.flags & 65536 /* FromSignature */) { var localErrors = reportErrors; for (var j = 0; j < sourceSignatures.length; j++) { var s = sourceSignatures[j]; - if (!s.hasStringLiterals || source.flags & 32768 /* FromSignature */) { - if (isSignatureSubtypeOrAssignableTo(s, t, localErrors)) { + if (!s.hasStringLiterals || source.flags & 65536 /* FromSignature */) { + if (signatureRelatedTo(s, t, localErrors)) { errorInfo = saveErrorInfo; continue outer; } @@ -11245,7 +11755,7 @@ var ts; } return true; } - function isSignatureSubtypeOrAssignableTo(source, target, reportErrors) { + function signatureRelatedTo(source, target, reportErrors) { if (source === target) { return true; } @@ -11293,67 +11803,107 @@ var ts; var s = getReturnTypeOfSignature(source); return isRelatedTo(s, t, reportErrors); } + function signaturesIdenticalTo(source, target, kind, reportErrors) { + var sourceSignatures = getSignaturesOfType(source, kind); + var targetSignatures = getSignaturesOfType(target, kind); + if (sourceSignatures.length !== targetSignatures.length) { + return false; + } + for (var i = 0, len = sourceSignatures.length; i < len; ++i) { + if (!compareSignatures(sourceSignatures[i], targetSignatures[i], true, isRelatedTo)) { + return false; + } + } + return true; + } function stringIndexTypesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(0 /* String */, source, target, reportErrors); + return indexTypesIdenticalTo(0 /* String */, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, 0 /* String */); - if (targetType) { - var sourceType = getIndexTypeOfType(source, 0 /* String */); - if (!sourceType) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return false; - } - if (!isRelatedTo(sourceType, targetType, reportErrors)) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, 0 /* String */); + if (targetType) { + var sourceType = getIndexTypeOfType(source, 0 /* String */); + if (!sourceType) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return false; + } + if (!isRelatedTo(sourceType, targetType, reportErrors)) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } function numberIndexTypesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(1 /* Number */, source, target, reportErrors); + return indexTypesIdenticalTo(1 /* Number */, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, 1 /* Number */); - if (targetType) { - var sourceStringType = getIndexTypeOfType(source, 0 /* String */); - var sourceNumberType = getIndexTypeOfType(source, 1 /* Number */); - if (!(sourceStringType || sourceNumberType)) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return false; - } - if (sourceStringType && sourceNumberType) { - var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); - } - else { - var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); - } - if (!compatible) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, 1 /* Number */); + if (targetType) { + var sourceStringType = getIndexTypeOfType(source, 0 /* String */); + var sourceNumberType = getIndexTypeOfType(source, 1 /* Number */); + if (!(sourceStringType || sourceNumberType)) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return false; + } + if (sourceStringType && sourceNumberType) { + var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); + } + else { + var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); + } + if (!compatible) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } - function areIndexTypesIdenticalTo(indexKind, source, target, reportErrors) { + function indexTypesIdenticalTo(indexKind, source, target, reportErrors) { var targetType = getIndexTypeOfType(target, indexKind); var sourceType = getIndexTypeOfType(source, indexKind); return (!sourceType && !targetType) || (sourceType && targetType && isRelatedTo(sourceType, targetType, reportErrors)); } } + function compareSignatures(source, target, compareReturnTypes, compareTypes) { + if (source === target) { + return true; + } + if (source.parameters.length !== target.parameters.length || source.minArgumentCount !== target.minArgumentCount || source.hasRestParameter !== target.hasRestParameter) { + return false; + } + if (source.typeParameters && target.typeParameters) { + if (source.typeParameters.length !== target.typeParameters.length) { + return false; + } + for (var i = 0, len = source.typeParameters.length; i < len; ++i) { + if (!compareTypes(source.typeParameters[i], target.typeParameters[i])) { + return false; + } + } + } + else if (source.typeParameters || source.typeParameters) { + return false; + } + source = getErasedSignature(source); + target = getErasedSignature(target); + for (var i = 0, len = source.parameters.length; i < len; i++) { + var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); + var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); + if (!compareTypes(s, t)) { + return false; + } + } + return !compareReturnTypes || compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + } function isSupertypeOfEach(candidate, types) { for (var i = 0, len = types.length; i < len; i++) { if (candidate !== types[i] && !isTypeSubtypeOf(types[i], candidate)) @@ -11361,13 +11911,11 @@ var ts; } return true; } - function getBestCommonType(types, contextualType, candidatesOnly) { - if (contextualType && isSupertypeOfEach(contextualType, types)) - return contextualType; - return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; }) || (candidatesOnly ? undefined : emptyObjectType); + function getCommonSupertype(types) { + return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; }); } function isTypeOfObjectLiteral(type) { - return (type.flags & 16384 /* Anonymous */) && type.symbol && (type.symbol.flags & 1024 /* ObjectLiteral */) ? true : false; + return (type.flags & 32768 /* Anonymous */) && type.symbol && (type.symbol.flags & 1024 /* ObjectLiteral */) ? true : false; } function isArrayType(type) { return type.flags & 4096 /* Reference */ && type.target === globalArrayType; @@ -11378,10 +11926,13 @@ var ts; } return type; } - function getWidenedType(type, supressNoImplicitAnyErrors) { + function getWidenedType(type, suppressNoImplicitAnyErrors) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } + if (type.flags & 16384 /* Union */) { + return getWidenedTypeOfUnion(type); + } if (isTypeOfObjectLiteral(type)) { return getWidenedTypeOfObjectLiteral(type); } @@ -11389,8 +11940,11 @@ var ts; return getWidenedTypeOfArrayLiteral(type); } return type; + function getWidenedTypeOfUnion(type) { + return getUnionType(ts.map(type.types, function (t) { return getWidenedType(t, suppressNoImplicitAnyErrors); })); + } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfType(type); + var properties = getPropertiesOfObjectType(type); if (properties.length) { var widenedTypes = []; var propTypeWasWidened = false; @@ -11399,7 +11953,7 @@ var ts; var widenedType = getWidenedType(propType); if (propType !== widenedType) { propTypeWasWidened = true; - if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (!suppressNoImplicitAnyErrors && compilerOptions.noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); } } @@ -11409,7 +11963,7 @@ var ts; var members = {}; var index = 0; ts.forEach(properties, function (p) { - var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, p.name); + var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */ | p.flags, p.name); symbol.declarations = p.declarations; symbol.parent = p.parent; symbol.type = widenedTypes[index++]; @@ -11431,7 +11985,7 @@ var ts; } function getWidenedTypeOfArrayLiteral(type) { var elementType = type.typeArguments[0]; - var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors); + var widenedType = getWidenedType(elementType, suppressNoImplicitAnyErrors); type = elementType !== widenedType ? createArrayType(widenedType) : type; return type; } @@ -11462,12 +12016,14 @@ var ts; callback(s, t); } } - function createInferenceContext(typeParameters) { + function createInferenceContext(typeParameters, inferUnionTypes) { var inferences = []; for (var i = 0; i < typeParameters.length; i++) inferences.push([]); return { typeParameters: typeParameters, + inferUnionTypes: inferUnionTypes, + inferenceCount: 0, inferences: inferences, inferredTypes: new Array(typeParameters.length) }; @@ -11502,6 +12058,7 @@ var ts; var typeParameters = context.typeParameters; for (var i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { + context.inferenceCount++; var inferences = context.inferences[i]; if (!ts.contains(inferences, source)) inferences.push(source); @@ -11516,7 +12073,32 @@ var ts; inferFromTypes(sourceTypes[i], targetTypes[i]); } } - else if (source.flags & ts.TypeFlags.ObjectType && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || (target.flags & 16384 /* Anonymous */) && target.symbol && target.symbol.flags & (2048 /* Method */ | 512 /* TypeLiteral */))) { + else if (target.flags & 16384 /* Union */) { + var targetTypes = target.types; + var startCount = context.inferenceCount; + var typeParameterCount = 0; + var typeParameter; + for (var i = 0; i < targetTypes.length; i++) { + var t = targetTypes[i]; + if (t.flags & 512 /* TypeParameter */ && ts.contains(context.typeParameters, t)) { + typeParameter = t; + typeParameterCount++; + } + else { + inferFromTypes(source, t); + } + } + if (context.inferenceCount === startCount && typeParameterCount === 1) { + inferFromTypes(source, typeParameter); + } + } + else if (source.flags & 16384 /* Union */) { + var sourceTypes = source.types; + for (var i = 0; i < sourceTypes.length; i++) { + inferFromTypes(sourceTypes[i], target); + } + } + else if (source.flags & ts.TypeFlags.ObjectType && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || (target.flags & 32768 /* Anonymous */) && target.symbol && target.symbol.flags & (2048 /* Method */ | 512 /* TypeLiteral */))) { if (!isInProcess(source, target) && isWithinDepthLimit(source, sourceStack) && isWithinDepthLimit(target, targetStack)) { if (depth === 0) { sourceStack = []; @@ -11536,10 +12118,10 @@ var ts; } } function inferFromProperties(source, target) { - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfType(source, targetProp.name); + var sourceProp = getPropertyOfObjectType(source, targetProp.name); if (sourceProp) { inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } @@ -11572,9 +12154,16 @@ var ts; function getInferredType(context, index) { var result = context.inferredTypes[index]; if (!result) { - var commonType = getWidenedType(getBestCommonType(context.inferences[index])); + var inferences = context.inferences[index]; + if (inferences.length) { + var unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences); + var inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : undefinedType; + } + else { + inferredType = emptyObjectType; + } var constraint = getConstraintOfTypeParameter(context.typeParameters[index]); - var result = constraint && !isTypeAssignableTo(commonType, constraint) ? constraint : commonType; + var result = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType; context.inferredTypes[index] = result; } return result; @@ -11589,37 +12178,244 @@ var ts; function hasAncestor(node, kind) { return ts.getAncestor(node, kind) !== undefined; } - function checkIdentifier(node) { - function isInTypeQuery(node) { - while (node) { - switch (node.kind) { - case 128 /* TypeQuery */: - return true; - case 59 /* Identifier */: - case 116 /* QualifiedName */: - node = node.parent; - continue; - default: - return false; + function getResolvedSymbol(node) { + var links = getNodeLinks(node); + if (!links.resolvedSymbol) { + links.resolvedSymbol = resolveName(node, node.text, ts.SymbolFlags.Value | 524288 /* ExportValue */, ts.Diagnostics.Cannot_find_name_0, ts.identifierToString(node)) || unknownSymbol; + } + return links.resolvedSymbol; + } + function isInTypeQuery(node) { + while (node) { + switch (node.kind) { + case 128 /* TypeQuery */: + return true; + case 59 /* Identifier */: + case 116 /* QualifiedName */: + node = node.parent; + continue; + default: + return false; + } + } + ts.Debug.fail("should not get here"); + } + function subtractPrimitiveTypes(type, subtractMask) { + if (type.flags & 16384 /* Union */) { + var types = type.types; + if (ts.forEach(types, function (t) { return t.flags & subtractMask; })) { + return getUnionType(ts.filter(types, function (t) { return !(t.flags & subtractMask); })); + } + } + return type; + } + function isVariableAssignedWithin(symbol, node) { + var links = getNodeLinks(node); + if (links.assignmentChecks) { + var cachedResult = links.assignmentChecks[symbol.id]; + if (cachedResult !== undefined) { + return cachedResult; + } + } + else { + links.assignmentChecks = {}; + } + return links.assignmentChecks[symbol.id] = isAssignedIn(node); + function isAssignedInBinaryExpression(node) { + if (node.operator >= ts.SyntaxKind.FirstAssignment && node.operator <= ts.SyntaxKind.LastAssignment) { + var n = node.left; + while (n.kind === 142 /* ParenExpression */) { + n = n.expression; + } + if (n.kind === 59 /* Identifier */ && getResolvedSymbol(n) === symbol) { + return true; } } - ts.Debug.fail("should not get here"); + return ts.forEachChild(node, isAssignedIn); } - var symbol = resolveName(node, node.text, ts.SymbolFlags.Value | 524288 /* ExportValue */, ts.Diagnostics.Cannot_find_name_0, ts.identifierToString(node)); - if (!symbol) { - symbol = unknownSymbol; + function isAssignedInVariableDeclaration(node) { + if (getSymbolOfNode(node) === symbol && node.initializer) { + return true; + } + return ts.forEachChild(node, isAssignedIn); } + function isAssignedIn(node) { + switch (node.kind) { + case 147 /* BinaryExpression */: + return isAssignedInBinaryExpression(node); + case 173 /* VariableDeclaration */: + return isAssignedInVariableDeclaration(node); + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 148 /* ConditionalExpression */: + case 150 /* Block */: + case 151 /* VariableStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 161 /* ReturnStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 167 /* ThrowStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + return ts.forEachChild(node, isAssignedIn); + } + return false; + } + } + function getNarrowedTypeOfSymbol(symbol, node) { + var type = getTypeOfSymbol(symbol); + if (symbol.flags & 1 /* Variable */ && type.flags & ts.TypeFlags.Structured) { + while (true) { + var child = node; + node = node.parent; + if (!node || node.kind === 175 /* FunctionBlock */ || node.kind === 180 /* ModuleBlock */) { + break; + } + var narrowedType = type; + switch (node.kind) { + case 154 /* IfStatement */: + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); + } + break; + case 148 /* ConditionalExpression */: + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); + } + break; + case 147 /* BinaryExpression */: + if (child === node.right) { + if (node.operator === 43 /* AmpersandAmpersandToken */) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operator === 44 /* BarBarToken */) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + } + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; + } + } + } + return type; + function narrowTypeByEquality(type, expr, assumeTrue) { + var left = expr.left; + var right = expr.right; + if (left.kind !== 145 /* PrefixOperator */ || left.operator !== 91 /* TypeOfKeyword */ || left.operand.kind !== 59 /* Identifier */ || right.kind !== 7 /* StringLiteral */ || getResolvedSymbol(left.operand) !== symbol) { + return type; + } + var t = right.text; + var checkType = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType; + if (expr.operator === 26 /* ExclamationEqualsEqualsToken */) { + assumeTrue = !assumeTrue; + } + if (assumeTrue) { + return checkType === emptyObjectType ? subtractPrimitiveTypes(type, 2 /* String */ | 4 /* Number */ | 8 /* Boolean */) : checkType; + } + else { + return checkType === emptyObjectType ? type : subtractPrimitiveTypes(type, checkType.flags); + } + } + function narrowTypeByAnd(type, expr, assumeTrue) { + if (assumeTrue) { + return narrowType(narrowType(type, expr.left, true), expr.right, true); + } + else { + return getUnionType([ + narrowType(type, expr.left, false), + narrowType(narrowType(type, expr.left, true), expr.right, false) + ]); + } + } + function narrowTypeByOr(type, expr, assumeTrue) { + if (assumeTrue) { + return getUnionType([ + narrowType(type, expr.left, true), + narrowType(narrowType(type, expr.left, false), expr.right, true) + ]); + } + else { + return narrowType(narrowType(type, expr.left, false), expr.right, false); + } + } + function narrowTypeByInstanceof(type, expr, assumeTrue) { + if (!assumeTrue || expr.left.kind !== 59 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + return type; + } + var rightType = checkExpression(expr.right); + if (!isTypeSubtypeOf(rightType, globalFunctionType)) { + return type; + } + var prototypeProperty = getPropertyOfType(rightType, "prototype"); + if (!prototypeProperty) { + return type; + } + var prototypeType = getTypeOfSymbol(prototypeProperty); + return isTypeSubtypeOf(prototypeType, type) ? prototypeType : type; + } + function narrowType(type, expr, assumeTrue) { + switch (expr.kind) { + case 142 /* ParenExpression */: + return narrowType(type, expr.expression, assumeTrue); + case 147 /* BinaryExpression */: + var operator = expr.operator; + if (operator === 25 /* EqualsEqualsEqualsToken */ || operator === 26 /* ExclamationEqualsEqualsToken */) { + return narrowTypeByEquality(type, expr, assumeTrue); + } + else if (operator === 43 /* AmpersandAmpersandToken */) { + return narrowTypeByAnd(type, expr, assumeTrue); + } + else if (operator === 44 /* BarBarToken */) { + return narrowTypeByOr(type, expr, assumeTrue); + } + else if (operator === 81 /* InstanceOfKeyword */) { + return narrowTypeByInstanceof(type, expr, assumeTrue); + } + break; + case 145 /* PrefixOperator */: + if (expr.operator === 41 /* ExclamationToken */) { + return narrowType(type, expr.operand, !assumeTrue); + } + break; + } + return type; + } + } + function checkIdentifier(node) { + var symbol = getResolvedSymbol(node); if (symbol.flags & 4194304 /* Import */) { getSymbolLinks(symbol).referenced = !isInTypeQuery(node); } - getNodeLinks(node).resolvedSymbol = symbol; checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); checkCollisionWithIndexVariableInGeneratedCode(node, node); - return getTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol)); + return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } function captureLexicalThis(node, container) { - var classNode = container.parent && container.parent.kind === 174 /* ClassDeclaration */ ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 176 /* ClassDeclaration */ ? container.parent : undefined; getNodeLinks(node).flags |= 2 /* LexicalThis */; if (container.kind === 119 /* Property */ || container.kind === 121 /* Constructor */) { getNodeLinks(classNode).flags |= 4 /* CaptureThis */; @@ -11631,15 +12427,15 @@ var ts; function checkThisExpression(node) { var container = ts.getThisContainer(node, true); var needToCaptureLexicalThis = false; - if (container.kind === 142 /* ArrowFunction */) { + if (container.kind === 144 /* ArrowFunction */) { container = ts.getThisContainer(container, false); needToCaptureLexicalThis = true; } switch (container.kind) { - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_body); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location); break; case 121 /* Constructor */: @@ -11656,7 +12452,7 @@ var ts; if (needToCaptureLexicalThis) { captureLexicalThis(node, container); } - var classNode = container.parent && container.parent.kind === 174 /* ClassDeclaration */ ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 176 /* ClassDeclaration */ ? container.parent : undefined; if (classNode) { var symbol = getSymbolOfNode(classNode); return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); @@ -11669,9 +12465,9 @@ var ts; if (!node) return node; switch (node.kind) { - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: case 119 /* Property */: case 120 /* Method */: case 121 /* Constructor */: @@ -11690,8 +12486,8 @@ var ts; return false; } function checkSuperExpression(node) { - var isCallExpression = node.parent.kind === 137 /* CallExpression */ && node.parent.func === node; - var enclosingClass = ts.getAncestor(node, 174 /* ClassDeclaration */); + var isCallExpression = node.parent.kind === 139 /* CallExpression */ && node.parent.func === node; + var enclosingClass = ts.getAncestor(node, 176 /* ClassDeclaration */); var baseClass; if (enclosingClass && enclosingClass.baseType) { var classType = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass)); @@ -11709,11 +12505,11 @@ var ts; } else { var needToCaptureLexicalThis = false; - while (container && container.kind === 142 /* ArrowFunction */) { + while (container && container.kind === 144 /* ArrowFunction */) { container = getSuperContainer(container); needToCaptureLexicalThis = true; } - if (container && container.parent && container.parent.kind === 174 /* ClassDeclaration */) { + if (container && container.parent && container.parent.kind === 176 /* ClassDeclaration */) { if (container.flags & 128 /* Static */) { canUseSuperExpression = container.kind === 120 /* Method */ || container.kind === 122 /* GetAccessor */ || container.kind === 123 /* SetAccessor */; } @@ -11752,11 +12548,19 @@ var ts; } function getContextuallyTypedParameterType(parameter) { var func = parameter.parent; - if (func.kind === 141 /* FunctionExpression */ || func.kind === 142 /* ArrowFunction */) { + if (func.kind === 143 /* FunctionExpression */ || func.kind === 144 /* ArrowFunction */) { if (isContextSensitiveExpression(func)) { - var signature = getContextualSignature(func); - if (signature) { - return getTypeAtPosition(signature, ts.indexOf(func.parameters, parameter)); + var contextualSignature = getContextualSignature(func); + if (contextualSignature) { + var funcHasRestParameters = ts.hasRestParameters(func); + var len = func.parameters.length - (funcHasRestParameters ? 1 : 0); + var indexOfParameter = ts.indexOf(func.parameters, parameter); + if (indexOfParameter < len) { + return getTypeAtPosition(contextualSignature, indexOfParameter); + } + if (indexOfParameter === (func.parameters.length - 1) && funcHasRestParameters && contextualSignature.hasRestParameter && func.parameters.length >= contextualSignature.parameters.length) { + return getTypeOfSymbol(contextualSignature.parameters[contextualSignature.parameters.length - 1]); + } } } } @@ -11813,17 +12617,51 @@ var ts; } return undefined; } + function applyToContextualType(type, mapper) { + if (!(type.flags & 16384 /* Union */)) { + return mapper(type); + } + var types = type.types; + var mappedType; + var mappedTypes; + for (var i = 0; i < types.length; i++) { + var t = mapper(types[i]); + if (t) { + if (!mappedType) { + mappedType = t; + } + else if (!mappedTypes) { + mappedTypes = [mappedType, t]; + } + else { + mappedTypes.push(t); + } + } + } + return mappedTypes ? getUnionType(mappedTypes) : mappedType; + } + function getTypeOfPropertyOfContextualType(type, name) { + return applyToContextualType(type, function (t) { + var prop = getPropertyOfObjectType(t, name); + return prop ? getTypeOfSymbol(prop) : undefined; + }); + } + function getIndexTypeOfContextualType(type, kind) { + return applyToContextualType(type, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }); + } + function contextualTypeIsTupleType(type) { + return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return getPropertyOfObjectType(t, "0"); }) : getPropertyOfObjectType(type, "0")); + } + function contextualTypeHasIndexSignature(type, kind) { + return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }) : getIndexTypeOfObjectOrUnionType(type, kind)); + } function getContextualTypeForPropertyExpression(node) { var declaration = node.parent; var objectLiteral = declaration.parent; var type = getContextualType(objectLiteral); var name = declaration.name.text; if (type && name) { - var prop = getPropertyOfType(type, name); - if (prop) { - return getTypeOfSymbol(prop); - } - return isNumericName(name) && getIndexTypeOfType(type, 1 /* Number */) || getIndexTypeOfType(type, 0 /* String */); + return getTypeOfPropertyOfContextualType(type, name) || isNumericName(name) && getIndexTypeOfContextualType(type, 1 /* Number */) || getIndexTypeOfContextualType(type, 0 /* String */); } return undefined; } @@ -11832,11 +12670,7 @@ var ts; var type = getContextualType(arrayLiteral); if (type) { var index = ts.indexOf(arrayLiteral.elements, node); - var prop = getPropertyOfType(type, "" + index); - if (prop) { - return getTypeOfSymbol(prop); - } - return getIndexTypeOfType(type, 1 /* Number */); + return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1 /* Number */); } return undefined; } @@ -11853,70 +12687,78 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 118 /* Parameter */: case 119 /* Property */: return getContextualTypeForInitializerExpression(node); - case 142 /* ArrowFunction */: - case 159 /* ReturnStatement */: + case 144 /* ArrowFunction */: + case 161 /* ReturnStatement */: return getContextualTypeForReturnExpression(node); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return getContextualTypeForArgument(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return getTypeFromTypeNode(parent.type); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return getContextualTypeForBinaryOperand(node); - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return getContextualTypeForPropertyExpression(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return getContextualTypeForElementExpression(node); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return getContextualTypeForConditionalOperand(node); } return undefined; } + function getNonGenericSignature(type) { + var signatures = getSignaturesOfObjectOrUnionType(type, 0 /* Call */); + if (signatures.length === 1) { + var signature = signatures[0]; + if (!signature.typeParameters) { + return signature; + } + } + } function getContextualSignature(node) { var type = getContextualType(node); - if (type) { - var signatures = getSignaturesOfType(type, 0 /* Call */); - if (signatures.length === 1) { - var signature = signatures[0]; - if (!signature.typeParameters) { - return signature; + if (!type) { + return undefined; + } + if (!(type.flags & 16384 /* Union */)) { + return getNonGenericSignature(type); + } + var result; + var types = type.types; + for (var i = 0; i < types.length; i++) { + var signature = getNonGenericSignature(types[i]); + if (signature) { + if (!result) { + result = signature; + } + else if (!compareSignatures(result, signature, true, isTypeIdenticalTo)) { + return undefined; } } } - return undefined; + return result; } function isInferentialContext(mapper) { return mapper && mapper !== identityMapper; } function checkArrayLiteral(node, contextualMapper) { - var contextualType = getContextualType(node); var elements = node.elements; - var elementTypes = []; - var isTupleLiteral = false; - for (var i = 0; i < elements.length; i++) { - if (contextualType && getPropertyOfType(contextualType, "" + i)) { - isTupleLiteral = true; - } - var element = elements[i]; - var type = element.kind !== 147 /* OmittedExpression */ ? checkExpression(element, contextualMapper) : undefinedType; - elementTypes.push(type); + if (!elements.length) { + return createArrayType(undefinedType); } - if (isTupleLiteral) { + var elementTypes = ts.map(elements, function (e) { return checkExpression(e, contextualMapper); }); + var contextualType = getContextualType(node); + if (contextualType && contextualTypeIsTupleType(contextualType)) { return createTupleType(elementTypes); } - var contextualElementType = contextualType && !isInferentialContext(contextualMapper) ? getIndexTypeOfType(contextualType, 1 /* Number */) : undefined; - var elementType = getBestCommonType(ts.uniqueElements(elementTypes), contextualElementType, true); - if (!elementType) { - elementType = elements.length ? emptyObjectType : undefinedType; - } - return createArrayType(elementType); + return createArrayType(getUnionType(elementTypes)); } function isNumericName(name) { - return !isNaN(name); + return (+name).toString() === name; } function checkObjectLiteral(node, contextualMapper) { var members = node.symbol.members; @@ -11927,7 +12769,7 @@ var ts; var member = members[id]; if (member.flags & 2 /* Property */) { var type = checkExpression(member.declarations[0].initializer, contextualMapper); - var prop = createSymbol(2 /* Property */ | 33554432 /* Transient */, member.name); + var prop = createSymbol(2 /* Property */ | 33554432 /* Transient */ | member.flags, member.name); prop.declarations = member.declarations; prop.parent = member.parent; if (member.valueDeclaration) @@ -11953,22 +12795,21 @@ var ts; var numberIndexType = getIndexType(1 /* Number */); return createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); function getIndexType(kind) { - if (contextualType) { - var indexType = getIndexTypeOfType(contextualType, kind); - if (indexType) { - var propTypes = []; - for (var id in properties) { - if (ts.hasProperty(properties, id)) { - if (kind === 0 /* String */ || isNumericName(id)) { - var type = getTypeOfSymbol(properties[id]); - if (!ts.contains(propTypes, type)) - propTypes.push(type); + if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { + var propTypes = []; + for (var id in properties) { + if (ts.hasProperty(properties, id)) { + if (kind === 0 /* String */ || isNumericName(id)) { + var type = getTypeOfSymbol(properties[id]); + if (!ts.contains(propTypes, type)) { + propTypes.push(type); } } } - return getBestCommonType(propTypes, isInferentialContext(contextualMapper) ? undefined : indexType); } + return propTypes.length ? getUnionType(propTypes) : undefinedType; } + return undefined; } } function getDeclarationKindFromSymbol(s) { @@ -11982,7 +12823,7 @@ var ts; if (!(flags & (32 /* Private */ | 64 /* Protected */))) { return; } - var enclosingClassDeclaration = ts.getAncestor(node, 174 /* ClassDeclaration */); + var enclosingClassDeclaration = ts.getAncestor(node, 176 /* ClassDeclaration */); var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; var declaringClass = getDeclaredTypeOfSymbol(prop.parent); if (flags & 32 /* Private */) { @@ -12014,7 +12855,7 @@ var ts; if (apparentType === unknownType) { return unknownType; } - var prop = getPropertyOfApparentType(apparentType, node.right.text); + var prop = getPropertyOfType(apparentType, node.right.text); if (!prop) { if (node.right.text) { error(node.right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.identifierToString(node.right), typeToString(type)); @@ -12034,30 +12875,43 @@ var ts; } return anyType; } + function isValidPropertyAccess(node, propertyName) { + var type = checkExpression(node.left); + if (type !== unknownType && type !== anyType) { + var prop = getPropertyOfType(getWidenedType(type), propertyName); + if (prop && prop.parent && prop.parent.flags & 16 /* Class */) { + if (node.left.kind === 85 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 120 /* Method */) { + return false; + } + else { + var diagnosticsCount = diagnostics.length; + checkClassPropertyAccess(node, type, prop); + return diagnostics.length === diagnosticsCount; + } + } + } + return true; + } function checkIndexedAccess(node) { - var objectType = checkExpression(node.object); + var objectType = getApparentType(checkExpression(node.object)); var indexType = checkExpression(node.index); if (objectType === unknownType) return unknownType; - var apparentType = getApparentType(objectType); - if (apparentType === unknownType) { - return unknownType; - } if (node.index.kind === 7 /* StringLiteral */ || node.index.kind === 6 /* NumericLiteral */) { var name = node.index.text; - var prop = getPropertyOfApparentType(apparentType, name); + var prop = getPropertyOfType(objectType, name); if (prop) { return getTypeOfSymbol(prop); } } if (indexType.flags & (1 /* Any */ | ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike)) { if (indexType.flags & (1 /* Any */ | ts.TypeFlags.NumberLike)) { - var numberIndexType = getIndexTypeOfType(apparentType, 1 /* Number */); + var numberIndexType = getIndexTypeOfType(objectType, 1 /* Number */); if (numberIndexType) { return numberIndexType; } } - var stringIndexType = getIndexTypeOfType(apparentType, 0 /* String */); + var stringIndexType = getIndexTypeOfType(objectType, 0 /* String */); if (stringIndexType) { return stringIndexType; } @@ -12079,46 +12933,24 @@ var ts; resolveUntypedCall(node); return unknownSignature; } - function isCandidateSignature(node, signature) { - var args = node.arguments || emptyArray; - return args.length >= signature.minArgumentCount && (signature.hasRestParameter || args.length <= signature.parameters.length) && (!node.typeArguments || signature.typeParameters && node.typeArguments.length === signature.typeParameters.length); - } - function collectCandidates(node, signatures) { - var result = []; - var lastParent; - var lastSymbol; - var cutoffPos = 0; - var pos; - for (var i = 0; i < signatures.length; i++) { - var signature = signatures[i]; - if (isCandidateSignature(node, signature)) { - var symbol = signature.declaration && getSymbolOfNode(signature.declaration); - var parent = signature.declaration && signature.declaration.parent; - if (!lastSymbol || symbol === lastSymbol) { - if (lastParent && parent === lastParent) { - pos++; - } - else { - lastParent = parent; - pos = cutoffPos; - } - } - else { - pos = cutoffPos = result.length; - lastParent = parent; - } - lastSymbol = symbol; - for (var j = result.length; j > pos; j--) { - result[j] = result[j - 1]; - } - result[pos] = signature; - } + function signatureHasCorrectArity(node, signature) { + if (!node.arguments) { + return signature.minArgumentCount === 0; } - return result; + var args = node.arguments; + var numberOfArgs = args.hasTrailingComma ? args.length + 1 : args.length; + var hasTooManyArguments = !signature.hasRestParameter && numberOfArgs > signature.parameters.length; + var hasRightNumberOfTypeArguments = !node.typeArguments || (signature.typeParameters && node.typeArguments.length === signature.typeParameters.length); + if (hasTooManyArguments || !hasRightNumberOfTypeArguments) { + return false; + } + var callIsIncomplete = args.end === node.end; + var hasEnoughArguments = numberOfArgs >= signature.minArgumentCount; + return callIsIncomplete || hasEnoughArguments; } function getSingleCallSignature(type) { if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 && resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) { return resolved.callSignatures[0]; } @@ -12126,7 +12958,7 @@ var ts; return undefined; } function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper) { - var context = createInferenceContext(signature.typeParameters); + var context = createInferenceContext(signature.typeParameters, true); forEachMatchingParameterType(contextualSignature, signature, function (source, target) { inferTypes(context, instantiateType(source, contextualMapper), target); }); @@ -12134,9 +12966,12 @@ var ts; } function inferTypeArguments(signature, args, excludeArgument) { var typeParameters = signature.typeParameters; - var context = createInferenceContext(typeParameters); + var context = createInferenceContext(typeParameters, false); var mapper = createInferenceMapper(context); for (var i = 0; i < args.length; i++) { + if (args[i].kind === 149 /* OmittedExpression */) { + continue; + } if (!excludeArgument || excludeArgument[i] === undefined) { var parameterType = getTypeAtPosition(signature, i); inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); @@ -12144,13 +12979,17 @@ var ts; } if (excludeArgument) { for (var i = 0; i < args.length; i++) { + if (args[i].kind === 149 /* OmittedExpression */) { + continue; + } if (excludeArgument[i] === false) { var parameterType = getTypeAtPosition(signature, i); inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); } } } - return getInferredTypes(context); + var inferredTypes = getInferredTypes(context); + return ts.contains(inferredTypes, undefinedType) ? undefined : inferredTypes; } function checkTypeArguments(signature, typeArguments) { var typeParameters = signature.typeParameters; @@ -12170,6 +13009,9 @@ var ts; if (node.arguments) { for (var i = 0; i < node.arguments.length; i++) { var arg = node.arguments[i]; + if (arg.kind === 149 /* OmittedExpression */) { + continue; + } var paramType = getTypeAtPosition(signature, i); var argType = arg.kind === 7 /* StringLiteral */ && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); var isValidArgument = checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1); @@ -12180,9 +13022,10 @@ var ts; } return true; } - function resolveCall(node, signatures) { + function resolveCall(node, signatures, candidatesOutArray) { ts.forEach(node.typeArguments, checkSourceElement); - var candidates = collectCandidates(node, signatures); + var candidates = candidatesOutArray || []; + collectCandidates(); if (!candidates.length) { error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); return resolveErrorCall(node); @@ -12197,14 +13040,22 @@ var ts; } } var relation = candidates.length === 1 ? assignableRelation : subtypeRelation; + var lastCandidate; while (true) { for (var i = 0; i < candidates.length; i++) { + if (!signatureHasCorrectArity(node, candidates[i])) { + continue; + } while (true) { var candidate = candidates[i]; if (candidate.typeParameters) { var typeArguments = node.typeArguments ? checkTypeArguments(candidate, node.typeArguments) : inferTypeArguments(candidate, args, excludeArgument); + if (!typeArguments) { + break; + } candidate = getSignatureInstantiation(candidate, typeArguments); } + lastCandidate = candidate; if (!checkApplicableSignature(node, candidate, relation, excludeArgument, false)) { break; } @@ -12220,28 +13071,70 @@ var ts; } relation = assignableRelation; } - checkApplicableSignature(node, candidate, relation, undefined, true); + if (lastCandidate) { + checkApplicableSignature(node, lastCandidate, relation, undefined, true); + } + else { + error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + } + if (!fullTypeCheck) { + for (var i = 0, n = candidates.length; i < n; i++) { + if (signatureHasCorrectArity(node, candidates[i])) { + return candidates[i]; + } + } + } return resolveErrorCall(node); + function collectCandidates() { + var result = candidates; + var lastParent; + var lastSymbol; + var cutoffPos = 0; + var pos; + ts.Debug.assert(!result.length); + for (var i = 0; i < signatures.length; i++) { + var signature = signatures[i]; + if (true) { + var symbol = signature.declaration && getSymbolOfNode(signature.declaration); + var parent = signature.declaration && signature.declaration.parent; + if (!lastSymbol || symbol === lastSymbol) { + if (lastParent && parent === lastParent) { + pos++; + } + else { + lastParent = parent; + pos = cutoffPos; + } + } + else { + pos = cutoffPos = result.length; + lastParent = parent; + } + lastSymbol = symbol; + for (var j = result.length; j > pos; j--) { + result[j] = result[j - 1]; + } + result[pos] = signature; + } + } + } } - function resolveCallExpression(node) { + function resolveCallExpression(node, candidatesOutArray) { if (node.func.kind === 85 /* SuperKeyword */) { var superType = checkSuperExpression(node.func); if (superType !== unknownType) { - return resolveCall(node, getSignaturesOfType(superType, 1 /* Construct */)); + return resolveCall(node, getSignaturesOfType(superType, 1 /* Construct */), candidatesOutArray); } return resolveUntypedCall(node); } var funcType = checkExpression(node.func); - if (funcType === unknownType) { - return resolveErrorCall(node); - } var apparentType = getApparentType(funcType); if (apparentType === unknownType) { return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); var constructSignatures = getSignaturesOfType(apparentType, 1 /* Construct */); - if ((funcType === anyType) || (!callSignatures.length && !constructSignatures.length && isTypeAssignableTo(funcType, globalFunctionType))) { + if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } @@ -12256,13 +13149,10 @@ var ts; } return resolveErrorCall(node); } - return resolveCall(node, callSignatures); + return resolveCall(node, callSignatures, candidatesOutArray); } - function resolveNewExpression(node) { + function resolveNewExpression(node, candidatesOutArray) { var expressionType = checkExpression(node.func); - if (expressionType === unknownType) { - return resolveErrorCall(node); - } if (expressionType === anyType) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); @@ -12275,11 +13165,11 @@ var ts; } var constructSignatures = getSignaturesOfType(expressionType, 1 /* Construct */); if (constructSignatures.length) { - return resolveCall(node, constructSignatures); + return resolveCall(node, constructSignatures, candidatesOutArray); } var callSignatures = getSignaturesOfType(expressionType, 0 /* Call */); if (callSignatures.length) { - var signature = resolveCall(node, callSignatures); + var signature = resolveCall(node, callSignatures, candidatesOutArray); if (getReturnTypeOfSignature(signature) !== voidType) { error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } @@ -12288,11 +13178,11 @@ var ts; error(node, ts.Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature); return resolveErrorCall(node); } - function getResolvedSignature(node) { + function getResolvedSignature(node, candidatesOutArray) { var links = getNodeLinks(node); - if (!links.resolvedSignature) { + if (!links.resolvedSignature || candidatesOutArray) { links.resolvedSignature = anySignature; - links.resolvedSignature = node.kind === 137 /* CallExpression */ ? resolveCallExpression(node) : resolveNewExpression(node); + links.resolvedSignature = node.kind === 139 /* CallExpression */ ? resolveCallExpression(node, candidatesOutArray) : resolveNewExpression(node, candidatesOutArray); } return links.resolvedSignature; } @@ -12301,7 +13191,7 @@ var ts; if (node.func.kind === 85 /* SuperKeyword */) { return voidType; } - if (node.kind === 138 /* NewExpression */) { + if (node.kind === 140 /* NewExpression */) { var declaration = signature.declaration; if (declaration && (declaration.kind !== 121 /* Constructor */ && declaration.kind !== 125 /* ConstructSignature */)) { if (compilerOptions.noImplicitAny) { @@ -12340,23 +13230,24 @@ var ts; } } function getReturnTypeFromBody(func, contextualMapper) { - if (func.body.kind !== 173 /* FunctionBlock */) { + var contextualSignature = getContextualSignature(func); + if (func.body.kind !== 175 /* FunctionBlock */) { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); var widenedType = getWidenedType(unwidenedType); - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(func, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeToString(widenedType)); } return widenedType; } var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); if (types.length > 0) { - var commonType = getBestCommonType(types, undefined, true); + var commonType = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!commonType) { error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); return unknownType; } var widenedType = getWidenedType(commonType); - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { var typeName = typeToString(widenedType); if (func.name) { error(func, ts.Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type, ts.identifierToString(func.name), typeName); @@ -12388,7 +13279,7 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 165 /* ThrowStatement */); + return (body.statements.length === 1) && (body.statements[0].kind === 167 /* ThrowStatement */); } function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) { if (!fullTypeCheck) { @@ -12397,7 +13288,7 @@ var ts; if (returnType === voidType || returnType === anyType) { return; } - if (!func.body || func.body.kind !== 173 /* FunctionBlock */) { + if (!func.body || func.body.kind !== 175 /* FunctionBlock */) { return; } var bodyBlock = func.body; @@ -12441,7 +13332,7 @@ var ts; if (node.type) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { checkSourceElement(node.body); } else { @@ -12469,12 +13360,12 @@ var ts; case 59 /* Identifier */: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 1 /* Variable */) !== 0; - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || (symbol.flags & ~4 /* EnumMember */) !== 0; - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return true; - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return isReferenceOrErrorExpression(n.expression); default: return false; @@ -12518,14 +13409,17 @@ var ts; } return numberType; } - function isTypeAnyTypeObjectTypeOrTypeParameter(type) { - return type === anyType || ((type.flags & (ts.TypeFlags.ObjectType | 512 /* TypeParameter */)) !== 0); + function isStructuredType(type) { + if (type.flags & 16384 /* Union */) { + return !ts.forEach(type.types, function (t) { return !isStructuredType(t); }); + } + return (type.flags & ts.TypeFlags.Structured) !== 0; } function checkInstanceOfExpression(node, leftType, rightType) { - if (!isTypeAnyTypeObjectTypeOrTypeParameter(leftType)) { + if (leftType !== unknownType && !isStructuredType(leftType)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } - if (rightType !== anyType && !isTypeSubtypeOf(rightType, globalFunctionType)) { + if (rightType !== unknownType && rightType !== anyType && !isTypeSubtypeOf(rightType, globalFunctionType)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; @@ -12534,7 +13428,7 @@ var ts; if (leftType !== anyType && leftType !== stringType && leftType !== numberType) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number); } - if (!isTypeAnyTypeObjectTypeOrTypeParameter(rightType)) { + if (!isStructuredType(rightType)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -12568,10 +13462,16 @@ var ts; leftType = rightType; if (rightType.flags & (32 /* Undefined */ | 64 /* Null */)) rightType = leftType; - var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - if (leftOk && rightOk) { - checkAssignmentOperator(numberType); + var suggestedOperator; + if ((leftType.flags & 8 /* Boolean */) && (rightType.flags & 8 /* Boolean */) && (suggestedOperator = getSuggestedBooleanOperator(node.operator)) !== undefined) { + error(node, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(node.operator), ts.tokenToString(suggestedOperator)); + } + else { + var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + if (leftOk && rightOk) { + checkAssignmentOperator(numberType); + } } return numberType; case 28 /* PlusToken */: @@ -12606,7 +13506,7 @@ var ts; case 20 /* GreaterThanToken */: case 21 /* LessThanEqualsToken */: case 22 /* GreaterThanEqualsToken */: - if (!isTypeSubtypeOf(leftType, rightType) && !isTypeSubtypeOf(rightType, leftType)) { + if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) { reportOperatorError(); } return booleanType; @@ -12617,13 +13517,28 @@ var ts; case 43 /* AmpersandAmpersandToken */: return rightType; case 44 /* BarBarToken */: - return getBestCommonType([leftType, rightType], isInferentialContext(contextualMapper) ? undefined : getContextualType(node)); + return getUnionType([leftType, rightType]); case 47 /* EqualsToken */: checkAssignmentOperator(rightType); return rightType; case 18 /* CommaToken */: return rightType; } + function getSuggestedBooleanOperator(operator) { + switch (operator) { + case 39 /* BarToken */: + case 57 /* BarEqualsToken */: + return 44 /* BarBarToken */; + case 40 /* CaretToken */: + case 58 /* CaretEqualsToken */: + return 26 /* ExclamationEqualsEqualsToken */; + case 38 /* AmpersandToken */: + case 56 /* AmpersandEqualsToken */: + return 43 /* AmpersandAmpersandToken */; + default: + return undefined; + } + } function checkAssignmentOperator(valueType) { if (fullTypeCheck && operator >= ts.SyntaxKind.FirstAssignment && operator <= ts.SyntaxKind.LastAssignment) { var ok = checkReferenceExpression(node.left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression); @@ -12640,18 +13555,7 @@ var ts; checkExpression(node.condition); var type1 = checkExpression(node.whenTrue, contextualMapper); var type2 = checkExpression(node.whenFalse, contextualMapper); - var contextualType = isInferentialContext(contextualMapper) ? undefined : getContextualType(node); - var resultType = getBestCommonType([type1, type2], contextualType, true); - if (!resultType) { - if (contextualType) { - error(node, ts.Diagnostics.No_best_common_type_exists_between_0_1_and_2, typeToString(contextualType), typeToString(type1), typeToString(type2)); - } - else { - error(node, ts.Diagnostics.No_best_common_type_exists_between_0_and_1, typeToString(type1), typeToString(type2)); - } - resultType = emptyObjectType; - } - return resultType; + return getUnionType([type1, type2]); } function checkExpressionWithContextualType(node, contextualType, contextualMapper) { var saveContextualType = node.contextualType; @@ -12702,32 +13606,34 @@ var ts; return globalRegExpType; case 116 /* QualifiedName */: return checkPropertyAccess(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return checkArrayLiteral(node, contextualMapper); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return checkObjectLiteral(node, contextualMapper); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return checkPropertyAccess(node); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return checkIndexedAccess(node); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return checkCallExpression(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return checkTypeAssertion(node); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return checkExpression(node.expression); - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return checkFunctionExpression(node, contextualMapper); - case 143 /* PrefixOperator */: + case 145 /* PrefixOperator */: return checkPrefixExpression(node); - case 144 /* PostfixOperator */: + case 146 /* PostfixOperator */: return checkPostfixExpression(node); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return checkBinaryExpression(node, contextualMapper); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return checkConditionalExpression(node, contextualMapper); + case 149 /* OmittedExpression */: + return undefinedType; } return unknownType; } @@ -12790,7 +13696,7 @@ var ts; if (fullTypeCheck) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { @@ -12806,7 +13712,7 @@ var ts; checkSpecializedSignatureDeclaration(node); } function checkTypeForDuplicateIndexSignatures(node) { - if (node.kind === 175 /* InterfaceDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */) { var nodeSymbol = getSymbolOfNode(node); if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) { return; @@ -12862,17 +13768,17 @@ var ts; return; } function isSuperCallExpression(n) { - return n.kind === 137 /* CallExpression */ && n.func.kind === 85 /* SuperKeyword */; + return n.kind === 139 /* CallExpression */ && n.func.kind === 85 /* SuperKeyword */; } function containsSuperCall(n) { if (isSuperCallExpression(n)) { return true; } switch (n.kind) { - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: - case 133 /* ObjectLiteral */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: + case 135 /* ObjectLiteral */: return false; default: return ts.forEachChild(n, containsSuperCall); @@ -12882,7 +13788,7 @@ var ts; if (n.kind === 87 /* ThisKeyword */) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } - else if (n.kind !== 141 /* FunctionExpression */ && n.kind !== 172 /* FunctionDeclaration */) { + else if (n.kind !== 143 /* FunctionExpression */ && n.kind !== 174 /* FunctionDeclaration */) { ts.forEachChild(n, markThisReferencesAsErrors); } } @@ -12894,7 +13800,7 @@ var ts; var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) || ts.forEach(node.parameters, function (p) { return p.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */); }); if (superCallShouldBeFirst) { var statements = node.body.statements; - if (!statements.length || statements[0].kind !== 151 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) { + if (!statements.length || statements[0].kind !== 153 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) { error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } else { @@ -12963,6 +13869,9 @@ var ts; function checkTupleType(node) { ts.forEach(node.elementTypes, checkSourceElement); } + function checkUnionType(node) { + ts.forEach(node.types, checkSourceElement); + } function isPrivateWithinAmbient(node) { return (node.flags & 32 /* Private */) && ts.isInAmbientContext(node); } @@ -12980,7 +13889,7 @@ var ts; } var symbol = getSymbolOfNode(signatureDeclarationNode); var signaturesToCheck; - if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 175 /* InterfaceDeclaration */) { + if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 177 /* InterfaceDeclaration */) { ts.Debug.assert(signatureDeclarationNode.kind === 124 /* CallSignature */ || signatureDeclarationNode.kind === 125 /* ConstructSignature */); var signatureKind = signatureDeclarationNode.kind === 124 /* CallSignature */ ? 0 /* Call */ : 1 /* Construct */; var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent); @@ -13000,7 +13909,7 @@ var ts; } function getEffectiveDeclarationFlags(n, flagsToCheck) { var flags = n.flags; - if (n.parent.kind !== 175 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { + if (n.parent.kind !== 177 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { if (!(flags & 2 /* Ambient */)) { flags |= 1 /* Export */; } @@ -13044,6 +13953,9 @@ var ts; var declarations = symbol.declarations; var isConstructor = (symbol.flags & 4096 /* Constructor */) !== 0; function reportImplementationExpectedError(node) { + if (node.name && node.name.kind === 115 /* Missing */) { + return; + } var seen = false; var subsequentNode = ts.forEachChild(node.parent, function (c) { if (seen) { @@ -13078,23 +13990,25 @@ var ts; } } var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & ts.SymbolFlags.Module; + var duplicateFunctionDeclaration = false; + var multipleConstructorImplementation = false; for (var i = 0; i < declarations.length; i++) { var node = declarations[i]; var inAmbientContext = ts.isInAmbientContext(node); - var inAmbientContextOrInterface = node.parent.kind === 175 /* InterfaceDeclaration */ || node.parent.kind === 129 /* TypeLiteral */ || inAmbientContext; + var inAmbientContextOrInterface = node.parent.kind === 177 /* InterfaceDeclaration */ || node.parent.kind === 129 /* TypeLiteral */ || inAmbientContext; if (inAmbientContextOrInterface) { previousDeclaration = undefined; } - if (node.kind === 172 /* FunctionDeclaration */ || node.kind === 120 /* Method */ || node.kind === 121 /* Constructor */) { + if (node.kind === 174 /* FunctionDeclaration */ || node.kind === 120 /* Method */ || node.kind === 121 /* Constructor */) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; if (node.body && bodyDeclaration) { if (isConstructor) { - error(node, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed); + multipleConstructorImplementation = true; } else { - error(node, ts.Diagnostics.Duplicate_function_implementation); + duplicateFunctionDeclaration = true; } } else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) { @@ -13114,6 +14028,16 @@ var ts; } } } + if (multipleConstructorImplementation) { + ts.forEach(declarations, function (declaration) { + error(declaration, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed); + }); + } + if (duplicateFunctionDeclaration) { + ts.forEach(declarations, function (declaration) { + error(declaration.name, ts.Diagnostics.Duplicate_function_implementation); + }); + } if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) { reportImplementationExpectedError(lastSeenNonAmbientDeclaration); } @@ -13169,14 +14093,14 @@ var ts; } function getDeclarationSpaces(d) { switch (d.kind) { - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return 1048576 /* ExportType */; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return d.name.kind === 7 /* StringLiteral */ || ts.isInstantiated(d) ? 2097152 /* ExportNamespace */ | 524288 /* ExportValue */ : 2097152 /* ExportNamespace */; - case 174 /* ClassDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: return 1048576 /* ExportType */ | 524288 /* ExportValue */; - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: var result = 0; var target = resolveImport(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { @@ -13251,10 +14175,10 @@ var ts; return; } switch (current.kind) { - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: case 120 /* Method */: - case 142 /* ArrowFunction */: + case 144 /* ArrowFunction */: case 121 /* Constructor */: if (ts.hasRestParameters(current)) { error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_i_that_compiler_uses_to_initialize_rest_parameter); @@ -13306,7 +14230,7 @@ var ts; if (!needCollisionCheckForIdentifier(node, name, "_super")) { return; } - var enclosingClass = ts.getAncestor(node, 174 /* ClassDeclaration */); + var enclosingClass = ts.getAncestor(node, 176 /* ClassDeclaration */); if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) { return; } @@ -13320,15 +14244,15 @@ var ts; } } } - function checkCollistionWithRequireExportsInGeneratedCode(node, name) { + function checkCollisionWithRequireExportsInGeneratedCode(node, name) { if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { return; } - if (node.kind === 177 /* ModuleDeclaration */ && !ts.isInstantiated(node)) { + if (node.kind === 179 /* ModuleDeclaration */ && !ts.isInstantiated(node)) { return; } - var parent = node.kind === 171 /* VariableDeclaration */ ? node.parent.parent : node.parent; - if (parent.kind === 182 /* SourceFile */ && ts.isExternalModule(parent)) { + var parent = node.kind === 173 /* VariableDeclaration */ ? node.parent.parent : node.parent; + if (parent.kind === 184 /* SourceFile */ && ts.isExternalModule(parent)) { error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module, name.text, name.text); } } @@ -13353,7 +14277,7 @@ var ts; } checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); if (!useTypeFromValueDeclaration) { if (typeOfValueDeclaration !== unknownType && type !== unknownType && !isTypeIdenticalTo(typeOfValueDeclaration, type)) { error(node.name, ts.Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, ts.identifierToString(node.name), typeToString(typeOfValueDeclaration), typeToString(type)); @@ -13408,7 +14332,7 @@ var ts; } } var exprType = checkExpression(node.expression); - if (!isTypeAnyTypeObjectTypeOrTypeParameter(exprType) && exprType !== unknownType) { + if (!isStructuredType(exprType) && exprType !== unknownType) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -13484,7 +14408,7 @@ var ts; errorNode = indexDeclaration; } else if (type.flags & 2048 /* Interface */) { - var someBaseClassHasBothPropertyAndIndexer = ts.forEach(type.baseTypes, function (base) { return getPropertyOfType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); + var someBaseClassHasBothPropertyAndIndexer = ts.forEach(type.baseTypes, function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : type.symbol.declarations[0]; } if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { @@ -13497,7 +14421,7 @@ var ts; var stringIndexType = getIndexTypeOfType(type, 0 /* String */); var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); if (stringIndexType || numberIndexType) { - ts.forEach(getPropertiesOfType(type), function (prop) { + ts.forEach(getPropertiesOfObjectType(type), function (prop) { var propType = getTypeOfSymbol(prop); checkIndexConstraintForProperty(prop, propType, declaredStringIndexer, stringIndexType, 0 /* String */); checkIndexConstraintForProperty(prop, propType, declaredNumberIndexer, numberIndexType, 1 /* Number */); @@ -13544,7 +14468,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); checkTypeParameters(node.typeParameters); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -13593,13 +14517,13 @@ var ts; return s.flags & 8388608 /* Instantiated */ ? getSymbolLinks(s).target : s; } function checkKindsOfPropertyMemberOverrides(type, baseType) { - var baseProperties = getPropertiesOfType(baseType); + var baseProperties = getPropertiesOfObjectType(baseType); for (var i = 0, len = baseProperties.length; i < len; ++i) { var base = getTargetSymbol(baseProperties[i]); if (base.flags & 67108864 /* Prototype */) { continue; } - var derived = getTargetSymbol(getPropertyOfType(type, base.name)); + var derived = getTargetSymbol(getPropertyOfObjectType(type, base.name)); if (derived) { var baseDeclarationFlags = getDeclarationFlagsFromSymbol(base); var derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived); @@ -13669,7 +14593,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - var firstInterfaceDecl = getDeclarationOfKind(symbol, 175 /* InterfaceDeclaration */); + var firstInterfaceDecl = getDeclarationOfKind(symbol, 177 /* InterfaceDeclaration */); if (symbol.declarations.length > 1) { if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) { error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters); @@ -13691,9 +14615,9 @@ var ts; checkTypeForDuplicateIndexSignatures(node); } } - function getConstantValue(node) { + function getConstantValueForExpression(node) { var isNegative = false; - if (node.kind === 143 /* PrefixOperator */) { + if (node.kind === 145 /* PrefixOperator */) { var unaryExpression = node; if (unaryExpression.operator === 29 /* MinusToken */ || unaryExpression.operator === 28 /* PlusToken */) { node = unaryExpression.operand; @@ -13706,38 +14630,49 @@ var ts; } return undefined; } + function computeEnumMemberValues(node) { + var nodeLinks = getNodeLinks(node); + if (!(nodeLinks.flags & 128 /* EnumValuesComputed */)) { + var enumSymbol = getSymbolOfNode(node); + var enumType = getDeclaredTypeOfSymbol(enumSymbol); + var autoValue = 0; + var ambient = ts.isInAmbientContext(node); + ts.forEach(node.members, function (member) { + if (isNumericName(member.name.text)) { + error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); + } + var initializer = member.initializer; + if (initializer) { + autoValue = getConstantValueForExpression(initializer); + if (autoValue === undefined && !ambient) { + checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined, undefined); + } + } + else if (ambient) { + autoValue = undefined; + } + if (autoValue !== undefined) { + getNodeLinks(member).enumMemberValue = autoValue++; + } + }); + nodeLinks.flags |= 128 /* EnumValuesComputed */; + } + } function checkEnumDeclaration(node) { if (!fullTypeCheck) { return; } checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); + computeEnumMemberValues(node); var enumSymbol = getSymbolOfNode(node); - var enumType = getDeclaredTypeOfSymbol(enumSymbol); - var autoValue = 0; - var ambient = ts.isInAmbientContext(node); - ts.forEach(node.members, function (member) { - var initializer = member.initializer; - if (initializer) { - autoValue = getConstantValue(initializer); - if (autoValue === undefined && !ambient) { - checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined, undefined); - } - } - else if (ambient) { - autoValue = undefined; - } - if (autoValue !== undefined) { - getNodeLinks(member).enumMemberValue = autoValue++; - } - }); var firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind); if (node === firstDeclaration) { var seenEnumMissingInitialInitializer = false; ts.forEach(enumSymbol.declarations, function (declaration) { - if (declaration.kind !== 176 /* EnumDeclaration */) { + if (declaration.kind !== 178 /* EnumDeclaration */) { return false; } var enumDeclaration = declaration; @@ -13760,7 +14695,7 @@ var ts; var declarations = symbol.declarations; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; - if ((declaration.kind === 174 /* ClassDeclaration */ || (declaration.kind === 172 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) { + if ((declaration.kind === 176 /* ClassDeclaration */ || (declaration.kind === 174 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) { return declaration; } } @@ -13769,7 +14704,7 @@ var ts; function checkModuleDeclaration(node) { if (fullTypeCheck) { checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); if (symbol.flags & 128 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node)) { @@ -13802,7 +14737,7 @@ var ts; } function checkImportDeclaration(node) { checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); var symbol = getSymbolOfNode(node); var target; if (node.entityName) { @@ -13823,10 +14758,10 @@ var ts; } } else { - if (node.parent.kind === 182 /* SourceFile */) { + if (node.parent.kind === 184 /* SourceFile */) { target = resolveImport(symbol); } - else if (node.parent.kind === 178 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) { + else if (node.parent.kind === 180 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) { if (isExternalModuleNameRelative(node.externalModuleName.text)) { error(node, ts.Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); target = unknownSymbol; @@ -13848,7 +14783,7 @@ var ts; } function checkExportAssignment(node) { var container = node.parent; - if (container.kind !== 182 /* SourceFile */) { + if (container.kind !== 184 /* SourceFile */) { container = container.parent; } checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container)); @@ -13884,62 +14819,66 @@ var ts; return checkArrayType(node); case 131 /* TupleType */: return checkTupleType(node); - case 172 /* FunctionDeclaration */: + case 132 /* UnionType */: + return checkUnionType(node); + case 133 /* ParenType */: + return checkSourceElement(node.type); + case 174 /* FunctionDeclaration */: return checkFunctionDeclaration(node); - case 148 /* Block */: + case 150 /* Block */: return checkBlock(node); - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: return checkBody(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return checkVariableStatement(node); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return checkExpressionStatement(node); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return checkIfStatement(node); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return checkDoStatement(node); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return checkWhileStatement(node); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return checkForStatement(node); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return checkForInStatement(node); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return checkBreakOrContinueStatement(node); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return checkReturnStatement(node); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return checkWithStatement(node); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return checkSwitchStatement(node); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return checkLabeledStatement(node); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return checkThrowStatement(node); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return checkTryStatement(node); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return ts.Debug.fail("Checker encountered variable declaration"); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return checkClassDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return checkEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return checkModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return checkImportDeclaration(node); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return checkExportAssignment(node); } } function checkFunctionExpressionBodies(node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: ts.forEach(node.parameters, checkFunctionExpressionBodies); checkFunctionExpressionBody(node); break; @@ -13947,54 +14886,54 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: ts.forEach(node.parameters, checkFunctionExpressionBodies); break; - case 160 /* WithStatement */: + case 162 /* WithStatement */: checkFunctionExpressionBodies(node.expression); break; case 118 /* Parameter */: case 119 /* Property */: - case 132 /* ArrayLiteral */: - case 133 /* ObjectLiteral */: - case 134 /* PropertyAssignment */: - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 137 /* CallExpression */: - case 138 /* NewExpression */: - case 139 /* TypeAssertion */: - case 140 /* ParenExpression */: - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: - case 145 /* BinaryExpression */: - case 146 /* ConditionalExpression */: - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 149 /* VariableStatement */: - case 151 /* ExpressionStatement */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: - case 159 /* ReturnStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 163 /* DefaultClause */: - case 164 /* LabeledStatement */: - case 165 /* ThrowStatement */: - case 166 /* TryStatement */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: - case 171 /* VariableDeclaration */: - case 174 /* ClassDeclaration */: - case 176 /* EnumDeclaration */: - case 181 /* EnumMember */: - case 182 /* SourceFile */: + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 136 /* PropertyAssignment */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 147 /* BinaryExpression */: + case 148 /* ConditionalExpression */: + case 150 /* Block */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 151 /* VariableStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: + case 161 /* ReturnStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 167 /* ThrowStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + case 173 /* VariableDeclaration */: + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: + case 183 /* EnumMember */: + case 184 /* SourceFile */: ts.forEachChild(node, checkFunctionExpressionBodies); break; } @@ -14065,7 +15004,7 @@ var ts; function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 160 /* WithStatement */ && node.parent.statement === node) { + if (node.parent.kind === 162 /* WithStatement */ && node.parent.statement === node) { return true; } node = node.parent; @@ -14101,27 +15040,27 @@ var ts; copySymbols(location.locals, meaning); } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & ts.SymbolFlags.ModuleMember); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & 4 /* EnumMember */); break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (!(memberFlags & 128 /* Static */)) { copySymbols(getSymbolOfNode(location).members, meaning & ts.SymbolFlags.Type); } break; - case 141 /* FunctionExpression */: + case 143 /* FunctionExpression */: if (location.name) { copySymbol(location.symbol, meaning); } break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: if (location.variable.text) { copySymbol(location.symbol, meaning); } @@ -14139,9 +15078,9 @@ var ts; function isTypeDeclaration(node) { switch (node.kind) { case 117 /* TypeParameter */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: return true; } } @@ -14159,21 +15098,21 @@ var ts; case 89 /* TrueKeyword */: case 74 /* FalseKeyword */: case 8 /* RegularExpressionLiteral */: - case 132 /* ArrayLiteral */: - case 133 /* ObjectLiteral */: - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 137 /* CallExpression */: - case 138 /* NewExpression */: - case 139 /* TypeAssertion */: - case 140 /* ParenExpression */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: - case 145 /* BinaryExpression */: - case 146 /* ConditionalExpression */: - case 147 /* OmittedExpression */: + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 147 /* BinaryExpression */: + case 148 /* ConditionalExpression */: + case 149 /* OmittedExpression */: return true; case 116 /* QualifiedName */: while (node.parent.kind === 116 /* QualifiedName */) @@ -14187,28 +15126,28 @@ var ts; case 7 /* StringLiteral */: var parent = node.parent; switch (parent.kind) { - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 118 /* Parameter */: case 119 /* Property */: - case 181 /* EnumMember */: - case 134 /* PropertyAssignment */: + case 183 /* EnumMember */: + case 136 /* PropertyAssignment */: return parent.initializer === node; - case 151 /* ExpressionStatement */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 159 /* ReturnStatement */: - case 160 /* WithStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 165 /* ThrowStatement */: - case 161 /* SwitchStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 161 /* ReturnStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 167 /* ThrowStatement */: + case 163 /* SwitchStatement */: return parent.expression === node; - case 155 /* ForStatement */: + case 157 /* ForStatement */: return parent.initializer === node || parent.condition === node || parent.iterator === node; - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return parent.variable === node || parent.expression === node; - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return node === parent.operand; default: if (isExpression(parent)) { @@ -14219,7 +15158,7 @@ var ts; return false; } function isTypeNode(node) { - if (node.kind >= ts.SyntaxKind.FirstTypeNode && node.kind <= ts.SyntaxKind.LastTypeNode) { + if (ts.SyntaxKind.FirstTypeNode <= node.kind && node.kind <= ts.SyntaxKind.LastTypeNode) { return true; } switch (node.kind) { @@ -14229,7 +15168,7 @@ var ts; case 106 /* BooleanKeyword */: return true; case 93 /* VoidKeyword */: - return node.parent.kind !== 143 /* PrefixOperator */; + return node.parent.kind !== 145 /* PrefixOperator */; case 7 /* StringLiteral */: return node.parent.kind === 118 /* Parameter */; case 59 /* Identifier */: @@ -14237,11 +15176,12 @@ var ts; node = node.parent; } case 116 /* QualifiedName */: + ts.Debug.assert(node.kind === 59 /* Identifier */ || node.kind === 116 /* QualifiedName */, "'node' was expected to be a qualified name or identifier in 'isTypeNode'."); var parent = node.parent; if (parent.kind === 128 /* TypeQuery */) { return false; } - if (parent.kind >= ts.SyntaxKind.FirstTypeNode && parent.kind <= ts.SyntaxKind.LastTypeNode) { + if (ts.SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= ts.SyntaxKind.LastTypeNode) { return true; } switch (parent.kind) { @@ -14249,11 +15189,11 @@ var ts; return node === parent.constraint; case 119 /* Property */: case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return node === parent.type; - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: case 121 /* Constructor */: case 120 /* Method */: case 122 /* GetAccessor */: @@ -14263,11 +15203,11 @@ var ts; case 125 /* ConstructSignature */: case 126 /* IndexSignature */: return node === parent.type; - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return node === parent.type; - case 137 /* CallExpression */: - case 138 /* NewExpression */: - return parent.typeArguments.indexOf(node) >= 0; + case 139 /* CallExpression */: + case 140 /* NewExpression */: + return parent.typeArguments && parent.typeArguments.indexOf(node) >= 0; } } return false; @@ -14276,22 +15216,22 @@ var ts; while (node.parent.kind === 116 /* QualifiedName */) { node = node.parent; } - if (node.parent.kind === 179 /* ImportDeclaration */) { + if (node.parent.kind === 181 /* ImportDeclaration */) { return node.parent.entityName === node; } - if (node.parent.kind === 180 /* ExportAssignment */) { + if (node.parent.kind === 182 /* ExportAssignment */) { return node.parent.exportName === node; } return false; } function isRightSideOfQualifiedNameOrPropertyAccess(node) { - return (node.parent.kind === 116 /* QualifiedName */ || node.parent.kind === 135 /* PropertyAccess */) && node.parent.right === node; + return (node.parent.kind === 116 /* QualifiedName */ || node.parent.kind === 137 /* PropertyAccess */) && node.parent.right === node; } function getSymbolOfEntityName(entityName) { if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { return getSymbolOfNode(entityName.parent); } - if (entityName.parent.kind === 180 /* ExportAssignment */) { + if (entityName.parent.kind === 182 /* ExportAssignment */) { return resolveEntityName(entityName.parent.parent, entityName, ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace | 4194304 /* Import */); } if (isInRightSideOfImportOrExportAssignment(entityName)) { @@ -14305,7 +15245,7 @@ var ts; var meaning = ts.SymbolFlags.Value | 4194304 /* Import */; return resolveEntityName(entityName, entityName, meaning); } - else if (entityName.kind === 116 /* QualifiedName */ || entityName.kind === 135 /* PropertyAccess */) { + else if (entityName.kind === 116 /* QualifiedName */ || entityName.kind === 137 /* PropertyAccess */) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkPropertyAccess(entityName); @@ -14331,11 +15271,11 @@ var ts; return getSymbolOfNode(node.parent); } if (node.kind === 59 /* Identifier */ && isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 180 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node); + return node.parent.kind === 182 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node); } switch (node.kind) { case 59 /* Identifier */: - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: case 116 /* QualifiedName */: return getSymbolOfEntityName(node); case 87 /* ThisKeyword */: @@ -14349,20 +15289,20 @@ var ts; } return undefined; case 7 /* StringLiteral */: - if (node.parent.kind === 179 /* ImportDeclaration */ && node.parent.externalModuleName === node) { + if (node.parent.kind === 181 /* ImportDeclaration */ && node.parent.externalModuleName === node) { var importSymbol = getSymbolOfNode(node.parent); var moduleType = getTypeOfSymbol(importSymbol); return moduleType ? moduleType.symbol : undefined; } case 6 /* NumericLiteral */: - if (node.parent.kind == 136 /* IndexedAccess */ && node.parent.index === node) { + if (node.parent.kind == 138 /* IndexedAccess */ && node.parent.index === node) { var objectType = checkExpression(node.parent.object); if (objectType === unknownType) return undefined; var apparentType = getApparentType(objectType); if (apparentType === unknownType) return undefined; - return getPropertyOfApparentType(apparentType, node.text); + return getPropertyOfType(apparentType, node.text); } break; } @@ -14407,41 +15347,37 @@ var ts; } return checkExpression(expr); } - function getAugmentedPropertiesOfApparentType(type) { - var apparentType = getApparentType(type); - if (apparentType.flags & ts.TypeFlags.ObjectType) { - var propertiesByName = {}; - var results = []; - ts.forEach(getPropertiesOfType(apparentType), function (s) { - propertiesByName[s.name] = s; - results.push(s); - }); - var resolved = resolveObjectTypeMembers(type); - ts.forEachValue(resolved.members, function (s) { - if (symbolIsValue(s) && !propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); + function getAugmentedPropertiesOfType(type) { + var type = getApparentType(type); + var propsByName = createSymbolTable(getPropertiesOfType(type)); + if (getSignaturesOfType(type, 0 /* Call */).length || getSignaturesOfType(type, 1 /* Construct */).length) { + ts.forEach(getPropertiesOfType(globalFunctionType), function (p) { + if (!ts.hasProperty(propsByName, p.name)) { + propsByName[p.name] = p; } }); - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - ts.forEach(getPropertiesOfType(globalFunctionType), function (s) { - if (!propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); - } - }); - } - return results; - } - else { - return getPropertiesOfType(apparentType); } + return getNamedMembers(propsByName); } - function getRootSymbol(symbol) { - return ((symbol.flags & 33554432 /* Transient */) && getSymbolLinks(symbol).target) || symbol; + function getRootSymbols(symbol) { + if (symbol.flags & 134217728 /* UnionProperty */) { + var symbols = []; + var name = symbol.name; + ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { + symbols.push(getPropertyOfType(t, name)); + }); + return symbols; + } + else if (symbol.flags & 33554432 /* Transient */) { + var target = getSymbolLinks(symbol).target; + if (target) { + return [target]; + } + } + return [symbol]; } function isExternalModuleSymbol(symbol) { - return symbol.flags & 128 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 182 /* SourceFile */; + return symbol.flags & 128 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 184 /* SourceFile */; } function isNodeDescendentOf(node, ancestor) { while (node) { @@ -14467,14 +15403,14 @@ var ts; while (!isUniqueLocalName(ts.escapeIdentifier(prefix + name), container)) { prefix += "_"; } - links.localModuleName = prefix + ts.getSourceTextOfNode(container.name); + links.localModuleName = prefix + ts.getTextOfNode(container.name); } return links.localModuleName; } function getLocalNameForSymbol(symbol, location) { var node = location; while (node) { - if ((node.kind === 177 /* ModuleDeclaration */ || node.kind === 176 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) { + if ((node.kind === 179 /* ModuleDeclaration */ || node.kind === 178 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) { return getLocalNameOfContainer(node); } node = node.parent; @@ -14493,22 +15429,12 @@ var ts; } } } - function getPropertyAccessSubstitution(node) { - var symbol = getNodeLinks(node).resolvedSymbol; - if (symbol && (symbol.flags & 4 /* EnumMember */)) { - var declaration = symbol.valueDeclaration; - var constantValue; - if (declaration.kind === 181 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) { - return constantValue.toString() + " /* " + ts.identifierToString(declaration.name) + " */"; - } - } - } function getExportAssignmentName(node) { var symbol = getExportAssignmentSymbol(getSymbolOfNode(node)); return symbol && symbolIsValue(symbol) ? symbolToString(symbol) : undefined; } function isTopLevelValueImportedViaEntityName(node) { - if (node.parent.kind !== 182 /* SourceFile */ || !node.entityName) { + if (node.parent.kind !== 184 /* SourceFile */ || !node.entityName) { return false; } var symbol = getSymbolOfNode(node); @@ -14543,23 +15469,34 @@ var ts; return getNodeLinks(node).flags; } function getEnumMemberValue(node) { + computeEnumMemberValues(node.parent); return getNodeLinks(node).enumMemberValue; } + function getConstantValue(node) { + var symbol = getNodeLinks(node).resolvedSymbol; + if (symbol && (symbol.flags & 4 /* EnumMember */)) { + var declaration = symbol.valueDeclaration; + var constantValue; + if (declaration.kind === 183 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) { + return constantValue; + } + } + return undefined; + } function writeTypeAtLocation(location, enclosingDeclaration, flags, writer) { var symbol = getSymbolOfNode(location); var type = symbol && !(symbol.flags & 512 /* TypeLiteral */) ? getTypeOfSymbol(symbol) : getTypeFromTypeNode(location); - writeTypeToTextWriter(type, enclosingDeclaration, flags, writer); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } function writeReturnTypeOfSignatureDeclaration(signatureDeclaration, enclosingDeclaration, flags, writer) { var signature = getSignatureFromDeclaration(signatureDeclaration); - writeTypeToTextWriter(getReturnTypeOfSignature(signature), enclosingDeclaration, flags, writer); + getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); } function invokeEmitter(targetSourceFile) { var resolver = { getProgram: function () { return program; }, getLocalNameOfContainer: getLocalNameOfContainer, getExpressionNamePrefix: getExpressionNamePrefix, - getPropertyAccessSubstitution: getPropertyAccessSubstitution, getExportAssignmentName: getExportAssignmentName, isReferencedImportDeclaration: isReferencedImportDeclaration, getNodeCheckFlags: getNodeCheckFlags, @@ -14570,9 +15507,9 @@ var ts; isImplementationOfOverload: isImplementationOfOverload, writeTypeAtLocation: writeTypeAtLocation, writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration, - writeSymbol: writeSymbolToTextWriter, isSymbolAccessible: isSymbolAccessible, - isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile + isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile, + getConstantValue: getConstantValue }; checkProgram(); return ts.emitFiles(resolver, targetSourceFile); @@ -15712,7 +16649,6 @@ var __extends = this.__extends || function (d, b) { }; var TypeScript; (function (TypeScript) { - TypeScript.LocalizedDiagnosticMessages = null; var Location = (function () { function Location(fileName, lineMap, start, length) { this._fileName = fileName; @@ -15884,10 +16820,6 @@ var TypeScript; } IntegerUtilities.integerDivide = integerDivide; function integerMultiplyLow32Bits(n1, n2) { - var n1Low16 = n1 & 0x0000ffff; - var n1High16 = n1 >>> 16; - var n2Low16 = n2 & 0x0000ffff; - var n2High16 = n2 >>> 16; var resultLow32 = (((n1 & 0xffff0000) * n2) >>> 0) + (((n1 & 0x0000ffff) * n2) >>> 0) >>> 0; return resultLow32; } @@ -19472,7 +20404,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { - TypeScript.nodeMetadata = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], ["moduleElements", "endOfFileToken"], ["left", "dotToken", "right"], ["openBraceToken", "typeMembers", "closeBraceToken"], ["typeParameterList", "parameterList", "equalsGreaterThanToken", "type"], ["type", "openBracketToken", "closeBracketToken"], ["newKeyword", "typeParameterList", "parameterList", "equalsGreaterThanToken", "type"], ["name", "typeArgumentList"], ["typeOfKeyword", "name"], ["openBracketToken", "types", "closeBracketToken"], ["modifiers", "interfaceKeyword", "identifier", "typeParameterList", "heritageClauses", "body"], ["modifiers", "functionKeyword", "identifier", "callSignature", "block", "semicolonToken"], ["modifiers", "moduleKeyword", "name", "stringLiteral", "openBraceToken", "moduleElements", "closeBraceToken"], ["modifiers", "classKeyword", "identifier", "typeParameterList", "heritageClauses", "openBraceToken", "classElements", "closeBraceToken"], ["modifiers", "enumKeyword", "identifier", "openBraceToken", "enumElements", "closeBraceToken"], ["modifiers", "importKeyword", "identifier", "equalsToken", "moduleReference", "semicolonToken"], ["exportKeyword", "equalsToken", "identifier", "semicolonToken"], ["modifiers", "propertyName", "callSignature", "block", "semicolonToken"], ["modifiers", "variableDeclarator", "semicolonToken"], ["modifiers", "constructorKeyword", "callSignature", "block", "semicolonToken"], ["modifiers", "indexSignature", "semicolonToken"], ["modifiers", "getKeyword", "propertyName", "callSignature", "block"], ["modifiers", "setKeyword", "propertyName", "callSignature", "block"], ["propertyName", "questionToken", "typeAnnotation"], ["typeParameterList", "parameterList", "typeAnnotation"], ["newKeyword", "callSignature"], ["openBracketToken", "parameters", "closeBracketToken", "typeAnnotation"], ["propertyName", "questionToken", "callSignature"], ["openBraceToken", "statements", "closeBraceToken"], ["ifKeyword", "openParenToken", "condition", "closeParenToken", "statement", "elseClause"], ["modifiers", "variableDeclaration", "semicolonToken"], ["expression", "semicolonToken"], ["returnKeyword", "expression", "semicolonToken"], ["switchKeyword", "openParenToken", "expression", "closeParenToken", "openBraceToken", "switchClauses", "closeBraceToken"], ["breakKeyword", "identifier", "semicolonToken"], ["continueKeyword", "identifier", "semicolonToken"], ["forKeyword", "openParenToken", "variableDeclaration", "initializer", "firstSemicolonToken", "condition", "secondSemicolonToken", "incrementor", "closeParenToken", "statement"], ["forKeyword", "openParenToken", "variableDeclaration", "left", "inKeyword", "expression", "closeParenToken", "statement"], ["semicolonToken"], ["throwKeyword", "expression", "semicolonToken"], ["whileKeyword", "openParenToken", "condition", "closeParenToken", "statement"], ["tryKeyword", "block", "catchClause", "finallyClause"], ["identifier", "colonToken", "statement"], ["doKeyword", "statement", "whileKeyword", "openParenToken", "condition", "closeParenToken", "semicolonToken"], ["debuggerKeyword", "semicolonToken"], ["withKeyword", "openParenToken", "condition", "closeParenToken", "statement"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["deleteKeyword", "expression"], ["typeOfKeyword", "expression"], ["voidKeyword", "expression"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["condition", "questionToken", "whenTrue", "colonToken", "whenFalse"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["operand", "operatorToken"], ["operand", "operatorToken"], ["expression", "dotToken", "name"], ["expression", "argumentList"], ["openBracketToken", "expressions", "closeBracketToken"], ["openBraceToken", "propertyAssignments", "closeBraceToken"], ["newKeyword", "expression", "argumentList"], ["openParenToken", "expression", "closeParenToken"], ["callSignature", "equalsGreaterThanToken", "block", "expression"], ["parameter", "equalsGreaterThanToken", "block", "expression"], ["lessThanToken", "type", "greaterThanToken", "expression"], ["expression", "openBracketToken", "argumentExpression", "closeBracketToken"], ["functionKeyword", "identifier", "callSignature", "block"], [], ["varKeyword", "variableDeclarators"], ["propertyName", "typeAnnotation", "equalsValueClause"], ["typeArgumentList", "openParenToken", "arguments", "closeParenToken"], ["openParenToken", "parameters", "closeParenToken"], ["lessThanToken", "typeArguments", "greaterThanToken"], ["lessThanToken", "typeParameters", "greaterThanToken"], ["extendsOrImplementsKeyword", "typeNames"], ["extendsOrImplementsKeyword", "typeNames"], ["equalsToken", "value"], ["caseKeyword", "expression", "colonToken", "statements"], ["defaultKeyword", "colonToken", "statements"], ["elseKeyword", "statement"], ["catchKeyword", "openParenToken", "identifier", "typeAnnotation", "closeParenToken", "block"], ["finallyKeyword", "block"], ["identifier", "constraint"], ["extendsKeyword", "typeOrExpression"], ["propertyName", "colonToken", "expression"], ["propertyName", "callSignature", "block"], ["dotDotDotToken", "modifiers", "identifier", "questionToken", "typeAnnotation", "equalsValueClause"], ["propertyName", "equalsValueClause"], ["colonToken", "type"], ["requireKeyword", "openParenToken", "stringLiteral", "closeParenToken"], ["moduleName"], ]; + TypeScript.nodeMetadata = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], ["moduleElements", "endOfFileToken"], ["left", "dotToken", "right"], ["openBraceToken", "typeMembers", "closeBraceToken"], ["typeParameterList", "parameterList", "equalsGreaterThanToken", "type"], ["type", "openBracketToken", "closeBracketToken"], ["newKeyword", "typeParameterList", "parameterList", "equalsGreaterThanToken", "type"], ["name", "typeArgumentList"], ["typeOfKeyword", "name"], ["openBracketToken", "types", "closeBracketToken"], ["modifiers", "interfaceKeyword", "identifier", "typeParameterList", "heritageClauses", "body"], ["modifiers", "functionKeyword", "identifier", "callSignature", "block", "semicolonToken"], ["modifiers", "moduleKeyword", "name", "stringLiteral", "openBraceToken", "moduleElements", "closeBraceToken"], ["modifiers", "classKeyword", "identifier", "typeParameterList", "heritageClauses", "openBraceToken", "classElements", "closeBraceToken"], ["modifiers", "enumKeyword", "identifier", "openBraceToken", "enumElements", "closeBraceToken"], ["modifiers", "importKeyword", "identifier", "equalsToken", "moduleReference", "semicolonToken"], ["exportKeyword", "equalsToken", "identifier", "semicolonToken"], ["modifiers", "propertyName", "callSignature", "block", "semicolonToken"], ["modifiers", "variableDeclarator", "semicolonToken"], ["modifiers", "constructorKeyword", "callSignature", "block", "semicolonToken"], ["modifiers", "indexSignature", "semicolonToken"], ["modifiers", "getKeyword", "propertyName", "callSignature", "block"], ["modifiers", "setKeyword", "propertyName", "callSignature", "block"], ["propertyName", "questionToken", "typeAnnotation"], ["typeParameterList", "parameterList", "typeAnnotation"], ["newKeyword", "callSignature"], ["openBracketToken", "parameters", "closeBracketToken", "typeAnnotation"], ["propertyName", "questionToken", "callSignature"], ["openBraceToken", "statements", "closeBraceToken"], ["ifKeyword", "openParenToken", "condition", "closeParenToken", "statement", "elseClause"], ["modifiers", "variableDeclaration", "semicolonToken"], ["expression", "semicolonToken"], ["returnKeyword", "expression", "semicolonToken"], ["switchKeyword", "openParenToken", "expression", "closeParenToken", "openBraceToken", "switchClauses", "closeBraceToken"], ["breakKeyword", "identifier", "semicolonToken"], ["continueKeyword", "identifier", "semicolonToken"], ["forKeyword", "openParenToken", "variableDeclaration", "initializer", "firstSemicolonToken", "condition", "secondSemicolonToken", "incrementor", "closeParenToken", "statement"], ["forKeyword", "openParenToken", "variableDeclaration", "left", "inKeyword", "expression", "closeParenToken", "statement"], ["semicolonToken"], ["throwKeyword", "expression", "semicolonToken"], ["whileKeyword", "openParenToken", "condition", "closeParenToken", "statement"], ["tryKeyword", "block", "catchClause", "finallyClause"], ["identifier", "colonToken", "statement"], ["doKeyword", "statement", "whileKeyword", "openParenToken", "condition", "closeParenToken", "semicolonToken"], ["debuggerKeyword", "semicolonToken"], ["withKeyword", "openParenToken", "condition", "closeParenToken", "statement"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["deleteKeyword", "expression"], ["typeOfKeyword", "expression"], ["voidKeyword", "expression"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["condition", "questionToken", "whenTrue", "colonToken", "whenFalse"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["operand", "operatorToken"], ["operand", "operatorToken"], ["expression", "dotToken", "name"], ["expression", "argumentList"], ["openBracketToken", "expressions", "closeBracketToken"], ["openBraceToken", "propertyAssignments", "closeBraceToken"], ["newKeyword", "expression", "argumentList"], ["openParenToken", "expression", "closeParenToken"], ["callSignature", "equalsGreaterThanToken", "block", "expression"], ["parameter", "equalsGreaterThanToken", "block", "expression"], ["lessThanToken", "type", "greaterThanToken", "expression"], ["expression", "openBracketToken", "argumentExpression", "closeBracketToken"], ["functionKeyword", "identifier", "callSignature", "block"], [], ["varKeyword", "variableDeclarators"], ["propertyName", "typeAnnotation", "equalsValueClause"], ["typeArgumentList", "openParenToken", "arguments", "closeParenToken"], ["openParenToken", "parameters", "closeParenToken"], ["lessThanToken", "typeArguments", "greaterThanToken"], ["lessThanToken", "typeParameters", "greaterThanToken"], ["extendsOrImplementsKeyword", "typeNames"], ["extendsOrImplementsKeyword", "typeNames"], ["equalsToken", "value"], ["caseKeyword", "expression", "colonToken", "statements"], ["defaultKeyword", "colonToken", "statements"], ["elseKeyword", "statement"], ["catchKeyword", "openParenToken", "identifier", "typeAnnotation", "closeParenToken", "block"], ["finallyKeyword", "block"], ["identifier", "constraint"], ["extendsKeyword", "typeOrExpression"], ["propertyName", "colonToken", "expression"], ["propertyName", "callSignature", "block"], ["dotDotDotToken", "modifiers", "identifier", "questionToken", "typeAnnotation", "equalsValueClause"], ["propertyName", "equalsValueClause"], ["colonToken", "type"], ["requireKeyword", "openParenToken", "stringLiteral", "closeParenToken"], ["moduleName"],]; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -24802,7 +25734,6 @@ var TypeScript; return this._languageVersion; }; SyntaxTree.prototype.cacheSyntaxTreeInfo = function () { - var sourceUnit = this.sourceUnit(); var firstToken = firstSyntaxTreeToken(this); var leadingTrivia = firstToken.leadingTrivia(this.text); this._isExternalModule = externalModuleIndicatorSpanWorker(this, firstToken) !== null; @@ -25976,10 +26907,10 @@ var TypeScript; throw TypeScript.Errors.argumentOutOfRange("languageVersion"); } }; - Unicode.unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - Unicode.unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - Unicode.unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - Unicode.unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; + Unicode.unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + Unicode.unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + Unicode.unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + Unicode.unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; return Unicode; })(); TypeScript.Unicode = Unicode; @@ -26394,17 +27325,28 @@ var ts; (function (OutliningElementsCollector) { function collectElements(sourceFile) { var elements = []; - function addOutlineRange(hintSpanNode, startElement, endElement) { + var collapseText = "..."; + function addOutliningSpan(hintSpanNode, startElement, endElement, autoCollapse) { if (hintSpanNode && startElement && endElement) { var span = { textSpan: TypeScript.TextSpan.fromBounds(startElement.pos, endElement.end), hintSpan: TypeScript.TextSpan.fromBounds(hintSpanNode.getStart(), hintSpanNode.end), - bannerText: "...", - autoCollapse: false + bannerText: collapseText, + autoCollapse: autoCollapse }; elements.push(span); } } + function autoCollapse(node) { + switch (node.kind) { + case 180 /* ModuleBlock */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + return false; + } + return true; + } var depth = 0; var maxDepth = 20; function walk(n) { @@ -26412,24 +27354,45 @@ var ts; return; } switch (n.kind) { - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 167 /* TryBlock */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: - var openBrace = ts.forEach(n.getChildren(), function (c) { return c.kind === 9 /* OpenBraceToken */ && c; }); - var closeBrace = ts.forEach(n.getChildren(), function (c) { return c.kind === 10 /* CloseBraceToken */ && c; }); - addOutlineRange(n.parent, openBrace, closeBrace); + case 150 /* Block */: + var parent = n.parent; + var openBrace = ts.findChildOfKind(n, 9 /* OpenBraceToken */, sourceFile); + var closeBrace = ts.findChildOfKind(n, 10 /* CloseBraceToken */, sourceFile); + if (parent.kind === 155 /* DoStatement */ || parent.kind === 158 /* ForInStatement */ || parent.kind === 157 /* ForStatement */ || parent.kind === 154 /* IfStatement */ || parent.kind === 156 /* WhileStatement */ || parent.kind === 162 /* WithStatement */) { + addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); + } + else { + var span = TypeScript.TextSpan.fromBounds(n.getStart(), n.end); + elements.push({ + textSpan: span, + hintSpan: span, + bannerText: collapseText, + autoCollapse: autoCollapse(n) + }); + } break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 133 /* ObjectLiteral */: - var openBrace = ts.forEach(n.getChildren(), function (c) { return c.kind === 9 /* OpenBraceToken */ && c; }); - var closeBrace = ts.forEach(n.getChildren(), function (c) { return c.kind === 10 /* CloseBraceToken */ && c; }); - addOutlineRange(n, openBrace, closeBrace); + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + var openBrace = ts.findChildOfKind(n, 9 /* OpenBraceToken */, sourceFile); + var closeBrace = ts.findChildOfKind(n, 10 /* CloseBraceToken */, sourceFile); + addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n)); + break; + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 135 /* ObjectLiteral */: + case 163 /* SwitchStatement */: + var openBrace = ts.findChildOfKind(n, 9 /* OpenBraceToken */, sourceFile); + var closeBrace = ts.findChildOfKind(n, 10 /* CloseBraceToken */, sourceFile); + addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n)); + break; + case 134 /* ArrayLiteral */: + var openBracket = ts.findChildOfKind(n, 13 /* OpenBracketToken */, sourceFile); + var closeBracket = ts.findChildOfKind(n, 14 /* CloseBracketToken */, sourceFile); + addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n)); break; } depth++; @@ -26442,96 +27405,117 @@ var ts; OutliningElementsCollector.collectElements = collectElements; })(OutliningElementsCollector = ts.OutliningElementsCollector || (ts.OutliningElementsCollector = {})); })(ts || (ts = {})); -var TypeScript; -(function (TypeScript) { - var Services; - (function (Services) { - var NavigationBarItemGetter = (function () { - function NavigationBarItemGetter() { - this.hasGlobalNode = false; - } - NavigationBarItemGetter.prototype.getIndent = function (node) { - var indent = this.hasGlobalNode ? 1 : 0; +var ts; +(function (ts) { + var NavigationBar; + (function (NavigationBar) { + function getNavigationBarItems(sourceFile) { + var hasGlobalNode = false; + return getItemsWorker(getTopLevelNodes(sourceFile), createTopLevelItem); + function getIndent(node) { + var indent = hasGlobalNode ? 1 : 0; var current = node.parent; - while (current != null) { - if (current.kind() == 131 /* ModuleDeclaration */ || current.kind() === 130 /* FunctionDeclaration */) { - indent++; + while (current) { + switch (current.kind) { + case 179 /* ModuleDeclaration */: + do { + current = current.parent; + } while (current.kind === 179 /* ModuleDeclaration */); + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: + case 177 /* InterfaceDeclaration */: + case 174 /* FunctionDeclaration */: + indent++; } current = current.parent; } return indent; - }; - NavigationBarItemGetter.prototype.getKindModifiers = function (modifiers) { - var result = []; - for (var i = 0, n = modifiers.length; i < n; i++) { - result.push(modifiers[i].text()); - } - return result.length > 0 ? result.join(',') : ts.ScriptElementKindModifier.none; - }; - NavigationBarItemGetter.prototype.getItems = function (node) { - var _this = this; - return this.getItemsWorker(function () { return _this.getTopLevelNodes(node); }, function (n) { return _this.createTopLevelItem(n); }); - }; - NavigationBarItemGetter.prototype.getChildNodes = function (nodes) { + } + function getChildNodes(nodes) { var childNodes = []; for (var i = 0, n = nodes.length; i < n; i++) { var node = nodes[i]; - if (node.kind() === 130 /* FunctionDeclaration */) { + if (node.kind === 176 /* ClassDeclaration */ || node.kind === 178 /* EnumDeclaration */ || node.kind === 177 /* InterfaceDeclaration */ || node.kind === 179 /* ModuleDeclaration */ || node.kind === 174 /* FunctionDeclaration */) { childNodes.push(node); } - else if (node.kind() === 149 /* VariableStatement */) { - var variableDeclaration = node.variableDeclaration; - childNodes.push.apply(childNodes, variableDeclaration.variableDeclarators); + else if (node.kind === 151 /* VariableStatement */) { + childNodes.push.apply(childNodes, node.declarations); } } - return childNodes; - }; - NavigationBarItemGetter.prototype.getTopLevelNodes = function (node) { + return sortNodes(childNodes); + } + function getTopLevelNodes(node) { var topLevelNodes = []; topLevelNodes.push(node); - this.addTopLevelNodes(node.moduleElements, topLevelNodes); + addTopLevelNodes(node.statements, topLevelNodes); return topLevelNodes; - }; - NavigationBarItemGetter.prototype.addTopLevelNodes = function (nodes, topLevelNodes) { + } + function sortNodes(nodes) { + return nodes.slice(0).sort(function (n1, n2) { + if (n1.name && n2.name) { + return n1.name.text.localeCompare(n2.name.text); + } + else if (n1.name) { + return 1; + } + else if (n2.name) { + -1; + } + else { + return n1.kind - n2.kind; + } + }); + } + function addTopLevelNodes(nodes, topLevelNodes) { + nodes = sortNodes(nodes); for (var i = 0, n = nodes.length; i < n; i++) { var node = nodes[i]; - switch (node.kind()) { - case 132 /* ClassDeclaration */: - case 133 /* EnumDeclaration */: - case 129 /* InterfaceDeclaration */: + switch (node.kind) { + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: + case 177 /* InterfaceDeclaration */: topLevelNodes.push(node); break; - case 131 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: var moduleDeclaration = node; topLevelNodes.push(node); - this.addTopLevelNodes(moduleDeclaration.moduleElements, topLevelNodes); + addTopLevelNodes(getInnermostModule(moduleDeclaration).body.statements, topLevelNodes); break; - case 130 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: var functionDeclaration = node; - if (this.isTopLevelFunctionDeclaration(functionDeclaration)) { + if (isTopLevelFunctionDeclaration(functionDeclaration)) { topLevelNodes.push(node); - this.addTopLevelNodes(functionDeclaration.block.statements, topLevelNodes); + addTopLevelNodes(functionDeclaration.body.statements, topLevelNodes); } break; } } - }; - NavigationBarItemGetter.prototype.isTopLevelFunctionDeclaration = function (functionDeclaration) { - return functionDeclaration.block && TypeScript.ArrayUtilities.any(functionDeclaration.block.statements, function (s) { return s.kind() === 130 /* FunctionDeclaration */; }); - }; - NavigationBarItemGetter.prototype.getItemsWorker = function (getNodes, createItem) { + } + function isTopLevelFunctionDeclaration(functionDeclaration) { + if (functionDeclaration.kind === 174 /* FunctionDeclaration */) { + if (functionDeclaration.body && functionDeclaration.body.kind === 175 /* FunctionBlock */) { + if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 174 /* FunctionDeclaration */ && !isEmpty(s.name.text); })) { + return true; + } + if (functionDeclaration.parent.kind !== 175 /* FunctionBlock */) { + return true; + } + } + } + return false; + } + function getItemsWorker(nodes, createItem) { var items = []; - var keyToItem = TypeScript.createIntrinsicsObject(); - var nodes = getNodes(); + var keyToItem = {}; for (var i = 0, n = nodes.length; i < n; i++) { var child = nodes[i]; var item = createItem(child); - if (item != null) { + if (item !== undefined) { if (item.text.length > 0) { - var key = item.text + "-" + item.kind; + var key = item.text + "-" + item.kind + "-" + item.indent; var itemWithSameName = keyToItem[key]; if (itemWithSameName) { - this.merge(itemWithSameName, item); + merge(itemWithSameName, item); } else { keyToItem[key] = item; @@ -26541,8 +27525,8 @@ var TypeScript; } } return items; - }; - NavigationBarItemGetter.prototype.merge = function (target, source) { + } + function merge(target, source) { target.spans.push.apply(target.spans, source.spans); if (source.childItems) { if (!target.childItems) { @@ -26553,206 +27537,154 @@ var TypeScript; for (var j = 0, m = target.childItems.length; j < m; j++) { var targetChild = target.childItems[j]; if (targetChild.text === sourceChild.text && targetChild.kind === sourceChild.kind) { - this.merge(targetChild, sourceChild); + merge(targetChild, sourceChild); continue outer; } } target.childItems.push(sourceChild); } } - }; - NavigationBarItemGetter.prototype.createChildItem = function (node) { - switch (node.kind()) { - case 243 /* Parameter */: - var parameter = node; - if (parameter.modifiers.length === 0) { - return null; - } - return new ts.NavigationBarItem(parameter.identifier.text(), ts.ScriptElementKind.memberVariableElement, this.getKindModifiers(parameter.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 136 /* MemberFunctionDeclaration */: - var memberFunction = node; - return new ts.NavigationBarItem(memberFunction.propertyName.text(), ts.ScriptElementKind.memberFunctionElement, this.getKindModifiers(memberFunction.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 140 /* GetAccessor */: - var getAccessor = node; - return new ts.NavigationBarItem(getAccessor.propertyName.text(), ts.ScriptElementKind.memberGetAccessorElement, this.getKindModifiers(getAccessor.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 141 /* SetAccessor */: - var setAccessor = node; - return new ts.NavigationBarItem(setAccessor.propertyName.text(), ts.ScriptElementKind.memberSetAccessorElement, this.getKindModifiers(setAccessor.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 145 /* IndexSignature */: - var indexSignature = node; - return new ts.NavigationBarItem("[]", ts.ScriptElementKind.indexSignatureElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 244 /* EnumElement */: - var enumElement = node; - return new ts.NavigationBarItem(enumElement.propertyName.text(), ts.ScriptElementKind.memberVariableElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 143 /* CallSignature */: - var callSignature = node; - return new ts.NavigationBarItem("()", ts.ScriptElementKind.callSignatureElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 144 /* ConstructSignature */: - var constructSignature = node; - return new ts.NavigationBarItem("new()", ts.ScriptElementKind.constructSignatureElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 146 /* MethodSignature */: - var methodSignature = node; - return new ts.NavigationBarItem(methodSignature.propertyName.text(), ts.ScriptElementKind.memberFunctionElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 142 /* PropertySignature */: - var propertySignature = node; - return new ts.NavigationBarItem(propertySignature.propertyName.text(), ts.ScriptElementKind.memberVariableElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 130 /* FunctionDeclaration */: - var functionDeclaration = node; - if (!this.isTopLevelFunctionDeclaration(functionDeclaration)) { - return new ts.NavigationBarItem(functionDeclaration.identifier.text(), ts.ScriptElementKind.functionElement, this.getKindModifiers(functionDeclaration.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - } - break; - case 137 /* MemberVariableDeclaration */: - var memberVariableDeclaration = node; - return new ts.NavigationBarItem(memberVariableDeclaration.variableDeclarator.propertyName.text(), ts.ScriptElementKind.memberVariableElement, this.getKindModifiers(memberVariableDeclaration.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(memberVariableDeclaration.variableDeclarator), TypeScript.end(memberVariableDeclaration.variableDeclarator))]); - case 226 /* VariableDeclarator */: - var variableDeclarator = node; - return new ts.NavigationBarItem(variableDeclarator.propertyName.text(), ts.ScriptElementKind.variableElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(variableDeclarator), TypeScript.end(variableDeclarator))]); - case 138 /* ConstructorDeclaration */: - var constructorDeclaration = node; - return new ts.NavigationBarItem("constructor", ts.ScriptElementKind.constructorImplementationElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - } - return null; - }; - NavigationBarItemGetter.prototype.createTopLevelItem = function (node) { - switch (node.kind()) { - case 120 /* SourceUnit */: - return this.createSourceUnitItem(node); - case 132 /* ClassDeclaration */: - return this.createClassItem(node); - case 133 /* EnumDeclaration */: - return this.createEnumItem(node); - case 129 /* InterfaceDeclaration */: - return this.createIterfaceItem(node); - case 131 /* ModuleDeclaration */: - return this.createModuleItem(node); - case 130 /* FunctionDeclaration */: - return this.createFunctionItem(node); - } - return null; - }; - NavigationBarItemGetter.prototype.getModuleNames = function (node) { - var result = []; - if (node.stringLiteral) { - result.push(node.stringLiteral.text()); - } - else { - this.getModuleNamesHelper(node.name, result); - } - return result; - }; - NavigationBarItemGetter.prototype.getModuleNamesHelper = function (name, result) { - if (name.kind() === 121 /* QualifiedName */) { - var qualifiedName = name; - this.getModuleNamesHelper(qualifiedName.left, result); - result.push(qualifiedName.right.text()); - } - else { - result.push(name.text()); - } - }; - NavigationBarItemGetter.prototype.createModuleItem = function (node) { - var _this = this; - var moduleNames = this.getModuleNames(node); - var childItems = this.getItemsWorker(function () { return _this.getChildNodes(node.moduleElements); }, function (n) { return _this.createChildItem(n); }); - return new ts.NavigationBarItem(moduleNames.join("."), ts.ScriptElementKind.moduleElement, this.getKindModifiers(node.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems, this.getIndent(node)); - }; - NavigationBarItemGetter.prototype.createFunctionItem = function (node) { - var _this = this; - var childItems = this.getItemsWorker(function () { return node.block.statements; }, function (n) { return _this.createChildItem(n); }); - return new ts.NavigationBarItem(node.identifier.text(), ts.ScriptElementKind.functionElement, this.getKindModifiers(node.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems, this.getIndent(node)); - }; - NavigationBarItemGetter.prototype.createSourceUnitItem = function (node) { - var _this = this; - var childItems = this.getItemsWorker(function () { return _this.getChildNodes(node.moduleElements); }, function (n) { return _this.createChildItem(n); }); - if (childItems === null || childItems.length === 0) { - return null; - } - this.hasGlobalNode = true; - return new ts.NavigationBarItem("", ts.ScriptElementKind.moduleElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems); - }; - NavigationBarItemGetter.prototype.createClassItem = function (node) { - var _this = this; - var constructor = TypeScript.ArrayUtilities.firstOrDefault(node.classElements, function (n) { return n.kind() === 138 /* ConstructorDeclaration */; }); - var nodes = constructor ? constructor.callSignature.parameterList.parameters.concat(node.classElements) : node.classElements; - var childItems = this.getItemsWorker(function () { return nodes; }, function (n) { return _this.createChildItem(n); }); - return new ts.NavigationBarItem(node.identifier.text(), ts.ScriptElementKind.classElement, this.getKindModifiers(node.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems, this.getIndent(node)); - }; - NavigationBarItemGetter.prototype.createEnumItem = function (node) { - var _this = this; - var childItems = this.getItemsWorker(function () { return node.enumElements; }, function (n) { return _this.createChildItem(n); }); - return new ts.NavigationBarItem(node.identifier.text(), ts.ScriptElementKind.enumElement, this.getKindModifiers(node.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems, this.getIndent(node)); - }; - NavigationBarItemGetter.prototype.createIterfaceItem = function (node) { - var _this = this; - var childItems = this.getItemsWorker(function () { return node.body.typeMembers; }, function (n) { return _this.createChildItem(n); }); - return new ts.NavigationBarItem(node.identifier.text(), ts.ScriptElementKind.interfaceElement, this.getKindModifiers(node.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems, this.getIndent(node)); - }; - return NavigationBarItemGetter; - })(); - Services.NavigationBarItemGetter = NavigationBarItemGetter; - })(Services = TypeScript.Services || (TypeScript.Services = {})); -})(TypeScript || (TypeScript = {})); -var TypeScript; -(function (TypeScript) { - var Services; - (function (Services) { - var BraceMatcher = (function () { - function BraceMatcher() { } - BraceMatcher.getMatchSpans = function (syntaxTree, position) { - var result = []; - var token = TypeScript.findToken(syntaxTree.sourceUnit(), position); - if (TypeScript.start(token) === position) { - var matchKind = BraceMatcher.getMatchingTokenKind(token); - if (matchKind !== null) { - var parentElement = token.parent; - for (var i = 0, n = TypeScript.childCount(parentElement); i < n; i++) { - var current = TypeScript.childAt(parentElement, i); - if (current !== null && TypeScript.fullWidth(current) > 0) { - if (current.kind() === matchKind) { - var range1 = new TypeScript.TextSpan(TypeScript.start(token), TypeScript.width(token)); - var range2 = new TypeScript.TextSpan(TypeScript.start(current), TypeScript.width(current)); - if (range1.start() < range2.start()) { - result.push(range1, range2); - } - else { - result.push(range2, range1); - } - break; - } - } + function createChildItem(node) { + switch (node.kind) { + case 118 /* Parameter */: + if ((node.flags & ts.NodeFlags.Modifier) === 0) { + return undefined; } + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 120 /* Method */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberFunctionElement); + case 122 /* GetAccessor */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberGetAccessorElement); + case 123 /* SetAccessor */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); + case 126 /* IndexSignature */: + return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); + case 183 /* EnumMember */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 124 /* CallSignature */: + return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); + case 125 /* ConstructSignature */: + return createItem(node, "new()", ts.ScriptElementKind.constructSignatureElement); + case 119 /* Property */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 174 /* FunctionDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.functionElement); + case 173 /* VariableDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.variableElement); + case 121 /* Constructor */: + return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); + } + return undefined; + function createItem(node, name, scriptElementKind) { + return getNavigationBarItem(name, scriptElementKind, ts.getNodeModifiers(node), [getNodeSpan(node)]); + } + } + function isEmpty(text) { + return !text || text.trim() === ""; + } + function getNavigationBarItem(text, kind, kindModifiers, spans, childItems, indent) { + if (childItems === void 0) { childItems = []; } + if (indent === void 0) { indent = 0; } + if (isEmpty(text)) { + return undefined; + } + return { + text: text, + kind: kind, + kindModifiers: kindModifiers, + spans: spans, + childItems: childItems, + indent: indent, + bolded: false, + grayed: false + }; + } + function createTopLevelItem(node) { + switch (node.kind) { + case 184 /* SourceFile */: + return createSourceFileItem(node); + case 176 /* ClassDeclaration */: + return createClassItem(node); + case 178 /* EnumDeclaration */: + return createEnumItem(node); + case 177 /* InterfaceDeclaration */: + return createIterfaceItem(node); + case 179 /* ModuleDeclaration */: + return createModuleItem(node); + case 174 /* FunctionDeclaration */: + return createFunctionItem(node); + } + return undefined; + function getModuleName(moduleDeclaration) { + if (moduleDeclaration.name.kind === 7 /* StringLiteral */) { + return getTextOfNode(moduleDeclaration.name); } + var result = []; + result.push(moduleDeclaration.name.text); + while (moduleDeclaration.body && moduleDeclaration.body.kind === 179 /* ModuleDeclaration */) { + moduleDeclaration = moduleDeclaration.body; + result.push(moduleDeclaration.name.text); + } + return result.join("."); } - return result; - }; - BraceMatcher.getMatchingTokenKind = function (token) { - switch (token.kind()) { - case 70 /* OpenBraceToken */: - return 71 /* CloseBraceToken */; - case 72 /* OpenParenToken */: - return 73 /* CloseParenToken */; - case 74 /* OpenBracketToken */: - return 75 /* CloseBracketToken */; - case 80 /* LessThanToken */: - return 81 /* GreaterThanToken */; - case 71 /* CloseBraceToken */: - return 70 /* OpenBraceToken */; - case 73 /* CloseParenToken */: - return 72 /* OpenParenToken */; - case 75 /* CloseBracketToken */: - return 74 /* OpenBracketToken */; - case 81 /* GreaterThanToken */: - return 80 /* LessThanToken */; + function createModuleItem(node) { + var moduleName = getModuleName(node); + var childItems = getItemsWorker(getChildNodes(getInnermostModule(node).body.statements), createChildItem); + return getNavigationBarItem(moduleName, ts.ScriptElementKind.moduleElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } - return null; - }; - return BraceMatcher; - })(); - Services.BraceMatcher = BraceMatcher; - })(Services = TypeScript.Services || (TypeScript.Services = {})); -})(TypeScript || (TypeScript = {})); + function createFunctionItem(node) { + if (node.name && node.body && node.body.kind === 175 /* FunctionBlock */) { + var childItems = getItemsWorker(sortNodes(node.body.statements), createChildItem); + return getNavigationBarItem(node.name.text, ts.ScriptElementKind.functionElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); + } + return undefined; + } + function createSourceFileItem(node) { + var childItems = getItemsWorker(getChildNodes(node.statements), createChildItem); + if (childItems === undefined || childItems.length === 0) { + return undefined; + } + hasGlobalNode = true; + var rootName = ts.isExternalModule(node) ? "\"" + ts.escapeString(ts.getBaseFilename(ts.removeFileExtension(ts.normalizePath(node.filename)))) + "\"" : ""; + return getNavigationBarItem(rootName, ts.ScriptElementKind.moduleElement, ts.ScriptElementKindModifier.none, [getNodeSpan(node)], childItems); + } + function createClassItem(node) { + var childItems; + if (node.members) { + var constructor = ts.forEach(node.members, function (member) { + return member.kind === 121 /* Constructor */ && member; + }); + var nodes = constructor ? constructor.parameters.concat(node.members) : node.members; + var childItems = getItemsWorker(sortNodes(nodes), createChildItem); + } + return getNavigationBarItem(node.name.text, ts.ScriptElementKind.classElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); + } + function createEnumItem(node) { + var childItems = getItemsWorker(sortNodes(node.members), createChildItem); + return getNavigationBarItem(node.name.text, ts.ScriptElementKind.enumElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); + } + function createIterfaceItem(node) { + var childItems = getItemsWorker(sortNodes(node.members), createChildItem); + return getNavigationBarItem(node.name.text, ts.ScriptElementKind.interfaceElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); + } + } + function getInnermostModule(node) { + while (node.body.kind === 179 /* ModuleDeclaration */) { + node = node.body; + } + return node; + } + function getNodeSpan(node) { + return node.kind === 184 /* SourceFile */ ? TypeScript.TextSpan.fromBounds(node.getFullStart(), node.getEnd()) : TypeScript.TextSpan.fromBounds(node.getStart(), node.getEnd()); + } + function getTextOfNode(node) { + return ts.getTextOfNodeFromSourceText(sourceFile.text, node); + } + } + NavigationBar.getNavigationBarItems = getNavigationBarItems; + })(NavigationBar = ts.NavigationBar || (ts.NavigationBar = {})); +})(ts || (ts = {})); var TypeScript; (function (TypeScript) { var Services; @@ -27741,6 +28673,353 @@ var TypeScript; Indentation.firstNonWhitespacePosition = firstNonWhitespacePosition; })(Indentation = TypeScript.Indentation || (TypeScript.Indentation = {})); })(TypeScript || (TypeScript = {})); +var ts; +(function (ts) { + var SignatureHelp; + (function (SignatureHelp) { + var emptyArray = []; + function getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken) { + var startingToken = ts.findTokenOnLeftOfPosition(sourceFile, position); + if (!startingToken) { + return undefined; + } + var argumentInfo = getContainingArgumentInfo(startingToken); + cancellationToken.throwIfCancellationRequested(); + if (!argumentInfo) { + return undefined; + } + var call = argumentInfo.list.parent; + var candidates = []; + var resolvedSignature = typeInfoResolver.getResolvedSignature(call, candidates); + cancellationToken.throwIfCancellationRequested(); + if (!candidates.length) { + return undefined; + } + return createSignatureHelpItems(candidates, resolvedSignature, argumentInfo); + function getImmediatelyContainingArgumentInfo(node) { + if (node.parent.kind !== 139 /* CallExpression */ && node.parent.kind !== 140 /* NewExpression */) { + return undefined; + } + var parent = node.parent; + if (node.kind === 19 /* LessThanToken */ || node.kind === 11 /* OpenParenToken */) { + var list = getChildListThatStartsWithOpenerToken(parent, node, sourceFile); + ts.Debug.assert(list); + return { + list: list, + listItemIndex: 0 + }; + } + if (node.kind === 20 /* GreaterThanToken */ || node.kind === 12 /* CloseParenToken */ || node === parent.func) { + return undefined; + } + return ts.findListItemInfo(node); + } + function getContainingArgumentInfo(node) { + for (var n = node; n.kind !== 184 /* SourceFile */; n = n.parent) { + if (n.kind === 175 /* FunctionBlock */) { + return undefined; + } + if (n.pos < n.parent.pos || n.end > n.parent.end) { + ts.Debug.fail("Node of kind " + ts.SyntaxKind[n.kind] + " is not a subspan of its parent of kind " + ts.SyntaxKind[n.parent.kind]); + } + var argumentInfo = getImmediatelyContainingArgumentInfo(n); + if (argumentInfo) { + return argumentInfo; + } + } + return undefined; + } + function getChildListThatStartsWithOpenerToken(parent, openerToken, sourceFile) { + var children = parent.getChildren(sourceFile); + var indexOfOpenerToken = children.indexOf(openerToken); + ts.Debug.assert(indexOfOpenerToken >= 0 && children.length > indexOfOpenerToken + 1); + return children[indexOfOpenerToken + 1]; + } + function selectBestInvalidOverloadIndex(candidates, argumentCount) { + var maxParamsSignatureIndex = -1; + var maxParams = -1; + for (var i = 0; i < candidates.length; i++) { + var candidate = candidates[i]; + if (candidate.hasRestParameter || candidate.parameters.length >= argumentCount) { + return i; + } + if (candidate.parameters.length > maxParams) { + maxParams = candidate.parameters.length; + maxParamsSignatureIndex = i; + } + } + return maxParamsSignatureIndex; + } + function createSignatureHelpItems(candidates, bestSignature, argumentInfoOrTypeArgumentInfo) { + var argumentListOrTypeArgumentList = argumentInfoOrTypeArgumentInfo.list; + var parent = argumentListOrTypeArgumentList.parent; + var isTypeParameterHelp = parent.typeArguments && parent.typeArguments.pos === argumentListOrTypeArgumentList.pos; + ts.Debug.assert(isTypeParameterHelp || parent.arguments.pos === argumentListOrTypeArgumentList.pos); + var callTargetNode = argumentListOrTypeArgumentList.parent.func; + var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTargetNode); + var callTargetDisplayParts = callTargetSymbol && ts.symbolToDisplayParts(typeInfoResolver, callTargetSymbol, undefined, undefined); + var items = ts.map(candidates, function (candidateSignature) { + var signatureHelpParameters; + var prefixParts = []; + var suffixParts = []; + if (callTargetDisplayParts) { + prefixParts.push.apply(prefixParts, callTargetDisplayParts); + } + if (isTypeParameterHelp) { + prefixParts.push(ts.punctuationPart(19 /* LessThanToken */)); + var typeParameters = candidateSignature.typeParameters; + signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; + suffixParts.push(ts.punctuationPart(20 /* GreaterThanToken */)); + var parameterParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, argumentListOrTypeArgumentList); }); + suffixParts.push.apply(suffixParts, parameterParts); + } + else { + var typeParameterParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, argumentListOrTypeArgumentList); }); + prefixParts.push.apply(prefixParts, typeParameterParts); + prefixParts.push(ts.punctuationPart(11 /* OpenParenToken */)); + var parameters = candidateSignature.parameters; + signatureHelpParameters = parameters.length > 0 ? ts.map(parameters, createSignatureHelpParameterForParameter) : emptyArray; + suffixParts.push(ts.punctuationPart(12 /* CloseParenToken */)); + } + var returnTypeParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, argumentListOrTypeArgumentList); }); + suffixParts.push.apply(suffixParts, returnTypeParts); + return { + isVariadic: candidateSignature.hasRestParameter, + prefixDisplayParts: prefixParts, + suffixDisplayParts: suffixParts, + separatorDisplayParts: [ts.punctuationPart(18 /* CommaToken */), ts.spacePart()], + parameters: signatureHelpParameters, + documentation: candidateSignature.getDocumentationComment() + }; + }); + var applicableSpanStart = argumentListOrTypeArgumentList.getFullStart(); + var applicableSpanEnd = ts.skipTrivia(sourceFile.text, argumentListOrTypeArgumentList.end, false); + var applicableSpan = new TypeScript.TextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart); + var argumentIndex = (argumentInfoOrTypeArgumentInfo.listItemIndex + 1) >> 1; + var argumentCount = argumentListOrTypeArgumentList.getChildCount() === 0 ? 0 : 1 + ts.countWhere(argumentListOrTypeArgumentList.getChildren(), function (arg) { return arg.kind === 18 /* CommaToken */; }); + var selectedItemIndex = candidates.indexOf(bestSignature); + if (selectedItemIndex < 0) { + selectedItemIndex = selectBestInvalidOverloadIndex(candidates, argumentCount); + } + return { + items: items, + applicableSpan: applicableSpan, + selectedItemIndex: selectedItemIndex, + argumentIndex: argumentIndex, + argumentCount: argumentCount + }; + function createSignatureHelpParameterForParameter(parameter) { + var displayParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, argumentListOrTypeArgumentList); }); + var isOptional = !!(parameter.valueDeclaration.flags & 4 /* QuestionMark */); + return { + name: parameter.name, + documentation: parameter.getDocumentationComment(), + displayParts: displayParts, + isOptional: isOptional + }; + } + function createSignatureHelpParameterForTypeParameter(typeParameter) { + var displayParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, argumentListOrTypeArgumentList); }); + return { + name: typeParameter.symbol.name, + documentation: emptyArray, + displayParts: displayParts, + isOptional: false + }; + } + } + } + SignatureHelp.getSignatureHelpItems = getSignatureHelpItems; + })(SignatureHelp = ts.SignatureHelp || (ts.SignatureHelp = {})); +})(ts || (ts = {})); +var ts; +(function (ts) { + function findListItemInfo(node) { + var syntaxList = findContainingList(node); + var children = syntaxList.getChildren(); + var index = ts.indexOf(children, node); + return { + listItemIndex: index, + list: syntaxList + }; + } + ts.findListItemInfo = findListItemInfo; + function findChildOfKind(n, kind, sourceFile) { + return ts.forEach(n.getChildren(sourceFile), function (c) { return c.kind === kind && c; }); + } + ts.findChildOfKind = findChildOfKind; + function findContainingList(node) { + var syntaxList = ts.forEach(node.parent.getChildren(), function (c) { + if (c.kind === 186 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { + return c; + } + }); + if (!syntaxList) { + ts.Debug.assert(findChildOfKind(node.parent, 186 /* SyntaxList */), "Node of kind " + ts.SyntaxKind[node.parent.kind] + " has no list children"); + } + return syntaxList; + } + ts.findContainingList = findContainingList; + function findListItemIndexContainingPosition(list, position) { + ts.Debug.assert(list.kind === 186 /* SyntaxList */); + var children = list.getChildren(); + for (var i = 0; i < children.length; i++) { + if (children[i].pos <= position && children[i].end > position) { + return i; + } + } + return -1; + } + ts.findListItemIndexContainingPosition = findListItemIndexContainingPosition; + function getTouchingWord(sourceFile, position) { + return getTouchingToken(sourceFile, position, isWord); + } + ts.getTouchingWord = getTouchingWord; + function getTouchingPropertyName(sourceFile, position) { + return getTouchingToken(sourceFile, position, isPropertyName); + } + ts.getTouchingPropertyName = getTouchingPropertyName; + function getTouchingToken(sourceFile, position, includeItemAtEndPosition) { + return getTokenAtPositionWorker(sourceFile, position, false, includeItemAtEndPosition); + } + ts.getTouchingToken = getTouchingToken; + function getTokenAtPosition(sourceFile, position) { + return getTokenAtPositionWorker(sourceFile, position, true, undefined); + } + ts.getTokenAtPosition = getTokenAtPosition; + function getTokenAtPositionWorker(sourceFile, position, allowPositionInLeadingTrivia, includeItemAtEndPosition) { + var current = sourceFile; + outer: while (true) { + if (isToken(current)) { + return current; + } + for (var i = 0, n = current.getChildCount(sourceFile); i < n; i++) { + var child = current.getChildAt(i); + var start = allowPositionInLeadingTrivia ? child.getFullStart() : child.getStart(sourceFile); + if (start <= position) { + if (position < child.getEnd()) { + current = child; + continue outer; + } + else if (includeItemAtEndPosition && child.getEnd() === position) { + var previousToken = findPrecedingToken(position, sourceFile, child); + if (previousToken && includeItemAtEndPosition(previousToken)) { + return previousToken; + } + } + } + } + return current; + } + } + function findTokenOnLeftOfPosition(file, position) { + var tokenAtPosition = getTokenAtPosition(file, position); + if (isToken(tokenAtPosition) && position > tokenAtPosition.getStart(file) && position < tokenAtPosition.getEnd()) { + return tokenAtPosition; + } + return findPrecedingToken(position, file); + } + ts.findTokenOnLeftOfPosition = findTokenOnLeftOfPosition; + function findNextToken(previousToken, parent) { + return find(parent); + function find(n) { + if (isToken(n) && n.pos === previousToken.end) { + return n; + } + var children = n.getChildren(); + for (var i = 0, len = children.length; i < len; ++i) { + var child = children[i]; + var shouldDiveInChildNode = (child.pos <= previousToken.pos && child.end > previousToken.end) || (child.pos === previousToken.end); + if (shouldDiveInChildNode && nodeHasTokens(child)) { + return find(child); + } + } + return undefined; + } + } + ts.findNextToken = findNextToken; + function findPrecedingToken(position, sourceFile, startNode) { + return find(startNode || sourceFile); + function findRightmostToken(n) { + if (isToken(n)) { + return n; + } + var children = n.getChildren(); + var candidate = findRightmostChildNodeWithTokens(children, children.length); + return candidate && findRightmostToken(candidate); + } + function find(n) { + if (isToken(n)) { + return n; + } + var children = n.getChildren(); + for (var i = 0, len = children.length; i < len; ++i) { + var child = children[i]; + if (nodeHasTokens(child)) { + if (position < child.end) { + if (child.getStart(sourceFile) >= position) { + var candidate = findRightmostChildNodeWithTokens(children, i); + return candidate && findRightmostToken(candidate); + } + else { + return find(child); + } + } + } + } + ts.Debug.assert(startNode || n.kind === 184 /* SourceFile */); + if (children.length) { + var candidate = findRightmostChildNodeWithTokens(children, children.length); + return candidate && findRightmostToken(candidate); + } + } + function findRightmostChildNodeWithTokens(children, exclusiveStartPosition) { + for (var i = exclusiveStartPosition - 1; i >= 0; --i) { + if (nodeHasTokens(children[i])) { + return children[i]; + } + } + } + } + ts.findPrecedingToken = findPrecedingToken; + function nodeHasTokens(n) { + if (n.kind === 153 /* ExpressionStatement */) { + return nodeHasTokens(n.expression); + } + if (n.kind === 1 /* EndOfFileToken */ || n.kind === 149 /* OmittedExpression */ || n.kind === 115 /* Missing */) { + return false; + } + return n.kind !== 186 /* SyntaxList */ || n.getChildCount() !== 0; + } + function getTypeArgumentOrTypeParameterList(node) { + if (node.kind === 127 /* TypeReference */ || node.kind === 139 /* CallExpression */) { + return node.typeArguments; + } + if (ts.isAnyFunction(node) || node.kind === 176 /* ClassDeclaration */ || node.kind === 177 /* InterfaceDeclaration */) { + return node.typeParameters; + } + return undefined; + } + ts.getTypeArgumentOrTypeParameterList = getTypeArgumentOrTypeParameterList; + function isToken(n) { + return n.kind >= ts.SyntaxKind.FirstToken && n.kind <= ts.SyntaxKind.LastToken; + } + ts.isToken = isToken; + function isWord(n) { + return n.kind === 59 /* Identifier */ || ts.isKeyword(n.kind); + } + function isPropertyName(n) { + return n.kind === 7 /* StringLiteral */ || n.kind === 6 /* NumericLiteral */ || isWord(n); + } + function isComment(n) { + return n.kind === 2 /* SingleLineCommentTrivia */ || n.kind === 3 /* MultiLineCommentTrivia */; + } + ts.isComment = isComment; + function isPunctuation(n) { + return ts.SyntaxKind.FirstPunctuation <= n.kind && n.kind <= ts.SyntaxKind.LastPunctuation; + } + ts.isPunctuation = isPunctuation; +})(ts || (ts = {})); var TypeScript; (function (TypeScript) { var Services; @@ -28027,8 +29306,10 @@ var TypeScript; var result = []; var formattingEdits = Formatting.Formatter.getEdits(span, this.syntaxTree.sourceUnit(), this.options, true, this.snapshot, this.rulesProvider, formattingRequestKind); formattingEdits.forEach(function (item) { - var edit = new ts.TextChange(new TypeScript.TextSpan(item.position, item.length), item.replaceWith); - result.push(edit); + result.push({ + span: new TypeScript.TextSpan(item.position, item.length), + newText: item.replaceWith + }); }); return result; }; @@ -29632,7 +30913,7 @@ var ts; if (position > sourceFile.text.length) { return 0; } - var precedingToken = findPrecedingToken(position, sourceFile); + var precedingToken = ts.findPrecedingToken(position, sourceFile); if (!precedingToken) { return 0; } @@ -29640,7 +30921,7 @@ var ts; return 0; } var lineAtPosition = sourceFile.getLineAndCharacterFromPosition(position).line; - if (precedingToken.kind === 18 /* CommaToken */ && precedingToken.parent.kind !== 145 /* BinaryExpression */) { + if (precedingToken.kind === 18 /* CommaToken */ && precedingToken.parent.kind !== 147 /* BinaryExpression */) { var actualIndentation = getActualIndentationForListItemBeforeComma(precedingToken, sourceFile, options); if (actualIndentation !== -1) { return actualIndentation; @@ -29695,18 +30976,19 @@ var ts; } SmartIndenter.getIndentation = getIndentation; function getActualIndentationForListItemBeforeComma(commaToken, sourceFile, options) { - var itemInfo = findPrecedingListItem(commaToken); - return deriveActualIndentationFromList(itemInfo.list.getChildren(), itemInfo.listItemIndex, sourceFile, options); + var commaItemInfo = ts.findListItemInfo(commaToken); + ts.Debug.assert(commaItemInfo.listItemIndex > 0); + return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options); } function getActualIndentationForNode(current, parent, currentLineAndChar, parentAndChildShareLine, sourceFile, options) { - var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && (parent.kind === 182 /* SourceFile */ || !parentAndChildShareLine); + var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && (parent.kind === 184 /* SourceFile */ || !parentAndChildShareLine); if (!useActualIndentation) { return -1; } return findColumnForFirstNonWhitespaceCharacterInLine(currentLineAndChar, sourceFile, options); } function nextTokenIsCurlyBraceOnSameLineAsCursor(precedingToken, current, lineAtPosition, sourceFile) { - var nextToken = findNextToken(precedingToken, current); + var nextToken = ts.findNextToken(precedingToken, current); if (!nextToken) { return false; } @@ -29722,27 +31004,12 @@ var ts; function getStartLineAndCharacterForNode(n, sourceFile) { return sourceFile.getLineAndCharacterFromPosition(n.getStart(sourceFile)); } - function findPrecedingListItem(commaToken) { - var syntaxList = ts.forEach(commaToken.parent.getChildren(), function (c) { - if (c.kind == 184 /* SyntaxList */ && c.pos <= commaToken.end && c.end >= commaToken.end) { - return c; - } - }); - ts.Debug.assert(syntaxList); - var children = syntaxList.getChildren(); - var commaIndex = ts.indexOf(children, commaToken); - ts.Debug.assert(commaIndex !== -1 && commaIndex !== 0); - return { - listItemIndex: commaIndex - 1, - list: syntaxList - }; - } function positionBelongsToNode(candidate, position, sourceFile) { return candidate.end > position || !isCompletedNode(candidate, sourceFile); } function childStartsOnTheSameLineWithElseInIfStatement(parent, child, childStartLine, sourceFile) { - if (parent.kind === 152 /* IfStatement */ && parent.elseStatement === child) { - var elseKeyword = ts.forEach(parent.getChildren(), function (c) { return c.kind === 70 /* ElseKeyword */ && c; }); + if (parent.kind === 154 /* IfStatement */ && parent.elseStatement === child) { + var elseKeyword = ts.findChildOfKind(parent, 70 /* ElseKeyword */, sourceFile); ts.Debug.assert(elseKeyword); var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line; return elseKeywordStartLine === childStartLine; @@ -29756,15 +31023,15 @@ var ts; return getActualIndentationFromList(node.parent.typeArguments); } break; - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return getActualIndentationFromList(node.parent.properties); case 129 /* TypeLiteral */: return getActualIndentationFromList(node.parent.members); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return getActualIndentationFromList(node.parent.elements); - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: case 120 /* Method */: case 124 /* CallSignature */: case 125 /* ConstructSignature */: @@ -29772,8 +31039,8 @@ var ts; return getActualIndentationFromList(node.parent.typeParameters); } return getActualIndentationFromList(node.parent.parameters); - case 138 /* NewExpression */: - case 137 /* CallExpression */: + case 140 /* NewExpression */: + case 139 /* CallExpression */: if (node.parent.typeArguments && node.end < node.parent.typeArguments.end) { return getActualIndentationFromList(node.parent.typeArguments); } @@ -29819,119 +31086,47 @@ var ts; } return column; } - function findNextToken(previousToken, parent) { - return find(parent); - function find(n) { - if (isToken(n) && n.pos === previousToken.end) { - return n; - } - var children = n.getChildren(); - for (var i = 0, len = children.length; i < len; ++i) { - var child = children[i]; - var shouldDiveInChildNode = (child.pos <= previousToken.pos && child.end > previousToken.end) || (child.pos === previousToken.end); - if (shouldDiveInChildNode && nodeHasTokens(child)) { - return find(child); - } - } - return undefined; - } - } - function findPrecedingToken(position, sourceFile) { - return find(sourceFile); - function findRightmostToken(n) { - if (isToken(n)) { - return n; - } - var children = n.getChildren(); - var candidate = findRightmostChildNodeWithTokens(children, children.length); - return candidate && findRightmostToken(candidate); - } - function find(n) { - if (isToken(n)) { - return n; - } - var children = n.getChildren(); - for (var i = 0, len = children.length; i < len; ++i) { - var child = children[i]; - if (nodeHasTokens(child)) { - if (position < child.end) { - if (child.getStart(sourceFile) >= position) { - var candidate = findRightmostChildNodeWithTokens(children, i); - return candidate && findRightmostToken(candidate); - } - else { - return find(child); - } - } - } - } - ts.Debug.assert(n.kind === 182 /* SourceFile */); - if (children.length) { - var candidate = findRightmostChildNodeWithTokens(children, children.length); - return candidate && findRightmostToken(candidate); - } - } - function findRightmostChildNodeWithTokens(children, exclusiveStartPosition) { - for (var i = exclusiveStartPosition - 1; i >= 0; --i) { - if (nodeHasTokens(children[i])) { - return children[i]; - } - } - } - } - function nodeHasTokens(n) { - if (n.kind === 151 /* ExpressionStatement */) { - return nodeHasTokens(n.expression); - } - if (n.kind === 1 /* EndOfFileToken */ || n.kind === 147 /* OmittedExpression */ || n.kind === 115 /* Missing */) { - return false; - } - return n.kind !== 184 /* SyntaxList */ || n.getChildCount() !== 0; - } - function isToken(n) { - return n.kind >= ts.SyntaxKind.FirstToken && n.kind <= ts.SyntaxKind.LastToken; - } function nodeContentIsIndented(parent, child) { switch (parent.kind) { - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: return true; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return false; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: - case 141 /* FunctionExpression */: + case 143 /* FunctionExpression */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: case 121 /* Constructor */: return false; - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 156 /* ForInStatement */: - case 155 /* ForStatement */: - return child && child.kind !== 148 /* Block */; - case 152 /* IfStatement */: - return child && child.kind !== 148 /* Block */; - case 166 /* TryStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 158 /* ForInStatement */: + case 157 /* ForStatement */: + return child && child.kind !== 150 /* Block */; + case 154 /* IfStatement */: + return child && child.kind !== 150 /* Block */; + case 168 /* TryStatement */: return false; - case 132 /* ArrayLiteral */: - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: - case 178 /* ModuleBlock */: - case 133 /* ObjectLiteral */: + case 134 /* ArrayLiteral */: + case 150 /* Block */: + case 175 /* FunctionBlock */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + case 180 /* ModuleBlock */: + case 135 /* ObjectLiteral */: case 129 /* TypeLiteral */: - case 161 /* SwitchStatement */: - case 163 /* DefaultClause */: - case 162 /* CaseClause */: - case 140 /* ParenExpression */: - case 137 /* CallExpression */: - case 138 /* NewExpression */: - case 149 /* VariableStatement */: - case 171 /* VariableDeclaration */: + case 163 /* SwitchStatement */: + case 165 /* DefaultClause */: + case 164 /* CaseClause */: + case 142 /* ParenExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 151 /* VariableStatement */: + case 173 /* VariableDeclaration */: return true; default: return false; @@ -29952,47 +31147,47 @@ var ts; } function isCompletedNode(n, sourceFile) { switch (n.kind) { - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 133 /* ObjectLiteral */: - case 148 /* Block */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 161 /* SwitchStatement */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 135 /* ObjectLiteral */: + case 150 /* Block */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 163 /* SwitchStatement */: return nodeEndsWith(n, 10 /* CloseBraceToken */, sourceFile); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: case 124 /* CallSignature */: - case 137 /* CallExpression */: + case 139 /* CallExpression */: case 125 /* ConstructSignature */: return nodeEndsWith(n, 12 /* CloseParenToken */, sourceFile); - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: case 120 /* Method */: - case 142 /* ArrowFunction */: + case 144 /* ArrowFunction */: return !n.body || isCompletedNode(n.body, sourceFile); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return n.body && isCompletedNode(n.body, sourceFile); - case 152 /* IfStatement */: + case 154 /* IfStatement */: if (n.elseStatement) { return isCompletedNode(n.elseStatement, sourceFile); } return isCompletedNode(n.thenStatement, sourceFile); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return isCompletedNode(n.expression, sourceFile); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return nodeEndsWith(n, 14 /* CloseBracketToken */, sourceFile); case 115 /* Missing */: return false; - case 162 /* CaseClause */: - case 163 /* DefaultClause */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: return false; - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return isCompletedNode(n.statement, sourceFile); - case 153 /* DoStatement */: - var hasWhileKeyword = ts.forEach(n.getChildren(), function (c) { return c.kind === 94 /* WhileKeyword */ && c; }); + case 155 /* DoStatement */: + var hasWhileKeyword = ts.findChildOfKind(n, 94 /* WhileKeyword */, sourceFile); if (hasWhileKeyword) { return nodeEndsWith(n, 12 /* CloseParenToken */, sourceFile); } @@ -31236,98 +32431,6 @@ var TypeScript; })(ASTHelpers = TypeScript.ASTHelpers || (TypeScript.ASTHelpers = {})); })(TypeScript || (TypeScript = {})); var TypeScript; -(function (TypeScript) { - var MemberName = (function () { - function MemberName() { - this.prefix = ""; - this.suffix = ""; - } - MemberName.prototype.isString = function () { - return false; - }; - MemberName.prototype.isArray = function () { - return false; - }; - MemberName.prototype.isMarker = function () { - return !this.isString() && !this.isArray(); - }; - MemberName.prototype.toString = function () { - return MemberName.memberNameToString(this); - }; - MemberName.memberNameToString = function (memberName, markerInfo, markerBaseLength) { - if (markerBaseLength === void 0) { markerBaseLength = 0; } - var result = memberName.prefix; - if (memberName.isString()) { - result += memberName.text; - } - else if (memberName.isArray()) { - var ar = memberName; - for (var index = 0; index < ar.entries.length; index++) { - if (ar.entries[index].isMarker()) { - if (markerInfo) { - markerInfo.push(markerBaseLength + result.length); - } - continue; - } - result += MemberName.memberNameToString(ar.entries[index], markerInfo, markerBaseLength + result.length); - result += ar.delim; - } - } - result += memberName.suffix; - return result; - }; - MemberName.create = function (arg1, arg2, arg3) { - if (typeof arg1 === "string") { - return new MemberNameString(arg1); - } - else { - var result = new MemberNameArray(); - if (arg2) - result.prefix = arg2; - if (arg3) - result.suffix = arg3; - result.entries.push(arg1); - return result; - } - }; - return MemberName; - })(); - TypeScript.MemberName = MemberName; - var MemberNameString = (function (_super) { - __extends(MemberNameString, _super); - function MemberNameString(text) { - _super.call(this); - this.text = text; - } - MemberNameString.prototype.isString = function () { - return true; - }; - return MemberNameString; - })(MemberName); - TypeScript.MemberNameString = MemberNameString; - var MemberNameArray = (function (_super) { - __extends(MemberNameArray, _super); - function MemberNameArray() { - _super.call(this); - this.delim = ""; - this.entries = []; - } - MemberNameArray.prototype.isArray = function () { - return true; - }; - MemberNameArray.prototype.add = function (entry) { - this.entries.push(entry); - }; - MemberNameArray.prototype.addAll = function (entries) { - for (var i = 0; i < entries.length; i++) { - this.entries.push(entries[i]); - } - }; - return MemberNameArray; - })(MemberName); - TypeScript.MemberNameArray = MemberNameArray; -})(TypeScript || (TypeScript = {})); -var TypeScript; (function (TypeScript) { function stripStartAndEndQuotes(str) { var firstCharCode = str && str.charCodeAt(0); @@ -31506,10 +32609,7 @@ var ts; function NodeObject() { } NodeObject.prototype.getSourceFile = function () { - var node = this; - while (node.kind !== 182 /* SourceFile */) - node = node.parent; - return node; + return ts.getSourceFileOfNode(this); }; NodeObject.prototype.getStart = function (sourceFile) { return ts.getTokenPosOfNode(this, sourceFile); @@ -31543,7 +32643,7 @@ var ts; return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(184 /* SyntaxList */, nodes.pos, nodes.end, 512 /* Synthetic */, this); + var list = createNode(186 /* SyntaxList */, nodes.pos, nodes.end, 512 /* Synthetic */, this); list._children = []; var pos = nodes.pos; for (var i = 0, len = nodes.length; i < len; i++) { @@ -31603,7 +32703,7 @@ var ts; return this._children; }; NodeObject.prototype.getFirstToken = function (sourceFile) { - var children = this.getChildren(sourceFile); + var children = this.getChildren(); for (var i = 0; i < children.length; i++) { var child = children[i]; if (child.kind < 115 /* Missing */) @@ -31638,8 +32738,225 @@ var ts; SymbolObject.prototype.getDeclarations = function () { return this.declarations; }; + SymbolObject.prototype.getDocumentationComment = function () { + if (this.documentationComment === undefined) { + this.documentationComment = getJsDocCommentsFromDeclarations(this.declarations, this.name, !(this.flags & 2 /* Property */)); + } + return this.documentationComment; + }; return SymbolObject; })(); + function getJsDocCommentsFromDeclarations(declarations, name, canUseParsedParamTagComments) { + var documentationComment = []; + var docComments = getJsDocCommentsSeparatedByNewLines(); + ts.forEach(docComments, function (docComment) { + if (documentationComment.length) { + documentationComment.push(lineBreakPart()); + } + documentationComment.push(docComment); + }); + return documentationComment; + function getJsDocCommentsSeparatedByNewLines() { + var paramTag = "@param"; + var jsDocCommentParts = []; + ts.forEach(declarations, function (declaration) { + var sourceFileOfDeclaration = ts.getSourceFileOfNode(declaration); + if (canUseParsedParamTagComments && declaration.kind === 118 /* Parameter */) { + ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), function (jsDocCommentTextRange) { + var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); + if (cleanedParamJsDocComment) { + jsDocCommentParts.push.apply(jsDocCommentParts, cleanedParamJsDocComment); + } + }); + } + if (declaration.kind === 179 /* ModuleDeclaration */ && declaration.body.kind === 179 /* ModuleDeclaration */) { + return; + } + while (declaration.kind === 179 /* ModuleDeclaration */ && declaration.parent.kind === 179 /* ModuleDeclaration */) { + declaration = declaration.parent; + } + ts.forEach(getJsDocCommentTextRange(declaration.kind === 173 /* VariableDeclaration */ ? declaration.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { + var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); + if (cleanedJsDocComment) { + jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment); + } + }); + }); + return jsDocCommentParts; + function getJsDocCommentTextRange(node, sourceFile) { + return ts.map(ts.getJsDocComments(node, sourceFile), function (jsDocComment) { + return { + pos: jsDocComment.pos + "/*".length, + end: jsDocComment.end - "*/".length + }; + }); + } + function consumeWhiteSpacesOnTheLine(pos, end, sourceFile, maxSpacesToRemove) { + if (maxSpacesToRemove !== undefined) { + end = Math.min(end, pos + maxSpacesToRemove); + } + for (; pos < end; pos++) { + var ch = sourceFile.text.charCodeAt(pos); + if (!ts.isWhiteSpace(ch) || ts.isLineBreak(ch)) { + return pos; + } + } + return end; + } + function consumeLineBreaks(pos, end, sourceFile) { + while (pos < end && ts.isLineBreak(sourceFile.text.charCodeAt(pos))) { + pos++; + } + return pos; + } + function isName(pos, end, sourceFile, name) { + return pos + name.length < end && sourceFile.text.substr(pos, name.length) === name && ts.isWhiteSpace(sourceFile.text.charCodeAt(pos + name.length)); + } + function isParamTag(pos, end, sourceFile) { + return isName(pos, end, sourceFile, paramTag); + } + function getCleanedJsDocComment(pos, end, sourceFile) { + var spacesToRemoveAfterAsterisk; + var docComments = []; + var isInParamTag = false; + while (pos < end) { + var docCommentTextOfLine = ""; + pos = consumeWhiteSpacesOnTheLine(pos, end, sourceFile); + if (pos < end && sourceFile.text.charCodeAt(pos) === 42 /* asterisk */) { + var lineStartPos = pos + 1; + pos = consumeWhiteSpacesOnTheLine(pos + 1, end, sourceFile, spacesToRemoveAfterAsterisk); + if (spacesToRemoveAfterAsterisk === undefined && pos < end && !ts.isLineBreak(sourceFile.text.charCodeAt(pos))) { + spacesToRemoveAfterAsterisk = pos - lineStartPos; + } + } + else if (spacesToRemoveAfterAsterisk === undefined) { + spacesToRemoveAfterAsterisk = 0; + } + while (pos < end && !ts.isLineBreak(sourceFile.text.charCodeAt(pos))) { + var ch = sourceFile.text.charAt(pos); + if (ch === "@") { + if (isParamTag(pos, end, sourceFile)) { + isInParamTag = true; + pos += paramTag.length; + continue; + } + else { + isInParamTag = false; + } + } + if (!isInParamTag) { + docCommentTextOfLine += ch; + } + pos++; + } + pos = consumeLineBreaks(pos, end, sourceFile); + if (docCommentTextOfLine) { + docComments.push(textPart(docCommentTextOfLine)); + } + } + return docComments; + } + function getCleanedParamJsDocComment(pos, end, sourceFile) { + var paramHelpStringMargin; + var paramDocComments = []; + while (pos < end) { + if (isParamTag(pos, end, sourceFile)) { + pos = consumeWhiteSpaces(pos + paramTag.length); + if (pos >= end) { + break; + } + if (sourceFile.text.charCodeAt(pos) === 123 /* openBrace */) { + pos++; + for (var curlies = 1; pos < end; pos++) { + var charCode = sourceFile.text.charCodeAt(pos); + if (charCode === 123 /* openBrace */) { + curlies++; + continue; + } + if (charCode === 125 /* closeBrace */) { + curlies--; + if (curlies === 0) { + pos++; + break; + } + else { + continue; + } + } + if (charCode === 64 /* at */) { + break; + } + } + pos = consumeWhiteSpaces(pos); + if (pos >= end) { + break; + } + } + if (isName(pos, end, sourceFile, name)) { + pos = consumeWhiteSpaces(pos + name.length); + if (pos >= end) { + break; + } + var paramHelpString = ""; + var firstLineParamHelpStringPos = pos; + while (pos < end) { + var ch = sourceFile.text.charCodeAt(pos); + if (ts.isLineBreak(ch)) { + if (paramHelpString) { + paramDocComments.push(textPart(paramHelpString)); + paramHelpString = ""; + } + setPosForParamHelpStringOnNextLine(firstLineParamHelpStringPos); + continue; + } + if (ch === 64 /* at */) { + break; + } + paramHelpString += sourceFile.text.charAt(pos); + pos++; + } + if (paramHelpString) { + paramDocComments.push(textPart(paramHelpString)); + } + paramHelpStringMargin = undefined; + } + if (sourceFile.text.charCodeAt(pos) === 64 /* at */) { + continue; + } + } + pos++; + } + return paramDocComments; + function consumeWhiteSpaces(pos) { + while (pos < end && ts.isWhiteSpace(sourceFile.text.charCodeAt(pos))) { + pos++; + } + return pos; + } + function setPosForParamHelpStringOnNextLine(firstLineParamHelpStringPos) { + pos = consumeLineBreaks(pos, end, sourceFile); + if (pos >= end) { + return; + } + if (paramHelpStringMargin === undefined) { + paramHelpStringMargin = sourceFile.getLineAndCharacterFromPosition(firstLineParamHelpStringPos).character - 1; + } + var startOfLinePos = pos; + pos = consumeWhiteSpacesOnTheLine(pos, end, sourceFile, paramHelpStringMargin); + if (pos >= end) { + return; + } + var consumedSpaces = pos - startOfLinePos; + if (consumedSpaces < paramHelpStringMargin) { + var ch = sourceFile.text.charCodeAt(pos); + if (ch === 42 /* asterisk */) { + pos = consumeWhiteSpacesOnTheLine(pos + 1, end, sourceFile, paramHelpStringMargin - consumedSpaces - 1); + } + } + } + } + } + } var TypeObject = (function () { function TypeObject(checker, flags) { this.checker = checker; @@ -31658,7 +32975,7 @@ var ts; return this.checker.getPropertyOfType(this, propertyName); }; TypeObject.prototype.getApparentProperties = function () { - return this.checker.getAugmentedPropertiesOfApparentType(this); + return this.checker.getAugmentedPropertiesOfType(this); }; TypeObject.prototype.getCallSignatures = function () { return this.checker.getSignaturesOfType(this, 0 /* Call */); @@ -31690,6 +33007,12 @@ var ts; SignatureObject.prototype.getReturnType = function () { return this.checker.getReturnTypeOfSignature(this); }; + SignatureObject.prototype.getDocumentationComment = function () { + if (this.documentationComment === undefined) { + this.documentationComment = this.declaration ? getJsDocCommentsFromDeclarations([this.declaration], this.declaration.name ? this.declaration.name.text : "", false) : []; + } + return this.documentationComment; + }; return SignatureObject; })(); var incrementalParse = TypeScript.IncrementalParser.parse; @@ -31717,41 +33040,51 @@ var ts; if (!this.namedDeclarations) { var sourceFile = this; var namedDeclarations = []; - var isExternalModule = ts.isExternalModule(sourceFile); ts.forEachChild(sourceFile, function visit(node) { switch (node.kind) { - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: - case 121 /* Constructor */: + var functionDeclaration = node; + if (functionDeclaration.name && functionDeclaration.name.kind !== 115 /* Missing */) { + var lastDeclaration = namedDeclarations.length > 0 ? namedDeclarations[namedDeclarations.length - 1] : undefined; + if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) { + if (functionDeclaration.body && !lastDeclaration.body) { + namedDeclarations[namedDeclarations.length - 1] = functionDeclaration; + } + } + else { + namedDeclarations.push(node); + } + ts.forEachChild(node, visit); + } + break; + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: case 129 /* TypeLiteral */: if (node.name) { namedDeclarations.push(node); } - ts.forEachChild(node, visit); - break; - case 149 /* VariableStatement */: - case 178 /* ModuleBlock */: - case 173 /* FunctionBlock */: + case 121 /* Constructor */: + case 151 /* VariableStatement */: + case 180 /* ModuleBlock */: + case 175 /* FunctionBlock */: ts.forEachChild(node, visit); break; case 118 /* Parameter */: if (!(node.flags & ts.NodeFlags.AccessibilityModifier)) { break; } - case 171 /* VariableDeclaration */: - case 181 /* EnumMember */: + case 173 /* VariableDeclaration */: + case 183 /* EnumMember */: case 119 /* Property */: namedDeclarations.push(node); break; } - return undefined; }); this.namedDeclarations = namedDeclarations; } @@ -31795,192 +33128,37 @@ var ts; }; return SourceFileObject; })(NodeObject); - var ClassificationTypeNames = (function () { - function ClassificationTypeNames() { - } - ClassificationTypeNames.comment = "comment"; - ClassificationTypeNames.identifier = "identifier"; - ClassificationTypeNames.keyword = "keyword"; - ClassificationTypeNames.numericLiteral = "number"; - ClassificationTypeNames.operator = "operator"; - ClassificationTypeNames.stringLiteral = "string"; - ClassificationTypeNames.whiteSpace = "whitespace"; - ClassificationTypeNames.text = "text"; - ClassificationTypeNames.punctuation = "punctuation"; - ClassificationTypeNames.className = "class name"; - ClassificationTypeNames.enumName = "enum name"; - ClassificationTypeNames.interfaceName = "interface name"; - ClassificationTypeNames.moduleName = "module name"; - ClassificationTypeNames.typeParameterName = "type parameter name"; - return ClassificationTypeNames; - })(); - ts.ClassificationTypeNames = ClassificationTypeNames; - var ClassifiedSpan = (function () { - function ClassifiedSpan(textSpan, classificationType) { - this.textSpan = textSpan; - this.classificationType = classificationType; - } - return ClassifiedSpan; - })(); - ts.ClassifiedSpan = ClassifiedSpan; - var NavigationBarItem = (function () { - function NavigationBarItem(text, kind, kindModifiers, spans, childItems, indent, bolded, grayed) { - if (childItems === void 0) { childItems = null; } - if (indent === void 0) { indent = 0; } - if (bolded === void 0) { bolded = false; } - if (grayed === void 0) { grayed = false; } - this.text = text; - this.kind = kind; - this.kindModifiers = kindModifiers; - this.spans = spans; - this.childItems = childItems; - this.indent = indent; - this.bolded = bolded; - this.grayed = grayed; - } - return NavigationBarItem; - })(); - ts.NavigationBarItem = NavigationBarItem; - var TodoCommentDescriptor = (function () { - function TodoCommentDescriptor(text, priority) { - this.text = text; - this.priority = priority; - } - return TodoCommentDescriptor; - })(); - ts.TodoCommentDescriptor = TodoCommentDescriptor; - var TodoComment = (function () { - function TodoComment(descriptor, message, position) { - this.descriptor = descriptor; - this.message = message; - this.position = position; - } - return TodoComment; - })(); - ts.TodoComment = TodoComment; var TextChange = (function () { - function TextChange(span, newText) { - this.span = span; - this.newText = newText; + function TextChange() { } - TextChange.createInsert = function (pos, newText) { - return new TextChange(new TypeScript.TextSpan(pos, 0), newText); - }; - TextChange.createDelete = function (start, end) { - return new TextChange(TypeScript.TextSpan.fromBounds(start, end), ""); - }; - TextChange.createReplace = function (start, end, newText) { - return new TextChange(TypeScript.TextSpan.fromBounds(start, end), newText); - }; return TextChange; })(); ts.TextChange = TextChange; - var ReferenceEntry = (function () { - function ReferenceEntry(fileName, textSpan, isWriteAccess) { - this.fileName = ""; - this.isWriteAccess = false; - this.fileName = fileName; - this.textSpan = textSpan; - this.isWriteAccess = isWriteAccess; - } - return ReferenceEntry; - })(); - ts.ReferenceEntry = ReferenceEntry; - var NavigateToItem = (function () { - function NavigateToItem(name, kind, kindModifiers, matchKind, fileName, textSpan, containerName, containerKind) { - this.name = name; - this.kind = kind; - this.kindModifiers = kindModifiers; - this.matchKind = matchKind; - this.fileName = fileName; - this.textSpan = textSpan; - this.containerName = containerName; - this.containerKind = containerKind; - } - return NavigateToItem; - })(); - ts.NavigateToItem = NavigateToItem; - var DefinitionInfo = (function () { - function DefinitionInfo(fileName, textSpan, kind, name, containerKind, containerName) { - this.fileName = fileName; - this.textSpan = textSpan; - this.kind = kind; - this.name = name; - this.containerKind = containerKind; - this.containerName = containerName; - } - return DefinitionInfo; - })(); - ts.DefinitionInfo = DefinitionInfo; - var TypeInfo = (function () { - function TypeInfo(memberName, docComment, fullSymbolName, kind, textSpan) { - this.memberName = memberName; - this.docComment = docComment; - this.fullSymbolName = fullSymbolName; - this.kind = kind; - this.textSpan = textSpan; - } - return TypeInfo; - })(); - ts.TypeInfo = TypeInfo; - var RenameInfo = (function () { - function RenameInfo(canRename, localizedErrorMessage, displayName, fullDisplayName, kind, kindModifiers, triggerSpan) { - this.canRename = canRename; - this.localizedErrorMessage = localizedErrorMessage; - this.displayName = displayName; - this.fullDisplayName = fullDisplayName; - this.kind = kind; - this.kindModifiers = kindModifiers; - this.triggerSpan = triggerSpan; - } - RenameInfo.CreateError = function (localizedErrorMessage) { - return new RenameInfo(false, localizedErrorMessage, null, null, null, null, null); - }; - RenameInfo.Create = function (displayName, fullDisplayName, kind, kindModifiers, triggerSpan) { - return new RenameInfo(true, null, displayName, fullDisplayName, kind, kindModifiers, triggerSpan); - }; - return RenameInfo; - })(); - ts.RenameInfo = RenameInfo; - var SignatureHelpParameter = (function () { - function SignatureHelpParameter(name, documentation, display, isOptional) { - this.name = name; - this.documentation = documentation; - this.display = display; - this.isOptional = isOptional; - } - return SignatureHelpParameter; - })(); - ts.SignatureHelpParameter = SignatureHelpParameter; - var SignatureHelpItem = (function () { - function SignatureHelpItem(isVariadic, prefix, suffix, separator, parameters, documentation) { - this.isVariadic = isVariadic; - this.prefix = prefix; - this.suffix = suffix; - this.separator = separator; - this.parameters = parameters; - this.documentation = documentation; - } - return SignatureHelpItem; - })(); - ts.SignatureHelpItem = SignatureHelpItem; - var SignatureHelpItems = (function () { - function SignatureHelpItems(items, applicableSpan, selectedItemIndex) { - this.items = items; - this.applicableSpan = applicableSpan; - this.selectedItemIndex = selectedItemIndex; - } - return SignatureHelpItems; - })(); - ts.SignatureHelpItems = SignatureHelpItems; - var SignatureHelpState = (function () { - function SignatureHelpState(argumentIndex, argumentCount) { - this.argumentIndex = argumentIndex; - this.argumentCount = argumentCount; - } - return SignatureHelpState; - })(); - ts.SignatureHelpState = SignatureHelpState; + (function (SymbolDisplayPartKind) { + SymbolDisplayPartKind[SymbolDisplayPartKind["aliasName"] = 0] = "aliasName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["className"] = 1] = "className"; + SymbolDisplayPartKind[SymbolDisplayPartKind["enumName"] = 2] = "enumName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["fieldName"] = 3] = "fieldName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["interfaceName"] = 4] = "interfaceName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["keyword"] = 5] = "keyword"; + SymbolDisplayPartKind[SymbolDisplayPartKind["lineBreak"] = 6] = "lineBreak"; + SymbolDisplayPartKind[SymbolDisplayPartKind["numericLiteral"] = 7] = "numericLiteral"; + SymbolDisplayPartKind[SymbolDisplayPartKind["stringLiteral"] = 8] = "stringLiteral"; + SymbolDisplayPartKind[SymbolDisplayPartKind["localName"] = 9] = "localName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["methodName"] = 10] = "methodName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["moduleName"] = 11] = "moduleName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["operator"] = 12] = "operator"; + SymbolDisplayPartKind[SymbolDisplayPartKind["parameterName"] = 13] = "parameterName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["propertyName"] = 14] = "propertyName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["punctuation"] = 15] = "punctuation"; + SymbolDisplayPartKind[SymbolDisplayPartKind["space"] = 16] = "space"; + SymbolDisplayPartKind[SymbolDisplayPartKind["text"] = 17] = "text"; + SymbolDisplayPartKind[SymbolDisplayPartKind["typeParameterName"] = 18] = "typeParameterName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["enumMemberName"] = 19] = "enumMemberName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["functionName"] = 20] = "functionName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["regularExpressionLiteral"] = 21] = "regularExpressionLiteral"; + })(ts.SymbolDisplayPartKind || (ts.SymbolDisplayPartKind = {})); + var SymbolDisplayPartKind = ts.SymbolDisplayPartKind; (function (OutputFileType) { OutputFileType[OutputFileType["JavaScript"] = 0] = "JavaScript"; OutputFileType[OutputFileType["SourceMap"] = 1] = "SourceMap"; @@ -32032,6 +33210,7 @@ var ts; ScriptElementKind.typeParameterElement = "type parameter"; ScriptElementKind.primitiveType = "primitive type"; ScriptElementKind.label = "label"; + ScriptElementKind.alias = "alias"; return ScriptElementKind; })(); ts.ScriptElementKind = ScriptElementKind; @@ -32041,12 +33220,33 @@ var ts; ScriptElementKindModifier.none = ""; ScriptElementKindModifier.publicMemberModifier = "public"; ScriptElementKindModifier.privateMemberModifier = "private"; + ScriptElementKindModifier.protectedMemberModifier = "protected"; ScriptElementKindModifier.exportedModifier = "export"; ScriptElementKindModifier.ambientModifier = "declare"; ScriptElementKindModifier.staticModifier = "static"; return ScriptElementKindModifier; })(); ts.ScriptElementKindModifier = ScriptElementKindModifier; + var ClassificationTypeNames = (function () { + function ClassificationTypeNames() { + } + ClassificationTypeNames.comment = "comment"; + ClassificationTypeNames.identifier = "identifier"; + ClassificationTypeNames.keyword = "keyword"; + ClassificationTypeNames.numericLiteral = "number"; + ClassificationTypeNames.operator = "operator"; + ClassificationTypeNames.stringLiteral = "string"; + ClassificationTypeNames.whiteSpace = "whitespace"; + ClassificationTypeNames.text = "text"; + ClassificationTypeNames.punctuation = "punctuation"; + ClassificationTypeNames.className = "class name"; + ClassificationTypeNames.enumName = "enum name"; + ClassificationTypeNames.interfaceName = "interface name"; + ClassificationTypeNames.moduleName = "module name"; + ClassificationTypeNames.typeParameterName = "type parameter name"; + return ClassificationTypeNames; + })(); + ts.ClassificationTypeNames = ClassificationTypeNames; var MatchKind; (function (MatchKind) { MatchKind[MatchKind["none"] = 0] = "none"; @@ -32054,6 +33254,177 @@ var ts; MatchKind[MatchKind["substring"] = 2] = "substring"; MatchKind[MatchKind["prefix"] = 3] = "prefix"; })(MatchKind || (MatchKind = {})); + function displayPartsToString(displayParts) { + if (displayParts) { + return ts.map(displayParts, function (displayPart) { return displayPart.text; }).join(""); + } + return ""; + } + ts.displayPartsToString = displayPartsToString; + var displayPartWriter = getDisplayPartWriter(); + function getDisplayPartWriter() { + var displayParts; + var lineStart; + var indent; + resetWriter(); + return { + displayParts: function () { return displayParts; }, + writeKeyword: function (text) { return writeKind(text, 5 /* keyword */); }, + writeOperator: function (text) { return writeKind(text, 12 /* operator */); }, + writePunctuation: function (text) { return writeKind(text, 15 /* punctuation */); }, + writeSpace: function (text) { return writeKind(text, 16 /* space */); }, + writeStringLiteral: function (text) { return writeKind(text, 8 /* stringLiteral */); }, + writeParameter: function (text) { return writeKind(text, 13 /* parameterName */); }, + writeSymbol: writeSymbol, + writeLine: writeLine, + increaseIndent: function () { + indent++; + }, + decreaseIndent: function () { + indent--; + }, + clear: resetWriter, + trackSymbol: function () { + } + }; + function writeIndent() { + if (lineStart) { + displayParts.push(displayPart(ts.getIndentString(indent), 16 /* space */)); + lineStart = false; + } + } + function writeKind(text, kind) { + writeIndent(); + displayParts.push(displayPart(text, kind)); + } + function writeSymbol(text, symbol) { + writeIndent(); + displayParts.push(symbolPart(text, symbol)); + } + function writeLine() { + displayParts.push(lineBreakPart()); + lineStart = true; + } + function resetWriter() { + displayParts = []; + lineStart = true; + indent = 0; + } + } + function displayPart(text, kind, symbol) { + return { + text: text, + kind: SymbolDisplayPartKind[kind] + }; + } + function spacePart() { + return displayPart(" ", 16 /* space */); + } + ts.spacePart = spacePart; + function keywordPart(kind) { + return displayPart(ts.tokenToString(kind), 5 /* keyword */); + } + ts.keywordPart = keywordPart; + function punctuationPart(kind) { + return displayPart(ts.tokenToString(kind), 15 /* punctuation */); + } + ts.punctuationPart = punctuationPart; + function operatorPart(kind) { + return displayPart(ts.tokenToString(kind), 12 /* operator */); + } + ts.operatorPart = operatorPart; + function textPart(text) { + return displayPart(text, 17 /* text */); + } + ts.textPart = textPart; + function lineBreakPart() { + return displayPart("\n", 6 /* lineBreak */); + } + ts.lineBreakPart = lineBreakPart; + function isFirstDeclarationOfSymbolParameter(symbol) { + return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 118 /* Parameter */; + } + function isLocalVariableOrFunction(symbol) { + if (symbol.parent) { + return false; + } + return ts.forEach(symbol.declarations, function (declaration) { + if (declaration.kind === 143 /* FunctionExpression */) { + return true; + } + if (declaration.kind !== 173 /* VariableDeclaration */ && declaration.kind !== 174 /* FunctionDeclaration */) { + return false; + } + for (var parent = declaration.parent; parent.kind !== 175 /* FunctionBlock */; parent = parent.parent) { + if (parent.kind === 184 /* SourceFile */ || parent.kind === 180 /* ModuleBlock */) { + return false; + } + } + return true; + }); + } + function symbolPart(text, symbol) { + return displayPart(text, displayPartKind(symbol), symbol); + function displayPartKind(symbol) { + var flags = symbol.flags; + if (flags & 1 /* Variable */) { + return isFirstDeclarationOfSymbolParameter(symbol) ? 13 /* parameterName */ : 9 /* localName */; + } + else if (flags & 2 /* Property */) { + return 14 /* propertyName */; + } + else if (flags & 4 /* EnumMember */) { + return 19 /* enumMemberName */; + } + else if (flags & 8 /* Function */) { + return 20 /* functionName */; + } + else if (flags & 16 /* Class */) { + return 1 /* className */; + } + else if (flags & 32 /* Interface */) { + return 4 /* interfaceName */; + } + else if (flags & 64 /* Enum */) { + return 2 /* enumName */; + } + else if (flags & ts.SymbolFlags.Module) { + return 11 /* moduleName */; + } + else if (flags & 2048 /* Method */) { + return 10 /* methodName */; + } + else if (flags & 262144 /* TypeParameter */) { + return 18 /* typeParameterName */; + } + return 17 /* text */; + } + } + ts.symbolPart = symbolPart; + function mapToDisplayParts(writeDisplayParts) { + writeDisplayParts(displayPartWriter); + var result = displayPartWriter.displayParts(); + displayPartWriter.clear(); + return result; + } + ts.mapToDisplayParts = mapToDisplayParts; + function typeToDisplayParts(typechecker, type, enclosingDeclaration, flags) { + return mapToDisplayParts(function (writer) { + typechecker.getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); + }); + } + ts.typeToDisplayParts = typeToDisplayParts; + function symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration, meaning, flags) { + return mapToDisplayParts(function (writer) { + typeChecker.getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags); + }); + } + ts.symbolToDisplayParts = symbolToDisplayParts; + function signatureToDisplayParts(typechecker, signature, enclosingDeclaration, flags) { + return mapToDisplayParts(function (writer) { + typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags); + }); + } function getDefaultCompilerOptions() { return { target: 1 /* ES5 */, @@ -32096,6 +33467,7 @@ var ts; CancellationTokenObject.None = new CancellationTokenObject(null); return CancellationTokenObject; })(); + ts.CancellationTokenObject = CancellationTokenObject; var HostCache = (function () { function HostCache(host) { this.host = host; @@ -32343,9 +33715,27 @@ var ts; }; } ts.createDocumentRegistry = createDocumentRegistry; + function getNodeModifiers(node) { + var flags = node.flags; + var result = []; + if (flags & 32 /* Private */) + result.push(ScriptElementKindModifier.privateMemberModifier); + if (flags & 64 /* Protected */) + result.push(ScriptElementKindModifier.protectedMemberModifier); + if (flags & 16 /* Public */) + result.push(ScriptElementKindModifier.publicMemberModifier); + if (flags & 128 /* Static */) + result.push(ScriptElementKindModifier.staticModifier); + if (flags & 1 /* Export */) + result.push(ScriptElementKindModifier.exportedModifier); + if (ts.isInAmbientContext(node)) + result.push(ScriptElementKindModifier.ambientModifier); + return result.length > 0 ? result.join(',') : ScriptElementKindModifier.none; + } + ts.getNodeModifiers = getNodeModifiers; function getTargetLabel(referenceNode, labelName) { while (referenceNode) { - if (referenceNode.kind === 164 /* LabeledStatement */ && referenceNode.label.text === labelName) { + if (referenceNode.kind === 166 /* LabeledStatement */ && referenceNode.label.text === labelName) { return referenceNode.label; } referenceNode = referenceNode.parent; @@ -32353,13 +33743,13 @@ var ts; return undefined; } function isJumpStatementTarget(node) { - return node.kind === 59 /* Identifier */ && (node.parent.kind === 158 /* BreakStatement */ || node.parent.kind === 157 /* ContinueStatement */) && node.parent.label === node; + return node.kind === 59 /* Identifier */ && (node.parent.kind === 160 /* BreakStatement */ || node.parent.kind === 159 /* ContinueStatement */) && node.parent.label === node; } function isLabelOfLabeledStatement(node) { - return node.kind === 59 /* Identifier */ && node.parent.kind === 164 /* LabeledStatement */ && node.parent.label === node; + return node.kind === 59 /* Identifier */ && node.parent.kind === 166 /* LabeledStatement */ && node.parent.label === node; } function isLabeledBy(node, labelName) { - for (var owner = node.parent; owner.kind === 164 /* LabeledStatement */; owner = owner.parent) { + for (var owner = node.parent; owner.kind === 166 /* LabeledStatement */; owner = owner.parent) { if (owner.label.text === labelName) { return true; } @@ -32370,48 +33760,49 @@ var ts; return isLabelOfLabeledStatement(node) || isJumpStatementTarget(node); } function isCallExpressionTarget(node) { - if (node.parent.kind === 135 /* PropertyAccess */ && node.parent.right === node) + if (node.parent.kind === 137 /* PropertyAccess */ && node.parent.right === node) node = node.parent; - return node.parent.kind === 137 /* CallExpression */ && node.parent.func === node; + return node.parent.kind === 139 /* CallExpression */ && node.parent.func === node; } function isNewExpressionTarget(node) { - if (node.parent.kind === 135 /* PropertyAccess */ && node.parent.right === node) + if (node.parent.kind === 137 /* PropertyAccess */ && node.parent.right === node) node = node.parent; - return node.parent.kind === 138 /* NewExpression */ && node.parent.func === node; + return node.parent.kind === 140 /* NewExpression */ && node.parent.func === node; } function isNameOfFunctionDeclaration(node) { return node.kind === 59 /* Identifier */ && ts.isAnyFunction(node.parent) && node.parent.name === node; } function isNameOfPropertyAssignment(node) { - return (node.kind === 59 /* Identifier */ || node.kind === 7 /* StringLiteral */ || node.kind === 6 /* NumericLiteral */) && node.parent.kind === 134 /* PropertyAssignment */ && node.parent.name === node; + return (node.kind === 59 /* Identifier */ || node.kind === 7 /* StringLiteral */ || node.kind === 6 /* NumericLiteral */) && node.parent.kind === 136 /* PropertyAssignment */ && node.parent.name === node; } function isLiteralNameOfPropertyDeclarationOrIndexAccess(node) { if (node.kind === 7 /* StringLiteral */ || node.kind === 6 /* NumericLiteral */) { switch (node.parent.kind) { case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: case 120 /* Method */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return node.parent.name === node; - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return node.parent.index === node; } } return false; } function isNameOfExternalModuleImportOrDeclaration(node) { - return node.kind === 7 /* StringLiteral */ && ((node.parent.kind === 177 /* ModuleDeclaration */ && node.parent.name === node) || (node.parent.kind === 179 /* ImportDeclaration */ && node.parent.externalModuleName === node)); + return node.kind === 7 /* StringLiteral */ && ((node.parent.kind === 179 /* ModuleDeclaration */ && node.parent.name === node) || (node.parent.kind === 181 /* ImportDeclaration */ && node.parent.externalModuleName === node)); } - var SearchMeaning; - (function (SearchMeaning) { - SearchMeaning[SearchMeaning["None"] = 0x0] = "None"; - SearchMeaning[SearchMeaning["Value"] = 0x1] = "Value"; - SearchMeaning[SearchMeaning["Type"] = 0x2] = "Type"; - SearchMeaning[SearchMeaning["Namespace"] = 0x4] = "Namespace"; - })(SearchMeaning || (SearchMeaning = {})); + var SemanticMeaning; + (function (SemanticMeaning) { + SemanticMeaning[SemanticMeaning["None"] = 0x0] = "None"; + SemanticMeaning[SemanticMeaning["Value"] = 0x1] = "Value"; + SemanticMeaning[SemanticMeaning["Type"] = 0x2] = "Type"; + SemanticMeaning[SemanticMeaning["Namespace"] = 0x4] = "Namespace"; + SemanticMeaning[SemanticMeaning["All"] = SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace] = "All"; + })(SemanticMeaning || (SemanticMeaning = {})); var BreakContinueSearchType; (function (BreakContinueSearchType) { BreakContinueSearchType[BreakContinueSearchType["None"] = 0x0] = "None"; @@ -32440,8 +33831,8 @@ var ts; var cancellationToken = new CancellationTokenObject(host.getCancellationToken()); var activeCompletionSession; var writer = undefined; - if (!TypeScript.LocalizedDiagnosticMessages) { - TypeScript.LocalizedDiagnosticMessages = host.getLocalizedDiagnosticMessages(); + if (!ts.localizedDiagnosticMessages) { + ts.localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages(); } function getSourceFile(filename) { return ts.lookUp(sourceFilesByName, filename); @@ -32573,9 +33964,13 @@ var ts; synchronizeHostData(); return program.getGlobalDiagnostics(); } - function getValidCompletionEntryDisplayName(displayName, target) { + function getValidCompletionEntryDisplayName(symbol, target) { + var displayName = symbol.getName(); if (displayName && displayName.length > 0) { var firstCharCode = displayName.charCodeAt(0); + if ((symbol.flags & ts.SymbolFlags.Namespace) && (firstCharCode === 39 /* singleQuote */ || firstCharCode === 34 /* doubleQuote */)) { + return undefined; + } if (displayName && displayName.length >= 2 && firstCharCode === displayName.charCodeAt(displayName.length - 1) && (firstCharCode === 39 /* singleQuote */ || firstCharCode === 34 /* doubleQuote */)) { displayName = displayName.substring(1, displayName.length - 1); } @@ -32589,22 +33984,21 @@ var ts; } return undefined; } - function createCompletionEntry(symbol) { - var displayName = getValidCompletionEntryDisplayName(symbol.getName(), program.getCompilerOptions().target); + function createCompletionEntry(symbol, typeChecker) { + var displayName = getValidCompletionEntryDisplayName(symbol, program.getCompilerOptions().target); if (!displayName) { return undefined; } - var declarations = symbol.getDeclarations(); return { name: displayName, - kind: getSymbolKind(symbol), - kindModifiers: declarations ? getNodeModifiers(declarations[0]) : ScriptElementKindModifier.none + kind: getSymbolKind(symbol, typeChecker), + kindModifiers: getSymbolModifiers(symbol) }; } function getCompletionsAtPosition(filename, position, isMemberCompletion) { function getCompletionEntriesFromSymbols(symbols, session) { ts.forEach(symbols, function (symbol) { - var entry = createCompletionEntry(symbol); + var entry = createCompletionEntry(symbol, session.typeChecker); if (entry && !ts.lookUp(session.symbols, entry.name)) { session.entries.push(entry); session.symbols[entry.name] = symbol; @@ -32698,21 +34092,13 @@ var ts; function isPunctuation(kind) { return (ts.SyntaxKind.FirstPunctuation <= kind && kind <= ts.SyntaxKind.LastPunctuation); } - function isVisibleWithinClassDeclaration(symbol, containingClass) { - var declaration = symbol.declarations && symbol.declarations[0]; - if (declaration && (declaration.flags & 32 /* Private */)) { - var declarationClass = ts.getAncestor(declaration, 174 /* ClassDeclaration */); - return containingClass === declarationClass; - } - return true; - } function filterContextualMembersList(contextualMemberSymbols, existingMembers) { if (!existingMembers || existingMembers.length === 0) { return contextualMemberSymbols; } var existingMemberNames = {}; ts.forEach(existingMembers, function (m) { - if (m.kind !== 134 /* PropertyAssignment */) { + if (m.kind !== 136 /* PropertyAssignment */) { return; } if (m.getStart() <= position && position <= m.getEnd()) { @@ -32757,9 +34143,16 @@ var ts; isRightOfDot = true; node = node.parent.left; } - var mappedNode = getNodeAtPosition(sourceFile, TypeScript.end(node) - 1); - if (isPunctuation(mappedNode.kind)) { - mappedNode = mappedNode.parent; + var precedingToken = ts.findTokenOnLeftOfPosition(sourceFile, TypeScript.end(node)); + var mappedNode; + if (!precedingToken) { + mappedNode = sourceFile; + } + else if (isPunctuation(precedingToken.kind)) { + mappedNode = precedingToken.parent; + } + else { + mappedNode = precedingToken; } ts.Debug.assert(mappedNode, "Could not map a Fidelity node to an AST node"); activeCompletionSession = { @@ -32772,23 +34165,24 @@ var ts; }; if (isRightOfDot) { var symbols = []; - var containingClass = ts.getAncestor(mappedNode, 174 /* ClassDeclaration */); isMemberCompletion = true; - if (mappedNode.kind === 59 /* Identifier */ || mappedNode.kind === 116 /* QualifiedName */ || mappedNode.kind === 135 /* PropertyAccess */) { + if (mappedNode.kind === 59 /* Identifier */ || mappedNode.kind === 116 /* QualifiedName */ || mappedNode.kind === 137 /* PropertyAccess */) { var symbol = typeInfoResolver.getSymbolInfo(mappedNode); + if (symbol && symbol.flags & 4194304 /* Import */) { + symbol = typeInfoResolver.getAliasedSymbol(symbol); + } if (symbol && symbol.flags & ts.SymbolFlags.HasExports) { ts.forEachValue(symbol.exports, function (symbol) { - if (isVisibleWithinClassDeclaration(symbol, containingClass)) { + if (typeInfoResolver.isValidPropertyAccess((mappedNode.parent), symbol.name)) { symbols.push(symbol); } }); } } var type = typeInfoResolver.getTypeOfNode(mappedNode); - var apparentType = type && typeInfoResolver.getApparentType(type); - if (apparentType) { - ts.forEach(apparentType.getApparentProperties(), function (symbol) { - if (isVisibleWithinClassDeclaration(symbol, containingClass)) { + if (type) { + ts.forEach(type.getApparentProperties(), function (symbol) { + if (typeInfoResolver.isValidPropertyAccess((mappedNode.parent), symbol.name)) { symbols.push(symbol); } }); @@ -32798,7 +34192,7 @@ var ts; else { var containingObjectLiteral = getContainingObjectLiteralApplicableForCompletion(sourceFile.getSyntaxTree().sourceUnit(), position); if (containingObjectLiteral) { - var objectLiteral = (mappedNode.kind === 133 /* ObjectLiteral */ ? mappedNode : ts.getAncestor(mappedNode, 133 /* ObjectLiteral */)); + var objectLiteral = (mappedNode.kind === 135 /* ObjectLiteral */ ? mappedNode : ts.getAncestor(mappedNode, 135 /* ObjectLiteral */)); ts.Debug.assert(objectLiteral); isMemberCompletion = true; var contextualType = typeInfoResolver.getContextualType(objectLiteral); @@ -32813,7 +34207,7 @@ var ts; } else { isMemberCompletion = false; - var symbolMeanings = ts.SymbolFlags.Type | ts.SymbolFlags.Value | ts.SymbolFlags.Namespace; + var symbolMeanings = ts.SymbolFlags.Type | ts.SymbolFlags.Value | ts.SymbolFlags.Namespace | 4194304 /* Import */; var symbols = typeInfoResolver.getSymbolsInScope(mappedNode, symbolMeanings); getCompletionEntriesFromSymbols(symbols, activeCompletionSession); } @@ -32836,14 +34230,14 @@ var ts; if (symbol) { var type = session.typeChecker.getTypeOfSymbol(symbol); ts.Debug.assert(type, "Could not find type for symbol"); - var completionEntry = createCompletionEntry(symbol); + var completionEntry = createCompletionEntry(symbol, session.typeChecker); + var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getSourceFile(filename), session.location, session.typeChecker, session.location, SemanticMeaning.All); return { name: entryName, - kind: completionEntry.kind, + kind: displayPartsDocumentationsAndSymbolKind.symbolKind, kindModifiers: completionEntry.kindModifiers, - type: session.typeChecker.typeToString(type, session.location), - fullSymbolName: typeInfoResolver.symbolToString(symbol, session.location), - docComment: "" + displayParts: displayPartsDocumentationsAndSymbolKind.displayParts, + documentation: displayPartsDocumentationsAndSymbolKind.documentation }; } else { @@ -32851,38 +34245,11 @@ var ts; name: entryName, kind: ScriptElementKind.keyword, kindModifiers: ScriptElementKindModifier.none, - type: undefined, - fullSymbolName: entryName, - docComment: undefined + displayParts: [displayPart(entryName, 5 /* keyword */)], + documentation: undefined }; } } - function getNodeAtPosition(sourceFile, position) { - var current = sourceFile; - outer: while (true) { - for (var i = 0, n = current.getChildCount(); i < n; i++) { - var child = current.getChildAt(i); - if (child.getStart() <= position && position < child.getEnd()) { - current = child; - continue outer; - } - } - return current; - } - } - function getTokenAtPosition(sourceFile, position) { - var current = sourceFile; - outer: while (true) { - for (var i = 0, n = current.getChildCount(); i < n; i++) { - var child = current.getChildAt(i); - if (child.getFullStart() <= position && position < child.getEnd()) { - current = child; - continue outer; - } - } - return current; - } - } function getContainerNode(node) { while (true) { node = node.parent; @@ -32890,54 +34257,80 @@ var ts; return node; } switch (node.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: return node; } } } - function getSymbolKind(symbol) { - var flags = typeInfoResolver.getRootSymbol(symbol).getFlags(); - if (flags & ts.SymbolFlags.Module) - return ScriptElementKind.moduleElement; + function getSymbolKind(symbol, typeResolver) { + var flags = symbol.getFlags(); if (flags & 16 /* Class */) return ScriptElementKind.classElement; - if (flags & 32 /* Interface */) - return ScriptElementKind.interfaceElement; if (flags & 64 /* Enum */) return ScriptElementKind.enumElement; - if (flags & 1 /* Variable */) + if (flags & 32 /* Interface */) + return ScriptElementKind.interfaceElement; + if (flags & 262144 /* TypeParameter */) + return ScriptElementKind.typeParameterElement; + var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver); + if (result === ScriptElementKind.unknown) { + if (flags & 262144 /* TypeParameter */) + return ScriptElementKind.typeParameterElement; + if (flags & 4 /* EnumMember */) + return ScriptElementKind.variableElement; + if (flags & 4194304 /* Import */) + return ScriptElementKind.alias; + } + return result; + } + function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver) { + if (typeResolver.isUndefinedSymbol(symbol)) { return ScriptElementKind.variableElement; + } + if (typeResolver.isArgumentsSymbol(symbol)) { + return ScriptElementKind.localVariableElement; + } + if (flags & 1 /* Variable */) { + if (isFirstDeclarationOfSymbolParameter(symbol)) { + return ScriptElementKind.parameterElement; + } + return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement; + } if (flags & 8 /* Function */) - return ScriptElementKind.functionElement; + return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localFunctionElement : ScriptElementKind.functionElement; if (flags & 8192 /* GetAccessor */) return ScriptElementKind.memberGetAccessorElement; if (flags & 16384 /* SetAccessor */) return ScriptElementKind.memberSetAccessorElement; if (flags & 2048 /* Method */) return ScriptElementKind.memberFunctionElement; - if (flags & 2 /* Property */) - return ScriptElementKind.memberVariableElement; - if (flags & 131072 /* IndexSignature */) - return ScriptElementKind.indexSignatureElement; - if (flags & 65536 /* ConstructSignature */) - return ScriptElementKind.constructSignatureElement; - if (flags & 32768 /* CallSignature */) - return ScriptElementKind.callSignatureElement; if (flags & 4096 /* Constructor */) return ScriptElementKind.constructorImplementationElement; - if (flags & 262144 /* TypeParameter */) - return ScriptElementKind.typeParameterElement; - if (flags & 4 /* EnumMember */) - return ScriptElementKind.variableElement; + if (flags & 2 /* Property */) { + if (flags & 134217728 /* UnionProperty */) { + return ts.forEach(typeInfoResolver.getRootSymbols(symbol), function (rootSymbol) { + var rootSymbolFlags = rootSymbol.getFlags(); + if (rootSymbolFlags & 2 /* Property */) { + return ScriptElementKind.memberVariableElement; + } + if (rootSymbolFlags & 8192 /* GetAccessor */) + return ScriptElementKind.memberVariableElement; + if (rootSymbolFlags & 16384 /* SetAccessor */) + return ScriptElementKind.memberVariableElement; + ts.Debug.assert(rootSymbolFlags & 2048 /* Method */); + }) || ScriptElementKind.memberFunctionElement; + } + return ScriptElementKind.memberVariableElement; + } return ScriptElementKind.unknown; } function getTypeKind(type) { @@ -32958,17 +34351,17 @@ var ts; } function getNodeKind(node) { switch (node.kind) { - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return ScriptElementKind.moduleElement; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return ScriptElementKind.classElement; - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return ScriptElementKind.interfaceElement; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return ScriptElementKind.enumElement; - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return ScriptElementKind.variableElement; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: return ScriptElementKind.functionElement; case 122 /* GetAccessor */: return ScriptElementKind.memberGetAccessorElement; @@ -32988,52 +34381,322 @@ var ts; return ScriptElementKind.constructorImplementationElement; case 117 /* TypeParameter */: return ScriptElementKind.typeParameterElement; - case 181 /* EnumMember */: + case 183 /* EnumMember */: return ScriptElementKind.variableElement; case 118 /* Parameter */: return (node.flags & ts.NodeFlags.AccessibilityModifier) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; return ScriptElementKind.unknown; } } - function getNodeModifiers(node) { - var flags = node.flags; - var result = []; - if (flags & 32 /* Private */) - result.push(ScriptElementKindModifier.privateMemberModifier); - if (flags & 16 /* Public */) - result.push(ScriptElementKindModifier.publicMemberModifier); - if (flags & 128 /* Static */) - result.push(ScriptElementKindModifier.staticModifier); - if (flags & 1 /* Export */) - result.push(ScriptElementKindModifier.exportedModifier); - if (ts.isInAmbientContext(node)) - result.push(ScriptElementKindModifier.ambientModifier); - return result.length > 0 ? result.join(',') : ScriptElementKindModifier.none; + function getSymbolModifiers(symbol) { + return symbol && symbol.declarations && symbol.declarations.length > 0 ? getNodeModifiers(symbol.declarations[0]) : ScriptElementKindModifier.none; } - function getTypeAtPosition(fileName, position) { + function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, enclosingDeclaration, typeResolver, location, semanticMeaning) { + if (semanticMeaning === void 0) { semanticMeaning = getMeaningFromLocation(location); } + var displayParts = []; + var documentation; + var symbolFlags = symbol.flags; + var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, typeResolver); + var hasAddedSymbolInfo; + if (symbolKind !== ScriptElementKind.unknown || symbolFlags & 16 /* Class */ || symbolFlags & 4194304 /* Import */) { + if (symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement) { + symbolKind = ScriptElementKind.memberVariableElement; + } + var type = typeResolver.getTypeOfSymbol(symbol); + if (type) { + if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) { + var callExpression; + if (location.parent.kind === 137 /* PropertyAccess */ && location.parent.right === location) { + location = location.parent; + } + callExpression = location.parent; + var candidateSignatures = []; + signature = typeResolver.getResolvedSignature(callExpression, candidateSignatures); + if (!signature && candidateSignatures.length) { + signature = candidateSignatures[0]; + } + var useConstructSignatures = callExpression.kind === 140 /* NewExpression */ || callExpression.func.kind === 85 /* SuperKeyword */; + var allSignatures = useConstructSignatures ? type.getConstructSignatures() : type.getCallSignatures(); + if (!ts.contains(allSignatures, signature.target || signature)) { + signature = allSignatures.length ? allSignatures[0] : undefined; + } + if (signature) { + if (useConstructSignatures && (symbolFlags & 16 /* Class */)) { + symbolKind = ScriptElementKind.constructorImplementationElement; + addPrefixForAnyFunctionOrVar(type.symbol, symbolKind); + } + else if (symbolFlags & 4194304 /* Import */) { + symbolKind = ScriptElementKind.alias; + displayParts.push(punctuationPart(11 /* OpenParenToken */)); + displayParts.push(textPart(symbolKind)); + displayParts.push(punctuationPart(12 /* CloseParenToken */)); + displayParts.push(spacePart()); + if (useConstructSignatures) { + displayParts.push(keywordPart(82 /* NewKeyword */)); + displayParts.push(spacePart()); + } + addFullSymbolName(symbol); + } + else { + addPrefixForAnyFunctionOrVar(symbol, symbolKind); + } + switch (symbolKind) { + case ScriptElementKind.memberVariableElement: + case ScriptElementKind.variableElement: + case ScriptElementKind.parameterElement: + case ScriptElementKind.localVariableElement: + displayParts.push(punctuationPart(46 /* ColonToken */)); + displayParts.push(spacePart()); + if (useConstructSignatures) { + displayParts.push(keywordPart(82 /* NewKeyword */)); + displayParts.push(spacePart()); + } + if (!(type.flags & 32768 /* Anonymous */)) { + displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, type.symbol, enclosingDeclaration, undefined, 1 /* WriteTypeParametersOrArguments */)); + } + addSignatureDisplayParts(signature, allSignatures, 8 /* WriteArrowStyleSignature */); + break; + default: + addSignatureDisplayParts(signature, allSignatures); + } + hasAddedSymbolInfo = true; + } + } + else if ((isNameOfFunctionDeclaration(location) && !(symbol.flags & ts.SymbolFlags.Accessor)) || (location.kind === 107 /* ConstructorKeyword */ && location.parent.kind === 121 /* Constructor */)) { + var signature; + var functionDeclaration = location.parent; + var allSignatures = functionDeclaration.kind === 121 /* Constructor */ ? type.getConstructSignatures() : type.getCallSignatures(); + if (!typeResolver.isImplementationOfOverload(functionDeclaration)) { + signature = typeResolver.getSignatureFromDeclaration(functionDeclaration); + } + else { + signature = allSignatures[0]; + } + if (functionDeclaration.kind === 121 /* Constructor */) { + addPrefixForAnyFunctionOrVar(type.symbol, ScriptElementKind.constructorImplementationElement); + } + else { + addPrefixForAnyFunctionOrVar(functionDeclaration.kind === 124 /* CallSignature */ && !(type.symbol.flags & 512 /* TypeLiteral */ || type.symbol.flags & 1024 /* ObjectLiteral */) ? type.symbol : symbol, symbolKind); + } + addSignatureDisplayParts(signature, allSignatures); + hasAddedSymbolInfo = true; + } + } + } + if (symbolFlags & 16 /* Class */ && !hasAddedSymbolInfo) { + displayParts.push(keywordPart(63 /* ClassKeyword */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + writeTypeParametersOfSymbol(symbol, sourceFile); + } + if ((symbolFlags & 32 /* Interface */) && (semanticMeaning & 2 /* Type */)) { + addNewLineIfDisplayPartsExist(); + displayParts.push(keywordPart(97 /* InterfaceKeyword */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + writeTypeParametersOfSymbol(symbol, sourceFile); + } + if (symbolFlags & 64 /* Enum */) { + addNewLineIfDisplayPartsExist(); + displayParts.push(keywordPart(71 /* EnumKeyword */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + } + if (symbolFlags & ts.SymbolFlags.Module) { + addNewLineIfDisplayPartsExist(); + displayParts.push(keywordPart(110 /* ModuleKeyword */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + } + if ((symbolFlags & 262144 /* TypeParameter */) && (semanticMeaning & 2 /* Type */)) { + addNewLineIfDisplayPartsExist(); + displayParts.push(punctuationPart(11 /* OpenParenToken */)); + displayParts.push(textPart("type parameter")); + displayParts.push(punctuationPart(12 /* CloseParenToken */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + displayParts.push(spacePart()); + displayParts.push(keywordPart(80 /* InKeyword */)); + displayParts.push(spacePart()); + if (symbol.parent) { + addFullSymbolName(symbol.parent, enclosingDeclaration); + writeTypeParametersOfSymbol(symbol.parent, enclosingDeclaration); + } + else { + var signatureDeclaration = ts.getDeclarationOfKind(symbol, 117 /* TypeParameter */).parent; + var signature = typeResolver.getSignatureFromDeclaration(signatureDeclaration); + if (signatureDeclaration.kind === 125 /* ConstructSignature */) { + displayParts.push(keywordPart(82 /* NewKeyword */)); + displayParts.push(spacePart()); + } + else if (signatureDeclaration.kind !== 124 /* CallSignature */ && signatureDeclaration.name) { + addFullSymbolName(signatureDeclaration.symbol); + } + displayParts.push.apply(displayParts, signatureToDisplayParts(typeResolver, signature, sourceFile, 32 /* WriteTypeArgumentsOfSignature */)); + } + } + if (symbolFlags & 4 /* EnumMember */) { + addPrefixForAnyFunctionOrVar(symbol, "enum member"); + var declaration = symbol.declarations[0]; + if (declaration.kind === 183 /* EnumMember */) { + var constantValue = typeResolver.getEnumMemberValue(declaration); + if (constantValue !== undefined) { + displayParts.push(spacePart()); + displayParts.push(operatorPart(47 /* EqualsToken */)); + displayParts.push(spacePart()); + displayParts.push(displayPart(constantValue.toString(), 7 /* numericLiteral */)); + } + } + } + if (symbolFlags & 4194304 /* Import */) { + addNewLineIfDisplayPartsExist(); + displayParts.push(keywordPart(79 /* ImportKeyword */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + displayParts.push(spacePart()); + displayParts.push(punctuationPart(47 /* EqualsToken */)); + displayParts.push(spacePart()); + ts.forEach(symbol.declarations, function (declaration) { + if (declaration.kind === 181 /* ImportDeclaration */) { + var importDeclaration = declaration; + if (importDeclaration.externalModuleName) { + displayParts.push(keywordPart(111 /* RequireKeyword */)); + displayParts.push(punctuationPart(11 /* OpenParenToken */)); + displayParts.push(displayPart(ts.getTextOfNode(importDeclaration.externalModuleName), 8 /* stringLiteral */)); + displayParts.push(punctuationPart(12 /* CloseParenToken */)); + } + else { + var internalAliasSymbol = typeResolver.getSymbolInfo(importDeclaration.entityName); + addFullSymbolName(internalAliasSymbol, enclosingDeclaration); + } + return true; + } + }); + } + if (!hasAddedSymbolInfo) { + if (symbolKind !== ScriptElementKind.unknown) { + if (type) { + addPrefixForAnyFunctionOrVar(symbol, symbolKind); + if (symbolKind === ScriptElementKind.memberVariableElement || symbolFlags & 1 /* Variable */ || symbolKind === ScriptElementKind.localVariableElement) { + displayParts.push(punctuationPart(46 /* ColonToken */)); + displayParts.push(spacePart()); + if (type.symbol && type.symbol.flags & 262144 /* TypeParameter */) { + var typeParameterParts = mapToDisplayParts(function (writer) { + typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); + }); + displayParts.push.apply(displayParts, typeParameterParts); + } + else { + displayParts.push.apply(displayParts, typeToDisplayParts(typeResolver, type, enclosingDeclaration)); + } + } + else if (symbolFlags & 8 /* Function */ || symbolFlags & 2048 /* Method */ || symbolFlags & 4096 /* Constructor */ || symbolFlags & ts.SymbolFlags.Signature || symbolFlags & ts.SymbolFlags.Accessor || symbolKind === ScriptElementKind.memberFunctionElement) { + var allSignatures = type.getCallSignatures(); + addSignatureDisplayParts(allSignatures[0], allSignatures); + } + } + } + else { + symbolKind = getSymbolKind(symbol, typeResolver); + } + } + if (!documentation) { + documentation = symbol.getDocumentationComment(); + } + return { displayParts: displayParts, documentation: documentation, symbolKind: symbolKind }; + function addNewLineIfDisplayPartsExist() { + if (displayParts.length) { + displayParts.push(lineBreakPart()); + } + } + function addFullSymbolName(symbol, enclosingDeclaration) { + var fullSymbolDisplayParts = symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration || sourceFile, undefined, 1 /* WriteTypeParametersOrArguments */ | 2 /* UseOnlyExternalAliasing */); + displayParts.push.apply(displayParts, fullSymbolDisplayParts); + } + function addPrefixForAnyFunctionOrVar(symbol, symbolKind) { + addNewLineIfDisplayPartsExist(); + if (symbolKind) { + displayParts.push(punctuationPart(11 /* OpenParenToken */)); + displayParts.push(textPart(symbolKind)); + displayParts.push(punctuationPart(12 /* CloseParenToken */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + } + } + function addSignatureDisplayParts(signature, allSignatures, flags) { + displayParts.push.apply(displayParts, signatureToDisplayParts(typeResolver, signature, enclosingDeclaration, flags | 32 /* WriteTypeArgumentsOfSignature */)); + if (allSignatures.length > 1) { + displayParts.push(spacePart()); + displayParts.push(punctuationPart(11 /* OpenParenToken */)); + displayParts.push(operatorPart(28 /* PlusToken */)); + displayParts.push(displayPart((allSignatures.length - 1).toString(), 7 /* numericLiteral */)); + displayParts.push(spacePart()); + displayParts.push(textPart(allSignatures.length === 2 ? "overload" : "overloads")); + displayParts.push(punctuationPart(12 /* CloseParenToken */)); + } + documentation = signature.getDocumentationComment(); + } + function writeTypeParametersOfSymbol(symbol, enclosingDeclaration) { + var typeParameterParts = mapToDisplayParts(function (writer) { + typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); + }); + displayParts.push.apply(displayParts, typeParameterParts); + } + } + function getQuickInfoAtPosition(fileName, position) { synchronizeHostData(); fileName = TypeScript.switchToForwardSlashes(fileName); var sourceFile = getSourceFile(fileName); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingPropertyName(sourceFile, position); if (!node) { return undefined; } var symbol = typeInfoResolver.getSymbolInfo(node); - var type = symbol && typeInfoResolver.getTypeOfSymbol(symbol); - if (type) { - return new TypeInfo(new TypeScript.MemberNameString(typeInfoResolver.typeToString(type)), "", typeInfoResolver.symbolToString(symbol, getContainerNode(node)), getSymbolKind(symbol), TypeScript.TextSpan.fromBounds(node.pos, node.end)); + if (!symbol) { + switch (node.kind) { + case 59 /* Identifier */: + case 137 /* PropertyAccess */: + case 116 /* QualifiedName */: + case 87 /* ThisKeyword */: + case 85 /* SuperKeyword */: + var type = typeInfoResolver.getTypeOfNode(node); + if (type) { + return { + kind: ScriptElementKind.unknown, + kindModifiers: ScriptElementKindModifier.none, + textSpan: new TypeScript.TextSpan(node.getStart(), node.getWidth()), + displayParts: typeToDisplayParts(typeInfoResolver, type, getContainerNode(node)), + documentation: type.symbol ? type.symbol.getDocumentationComment() : undefined + }; + } + } + return undefined; } - return undefined; + var displayPartsDocumentationsAndKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, getContainerNode(node), typeInfoResolver, node); + return { + kind: displayPartsDocumentationsAndKind.symbolKind, + kindModifiers: getSymbolModifiers(symbol), + textSpan: new TypeScript.TextSpan(node.getStart(), node.getWidth()), + displayParts: displayPartsDocumentationsAndKind.displayParts, + documentation: displayPartsDocumentationsAndKind.documentation + }; } function getDefinitionAtPosition(filename, position) { function getDefinitionInfo(node, symbolKind, symbolName, containerName) { - return new DefinitionInfo(node.getSourceFile().filename, TypeScript.TextSpan.fromBounds(node.getStart(), node.getEnd()), symbolKind, symbolName, undefined, containerName); + return { + fileName: node.getSourceFile().filename, + textSpan: TypeScript.TextSpan.fromBounds(node.getStart(), node.getEnd()), + kind: symbolKind, + name: symbolName, + containerKind: undefined, + containerName: containerName + }; } function tryAddSignature(signatureDeclarations, selectConstructors, symbolKind, symbolName, containerName, result) { var declarations = []; var definition; ts.forEach(signatureDeclarations, function (d) { - if ((selectConstructors && d.kind === 121 /* Constructor */) || (!selectConstructors && (d.kind === 172 /* FunctionDeclaration */ || d.kind === 120 /* Method */))) { + if ((selectConstructors && d.kind === 121 /* Constructor */) || (!selectConstructors && (d.kind === 174 /* FunctionDeclaration */ || d.kind === 120 /* Method */))) { declarations.push(d); if (d.body) definition = d; @@ -33053,7 +34716,7 @@ var ts; if (isNewExpressionTarget(location) || location.kind === 107 /* ConstructorKeyword */) { if (symbol.flags & 16 /* Class */) { var classDeclaration = symbol.getDeclarations()[0]; - ts.Debug.assert(classDeclaration && classDeclaration.kind === 174 /* ClassDeclaration */); + ts.Debug.assert(classDeclaration && classDeclaration.kind === 176 /* ClassDeclaration */); return tryAddSignature(classDeclaration.members, true, symbolKind, symbolName, containerName, result); } } @@ -33068,7 +34731,7 @@ var ts; synchronizeHostData(); filename = TypeScript.switchToForwardSlashes(filename); var sourceFile = getSourceFile(filename); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingPropertyName(sourceFile, position); if (!node) { return undefined; } @@ -33079,23 +34742,30 @@ var ts; } var comment = ts.forEach(sourceFile.referencedFiles, function (r) { return (r.pos <= position && position < r.end) ? r : undefined; }); if (comment) { - var targetFilename = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(filename), comment.filename)); + var targetFilename = ts.isRootedDiskPath(comment.filename) ? comment.filename : ts.combinePaths(ts.getDirectoryPath(filename), comment.filename); + targetFilename = ts.normalizePath(targetFilename); if (program.getSourceFile(targetFilename)) { - return [new DefinitionInfo(targetFilename, TypeScript.TextSpan.fromBounds(0, 0), ScriptElementKind.scriptElement, comment.filename, undefined, undefined)]; + return [{ + fileName: targetFilename, + textSpan: TypeScript.TextSpan.fromBounds(0, 0), + kind: ScriptElementKind.scriptElement, + name: comment.filename, + containerName: undefined, + containerKind: undefined + }]; } return undefined; } var symbol = typeInfoResolver.getSymbolInfo(node); - if (!symbol || !(symbol.getDeclarations())) { + if (!symbol) { return undefined; } var result = []; var declarations = symbol.getDeclarations(); - var symbolName = typeInfoResolver.symbolToString(symbol, node); - var symbolKind = getSymbolKind(symbol); + var symbolName = typeInfoResolver.symbolToString(symbol); + var symbolKind = getSymbolKind(symbol, typeInfoResolver); var containerSymbol = symbol.parent; var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : ""; - var containerKind = containerSymbol ? getSymbolKind(symbol) : ""; if (!tryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) && !tryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) { ts.forEach(declarations, function (declaration) { result.push(getDefinitionInfo(declaration, symbolKind, symbolName, containerName)); @@ -33107,57 +34777,62 @@ var ts; synchronizeHostData(); filename = TypeScript.switchToForwardSlashes(filename); var sourceFile = getSourceFile(filename); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingWord(sourceFile, position); if (!node) { return undefined; } if (node.kind === 59 /* Identifier */ || node.kind === 87 /* ThisKeyword */ || node.kind === 85 /* SuperKeyword */ || isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { - return getReferencesForNode(node, [sourceFile]); + return getReferencesForNode(node, [sourceFile], false, false); } switch (node.kind) { case 78 /* IfKeyword */: case 70 /* ElseKeyword */: - if (hasKind(node.parent, 152 /* IfStatement */)) { + if (hasKind(node.parent, 154 /* IfStatement */)) { return getIfElseOccurrences(node.parent); } break; case 84 /* ReturnKeyword */: - if (hasKind(node.parent, 159 /* ReturnStatement */)) { + if (hasKind(node.parent, 161 /* ReturnStatement */)) { return getReturnOccurrences(node.parent); } break; + case 88 /* ThrowKeyword */: + if (hasKind(node.parent, 167 /* ThrowStatement */)) { + return getThrowOccurrences(node.parent); + } + break; case 90 /* TryKeyword */: case 62 /* CatchKeyword */: case 75 /* FinallyKeyword */: - if (hasKind(parent(parent(node)), 166 /* TryStatement */)) { + if (hasKind(parent(parent(node)), 168 /* TryStatement */)) { return getTryCatchFinallyOccurrences(node.parent.parent); } break; case 86 /* SwitchKeyword */: - if (hasKind(node.parent, 161 /* SwitchStatement */)) { + if (hasKind(node.parent, 163 /* SwitchStatement */)) { return getSwitchCaseDefaultOccurrences(node.parent); } break; case 61 /* CaseKeyword */: case 67 /* DefaultKeyword */: - if (hasKind(parent(parent(node)), 161 /* SwitchStatement */)) { + if (hasKind(parent(parent(node)), 163 /* SwitchStatement */)) { return getSwitchCaseDefaultOccurrences(node.parent.parent); } break; case 60 /* BreakKeyword */: case 65 /* ContinueKeyword */: - if (hasKind(node.parent, 158 /* BreakStatement */) || hasKind(node.parent, 157 /* ContinueStatement */)) { + if (hasKind(node.parent, 160 /* BreakStatement */) || hasKind(node.parent, 159 /* ContinueStatement */)) { return getBreakOrContinueStatementOccurences(node.parent); } break; case 76 /* ForKeyword */: - if (hasKind(node.parent, 155 /* ForStatement */) || hasKind(node.parent, 156 /* ForInStatement */)) { + if (hasKind(node.parent, 157 /* ForStatement */) || hasKind(node.parent, 158 /* ForInStatement */)) { return getLoopBreakContinueOccurrences(node.parent); } break; case 94 /* WhileKeyword */: case 69 /* DoKeyword */: - if (hasKind(node.parent, 154 /* WhileStatement */) || hasKind(node.parent, 153 /* DoStatement */)) { + if (hasKind(node.parent, 156 /* WhileStatement */) || hasKind(node.parent, 155 /* DoStatement */)) { return getLoopBreakContinueOccurrences(node.parent); } break; @@ -33166,11 +34841,16 @@ var ts; return getConstructorOccurrences(node.parent); } break; + case 109 /* GetKeyword */: + case 113 /* SetKeyword */: + if (hasKind(node.parent, 122 /* GetAccessor */) || hasKind(node.parent, 123 /* SetAccessor */)) { + return getGetAndSetOccurrences(node.parent); + } } return undefined; function getIfElseOccurrences(ifStatement) { var keywords = []; - while (hasKind(ifStatement.parent, 152 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) { + while (hasKind(ifStatement.parent, 154 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) { ifStatement = ifStatement.parent; } while (ifStatement) { @@ -33181,7 +34861,7 @@ var ts; break; } } - if (!hasKind(ifStatement.elseStatement, 152 /* IfStatement */)) { + if (!hasKind(ifStatement.elseStatement, 154 /* IfStatement */)) { break; } ifStatement = ifStatement.elseStatement; @@ -33199,7 +34879,11 @@ var ts; } } if (shouldHighlightNextKeyword) { - result.push(new ReferenceEntry(filename, TypeScript.TextSpan.fromBounds(elseKeyword.getStart(), ifKeyword.end), false)); + result.push({ + fileName: filename, + textSpan: TypeScript.TextSpan.fromBounds(elseKeyword.getStart(), ifKeyword.end), + isWriteAccess: false + }); i++; continue; } @@ -33210,15 +34894,77 @@ var ts; } function getReturnOccurrences(returnStatement) { var func = ts.getContainingFunction(returnStatement); - if (!(func && hasKind(func.body, 173 /* FunctionBlock */))) { + if (!(func && hasKind(func.body, 175 /* FunctionBlock */))) { return undefined; } var keywords = []; ts.forEachReturnStatement(func.body, function (returnStatement) { pushKeywordIf(keywords, returnStatement.getFirstToken(), 84 /* ReturnKeyword */); }); + ts.forEach(aggregateOwnedThrowStatements(func.body), function (throwStatement) { + pushKeywordIf(keywords, throwStatement.getFirstToken(), 88 /* ThrowKeyword */); + }); return ts.map(keywords, getReferenceEntryFromNode); } + function getThrowOccurrences(throwStatement) { + var owner = getThrowStatementOwner(throwStatement); + if (!owner) { + return undefined; + } + var keywords = []; + ts.forEach(aggregateOwnedThrowStatements(owner), function (throwStatement) { + pushKeywordIf(keywords, throwStatement.getFirstToken(), 88 /* ThrowKeyword */); + }); + if (owner.kind === 175 /* FunctionBlock */) { + ts.forEachReturnStatement(owner, function (returnStatement) { + pushKeywordIf(keywords, returnStatement.getFirstToken(), 84 /* ReturnKeyword */); + }); + } + return ts.map(keywords, getReferenceEntryFromNode); + } + function aggregateOwnedThrowStatements(node) { + var statementAccumulator = []; + aggregate(node); + return statementAccumulator; + function aggregate(node) { + if (node.kind === 167 /* ThrowStatement */) { + statementAccumulator.push(node); + } + else if (node.kind === 168 /* TryStatement */) { + var tryStatement = node; + if (tryStatement.catchBlock) { + aggregate(tryStatement.catchBlock); + } + else { + aggregate(tryStatement.tryBlock); + } + if (tryStatement.finallyBlock) { + aggregate(tryStatement.finallyBlock); + } + } + else if (!ts.isAnyFunction(node)) { + ts.forEachChild(node, aggregate); + } + } + ; + } + function getThrowStatementOwner(throwStatement) { + var child = throwStatement; + while (child.parent) { + var parent = child.parent; + if (parent.kind === 175 /* FunctionBlock */ || parent.kind === 184 /* SourceFile */) { + return parent; + } + if (parent.kind === 168 /* TryStatement */) { + var tryStatement = parent; + if (tryStatement.tryBlock === child && tryStatement.catchBlock) { + return child; + } + } + child = parent; + } + return undefined; + } function getTryCatchFinallyOccurrences(tryStatement) { var keywords = []; pushKeywordIf(keywords, tryStatement.getFirstToken(), 90 /* TryKeyword */); @@ -33233,7 +34979,7 @@ var ts; function getLoopBreakContinueOccurrences(loopNode) { var keywords = []; if (pushKeywordIf(keywords, loopNode.getFirstToken(), 76 /* ForKeyword */, 94 /* WhileKeyword */, 69 /* DoKeyword */)) { - if (loopNode.kind === 153 /* DoStatement */) { + if (loopNode.kind === 155 /* DoStatement */) { var loopTokens = loopNode.getChildren(); for (var i = loopTokens.length - 1; i >= 0; i--) { if (pushKeywordIf(keywords, loopTokens[i], 94 /* WhileKeyword */)) { @@ -33269,12 +35015,12 @@ var ts; var owner = getBreakOrContinueOwner(breakOrContinueStatement); if (owner) { switch (owner.kind) { - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: return getLoopBreakContinueOccurrences(owner); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return getSwitchCaseDefaultOccurrences(owner); } } @@ -33285,7 +35031,7 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 158 /* BreakStatement */ || node.kind === 157 /* ContinueStatement */) { + if (node.kind === 160 /* BreakStatement */ || node.kind === 159 /* ContinueStatement */) { statementAccumulator.push(node); } else if (!ts.isAnyFunction(node)) { @@ -33301,14 +35047,14 @@ var ts; function getBreakOrContinueOwner(statement) { for (var node = statement.parent; node; node = node.parent) { switch (node.kind) { - case 161 /* SwitchStatement */: - if (statement.kind === 157 /* ContinueStatement */) { + case 163 /* SwitchStatement */: + if (statement.kind === 159 /* ContinueStatement */) { continue; } - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 154 /* WhileStatement */: - case 153 /* DoStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 156 /* WhileStatement */: + case 155 /* DoStatement */: if (!statement.label || isLabeledBy(node, statement.label.text)) { return node; } @@ -33332,6 +35078,18 @@ var ts; }); return ts.map(keywords, getReferenceEntryFromNode); } + function getGetAndSetOccurrences(accessorDeclaration) { + var keywords = []; + tryPushAccessorKeyword(accessorDeclaration.symbol, 122 /* GetAccessor */); + tryPushAccessorKeyword(accessorDeclaration.symbol, 123 /* SetAccessor */); + return ts.map(keywords, getReferenceEntryFromNode); + function tryPushAccessorKeyword(accessorSymbol, accessorKind) { + var accessor = ts.getDeclarationOfKind(accessorSymbol, accessorKind); + if (accessor) { + ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 109 /* GetKeyword */, 113 /* SetKeyword */); }); + } + } + } function hasKind(node, kind) { return node !== undefined && node.kind === kind; } @@ -33350,20 +35108,27 @@ var ts; return false; } } - function getReferencesAtPosition(filename, position) { + function findRenameLocations(fileName, position, findInStrings, findInComments) { + return findReferences(fileName, position, findInStrings, findInComments); + } + function getReferencesAtPosition(fileName, position) { + return findReferences(fileName, position, false, false); + } + function findReferences(fileName, position, findInStrings, findInComments) { synchronizeHostData(); - filename = TypeScript.switchToForwardSlashes(filename); - var sourceFile = getSourceFile(filename); - var node = getNodeAtPosition(sourceFile, position); + fileName = TypeScript.switchToForwardSlashes(fileName); + var sourceFile = getSourceFile(fileName); + var node = ts.getTouchingPropertyName(sourceFile, position); if (!node) { return undefined; } if (node.kind !== 59 /* Identifier */ && !isLiteralNameOfPropertyDeclarationOrIndexAccess(node) && !isNameOfExternalModuleImportOrDeclaration(node)) { return undefined; } - return getReferencesForNode(node, program.getSourceFiles()); + ts.Debug.assert(node.kind === 59 /* Identifier */ || node.kind === 6 /* NumericLiteral */ || node.kind === 7 /* StringLiteral */); + return getReferencesForNode(node, program.getSourceFiles(), findInStrings, findInComments); } - function getReferencesForNode(node, sourceFiles) { + function getReferencesForNode(node, sourceFiles, findInStrings, findInComments) { if (isLabelName(node)) { if (isJumpStatementTarget(node)) { var labelDefinition = getTargetLabel(node.parent, node.text); @@ -33383,34 +35148,35 @@ var ts; if (!symbol) { return [getReferenceEntryFromNode(node)]; } - if (!symbol.getDeclarations()) { + var declarations = symbol.declarations; + if (!declarations || !declarations.length) { return undefined; } var result; - var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), symbol.getDeclarations()); - var symbolName = getNormalizedSymbolName(symbol); + var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); + var symbolName = getNormalizedSymbolName(symbol.name, declarations); var scope = getSymbolScope(symbol); if (scope) { result = []; - getReferencesInNode(scope, symbol, symbolName, node, searchMeaning, result); + getReferencesInNode(scope, symbol, symbolName, node, searchMeaning, findInStrings, findInComments, result); } else { ts.forEach(sourceFiles, function (sourceFile) { cancellationToken.throwIfCancellationRequested(); if (ts.lookUp(sourceFile.identifiers, symbolName)) { result = result || []; - getReferencesInNode(sourceFile, symbol, symbolName, node, searchMeaning, result); + getReferencesInNode(sourceFile, symbol, symbolName, node, searchMeaning, findInStrings, findInComments, result); } }); } return result; - function getNormalizedSymbolName(symbol) { - var functionExpression = ts.getDeclarationOfKind(symbol, 141 /* FunctionExpression */); + function getNormalizedSymbolName(symbolName, declarations) { + var functionExpression = ts.forEach(declarations, function (d) { return d.kind === 143 /* FunctionExpression */ ? d : undefined; }); if (functionExpression && functionExpression.name) { var name = functionExpression.name.text; } else { - var name = symbol.name; + var name = symbolName; } var length = name.length; if (length >= 2 && name.charCodeAt(0) === 34 /* doubleQuote */ && name.charCodeAt(length - 1) === 34 /* doubleQuote */) { @@ -33431,15 +35197,17 @@ var ts; } var scope = undefined; var declarations = symbol.getDeclarations(); - for (var i = 0, n = declarations.length; i < n; i++) { - var container = getContainerNode(declarations[i]); - if (scope && scope !== container) { - return undefined; + if (declarations) { + for (var i = 0, n = declarations.length; i < n; i++) { + var container = getContainerNode(declarations[i]); + if (scope && scope !== container) { + return undefined; + } + if (container.kind === 184 /* SourceFile */ && !ts.isExternalModule(container)) { + return undefined; + } + scope = container; } - if (container.kind === 182 /* SourceFile */ && !ts.isExternalModule(container)) { - return undefined; - } - scope = container; } return scope; } @@ -33471,7 +35239,7 @@ var ts; var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, labelName, container.getStart(), container.getEnd()); ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingWord(sourceFile, position); if (!node || node.getWidth() !== labelName.length) { return; } @@ -33500,29 +35268,53 @@ var ts; } return false; } - function getReferencesInNode(container, searchSymbol, searchText, searchLocation, searchMeaning, result) { + function getReferencesInNode(container, searchSymbol, searchText, searchLocation, searchMeaning, findInStrings, findInComments, result) { var sourceFile = container.getSourceFile(); + var tripleSlashDirectivePrefixRegex = /^\/\/\/\s* token.getStart(); + } + function isInComment(position) { + var token = ts.getTokenAtPosition(sourceFile, position); + if (token && position < token.getStart()) { + var commentRanges = ts.getLeadingCommentRanges(sourceFile.text, token.pos); + return ts.forEach(commentRanges, function (c) { + if (c.pos < position && position < c.end) { + var commentText = sourceFile.text.substring(c.pos, c.end); + if (!tripleSlashDirectivePrefixRegex.test(commentText)) { + return true; + } + } + }); + } + return false; + } } function getReferencesForSuperKeyword(superKeyword) { var searchSpaceNode = ts.getSuperContainer(superKeyword); @@ -33547,7 +35339,7 @@ var ts; var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "super", searchSpaceNode.getStart(), searchSpaceNode.getEnd()); ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingWord(sourceFile, position); if (!node || node.kind !== 85 /* SuperKeyword */) { return; } @@ -33570,18 +35362,18 @@ var ts; staticFlag &= searchSpaceNode.flags; searchSpaceNode = searchSpaceNode.parent; break; - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (ts.isExternalModule(searchSpaceNode)) { return undefined; } - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: break; default: return undefined; } var result = []; - if (searchSpaceNode.kind === 182 /* SourceFile */) { + if (searchSpaceNode.kind === 184 /* SourceFile */) { ts.forEach(sourceFiles, function (sourceFile) { var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", sourceFile.getStart(), sourceFile.getEnd()); getThisReferencesInFile(sourceFile, sourceFile, possiblePositions, result); @@ -33596,25 +35388,25 @@ var ts; function getThisReferencesInFile(sourceFile, searchSpaceNode, possiblePositions, result) { ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingWord(sourceFile, position); if (!node || node.kind !== 87 /* ThisKeyword */) { return; } var container = ts.getThisContainer(node, false); switch (searchSpaceNode.kind) { - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: if (searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } break; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: if (container.parent && searchSpaceNode.symbol === container.parent.symbol && (container.flags & 128 /* Static */) === staticFlag) { result.push(getReferenceEntryFromNode(node)); } break; - case 182 /* SourceFile */: - if (container.kind === 182 /* SourceFile */ && !ts.isExternalModule(container)) { + case 184 /* SourceFile */: + if (container.kind === 184 /* SourceFile */ && !ts.isExternalModule(container)) { result.push(getReferenceEntryFromNode(node)); } break; @@ -33624,28 +35416,29 @@ var ts; } function populateSearchSymbolSet(symbol, location) { var result = [symbol]; - var rootSymbol = typeInfoResolver.getRootSymbol(symbol); - if (rootSymbol && rootSymbol !== symbol) { - result.push(rootSymbol); - } if (isNameOfPropertyAssignment(location)) { - var symbolFromContextualType = getPropertySymbolFromContextualType(location); - if (symbolFromContextualType) - result.push(typeInfoResolver.getRootSymbol(symbolFromContextualType)); - } - if (symbol.parent && symbol.parent.flags & (16 /* Class */ | 32 /* Interface */)) { - getPropertySymbolsFromBaseTypes(symbol.parent, symbol.getName(), result); + ts.forEach(getPropertySymbolsFromContextualType(location), function (contextualSymbol) { + result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol)); + }); } + ts.forEach(typeInfoResolver.getRootSymbols(symbol), function (rootSymbol) { + if (rootSymbol !== symbol) { + result.push(rootSymbol); + } + if (rootSymbol.parent && rootSymbol.parent.flags & (16 /* Class */ | 32 /* Interface */)) { + getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result); + } + }); return result; } function getPropertySymbolsFromBaseTypes(symbol, propertyName, result) { - if (symbol.flags & (16 /* Class */ | 32 /* Interface */)) { + if (symbol && symbol.flags & (16 /* Class */ | 32 /* Interface */)) { ts.forEach(symbol.getDeclarations(), function (declaration) { - if (declaration.kind === 174 /* ClassDeclaration */) { + if (declaration.kind === 176 /* ClassDeclaration */) { getPropertySymbolFromTypeReference(declaration.baseType); ts.forEach(declaration.implementedTypes, getPropertySymbolFromTypeReference); } - else if (declaration.kind === 175 /* InterfaceDeclaration */) { + else if (declaration.kind === 177 /* InterfaceDeclaration */) { ts.forEach(declaration.baseTypes, getPropertySymbolFromTypeReference); } }); @@ -33653,131 +35446,70 @@ var ts; return; function getPropertySymbolFromTypeReference(typeReference) { if (typeReference) { - var typeReferenceSymbol = typeInfoResolver.getSymbolInfo(typeReference.typeName); - if (typeReferenceSymbol) { - var propertySymbol = typeReferenceSymbol.members[propertyName]; - if (propertySymbol) - result.push(typeReferenceSymbol.members[propertyName]); - getPropertySymbolsFromBaseTypes(typeReferenceSymbol, propertyName, result); + var type = typeInfoResolver.getTypeOfNode(typeReference); + if (type) { + var propertySymbol = typeInfoResolver.getPropertyOfType(type, propertyName); + if (propertySymbol) { + result.push(propertySymbol); + } + getPropertySymbolsFromBaseTypes(type.symbol, propertyName, result); } } } } function isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation) { - var referenceSymbolTarget = typeInfoResolver.getRootSymbol(referenceSymbol); - if (searchSymbols.indexOf(referenceSymbolTarget) >= 0) { + if (searchSymbols.indexOf(referenceSymbol) >= 0) { return true; } if (isNameOfPropertyAssignment(referenceLocation)) { - var symbolFromContextualType = getPropertySymbolFromContextualType(referenceLocation); - if (symbolFromContextualType && searchSymbols.indexOf(typeInfoResolver.getRootSymbol(symbolFromContextualType)) >= 0) { + return ts.forEach(getPropertySymbolsFromContextualType(referenceLocation), function (contextualSymbol) { + return ts.forEach(typeInfoResolver.getRootSymbols(contextualSymbol), function (s) { return searchSymbols.indexOf(s) >= 0; }); + }); + } + return ts.forEach(typeInfoResolver.getRootSymbols(referenceSymbol), function (rootSymbol) { + if (searchSymbols.indexOf(rootSymbol) >= 0) { return true; } - } - if (referenceSymbol.parent && referenceSymbol.parent.flags & (16 /* Class */ | 32 /* Interface */)) { - var result = []; - getPropertySymbolsFromBaseTypes(referenceSymbol.parent, referenceSymbol.getName(), result); - return ts.forEach(result, function (s) { return searchSymbols.indexOf(s) >= 0; }); - } - return false; + if (rootSymbol.parent && rootSymbol.parent.flags & (16 /* Class */ | 32 /* Interface */)) { + var result = []; + getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result); + return ts.forEach(result, function (s) { return searchSymbols.indexOf(s) >= 0; }); + } + return false; + }); } - function getPropertySymbolFromContextualType(node) { + function getPropertySymbolsFromContextualType(node) { if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeInfoResolver.getContextualType(objectLiteral); + var name = node.text; if (contextualType) { - return typeInfoResolver.getPropertyOfType(contextualType, node.text); + if (contextualType.flags & 16384 /* Union */) { + var unionProperty = contextualType.getProperty(name); + if (unionProperty) { + return [unionProperty]; + } + else { + var result = []; + ts.forEach(contextualType.types, function (t) { + var symbol = t.getProperty(name); + if (symbol) { + result.push(symbol); + } + }); + return result; + } + } + else { + var symbol = contextualType.getProperty(name); + if (symbol) { + return [symbol]; + } + } } } return undefined; } - function getMeaningFromDeclaration(node) { - switch (node.kind) { - case 118 /* Parameter */: - case 171 /* VariableDeclaration */: - case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: - case 120 /* Method */: - case 121 /* Constructor */: - case 122 /* GetAccessor */: - case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: - case 168 /* CatchBlock */: - return 1 /* Value */; - case 117 /* TypeParameter */: - case 175 /* InterfaceDeclaration */: - case 129 /* TypeLiteral */: - return 2 /* Type */; - case 174 /* ClassDeclaration */: - case 176 /* EnumDeclaration */: - return 1 /* Value */ | 2 /* Type */; - case 177 /* ModuleDeclaration */: - if (node.name.kind === 7 /* StringLiteral */) { - return 4 /* Namespace */ | 1 /* Value */; - } - else if (ts.isInstantiated(node)) { - return 4 /* Namespace */ | 1 /* Value */; - } - else { - return 4 /* Namespace */; - } - break; - case 179 /* ImportDeclaration */: - return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; - } - ts.Debug.fail("Unknown declaration type"); - } - function isTypeReference(node) { - if (node.parent.kind === 116 /* QualifiedName */ && node.parent.right === node) - node = node.parent; - return node.parent.kind === 127 /* TypeReference */; - } - function isNamespaceReference(node) { - var root = node; - var isLastClause = true; - if (root.parent.kind === 116 /* QualifiedName */) { - while (root.parent && root.parent.kind === 116 /* QualifiedName */) - root = root.parent; - isLastClause = root.right === node; - } - return root.parent.kind === 127 /* TypeReference */ && !isLastClause; - } - function isInRightSideOfImport(node) { - while (node.parent.kind === 116 /* QualifiedName */) { - node = node.parent; - } - return node.parent.kind === 179 /* ImportDeclaration */ && node.parent.entityName === node; - } - function getMeaningFromRightHandSideOfImport(node) { - ts.Debug.assert(node.kind === 59 /* Identifier */); - if (node.parent.kind === 116 /* QualifiedName */ && node.parent.right === node && node.parent.parent.kind === 179 /* ImportDeclaration */) { - return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; - } - return 4 /* Namespace */; - } - function getMeaningFromLocation(node) { - if (node.parent.kind === 180 /* ExportAssignment */) { - return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; - } - else if (isInRightSideOfImport(node)) { - return getMeaningFromRightHandSideOfImport(node); - } - else if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { - return getMeaningFromDeclaration(node.parent); - } - else if (isTypeReference(node)) { - return 2 /* Type */; - } - else if (isNamespaceReference(node)) { - return 4 /* Namespace */; - } - else { - return 1 /* Value */; - } - } function getIntersectingMeaningFromDeclarations(meaning, declarations) { if (declarations) { do { @@ -33800,7 +35532,11 @@ var ts; start += 1; end -= 1; } - return new ReferenceEntry(node.getSourceFile().filename, TypeScript.TextSpan.fromBounds(start, end), isWriteAccess(node)); + return { + fileName: node.getSourceFile().filename, + textSpan: TypeScript.TextSpan.fromBounds(start, end), + isWriteAccess: isWriteAccess(node) + }; } function isWriteAccess(node) { if (node.kind === 59 /* Identifier */ && ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { @@ -33808,10 +35544,10 @@ var ts; } var parent = node.parent; if (parent) { - if (parent.kind === 144 /* PostfixOperator */ || parent.kind === 143 /* PrefixOperator */) { + if (parent.kind === 146 /* PostfixOperator */ || parent.kind === 145 /* PrefixOperator */) { return true; } - else if (parent.kind === 145 /* BinaryExpression */ && parent.left === node) { + else if (parent.kind === 147 /* BinaryExpression */ && parent.left === node) { var operator = parent.operator; return ts.SyntaxKind.FirstAssignment <= operator && operator <= ts.SyntaxKind.LastAssignment; } @@ -33886,7 +35622,7 @@ var ts; filename = TypeScript.switchToForwardSlashes(filename); var compilerOptions = program.getCompilerOptions(); var targetSourceFile = program.getSourceFile(filename); - var emitToSingleFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions); + var shouldEmitToOwnFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions); var emitDeclaration = compilerOptions.declaration; var emitOutput = { outputFiles: [], @@ -33902,7 +35638,7 @@ var ts; writer = getEmitOutputWriter; var syntacticDiagnostics = []; var containSyntacticErrors = false; - if (emitToSingleFile) { + if (shouldEmitToOwnFile) { containSyntacticErrors = containErrors(program.getDiagnostics(targetSourceFile)); } else { @@ -33918,11 +35654,152 @@ var ts; writer = undefined; return emitOutput; } - var emitFilesResult = emitToSingleFile ? getFullTypeCheckChecker().emitFiles(targetSourceFile) : getFullTypeCheckChecker().emitFiles(); + var emitFilesResult = getFullTypeCheckChecker().emitFiles(targetSourceFile); emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus; writer = undefined; return emitOutput; } + function getMeaningFromDeclaration(node) { + switch (node.kind) { + case 118 /* Parameter */: + case 173 /* VariableDeclaration */: + case 119 /* Property */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: + case 120 /* Method */: + case 121 /* Constructor */: + case 122 /* GetAccessor */: + case 123 /* SetAccessor */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: + case 170 /* CatchBlock */: + return 1 /* Value */; + case 117 /* TypeParameter */: + case 177 /* InterfaceDeclaration */: + case 129 /* TypeLiteral */: + return 2 /* Type */; + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: + return 1 /* Value */ | 2 /* Type */; + case 179 /* ModuleDeclaration */: + if (node.name.kind === 7 /* StringLiteral */) { + return 4 /* Namespace */ | 1 /* Value */; + } + else if (ts.isInstantiated(node)) { + return 4 /* Namespace */ | 1 /* Value */; + } + else { + return 4 /* Namespace */; + } + break; + case 181 /* ImportDeclaration */: + return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; + } + ts.Debug.fail("Unknown declaration type"); + } + function isTypeReference(node) { + if (node.parent.kind === 116 /* QualifiedName */ && node.parent.right === node) + node = node.parent; + return node.parent.kind === 127 /* TypeReference */; + } + function isNamespaceReference(node) { + var root = node; + var isLastClause = true; + if (root.parent.kind === 116 /* QualifiedName */) { + while (root.parent && root.parent.kind === 116 /* QualifiedName */) + root = root.parent; + isLastClause = root.right === node; + } + return root.parent.kind === 127 /* TypeReference */ && !isLastClause; + } + function isInRightSideOfImport(node) { + while (node.parent.kind === 116 /* QualifiedName */) { + node = node.parent; + } + return node.parent.kind === 181 /* ImportDeclaration */ && node.parent.entityName === node; + } + function getMeaningFromRightHandSideOfImport(node) { + ts.Debug.assert(node.kind === 59 /* Identifier */); + if (node.parent.kind === 116 /* QualifiedName */ && node.parent.right === node && node.parent.parent.kind === 181 /* ImportDeclaration */) { + return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; + } + return 4 /* Namespace */; + } + function getMeaningFromLocation(node) { + if (node.parent.kind === 182 /* ExportAssignment */) { + return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; + } + else if (isInRightSideOfImport(node)) { + return getMeaningFromRightHandSideOfImport(node); + } + else if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + return getMeaningFromDeclaration(node.parent); + } + else if (isTypeReference(node)) { + return 2 /* Type */; + } + else if (isNamespaceReference(node)) { + return 4 /* Namespace */; + } + else { + return 1 /* Value */; + } + } + function getSignatureHelpItems(fileName, position) { + synchronizeHostData(); + fileName = TypeScript.switchToForwardSlashes(fileName); + var sourceFile = getSourceFile(fileName); + return ts.SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken); + } + function getSignatureAtPosition(filename, position) { + var signatureHelpItems = getSignatureHelpItems(filename, position); + if (!signatureHelpItems) { + return undefined; + } + var currentArgumentState = { argumentIndex: signatureHelpItems.argumentIndex, argumentCount: signatureHelpItems.argumentCount }; + var formalSignatures = []; + ts.forEach(signatureHelpItems.items, function (signature) { + var signatureInfoString = displayPartsToString(signature.prefixDisplayParts); + var parameters = []; + if (signature.parameters) { + for (var i = 0, n = signature.parameters.length; i < n; i++) { + var parameter = signature.parameters[i]; + if (i) { + signatureInfoString += displayPartsToString(signature.separatorDisplayParts); + } + var start = signatureInfoString.length; + signatureInfoString += displayPartsToString(parameter.displayParts); + var end = signatureInfoString.length - 1; + parameters.push({ + name: parameter.name, + isVariable: i === n - 1 && signature.isVariadic, + docComment: displayPartsToString(parameter.documentation), + minChar: start, + limChar: end + }); + } + } + signatureInfoString += displayPartsToString(signature.suffixDisplayParts); + formalSignatures.push({ + signatureInfo: signatureInfoString, + docComment: displayPartsToString(signature.documentation), + parameters: parameters, + typeParameters: [] + }); + }); + var actualSignature = { + parameterMinChar: signatureHelpItems.applicableSpan.start(), + parameterLimChar: signatureHelpItems.applicableSpan.end(), + currentParameterIsTypeParameter: false, + currentParameter: currentArgumentState.argumentIndex + }; + return { + actual: actualSignature, + formal: formalSignatures, + activeFormal: 0 + }; + } function getSyntaxTree(filename) { filename = TypeScript.switchToForwardSlashes(filename); return syntaxTreeCache.getCurrentFileSyntaxTree(filename); @@ -33985,8 +35862,7 @@ var ts; } function getNavigationBarItems(filename) { filename = TypeScript.switchToForwardSlashes(filename); - var syntaxTree = getSyntaxTree(filename); - return new TypeScript.Services.NavigationBarItemGetter().getItems(syntaxTree.sourceUnit()); + return ts.NavigationBar.getNavigationBarItems(getCurrentSourceFile(filename)); } function getSemanticClassifications(fileName, span) { synchronizeHostData(); @@ -33995,7 +35871,7 @@ var ts; var result = []; processNode(sourceFile); return result; - function classifySymbol(symbol) { + function classifySymbol(symbol, meaningAtPosition) { var flags = symbol.getFlags(); if (flags & 16 /* Class */) { return ClassificationTypeNames.className; @@ -34003,14 +35879,24 @@ var ts; else if (flags & 64 /* Enum */) { return ClassificationTypeNames.enumName; } - else if (flags & 32 /* Interface */) { - return ClassificationTypeNames.interfaceName; + else if (meaningAtPosition & 2 /* Type */) { + if (flags & 32 /* Interface */) { + return ClassificationTypeNames.interfaceName; + } + else if (flags & 262144 /* TypeParameter */) { + return ClassificationTypeNames.typeParameterName; + } } else if (flags & ts.SymbolFlags.Module) { - return ClassificationTypeNames.moduleName; + if (meaningAtPosition & 4 /* Namespace */ || (meaningAtPosition & 1 /* Value */ && hasValueSideModule(symbol))) { + return ClassificationTypeNames.moduleName; + } } - else if (flags & 262144 /* TypeParameter */) { - return ClassificationTypeNames.typeParameterName; + return undefined; + function hasValueSideModule(symbol) { + return ts.forEach(symbol.declarations, function (declaration) { + return declaration.kind === 179 /* ModuleDeclaration */ && ts.isInstantiated(declaration); + }); } } function processNode(node) { @@ -34018,9 +35904,12 @@ var ts; if (node.kind === 59 /* Identifier */ && node.getWidth() > 0) { var symbol = typeInfoResolver.getSymbolInfo(node); if (symbol) { - var type = classifySymbol(symbol); + var type = classifySymbol(symbol, getMeaningFromLocation(node)); if (type) { - result.push(new ClassifiedSpan(new TypeScript.TextSpan(node.getStart(), node.getWidth()), type)); + result.push({ + textSpan: new TypeScript.TextSpan(node.getStart(), node.getWidth()), + classificationType: type + }); } } } @@ -34032,93 +35921,81 @@ var ts; fileName = TypeScript.switchToForwardSlashes(fileName); var sourceFile = getCurrentSourceFile(fileName); var result = []; - processElement(sourceFile.getSourceUnit()); + processElement(sourceFile); return result; - function classifyTrivia(trivia) { - if (trivia.isComment() && span.intersectsWith(trivia.fullStart(), trivia.fullWidth())) { - result.push(new ClassifiedSpan(new TypeScript.TextSpan(trivia.fullStart(), trivia.fullWidth()), ClassificationTypeNames.comment)); - } - } - function classifyTriviaList(trivia) { - for (var i = 0, n = trivia.count(); i < n; i++) { - classifyTrivia(trivia.syntaxTriviaAt(i)); + function classifyComment(comment) { + var width = comment.end - comment.pos; + if (span.intersectsWith(comment.pos, width)) { + result.push({ + textSpan: new TypeScript.TextSpan(comment.pos, width), + classificationType: ClassificationTypeNames.comment + }); } } function classifyToken(token) { - if (token.hasLeadingComment()) { - classifyTriviaList(token.leadingTrivia()); - } - if (TypeScript.width(token) > 0) { + ts.forEach(ts.getLeadingCommentRanges(sourceFile.text, token.getFullStart()), classifyComment); + if (token.getWidth() > 0) { var type = classifyTokenType(token); if (type) { - result.push(new ClassifiedSpan(new TypeScript.TextSpan(TypeScript.start(token), TypeScript.width(token)), type)); + result.push({ + textSpan: new TypeScript.TextSpan(token.getStart(), token.getWidth()), + classificationType: type + }); } } - if (token.hasTrailingComment()) { - classifyTriviaList(token.trailingTrivia()); - } + ts.forEach(ts.getTrailingCommentRanges(sourceFile.text, token.getEnd()), classifyComment); } function classifyTokenType(token) { - var tokenKind = token.kind(); - if (TypeScript.SyntaxFacts.isAnyKeyword(token.kind())) { + var tokenKind = token.kind; + if (ts.isKeyword(tokenKind)) { return ClassificationTypeNames.keyword; } - if (tokenKind === 80 /* LessThanToken */ || tokenKind === 81 /* GreaterThanToken */) { - var tokenParentKind = token.parent.kind(); - if (tokenParentKind === 229 /* TypeArgumentList */ || tokenParentKind === 230 /* TypeParameterList */) { + if (tokenKind === 19 /* LessThanToken */ || tokenKind === 20 /* GreaterThanToken */) { + if (ts.getTypeArgumentOrTypeParameterList(token.parent)) { return ClassificationTypeNames.punctuation; } } - if (TypeScript.SyntaxFacts.isBinaryExpressionOperatorToken(tokenKind) || TypeScript.SyntaxFacts.isPrefixUnaryExpressionOperatorToken(tokenKind)) { - return ClassificationTypeNames.operator; + if (ts.isPunctuation(token)) { + if (token.parent.kind === 147 /* BinaryExpression */ || token.parent.kind === 173 /* VariableDeclaration */ || token.parent.kind === 145 /* PrefixOperator */ || token.parent.kind === 146 /* PostfixOperator */ || token.parent.kind === 148 /* ConditionalExpression */) { + return ClassificationTypeNames.operator; + } + else { + return ClassificationTypeNames.punctuation; + } } - else if (TypeScript.SyntaxFacts.isAnyPunctuation(tokenKind)) { - return ClassificationTypeNames.punctuation; - } - else if (tokenKind === 13 /* NumericLiteral */) { + else if (tokenKind === 6 /* NumericLiteral */) { return ClassificationTypeNames.numericLiteral; } - else if (tokenKind === 14 /* StringLiteral */) { + else if (tokenKind === 7 /* StringLiteral */) { return ClassificationTypeNames.stringLiteral; } - else if (tokenKind === 12 /* RegularExpressionLiteral */) { + else if (tokenKind === 8 /* RegularExpressionLiteral */) { return ClassificationTypeNames.stringLiteral; } - else if (tokenKind === 11 /* IdentifierName */) { - var current = token; - var parent = token.parent; - while (parent.kind() === 121 /* QualifiedName */) { - current = parent; - parent = parent.parent; - } - switch (parent.kind()) { - case 241 /* SimplePropertyAssignment */: - if (parent.propertyName === token) { - return ClassificationTypeNames.identifier; - } - return; - case 132 /* ClassDeclaration */: - if (parent.identifier === token) { + else if (tokenKind === 59 /* Identifier */) { + switch (token.parent.kind) { + case 176 /* ClassDeclaration */: + if (token.parent.name === token) { return ClassificationTypeNames.className; } return; - case 239 /* TypeParameter */: - if (parent.identifier === token) { + case 117 /* TypeParameter */: + if (token.parent.name === token) { return ClassificationTypeNames.typeParameterName; } return; - case 129 /* InterfaceDeclaration */: - if (parent.identifier === token) { + case 177 /* InterfaceDeclaration */: + if (token.parent.name === token) { return ClassificationTypeNames.interfaceName; } return; - case 133 /* EnumDeclaration */: - if (parent.identifier === token) { + case 178 /* EnumDeclaration */: + if (token.parent.name === token) { return ClassificationTypeNames.enumName; } return; - case 131 /* ModuleDeclaration */: - if (parent.name === current) { + case 179 /* ModuleDeclaration */: + if (token.parent.name === token) { return ClassificationTypeNames.moduleName; } return; @@ -34128,16 +36005,15 @@ var ts; } } function processElement(element) { - if (!TypeScript.isShared(element) && span.intersectsWith(TypeScript.fullStart(element), TypeScript.fullWidth(element))) { - for (var i = 0, n = TypeScript.childCount(element); i < n; i++) { - var child = TypeScript.childAt(element, i); - if (child) { - if (TypeScript.isToken(child)) { - classifyToken(child); - } - else { - processElement(child); - } + if (span.intersectsWith(element.getFullStart(), element.getFullWidth())) { + var children = element.getChildren(); + for (var i = 0, n = children.length; i < n; i++) { + var child = children[i]; + if (ts.isToken(child)) { + classifyToken(child); + } + else { + processElement(child); } } } @@ -34149,9 +36025,52 @@ var ts; return ts.OutliningElementsCollector.collectElements(sourceFile); } function getBraceMatchingAtPosition(filename, position) { - filename = TypeScript.switchToForwardSlashes(filename); - var syntaxTree = getSyntaxTree(filename); - return TypeScript.Services.BraceMatcher.getMatchSpans(syntaxTree, position); + var sourceFile = getCurrentSourceFile(filename); + var result = []; + var token = ts.getTouchingToken(sourceFile, position); + if (token.getStart(sourceFile) === position) { + var matchKind = getMatchingTokenKind(token); + if (matchKind) { + var parentElement = token.parent; + var childNodes = parentElement.getChildren(sourceFile); + for (var i = 0, n = childNodes.length; i < n; i++) { + var current = childNodes[i]; + if (current.kind === matchKind) { + var range1 = new TypeScript.TextSpan(token.getStart(sourceFile), token.getWidth(sourceFile)); + var range2 = new TypeScript.TextSpan(current.getStart(sourceFile), current.getWidth(sourceFile)); + if (range1.start() < range2.start()) { + result.push(range1, range2); + } + else { + result.push(range2, range1); + } + break; + } + } + } + } + return result; + function getMatchingTokenKind(token) { + switch (token.kind) { + case 9 /* OpenBraceToken */: + return 10 /* CloseBraceToken */; + case 11 /* OpenParenToken */: + return 12 /* CloseParenToken */; + case 13 /* OpenBracketToken */: + return 14 /* CloseBracketToken */; + case 19 /* LessThanToken */: + return 20 /* GreaterThanToken */; + case 10 /* CloseBraceToken */: + return 9 /* OpenBraceToken */; + case 12 /* CloseParenToken */: + return 11 /* OpenParenToken */; + case 14 /* CloseBracketToken */: + return 13 /* OpenBracketToken */; + case 20 /* GreaterThanToken */: + return 19 /* LessThanToken */; + } + return undefined; + } } function getIndentationAtPosition(filename, position, editorOptions) { filename = TypeScript.switchToForwardSlashes(filename); @@ -34211,11 +36130,11 @@ var ts; ts.Debug.assert(matchArray.length === descriptors.length + firstDescriptorCaptureIndex); var preamble = matchArray[1]; var matchPosition = matchArray.index + preamble.length; - var token = getTokenAtPosition(sourceFile, matchPosition); + var token = ts.getTokenAtPosition(sourceFile, matchPosition); if (token.getStart() <= matchPosition && matchPosition < token.getEnd()) { continue; } - if (!getContainingComment(ts.getTrailingComments(fileContents, token.getFullStart()), matchPosition) && !getContainingComment(ts.getLeadingComments(fileContents, token.getFullStart()), matchPosition)) { + if (!getContainingComment(ts.getTrailingCommentRanges(fileContents, token.getFullStart()), matchPosition) && !getContainingComment(ts.getLeadingCommentRanges(fileContents, token.getFullStart()), matchPosition)) { continue; } var descriptor = undefined; @@ -34229,7 +36148,11 @@ var ts; continue; } var message = matchArray[2]; - result.push(new TodoComment(descriptor, message, matchPosition)); + result.push({ + descriptor: descriptor, + message: message, + position: matchPosition + }); } } return result; @@ -34267,17 +36190,39 @@ var ts; synchronizeHostData(); fileName = TypeScript.switchToForwardSlashes(fileName); var sourceFile = getSourceFile(fileName); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingWord(sourceFile, position); if (node && node.kind === 59 /* Identifier */) { var symbol = typeInfoResolver.getSymbolInfo(node); if (symbol && symbol.getDeclarations() && symbol.getDeclarations().length > 0) { - var kind = getSymbolKind(symbol); + var kind = getSymbolKind(symbol, typeInfoResolver); if (kind) { - return RenameInfo.Create(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, getNodeModifiers(symbol.getDeclarations()[0]), new TypeScript.TextSpan(node.getStart(), node.getWidth())); + return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, getSymbolModifiers(symbol), new TypeScript.TextSpan(node.getStart(), node.getWidth())); } } } - return RenameInfo.CreateError(ts.getLocaleSpecificMessage(ts.Diagnostics.You_cannot_rename_this_element.key)); + return getRenameInfoError(ts.getLocaleSpecificMessage(ts.Diagnostics.You_cannot_rename_this_element.key)); + function getRenameInfoError(localizedErrorMessage) { + return { + canRename: false, + localizedErrorMessage: ts.getLocaleSpecificMessage(ts.Diagnostics.You_cannot_rename_this_element.key), + displayName: undefined, + fullDisplayName: undefined, + kind: undefined, + kindModifiers: undefined, + triggerSpan: undefined + }; + } + function getRenameInfo(displayName, fullDisplayName, kind, kindModifiers, triggerSpan) { + return { + canRename: true, + localizedErrorMessage: undefined, + displayName: displayName, + fullDisplayName: fullDisplayName, + kind: kind, + kindModifiers: kindModifiers, + triggerSpan: triggerSpan + }; + } } return { dispose: dispose, @@ -34289,9 +36234,8 @@ var ts; getSemanticClassifications: getSemanticClassifications, getCompletionsAtPosition: getCompletionsAtPosition, getCompletionEntryDetails: getCompletionEntryDetails, - getTypeAtPosition: getTypeAtPosition, - getSignatureHelpItems: function (filename, position) { return null; }, - getSignatureHelpCurrentArgumentState: function (fileName, position, applicableSpanStart) { return null; }, + getSignatureHelpItems: getSignatureHelpItems, + getQuickInfoAtPosition: getQuickInfoAtPosition, getDefinitionAtPosition: getDefinitionAtPosition, getReferencesAtPosition: getReferencesAtPosition, getOccurrencesAtPosition: getOccurrencesAtPosition, @@ -34300,6 +36244,7 @@ var ts; getBreakpointStatementAtPosition: getBreakpointStatementAtPosition, getNavigateToItems: getNavigateToItems, getRenameInfo: getRenameInfo, + findRenameLocations: findRenameLocations, getNavigationBarItems: getNavigationBarItems, getOutliningSpans: getOutliningSpans, getTodoComments: getTodoComments, @@ -34308,33 +36253,49 @@ var ts; getFormattingEditsForRange: getFormattingEditsForRange, getFormattingEditsForDocument: getFormattingEditsForDocument, getFormattingEditsAfterKeystroke: getFormattingEditsAfterKeystroke, - getEmitOutput: getEmitOutput + getEmitOutput: getEmitOutput, + getSignatureAtPosition: getSignatureAtPosition }; } ts.createLanguageService = createLanguageService; function createClassifier(host) { - var scanner; - var noRegexTable; - if (!noRegexTable) { - noRegexTable = []; - noRegexTable[59 /* Identifier */] = true; - noRegexTable[7 /* StringLiteral */] = true; - noRegexTable[6 /* NumericLiteral */] = true; - noRegexTable[8 /* RegularExpressionLiteral */] = true; - noRegexTable[87 /* ThisKeyword */] = true; - noRegexTable[33 /* PlusPlusToken */] = true; - noRegexTable[34 /* MinusMinusToken */] = true; - noRegexTable[12 /* CloseParenToken */] = true; - noRegexTable[14 /* CloseBracketToken */] = true; - noRegexTable[10 /* CloseBraceToken */] = true; - noRegexTable[89 /* TrueKeyword */] = true; - noRegexTable[74 /* FalseKeyword */] = true; + var scanner = ts.createScanner(1 /* ES5 */, false); + var noRegexTable = []; + noRegexTable[59 /* Identifier */] = true; + noRegexTable[7 /* StringLiteral */] = true; + noRegexTable[6 /* NumericLiteral */] = true; + noRegexTable[8 /* RegularExpressionLiteral */] = true; + noRegexTable[87 /* ThisKeyword */] = true; + noRegexTable[33 /* PlusPlusToken */] = true; + noRegexTable[34 /* MinusMinusToken */] = true; + noRegexTable[12 /* CloseParenToken */] = true; + noRegexTable[14 /* CloseBracketToken */] = true; + noRegexTable[10 /* CloseBraceToken */] = true; + noRegexTable[89 /* TrueKeyword */] = true; + noRegexTable[74 /* FalseKeyword */] = true; + function isAccessibilityModifier(kind) { + switch (kind) { + case 102 /* PublicKeyword */: + case 100 /* PrivateKeyword */: + case 101 /* ProtectedKeyword */: + return true; + } + return false; + } + function canFollow(keyword1, keyword2) { + if (isAccessibilityModifier(keyword1)) { + if (keyword2 === 109 /* GetKeyword */ || keyword2 === 113 /* SetKeyword */ || keyword2 === 107 /* ConstructorKeyword */ || keyword2 === 103 /* StaticKeyword */) { + return true; + } + return false; + } + return true; } function getClassificationsForLine(text, lexState) { var offset = 0; var lastTokenOrCommentEnd = 0; - var lastToken = 0 /* Unknown */; - var inUnterminatedMultiLineComment = false; + var token = 0 /* Unknown */; + var lastNonTriviaToken = 0 /* Unknown */; switch (lexState) { case 3 /* InDoubleQuoteStringLiteral */: text = '"\\\n' + text; @@ -34349,57 +36310,62 @@ var ts; offset = 3; break; } + scanner.setText(text); var result = { finalLexState: 0 /* Start */, entries: [] }; - scanner = ts.createScanner(1 /* ES5 */, true, text, onError, processComment); - var token = 0 /* Unknown */; + var angleBracketStack = 0; do { token = scanner.scan(); - if ((token === 31 /* SlashToken */ || token === 51 /* SlashEqualsToken */) && !noRegexTable[lastToken]) { - if (scanner.reScanSlashToken() === 8 /* RegularExpressionLiteral */) { - token = 8 /* RegularExpressionLiteral */; + if (!ts.isTrivia(token)) { + if ((token === 31 /* SlashToken */ || token === 51 /* SlashEqualsToken */) && !noRegexTable[lastNonTriviaToken]) { + if (scanner.reScanSlashToken() === 8 /* RegularExpressionLiteral */) { + token = 8 /* RegularExpressionLiteral */; + } } + else if (lastNonTriviaToken === 15 /* DotToken */ && isKeyword(token)) { + token = 59 /* Identifier */; + } + else if (isKeyword(lastNonTriviaToken) && isKeyword(token) && !canFollow(lastNonTriviaToken, token)) { + token = 59 /* Identifier */; + } + else if (lastNonTriviaToken === 59 /* Identifier */ && token === 19 /* LessThanToken */) { + angleBracketStack++; + } + else if (token === 20 /* GreaterThanToken */ && angleBracketStack > 0) { + angleBracketStack--; + } + else if (token === 105 /* AnyKeyword */ || token === 114 /* StringKeyword */ || token === 112 /* NumberKeyword */ || token === 106 /* BooleanKeyword */) { + if (angleBracketStack > 0) { + token = 59 /* Identifier */; + } + } + lastNonTriviaToken = token; } - else if (lastToken === 15 /* DotToken */) { - token = 59 /* Identifier */; - } - lastToken = token; processToken(); } while (token !== 1 /* EndOfFileToken */); return result; - function onError(message) { - inUnterminatedMultiLineComment = message.key === ts.Diagnostics.Asterisk_Slash_expected.key; - } - function processComment(start, end) { - addLeadingWhiteSpace(start, end); - addResult(end - start, 3 /* Comment */); - } function processToken() { var start = scanner.getTokenPos(); var end = scanner.getTextPos(); - addLeadingWhiteSpace(start, end); addResult(end - start, classFromKind(token)); if (end >= text.length) { - if (inUnterminatedMultiLineComment) { - result.finalLexState = 1 /* InMultiLineCommentTrivia */; - } - else if (token === 7 /* StringLiteral */) { + if (token === 7 /* StringLiteral */) { var tokenText = scanner.getTokenText(); if (tokenText.length > 0 && tokenText.charCodeAt(tokenText.length - 1) === 92 /* backslash */) { var quoteChar = tokenText.charCodeAt(0); result.finalLexState = quoteChar === 34 /* doubleQuote */ ? 3 /* InDoubleQuoteStringLiteral */ : 2 /* InSingleQuoteStringLiteral */; } } + else if (token === 3 /* MultiLineCommentTrivia */) { + var tokenText = scanner.getTokenText(); + if (!(tokenText.length > 3 && tokenText.charCodeAt(tokenText.length - 2) === 42 /* asterisk */ && tokenText.charCodeAt(tokenText.length - 1) === 47 /* slash */)) { + result.finalLexState = 1 /* InMultiLineCommentTrivia */; + } + } } } - function addLeadingWhiteSpace(start, end) { - if (start > lastTokenOrCommentEnd) { - addResult(start - lastTokenOrCommentEnd, 4 /* Whitespace */); - } - lastTokenOrCommentEnd = end; - } function addResult(length, classification) { if (length > 0) { if (result.entries.length === 0) { @@ -34485,6 +36451,11 @@ var ts; return 7 /* StringLiteral */; case 8 /* RegularExpressionLiteral */: return 8 /* RegExpLiteral */; + case 3 /* MultiLineCommentTrivia */: + case 2 /* SingleLineCommentTrivia */: + return 3 /* Comment */; + case 5 /* WhitespaceTrivia */: + return 4 /* Whitespace */; case 59 /* Identifier */: default: return 5 /* Identifier */; @@ -34500,7 +36471,7 @@ var ts; getNodeConstructor: function (kind) { function Node() { } - var proto = kind === 182 /* SourceFile */ ? new SourceFileObject() : new NodeObject(); + var proto = kind === 184 /* SourceFile */ ? new SourceFileObject() : new NodeObject(); proto.kind = kind; proto.pos = 0; proto.end = 0; @@ -34641,11 +36612,11 @@ var TypeScript; var debugObjectHost = this; var ts; (function (ts) { - var LanguageVersion; (function (LanguageVersion) { LanguageVersion[LanguageVersion["EcmaScript3"] = 0] = "EcmaScript3"; LanguageVersion[LanguageVersion["EcmaScript5"] = 1] = "EcmaScript5"; - })(LanguageVersion || (LanguageVersion = {})); + })(ts.LanguageVersion || (ts.LanguageVersion = {})); + var LanguageVersion = ts.LanguageVersion; (function (ModuleGenTarget) { ModuleGenTarget[ModuleGenTarget["Unspecified"] = 0] = "Unspecified"; ModuleGenTarget[ModuleGenTarget["Synchronous"] = 1] = "Synchronous"; @@ -34785,7 +36756,6 @@ var ts; return null; } var options = compilationSettingsToCompilerOptions(JSON.parse(settingsJson)); - options.noResolve = true; return options; }; LanguageServiceShimHostAdapter.prototype.getScriptFileNames = function () { @@ -34904,7 +36874,8 @@ var ts; message: diagnostic.messageText, start: diagnostic.start, length: diagnostic.length, - category: ts.DiagnosticCategory[diagnostic.category].toLowerCase() + category: ts.DiagnosticCategory[diagnostic.category].toLowerCase(), + code: diagnostic.code }; }; LanguageServiceShimObject.prototype.realizeDiagnosticWithFileName = function (diagnostic) { @@ -34951,11 +36922,11 @@ var ts; return errors.map(function (d) { return _this.realizeDiagnosticWithFileName(d); }); }); }; - LanguageServiceShimObject.prototype.getTypeAtPosition = function (fileName, position) { + LanguageServiceShimObject.prototype.getQuickInfoAtPosition = function (fileName, position) { var _this = this; - return this.forwardJSONCall("getTypeAtPosition('" + fileName + "', " + position + ")", function () { - var typeInfo = _this.languageService.getTypeAtPosition(fileName, position); - return typeInfo; + return this.forwardJSONCall("getQuickInfoAtPosition('" + fileName + "', " + position + ")", function () { + var quickInfo = _this.languageService.getQuickInfoAtPosition(fileName, position); + return quickInfo; }); }; LanguageServiceShimObject.prototype.getNameOrDottedNameSpan = function (fileName, startPos, endPos) { @@ -34979,11 +36950,10 @@ var ts; return signatureInfo; }); }; - LanguageServiceShimObject.prototype.getSignatureHelpCurrentArgumentState = function (fileName, position, applicableSpanStart) { + LanguageServiceShimObject.prototype.getSignatureAtPosition = function (fileName, position) { var _this = this; - return this.forwardJSONCall("getSignatureHelpCurrentArgumentState('" + fileName + "', " + position + ", " + applicableSpanStart + ")", function () { - var signatureInfo = _this.languageService.getSignatureHelpItems(fileName, position); - return signatureInfo; + return this.forwardJSONCall("getSignatureAtPosition('" + fileName + "', " + position + ")", function () { + return _this.languageService.getSignatureAtPosition(fileName, position); }); }; LanguageServiceShimObject.prototype.getDefinitionAtPosition = function (fileName, position) { @@ -34998,6 +36968,12 @@ var ts; return _this.languageService.getRenameInfo(fileName, position); }); }; + LanguageServiceShimObject.prototype.findRenameLocations = function (fileName, position, findInStrings, findInComments) { + var _this = this; + return this.forwardJSONCall("findRenameLocations('" + fileName + "', " + position + ", " + findInStrings + ", " + findInComments + ")", function () { + return _this.languageService.findRenameLocations(fileName, position, findInStrings, findInComments); + }); + }; LanguageServiceShimObject.prototype.getBraceMatchingAtPosition = function (fileName, position) { var _this = this; return this.forwardJSONCall("getBraceMatchingAtPosition('" + fileName + "', " + position + ")", function () { diff --git a/doc/TypeScript Language Specification (Change Markup).docx b/doc/TypeScript Language Specification (Change Markup).docx index 5bc24af5ec8..bb4be4fac1c 100644 Binary files a/doc/TypeScript Language Specification (Change Markup).docx and b/doc/TypeScript Language Specification (Change Markup).docx differ diff --git a/doc/TypeScript Language Specification (Change Markup).pdf b/doc/TypeScript Language Specification (Change Markup).pdf index 52998e9ec79..0cffd20b7c7 100644 Binary files a/doc/TypeScript Language Specification (Change Markup).pdf and b/doc/TypeScript Language Specification (Change Markup).pdf differ diff --git a/doc/TypeScript Language Specification.docx b/doc/TypeScript Language Specification.docx index 381ac186a4b..3d2014252f2 100644 Binary files a/doc/TypeScript Language Specification.docx and b/doc/TypeScript Language Specification.docx differ diff --git a/doc/TypeScript Language Specification.pdf b/doc/TypeScript Language Specification.pdf index 049f7e06fb3..203269c3f24 100644 Binary files a/doc/TypeScript Language Specification.pdf and b/doc/TypeScript Language Specification.pdf differ diff --git a/doc/header.md b/doc/header.md deleted file mode 100644 index 3cf5b569800..00000000000 --- a/doc/header.md +++ /dev/null @@ -1,2 +0,0 @@ -# TypeScript Language Specification - diff --git a/doc/spec.md b/doc/spec.md index 5635c100a40..158c431c229 100644 --- a/doc/spec.md +++ b/doc/spec.md @@ -1,12 +1,12 @@ # TypeScript Language Specification -Version 1.3 +Version 1.4 -September, 2014 +October, 2014
-Microsoft is making this Specification available under the Open Web Foundation Final Specification Agreement Version 1.0 (“OWF 1.0”) as of October 1, 2012. The OWF 1.0 is available at http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0. +Microsoft is making this Specification available under the Open Web Foundation Final Specification Agreement Version 1.0 ("OWF 1.0") as of October 1, 2012. The OWF 1.0 is available at http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0. TypeScript is a trademark of Microsoft Corporation. @@ -45,9 +45,10 @@ TypeScript is a trademark of Microsoft Corporation. * [3.3.1 Named Type References](#3.3.1) * [3.3.2 Array Types](#3.3.2) * [3.3.3 Tuple Types](#3.3.3) - * [3.3.4 Function Types](#3.3.4) - * [3.3.5 Constructor Types](#3.3.5) - * [3.3.6 Members](#3.3.6) + * [3.3.4 Union Types](#3.3.4) + * [3.3.5 Function Types](#3.3.5) + * [3.3.6 Constructor Types](#3.3.6) + * [3.3.7 Members](#3.3.7) * [3.4 Type Parameters](#3.4) * [3.4.1 Type Parameter Lists](#3.4.1) * [3.4.2 Type Argument Lists](#3.4.2) @@ -59,9 +60,10 @@ TypeScript is a trademark of Microsoft Corporation. * [3.6.3 Object Type Literals](#3.6.3) * [3.6.4 Array Type Literals](#3.6.4) * [3.6.5 Tuple Type Literals](#3.6.5) - * [3.6.6 Function Type Literals](#3.6.6) - * [3.6.7 Constructor Type Literals](#3.6.7) - * [3.6.8 Type Queries](#3.6.8) + * [3.6.6 Union Type Literals](#3.6.6) + * [3.6.7 Function Type Literals](#3.6.7) + * [3.6.8 Constructor Type Literals](#3.6.8) + * [3.6.9 Type Queries](#3.6.9) * [3.7 Specifying Members](#3.7) * [3.7.1 Property Signatures](#3.7.1) * [3.7.2 Call Signatures](#3.7.2) @@ -77,7 +79,6 @@ TypeScript is a trademark of Microsoft Corporation. * [3.8.6 Type Inference](#3.8.6) * [3.8.7 Recursive Types](#3.8.7) * [3.9 Widened Types](#3.9) - * [3.10 Best Common Type](#3.10) * [4 Expressions](#4) * [4.1 Values and References](#4.1) * [4.2 The this Keyword](#4.2) @@ -102,13 +103,13 @@ TypeScript is a trademark of Microsoft Corporation. * [4.13 Type Assertions](#4.13) * [4.14 Unary Operators](#4.14) * [4.14.1 The ++ and -- operators](#4.14.1) - * [4.14.2 The +, –, and ~ operators](#4.14.2) + * [4.14.2 The +, –, and ~ operators](#4.14.2) * [4.14.3 The ! operator](#4.14.3) * [4.14.4 The delete Operator](#4.14.4) * [4.14.5 The void Operator](#4.14.5) * [4.14.6 The typeof Operator](#4.14.6) * [4.15 Binary Operators](#4.15) - * [4.15.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators](#4.15.1) + * [4.15.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators](#4.15.1) * [4.15.2 The + operator](#4.15.2) * [4.15.3 The <, >, <=, >=, ==, !=, ===, and !== operators](#4.15.3) * [4.15.4 The instanceof operator](#4.15.4) @@ -119,6 +120,7 @@ TypeScript is a trademark of Microsoft Corporation. * [4.17 Assignment Operators](#4.17) * [4.18 The Comma Operator](#4.18) * [4.19 Contextually Typed Expressions](#4.19) + * [4.20 Type Guards](#4.20) * [5 Statements](#5) * [5.1 Variable Statements](#5.1) * [5.2 If, Do, and While Statements](#5.2) @@ -210,7 +212,7 @@ TypeScript is a trademark of Microsoft Corporation. # 1 Introduction -JavaScript applications such as web e-mail, maps, document editing, and collaboration tools are becoming an increasingly important part of the everyday computing. We designed TypeScript to meet the needs of the JavaScript programming teams that build and maintain large JavaScript programs. TypeScript helps programming teams to define interfaces between software components and to gain insight into the behavior of existing JavaScript libraries. TypeScript also enables teams to reduce naming conflicts by organizing their code into dynamically-loadable modules. TypeScript’s optional type system enables JavaScript programmers to use highly-productive development tools and practices: static checking, symbol-based navigation, statement completion, and code re-factoring. +JavaScript applications such as web e-mail, maps, document editing, and collaboration tools are becoming an increasingly important part of the everyday computing. We designed TypeScript to meet the needs of the JavaScript programming teams that build and maintain large JavaScript programs. TypeScript helps programming teams to define interfaces between software components and to gain insight into the behavior of existing JavaScript libraries. TypeScript also enables teams to reduce naming conflicts by organizing their code into dynamically-loadable modules. TypeScript's optional type system enables JavaScript programmers to use highly-productive development tools and practices: static checking, symbol-based navigation, statement completion, and code re-factoring. TypeScript is a syntactic sugar for JavaScript. TypeScript syntax is a superset of Ecmascript 5 (ES5) syntax. Every JavaScript program is also a TypeScript program. The TypeScript compiler performs only file-local transformations on TypeScript programs and does not re-order variables declared in TypeScript. This leads to JavaScript output that closely matches the TypeScript input. TypeScript does not transform variable names, making tractable the direct debugging of emitted JavaScript. TypeScript optionally provides source maps, enabling source-level debugging. TypeScript tools typically emit JavaScript upon file save, preserving the test, edit, refresh cycle commonly used in JavaScript development. @@ -218,7 +220,7 @@ TypeScript syntax includes several proposed features of Ecmascript 6 (ES6), incl TypeScript also provides to JavaScript programmers a system of optional type annotations. These type annotations are like the JSDoc comments found in the Closure system, but in TypeScript they are integrated directly into the language syntax. This integration makes the code more readable and reduces the maintenance cost of synchronizing type annotations with their corresponding variables. -The TypeScript type system enables programmers to express limits on the capabilities of JavaScript objects, and to use tools that enforce these limits. To minimize the number of annotations needed for tools to become useful, the TypeScript type system makes extensive use of type inference. For example, from the following statement, TypeScript will infer that the variable ‘i’ has the type number. +The TypeScript type system enables programmers to express limits on the capabilities of JavaScript objects, and to use tools that enforce these limits. To minimize the number of annotations needed for tools to become useful, the TypeScript type system makes extensive use of type inference. For example, from the following statement, TypeScript will infer that the variable 'i' has the type number. ```TypeScript var i = 0; @@ -247,7 +249,7 @@ f({}); // Error f("hello"); // Ok ``` -This optional type annotation on the parameter ‘s’ lets the TypeScript type checker know that the programmer expects parameter ‘s’ to be of type ‘string’. Within the body of function ‘f’, tools can assume ‘s’ is of type ‘string’ and provide operator type checking and member completion consistent with this assumption. Tools can also signal an error on the first call to ‘f’, because ‘f’ expects a string, not an object, as its parameter. For the function ‘f’, the TypeScript compiler will emit the following JavaScript code: +This optional type annotation on the parameter 's' lets the TypeScript type checker know that the programmer expects parameter 's' to be of type 'string'. Within the body of function 'f', tools can assume 's' is of type 'string' and provide operator type checking and member completion consistent with this assumption. Tools can also signal an error on the first call to 'f', because 'f' expects a string, not an object, as its parameter. For the function 'f', the TypeScript compiler will emit the following JavaScript code: ```TypeScript function f(s) { @@ -259,14 +261,14 @@ In the JavaScript output, all type annotations have been erased. In general, Typ ## 1.1 Ambient Declarations -An ambient declaration introduces a variable into a TypeScript scope, but has zero impact on the emitted JavaScript program. Programmers can use ambient declarations to tell the TypeScript compiler that some other component will supply a variable. For example, by default the TypeScript compiler will print an error for uses of undefined variables. To add some of the common variables defined by browsers, a TypeScript programmer can use ambient declarations. The following example declares the ‘document’ object supplied by browsers. Because the declaration does not specify a type, the type ‘any’ is inferred. The type ‘any’ means that a tool can assume nothing about the shape or behavior of the document object. Some of the examples below will illustrate how programmers can use types to further characterize the expected behavior of an object. +An ambient declaration introduces a variable into a TypeScript scope, but has zero impact on the emitted JavaScript program. Programmers can use ambient declarations to tell the TypeScript compiler that some other component will supply a variable. For example, by default the TypeScript compiler will print an error for uses of undefined variables. To add some of the common variables defined by browsers, a TypeScript programmer can use ambient declarations. The following example declares the 'document' object supplied by browsers. Because the declaration does not specify a type, the type 'any' is inferred. The type 'any' means that a tool can assume nothing about the shape or behavior of the document object. Some of the examples below will illustrate how programmers can use types to further characterize the expected behavior of an object. ```TypeScript declare var document; document.title = "Hello"; // Ok because document has been declared ``` -In the case of ‘document’, the TypeScript compiler automatically supplies a declaration, because TypeScript by default includes a file ‘lib.d.ts’ that provides interface declarations for the built-in JavaScript library as well as the Document Object Model. +In the case of 'document', the TypeScript compiler automatically supplies a declaration, because TypeScript by default includes a file 'lib.d.ts' that provides interface declarations for the built-in JavaScript library as well as the Document Object Model. The TypeScript compiler does not include by default an interface for jQuery, so to use jQuery, a programmer could supply a declaration such as: @@ -278,7 +280,7 @@ Section [1.3](#1.3) provides a more extensive example of how a programmer can ad ## 1.2 Function Types -Function expressions are a powerful feature of JavaScript. They enable function definitions to create closures: functions that capture information from the lexical scope surrounding the function’s definition. Closures are currently JavaScript’s only way of enforcing data encapsulation. By capturing and using environment variables, a closure can retain information that cannot be accessed from outside the closure. JavaScript programmers often use closures to express event handlers and other asynchronous callbacks, in which another software component, such as the DOM, will call back into JavaScript through a handler function. +Function expressions are a powerful feature of JavaScript. They enable function definitions to create closures: functions that capture information from the lexical scope surrounding the function's definition. Closures are currently JavaScript's only way of enforcing data encapsulation. By capturing and using environment variables, a closure can retain information that cannot be accessed from outside the closure. JavaScript programmers often use closures to express event handlers and other asynchronous callbacks, in which another software component, such as the DOM, will call back into JavaScript through a handler function. TypeScript function types make it possible for programmers to express the expected *signature* of a function. A function signature is a sequence of parameter types plus a return type. The following example uses function types to express the callback signature requirements of an asynchronous voting mechanism. @@ -296,19 +298,19 @@ vote("BigPig", ); ``` -In this example, the second parameter to ‘vote’ has the function type +In this example, the second parameter to 'vote' has the function type ```TypeScript (result: string) => any ``` -which means the second parameter is a function returning type ‘any’ that has a single parameter of type ‘string’ named ‘result’. +which means the second parameter is a function returning type 'any' that has a single parameter of type 'string' named 'result'. Section [3.7.2](#3.7.2) provides additional information about function types. ## 1.3 Object Types -TypeScript programmers use *object types* to declare their expectations of object behavior. The following code uses an *object type literal* to specify the return type of the ‘MakePoint’ function. +TypeScript programmers use *object types* to declare their expectations of object behavior. The following code uses an *object type literal* to specify the return type of the 'MakePoint' function. ```TypeScript var MakePoint: () => { @@ -333,7 +335,7 @@ add({ favoriteColor: "blue" }); // Error, name required add({ name: "Jill", favoriteColor: "green" }); // Ok ``` -TypeScript object types model the diversity of behaviors that a JavaScript object can exhibit. For example, the jQuery library defines an object, ‘$’, that has methods, such as ‘get’ (which sends an Ajax message), and fields, such as ‘browser’ (which gives browser vendor information). However, jQuery clients can also call ‘$’ as a function. The behavior of this function depends on the type of parameters passed to the function. +TypeScript object types model the diversity of behaviors that a JavaScript object can exhibit. For example, the jQuery library defines an object, '$', that has methods, such as 'get' (which sends an Ajax message), and fields, such as 'browser' (which gives browser vendor information). However, jQuery clients can also call '$' as a function. The behavior of this function depends on the type of parameters passed to the function. The following code fragment captures a small subset of jQuery behavior, just enough to use jQuery in a simple way. @@ -356,9 +358,9 @@ $.get("http://mysite.org/divContent", ); ``` -The ‘JQueryStatic’ interface references another interface: ‘JQuery’. This interface represents a collection of one or more DOM elements. The jQuery library can perform many operations on such a collection, but in this example the jQuery client only needs to know that it can set the text content of each jQuery element in a collection by passing a string to the ‘text’ method. The ‘JQueryStatic’ interface also contains a method, ‘get’, that performs an Ajax get operation on the provided URL and arranges to invoke the provided callback upon receipt of a response. +The 'JQueryStatic' interface references another interface: 'JQuery'. This interface represents a collection of one or more DOM elements. The jQuery library can perform many operations on such a collection, but in this example the jQuery client only needs to know that it can set the text content of each jQuery element in a collection by passing a string to the 'text' method. The 'JQueryStatic' interface also contains a method, 'get', that performs an Ajax get operation on the provided URL and arranges to invoke the provided callback upon receipt of a response. -Finally, the ‘JQueryStatic’ interface contains a bare function signature +Finally, the 'JQueryStatic' interface contains a bare function signature ```TypeScript (query: string): JQuery; @@ -372,13 +374,13 @@ var sameType: () => string = f; // Ok var nope: () => number = sameType; // Error: type mismatch ``` -We mentioned above that the ‘$’ function behaves differently depending on the type of its parameter. So far, our jQuery typing only captures one of these behaviors: return an object of type ‘JQuery’ when passed a string. To specify multiple behaviors, TypeScript supports *overloading* of function signatures in object types. For example, we can add an additional call signature to the ‘JQueryStatic’ interface. +We mentioned above that the '$' function behaves differently depending on the type of its parameter. So far, our jQuery typing only captures one of these behaviors: return an object of type 'JQuery' when passed a string. To specify multiple behaviors, TypeScript supports *overloading* of function signatures in object types. For example, we can add an additional call signature to the 'JQueryStatic' interface. ```TypeScript (ready: () => any): any; ``` -This signature denotes that a function may be passed as the parameter of the ‘$’ function. When a function is passed to ‘$’, the jQuery library will invoke that function when a DOM document is ready. Because TypeScript supports overloading, tools can use TypeScript to show all available function signatures with their documentation tips and to give the correct documentation once a function has been called with a particular signature. +This signature denotes that a function may be passed as the parameter of the '$' function. When a function is passed to '$', the jQuery library will invoke that function when a DOM document is ready. Because TypeScript supports overloading, tools can use TypeScript to show all available function signatures with their documentation tips and to give the correct documentation once a function has been called with a particular signature. A typical client would not need to add any additional typing but could just use a community-supplied typing to discover (through statement completion with documentation tips) and verify (through static checking) correct use of the library, as in the following screen shot. @@ -388,7 +390,7 @@ Section [3.3](#3.3) provides additional information about object types. ## 1.4 Structural Subtyping -Object types are compared *structurally*. For example, in the code fragment below, class ‘CPoint’ matches interface ‘Point’ because ‘CPoint’ has all of the required members of ‘Point’. A class may optionally declare that it implements an interface, so that the compiler will check the declaration for structural compatibility. The example also illustrates that an object type can match the type inferred from an object literal, as long as the object literal supplies all of the required members. +Object types are compared *structurally*. For example, in the code fragment below, class 'CPoint' matches interface 'Point' because 'CPoint' has all of the required members of 'Point'. A class may optionally declare that it implements an interface, so that the compiler will check the declaration for structural compatibility. The example also illustrates that an object type can match the type inferred from an object literal, as long as the object literal supplies all of the required members. ```TypeScript interface Point { @@ -420,7 +422,7 @@ See section [3.8](#3.8) for more information about type comparisons. ## 1.5 Contextual Typing -Ordinarily, TypeScript type inference proceeds “bottom-up”: from the leaves of an expression tree to its root. In the following example, TypeScript infers ‘number’ as the return type of the function ‘mul’ by flowing type information bottom up in the return expression. +Ordinarily, TypeScript type inference proceeds "bottom-up": from the leaves of an expression tree to its root. In the following example, TypeScript infers 'number' as the return type of the function 'mul' by flowing type information bottom up in the return expression. ```TypeScript function mul(a: number, b: number) { @@ -428,9 +430,9 @@ function mul(a: number, b: number) { } ``` -For variables and parameters without a type annotation or a default value, TypeScript infers type ‘any’, ensuring that compilers do not need non-local information about a function’s call sites to infer the function’s return type. Generally, this bottom-up approach provides programmers with a clear intuition about the flow of type information. +For variables and parameters without a type annotation or a default value, TypeScript infers type 'any', ensuring that compilers do not need non-local information about a function's call sites to infer the function's return type. Generally, this bottom-up approach provides programmers with a clear intuition about the flow of type information. -However, in some limited contexts, inference proceeds “top-down” from the context of an expression. Where this happens, it is called contextual typing. Contextual typing helps tools provide excellent information when a programmer is using a type but may not know all of the details of the type. For example, in the jQuery example, above, the programmer supplies a function expression as the second parameter to the ‘get’ method. During typing of that expression, tools can assume that the type of the function expression is as given in the ‘get’ signature and can provide a template that includes parameter names and types. +However, in some limited contexts, inference proceeds "top-down" from the context of an expression. Where this happens, it is called contextual typing. Contextual typing helps tools provide excellent information when a programmer is using a type but may not know all of the details of the type. For example, in the jQuery example, above, the programmer supplies a function expression as the second parameter to the 'get' method. During typing of that expression, tools can assume that the type of the function expression is as given in the 'get' signature and can provide a template that includes parameter names and types. ```TypeScript $.get("http://mysite.org/divContent", @@ -446,9 +448,9 @@ Section [4.19](#4.19) provides additional information about contextually typed e ## 1.6 Classes -JavaScript practice has at least two common design patterns: the module pattern and the class pattern. Roughly speaking, the module pattern uses closures to hide names and to encapsulate private data, while the class pattern uses prototype chains to implement many variations on object-oriented inheritance mechanisms. Libraries such as ‘prototype.js’ are typical of this practice. +JavaScript practice has at least two common design patterns: the module pattern and the class pattern. Roughly speaking, the module pattern uses closures to hide names and to encapsulate private data, while the class pattern uses prototype chains to implement many variations on object-oriented inheritance mechanisms. Libraries such as 'prototype.js' are typical of this practice. -This section and the module section below will show how TypeScript emits consistent, idiomatic JavaScript code to implement classes and modules that are closely aligned with the current ES6 proposal. The goal of TypeScript’s translation is to emit exactly what a programmer would type when implementing a class or module unaided by a tool. This section will also describe how TypeScript infers a type for each class declaration. We’ll start with a simple BankAccount class. +This section and the module section below will show how TypeScript emits consistent, idiomatic JavaScript code to implement classes and modules that are closely aligned with the current ES6 proposal. The goal of TypeScript's translation is to emit exactly what a programmer would type when implementing a class or module unaided by a tool. This section will also describe how TypeScript infers a type for each class declaration. We'll start with a simple BankAccount class. ```TypeScript class BankAccount { @@ -475,7 +477,7 @@ var BankAccount = (function () { })(); ``` -This TypeScript class declaration creates a variable named ‘BankAccount’ whose value is the constructor function for ‘BankAccount’ instances. This declaration also creates an instance type of the same name. If we were to write this type as an interface it would look like the following. +This TypeScript class declaration creates a variable named 'BankAccount' whose value is the constructor function for 'BankAccount' instances. This declaration also creates an instance type of the same name. If we were to write this type as an interface it would look like the following. ```TypeScript interface BankAccount { @@ -484,15 +486,15 @@ interface BankAccount { } ``` -If we were to write out the function type declaration for the ‘BankAccount’ constructor variable, it would have the following form. +If we were to write out the function type declaration for the 'BankAccount' constructor variable, it would have the following form. ```TypeScript var BankAccount: new() => BankAccount; ``` -The function signature is prefixed with the keyword ‘new’ indicating that the ‘BankAccount’ function must be called as a constructor. It is possible for a function’s type to have both call and constructor signatures. For example, the type of the built-in JavaScript Date object includes both kinds of signatures. +The function signature is prefixed with the keyword 'new' indicating that the 'BankAccount' function must be called as a constructor. It is possible for a function's type to have both call and constructor signatures. For example, the type of the built-in JavaScript Date object includes both kinds of signatures. -If we want to start our bank account with an initial balance, we can add to the ‘BankAccount’ class a constructor declaration. +If we want to start our bank account with an initial balance, we can add to the 'BankAccount' class a constructor declaration. ```TypeScript class BankAccount { @@ -507,7 +509,7 @@ class BankAccount { } ``` -This version of the ‘BankAccount’ class requires us to introduce a constructor parameter and then assign it to the ‘balance’ field. To simplify this common case, TypeScript accepts the following shorthand syntax. +This version of the 'BankAccount' class requires us to introduce a constructor parameter and then assign it to the 'balance' field. To simplify this common case, TypeScript accepts the following shorthand syntax. ```TypeScript class BankAccount { @@ -520,7 +522,7 @@ class BankAccount { } ``` -The ‘public’ keyword denotes that the constructor parameter is to be retained as a field. Public is the default accessibility for class members, but a programmer can also specify private or protected accessibility for a class member. Accessibility is a design-time construct; it is enforced during static type checking but does not imply any runtime enforcement. +The 'public' keyword denotes that the constructor parameter is to be retained as a field. Public is the default accessibility for class members, but a programmer can also specify private or protected accessibility for a class member. Accessibility is a design-time construct; it is enforced during static type checking but does not imply any runtime enforcement. TypeScript classes also support inheritance, as in the following example.* * @@ -535,7 +537,7 @@ class CheckingAccount extends BankAccount { } ``` -In this example, the class ‘CheckingAccount’ *derives* from class ‘BankAccount’. The constructor for ‘CheckingAccount’ calls the constructor for class ‘BankAccount’ using the ‘super’ keyword. In the emitted JavaScript code, the prototype of ‘CheckingAccount’ will chain to the prototype of ‘BankingAccount’. +In this example, the class 'CheckingAccount' *derives* from class 'BankAccount'. The constructor for 'CheckingAccount' calls the constructor for class 'BankAccount' using the 'super' keyword. In the emitted JavaScript code, the prototype of 'CheckingAccount' will chain to the prototype of 'BankingAccount'. TypeScript classes may also specify static members. Static class members become properties of the class constructor. @@ -559,11 +561,11 @@ function compute(op: Operator, a: number, b: number) { } ``` -In this example, the compute function logs the operator ‘op’ using a feature of enum types: reverse mapping from the enum value (‘op’) to the string corresponding to that value. For example, the declaration of ‘Operator’ automatically assigns integers, starting from zero, to the listed enum members. Section [9](#9) describes how programmers can also explicitly assign integers to enum members, and can use any string to name an enum member. +In this example, the compute function logs the operator 'op' using a feature of enum types: reverse mapping from the enum value ('op') to the string corresponding to that value. For example, the declaration of 'Operator' automatically assigns integers, starting from zero, to the listed enum members. Section [9](#9) describes how programmers can also explicitly assign integers to enum members, and can use any string to name an enum member. -If all enum members have explicitly assigned literal integers, or if an enum has all members automatically assigned, the TypeScript compiler will emit for an enum member a JavaScript constant corresponding to that member’s assigned value (annotated with a comment). This improves performance on many JavaScript engines. +If all enum members have explicitly assigned literal integers, or if an enum has all members automatically assigned, the TypeScript compiler will emit for an enum member a JavaScript constant corresponding to that member's assigned value (annotated with a comment). This improves performance on many JavaScript engines. -For example, the ‘compute’ function could contain a switch statement like the following. +For example, the 'compute' function could contain a switch statement like the following. ```TypeScript switch (op) { @@ -597,18 +599,18 @@ JavaScript implementations can use these explicit constants to generate efficien An important goal of TypeScript is to provide accurate and straightforward types for existing JavaScript programming patterns. To that end, TypeScript includes generic types, discussed in the next section, and *overloading on string parameters*, the topic of this section. -JavaScript programming interfaces often include functions whose behavior is discriminated by a string constant passed to the function. The Document Object Model makes heavy use of this pattern. For example, the following screen shot shows that the ‘createElement’ method of the ‘document’ object has multiple signatures, some of which identify the types returned when specific strings are passed into the method. +JavaScript programming interfaces often include functions whose behavior is discriminated by a string constant passed to the function. The Document Object Model makes heavy use of this pattern. For example, the following screen shot shows that the 'createElement' method of the 'document' object has multiple signatures, some of which identify the types returned when specific strings are passed into the method. / -The following code fragment uses this feature. Because the ‘span’ variable is inferred to have the type ‘HTMLSpanElement’, the code can reference without static error the ‘isMultiline’ property of ‘span’. +The following code fragment uses this feature. Because the 'span' variable is inferred to have the type 'HTMLSpanElement', the code can reference without static error the 'isMultiline' property of 'span'. ```TypeScript var span = document.createElement("span"); span.isMultiLine = false; // OK: HTMLSpanElement has isMultiline property ``` -In the following screen shot, a programming tool combines information from overloading on string parameters with contextual typing to infer that the type of the variable ‘e’ is ‘MouseEvent’ and that therefore ‘e’ has a ‘clientX’ property. +In the following screen shot, a programming tool combines information from overloading on string parameters with contextual typing to infer that the type of the variable 'e' is 'MouseEvent' and that therefore 'e' has a 'clientX' property. / @@ -618,7 +620,7 @@ Section [3.7.2.4](#3.7.2.4) provides details on how to use string literals in fu Like overloading on string parameters, *generic types* make it easier for TypeScript to accurately capture the behavior of JavaScript libraries. Because they enable type information to flow from client code, through library code, and back into client code, generic types may do more than any other TypeScript feature to support detailed API descriptions. -To illustrate this, let’s take a look at part of the TypeScript interface for the built-in JavaScript array type. You can find this interface in the ‘lib.d.ts’ file that accompanies a TypeScript distribution. +To illustrate this, let's take a look at part of the TypeScript interface for the built-in JavaScript array type. You can find this interface in the 'lib.d.ts' file that accompanies a TypeScript distribution. ```TypeScript interface Array { @@ -628,17 +630,17 @@ interface Array { } ``` -Interface definitions, like the one above, can have one or more *type parameters*. In this case the ‘Array’ interface has a single parameter, ‘T’, that defines the element type for the array. The ‘reverse’ method returns an array with the same element type. The sort method takes an optional parameter, ‘compareFn’, whose type is a function that takes two parameters of type ‘T’ and returns a number. Finally, sort returns an array with element type ‘T’. +Interface definitions, like the one above, can have one or more *type parameters*. In this case the 'Array' interface has a single parameter, 'T', that defines the element type for the array. The 'reverse' method returns an array with the same element type. The sort method takes an optional parameter, 'compareFn', whose type is a function that takes two parameters of type 'T' and returns a number. Finally, sort returns an array with element type 'T'. -Functions can also have generic parameters. For example, the array interface contains a ‘map’ method, defined as follows: +Functions can also have generic parameters. For example, the array interface contains a 'map' method, defined as follows: ```TypeScript map(func: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; ``` -The map method, invoked on an array ‘a’ with element type ‘T’, will apply function ‘func’ to each element of ‘a’, returning a value of type ‘U’. +The map method, invoked on an array 'a' with element type 'T', will apply function 'func' to each element of 'a', returning a value of type 'U'. -The TypeScript compiler can often infer generic method parameters, making it unnecessary for the programmer to explicitly provide them. In the following example, the compiler infers that parameter ‘U’ of the map method has type ‘string’, because the function passed to map returns a string. +The TypeScript compiler can often infer generic method parameters, making it unnecessary for the programmer to explicitly provide them. In the following example, the compiler infers that parameter 'U' of the map method has type 'string', because the function passed to map returns a string. ```TypeScript function numberToString(a: number[]) { @@ -647,9 +649,9 @@ function numberToString(a: number[]) { } ``` -The compiler infers in this example that the ‘numberToString’ function returns an array of strings. +The compiler infers in this example that the 'numberToString' function returns an array of strings. -In TypeScript, classes can also have type parameters. The following code declares a class that implements a linked list of items of type ‘T’. This code illustrates how programmers can *constrain* type parameters to extend a specific type. In this case, the items on the list must extend the type ‘NamedItem’. This enables the programmer to implement the ‘log’ function, which logs the name of the item. +In TypeScript, classes can also have type parameters. The following code declares a class that implements a linked list of items of type 'T'. This code illustrates how programmers can *constrain* type parameters to extend a specific type. In this case, the items on the list must extend the type 'NamedItem'. This enables the programmer to implement the 'log' function, which logs the name of the item. ```TypeScript interface NamedItem { @@ -680,7 +682,7 @@ Section [3.5](#3.5) provides further information about generic types. ## 1.10 Modules -Classes and interfaces support large-scale JavaScript development by providing a mechanism for describing how to use a software component that can be separated from that component’s implementation. TypeScript enforces *encapsulation* of implementation in classes at design time (by restricting use of private and protected members), but cannot enforce encapsulation at runtime because all object properties are accessible at runtime. Future versions of JavaScript may provide *private names* which would enable runtime enforcement of private and protected members. +Classes and interfaces support large-scale JavaScript development by providing a mechanism for describing how to use a software component that can be separated from that component's implementation. TypeScript enforces *encapsulation* of implementation in classes at design time (by restricting use of private and protected members), but cannot enforce encapsulation at runtime because all object properties are accessible at runtime. Future versions of JavaScript may provide *private names* which would enable runtime enforcement of private and protected members. In the current version of JavaScript, the only way to enforce encapsulation at runtime is to use the module pattern: encapsulate private fields and methods using closure variables. The module pattern is a natural way to provide organizational structure and dynamic loading options by drawing a boundary around a software component. A module can also provide the ability to introduce namespaces, avoiding use of the global namespace for most software components. @@ -696,9 +698,9 @@ The following example illustrates the JavaScript module pattern. })(MessageModule); ``` -This example illustrates the two essential elements of the module pattern: a *module closure* and a *module* *object*. The module closure is a function that encapsulates the module’s implementation, in this case the variable ‘key’ and the function ‘sendMessage’. The module object contains the exported variables and functions of the module. Simple modules may create and return the module object. The module above takes the module object as a parameter, ‘exports’, and adds the ‘sendMessage’ property to the module object. This *augmentation* approach simplifies dynamic loading of modules and also supports separation of module code into multiple files. +This example illustrates the two essential elements of the module pattern: a *module closure* and a *module* *object*. The module closure is a function that encapsulates the module's implementation, in this case the variable 'key' and the function 'sendMessage'. The module object contains the exported variables and functions of the module. Simple modules may create and return the module object. The module above takes the module object as a parameter, 'exports', and adds the 'sendMessage' property to the module object. This *augmentation* approach simplifies dynamic loading of modules and also supports separation of module code into multiple files. -The example assumes that an outer lexical scope defines the functions ‘generateSecretKey’ and ‘sendSecureMessage’; it also assumes that the outer scope has assigned the module object to the variable ‘MessageModule’. +The example assumes that an outer lexical scope defines the functions 'generateSecretKey' and 'sendSecureMessage'; it also assumes that the outer scope has assigned the module object to the variable 'MessageModule'. TypeScript modules provide a mechanism for succinctly expressing the module pattern. In TypeScript, programmers can combine the module pattern with the class pattern by nesting modules and classes within an outer module. @@ -716,7 +718,7 @@ M.f(); M.s; // Error, s is not exported ``` -In this example, variable ‘s’ is a private feature of the module, but function ‘f’ is exported from the module and accessible to code outside of the module. If we were to describe the effect of module ‘M’ in terms of interfaces and variables, we would write +In this example, variable 's' is a private feature of the module, but function 'f' is exported from the module and accessible to code outside of the module. If we were to describe the effect of module 'M' in terms of interfaces and variables, we would write ```TypeScript interface M { @@ -726,9 +728,9 @@ interface M { var M: M; ``` -The interface ‘M’ summarizes the externally visible behavior of module ‘M’. In this example, we can use the same name for the interface as for the initialized variable because in TypeScript type names and variable names do not conflict: each lexical scope contains a variable declaration space and type declaration space (see section [2.3](#2.3) for more details). +The interface 'M' summarizes the externally visible behavior of module 'M'. In this example, we can use the same name for the interface as for the initialized variable because in TypeScript type names and variable names do not conflict: each lexical scope contains a variable declaration space and type declaration space (see section [2.3](#2.3) for more details). -Module ‘M’ is an example of an *internal* module, because it is nested within the *global* module (see section [10](#10) for more details). The TypeScript compiler emits the following JavaScript code for this module. +Module 'M' is an example of an *internal* module, because it is nested within the *global* module (see section [10](#10) for more details). The TypeScript compiler emits the following JavaScript code for this module. ```TypeScript var M; @@ -741,7 +743,7 @@ var M; })(M || (M = {})); ``` -In this case, the compiler assumes that the module object resides in global variable ‘M’, which may or may not have been initialized to the desired module object. +In this case, the compiler assumes that the module object resides in global variable 'M', which may or may not have been initialized to the desired module object. TypeScript also supports *external* modules, which are files that contain top-level *export* and *import *directives. For this type of module the TypeScript compiler will emit code whose module closure and module object implementation vary according to the specified dynamic loading system, for example, the Asynchronous Module Definition system. @@ -756,13 +758,13 @@ The remainder of this document is the formal specification of the TypeScript pro The syntactic grammar added by TypeScript language is specified throughout this document using the existing conventions and production names of the ECMAScript grammar. In places where TypeScript augments an existing grammar production it is so noted. For example:   *CallExpression:* *( Modified )* -   … +   …    `super` `(` *ArgumentListopt* `)`    `super` `.` *IdentifierName* -The ‘*( Modified )*’ annotation indicates that an existing grammar production is being replaced, and the ‘…’ references the contents of the original grammar production. +The '*( Modified )*' annotation indicates that an existing grammar production is being replaced, and the '…' references the contents of the original grammar production. -Similar to the ECMAScript grammar, if the phrase “*[no LineTerminator here]*” appears in the right-hand side of a production of the syntactic grammar, it indicates that the production is not a match if a *LineTerminator* occurs in the input stream at the indicated position. +Similar to the ECMAScript grammar, if the phrase "*[no LineTerminator here]*" appears in the right-hand side of a production of the syntactic grammar, it indicates that the production is not a match if a *LineTerminator* occurs in the input stream at the indicated position. ## 2.2 Namespaces and Named Types @@ -777,7 +779,7 @@ module X { } ``` -declares two interface types with the qualified names ‘X.Y.Z’ and ‘X.Y’ relative to the root module in which ‘X’ is declared. +declares two interface types with the qualified names 'X.Y.Z' and 'X.Y' relative to the root module in which 'X' is declared. In a qualified type name all identifiers but the last one refer to namespaces and the last identifier refers to a named type. Named type and namespace names are in separate declaration spaces and it is therefore possible for a named type and a namespace to have the same name, as in the example above. @@ -791,23 +793,23 @@ module A { } ``` -introduces a named type with the qualified name ‘A.B.C’ and also introduces a constructor function that can be accessed using the expression ‘A.B.C’. Thus, in the example +introduces a named type with the qualified name 'A.B.C' and also introduces a constructor function that can be accessed using the expression 'A.B.C'. Thus, in the example ```TypeScript var c: A.B.C = new A.B.C(); ``` -the two occurrences of ‘A.B.C’ in fact refer to different entities. It is the context of the occurrences that determines whether ‘A.B.C’ is processed as a type name or an expression. +the two occurrences of 'A.B.C' in fact refer to different entities. It is the context of the occurrences that determines whether 'A.B.C' is processed as a type name or an expression. ## 2.3 Declarations Declarations introduce names in the ***declaration spaces*** to which they belong. It is an error to have two names with same spelling in the same declaration space. Declaration spaces exist as follows: * The global module and each external or internal module has a declaration space for variables (including functions, modules, class constructor functions, and enum objects), a declaration space for named types (classes, interfaces, and enums), and a declaration space for namespaces (containers of named types). Every declaration (whether local or exported) in a module contributes to one or more of these declaration spaces. -* Each external or internal module has a declaration space for exported members, a declaration space for exported named types, and a declaration space for exported namespaces. All export declarations in the module contribute to these declaration spaces. Each internal module’s export declaration spaces are shared with other internal modules that have the same root module and the same qualified name starting from that root module. +* Each external or internal module has a declaration space for exported members, a declaration space for exported named types, and a declaration space for exported namespaces. All export declarations in the module contribute to these declaration spaces. Each internal module's export declaration spaces are shared with other internal modules that have the same root module and the same qualified name starting from that root module. * Each class declaration has a declaration space for instance members, a declaration space for static members, and a declaration space for type parameters. -* Each interface declaration has a declaration space for members and a declaration space for type parameters. An interface’s declaration space is shared with other interfaces that have the same root module and the same qualified name starting from that root module. -* Each enum declaration has a declaration space for its enum members. An enum’s declaration space is shared with other enums that have the same root module and the same qualified name starting from that root module. +* Each interface declaration has a declaration space for members and a declaration space for type parameters. An interface's declaration space is shared with other interfaces that have the same root module and the same qualified name starting from that root module. +* Each enum declaration has a declaration space for its enum members. An enum's declaration space is shared with other enums that have the same root module and the same qualified name starting from that root module. * Each function declaration (including constructor, member function, and member accessor declarations) and each function expression has a declaration space for variables (parameters, local variables, and local functions) and a declaration space for type parameters. * Each object literal has a declaration space for its properties. * Each object type literal has a declaration space for its members. @@ -825,14 +827,14 @@ The ***parent module*** of an entity is defined as follows: The ***root module*** of an entity is defined as follows: -* The root module of a non-exported entity is the entity’s parent module. -* The root module of an exported entity is the root module of the entity’s parent module. +* The root module of a non-exported entity is the entity's parent module. +* The root module of an exported entity is the root module of the entity's parent module. Intuitively, the root module of an entity is the outermost module body from within which the entity is reachable. -Interfaces, enums, and internal modules are “open ended,” meaning that interface, enum, and internal module declarations with the same qualified name relative to a common root are automatically merged. For further details, see sections [7.2](#7.2), [9.3](#9.3), and [10.5](#10.5). +Interfaces, enums, and internal modules are "open ended," meaning that interface, enum, and internal module declarations with the same qualified name relative to a common root are automatically merged. For further details, see sections [7.2](#7.2), [9.3](#9.3), and [10.5](#10.5). -Namespace, type, and member names exist in separate declaration spaces. Furthermore, declarations of non-instantiated modules (modules that contain only interfaces or modules at all levels of nesting) do not introduce a member name in their containing declaration space. This means that the following is permitted, provided module ‘X’ contains only interface or module declarations at all levels of nesting: +Namespace, type, and member names exist in separate declaration spaces. Furthermore, declarations of non-instantiated modules (modules that contain only interfaces or modules at all levels of nesting) do not introduce a member name in their containing declaration space. This means that the following is permitted, provided module 'X' contains only interface or module declarations at all levels of nesting: ```TypeScript module M { @@ -842,7 +844,7 @@ module M { } ``` -If module ‘X’ above was an instantiated module (section [10.1](#10.1)) it would cause a member ‘X’ to be introduced in ‘M’. This member would conflict with the variable ‘X’ and thus cause an error. +If module 'X' above was an instantiated module (section [10.1](#10.1)) it would cause a member 'X' to be introduced in 'M'. This member would conflict with the variable 'X' and thus cause an error. Instance and static members in a class are likewise in separate declaration spaces. Thus the following is permitted: @@ -874,7 +876,7 @@ When an identifier is resolved as a *ModuleName* (section [3.6.2](#3.6.2)), only When an identifier is resolved as a *PrimaryExpression* (section [4.3](#4.3)), only instantiated modules (section [10.1](#10.1)), classes, enums, functions, variables, and parameters are considered and other entities in scope are ignored. -Note that class and enum members are never directly in scope—they can only be accessed by applying the dot (‘.’) operator to a class instance or enum object. This even includes members of the current instance in a constructor or member function, which are accessed by applying the dot operator to `this`. +Note that class and enum members are never directly in scope—they can only be accessed by applying the dot ('.') operator to a class instance or enum object. This even includes members of the current instance in a constructor or member function, which are accessed by applying the dot operator to `this`. As the rules above imply, locally declared entities in an internal module are closer in scope than exported entities declared in other module declarations for the same internal module. For example: @@ -897,11 +899,11 @@ module M { # 3 Types -TypeScript adds optional static types to JavaScript. Types are used to place static constraints on program entities such as functions, variables, and properties so that compilers and development tools can offer better verification and assistance during software development. TypeScript’s *static* compile-time type system closely models the *dynamic* run-time type system of JavaScript, allowing programmers to accurately express the type relationships that are expected to exist when their programs run and have those assumptions pre-validated by the TypeScript compiler. TypeScript’s type analysis occurs entirely at compile-time and adds no run-time overhead to program execution. +TypeScript adds optional static types to JavaScript. Types are used to place static constraints on program entities such as functions, variables, and properties so that compilers and development tools can offer better verification and assistance during software development. TypeScript's *static* compile-time type system closely models the *dynamic* run-time type system of JavaScript, allowing programmers to accurately express the type relationships that are expected to exist when their programs run and have those assumptions pre-validated by the TypeScript compiler. TypeScript's type analysis occurs entirely at compile-time and adds no run-time overhead to program execution. All types in TypeScript are subtypes of a single top type called the Any type. The `any` keyword references this type. The Any type is the one type that can represent *any* JavaScript value with no constraints. All other types are categorized as ***primitive types***, ***object types***, or ***type parameters***. These types introduce various static constraints on their values. -The primitive types are the Number, Boolean, String, Void, Null, and Undefined types along with user defined enum types. The `number`, `boolean`, `string`, and `void` keywords reference the Number, Boolean, String, and Void primitive types respectively. The Void type exists purely to indicate the absence of a value, such as in a function with no return value. It is not possible to explicitly reference the Null and Undefined types—only *values* of those types can be referenced, using the `null` and `undefined` literals. +The primitive types are the Number, Boolean, String, Void, Null, and Undefined types along with user defined enum types. The `number`, `boolean`, `string`, and `void` keywords reference the Number, Boolean, String, and Void primitive types respectively. The Void type exists purely to indicate the absence of a value, such as in a function with no return value. It is not possible to explicitly reference the Null and Undefined types—only *values* of those types can be referenced, using the `null` and `undefined` literals. The object types are all class, interface, array, and literal types. Class and interface types are introduced through class and interface declarations and are referenced by the name given to them in their declarations. Class and interface types may be ***generic types*** which have one or more type parameters. Literal types are written as object, array, function, or constructor type literals and are used to compose new types from other types. @@ -917,7 +919,7 @@ or through implicit ***type inference***, as in var x = 1; ``` -which infers the type of ‘x’ to be the Number primitive type because that is the type of the value used to initialize ‘x’. +which infers the type of 'x' to be the Number primitive type because that is the type of the value used to initialize 'x'. ## 3.1 The Any Type @@ -949,7 +951,7 @@ The Number primitive type corresponds to the similarly named JavaScript primitiv The `number` keyword references the Number primitive type and numeric literals may be used to write values of the Number primitive type. -For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the Number primitive type behaves as an object type with the same properties as the global interface type ‘Number’. +For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the Number primitive type behaves as an object type with the same properties as the global interface type 'Number'. Some examples: @@ -966,7 +968,7 @@ The Boolean primitive type corresponds to the similarly named JavaScript primiti The `boolean` keyword references the Boolean primitive type and the `true` and `false` literals reference the two Boolean truth values. -For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the Boolean primitive type behaves as an object type with the same properties as the global interface type ‘Boolean’. +For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the Boolean primitive type behaves as an object type with the same properties as the global interface type 'Boolean'. Some examples: @@ -982,7 +984,7 @@ The String primitive type corresponds to the similarly named JavaScript primitiv The `string` keyword references the String primitive type and string literals may be used to write values of the String primitive type. -For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the String primitive type behaves as an object type with the same properties as the global interface type ‘String’. +For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the String primitive type behaves as an object type with the same properties as the global interface type 'String'. Some examples: @@ -1049,13 +1051,14 @@ All string literal types are subtypes of the String primitive type. Object types are composed from properties, call signatures, construct signatures, and index signatures, collectively called members. -Class and interface type references, array types, tuple types, function types, and constructor types are all classified as object types. Multiple constructs in the TypeScript language create object types, including: +Class and interface type references, array types, tuple types, union types, function types, and constructor types are all classified as object types. Multiple constructs in the TypeScript language create object types, including: * Object type literals (section [3.6.3](#3.6.3)). * Array type literals (section [3.6.4](#3.6.4)). * Tuple type literals (section [3.6.5](#3.6.5)). -* Function type literals (section [3.6.6](#3.6.6)). -* Constructor type literals (section [3.6.7](#3.6.7)). +* Union type literals (section [3.6.6](#3.6.6)). +* Function type literals (section [3.6.7](#3.6.7)). +* Constructor type literals (section [3.6.8](#3.6.8)). * Object literals (section [4.5](#4.5)). * Array literals (section [4.6](#4.6)). * Function expressions (section [4.9](#4.9)) and function declarations ([6.1](#6.1)). @@ -1068,9 +1071,9 @@ Type references (section [3.6.2](#3.6.2)) to class and interface types are class ### 3.3.2 Array Types -***Array types*** represent JavaScript arrays with a common element type. Array types are named type references created from the generic interface type ‘Array’ in the global module with the array element type as a type argument. Array type literals (section [3.6.4](#3.6.4)) provide a shorthand notation for creating such references. +***Array types*** represent JavaScript arrays with a common element type. Array types are named type references created from the generic interface type 'Array' in the global module with the array element type as a type argument. Array type literals (section [3.6.4](#3.6.4)) provide a shorthand notation for creating such references. -The declaration of the ‘Array’ interface includes a property ‘length’ and a numeric index signature for the element type, along with other members: +The declaration of the 'Array' interface includes a property 'length' and a numeric index signature for the element type, along with other members: ```TypeScript interface Array { @@ -1105,23 +1108,111 @@ combines the set of properties } ``` -with the members of an array type whose element type is the best common type (section [3.10](#3.10)) of the tuple element types. +with the members of an array type whose element type is the union type (section [3.3.4](#3.3.4)) of the tuple element types. -Array literals (section [4.6](#4.6)) may be used to create values of tuple types. For example +Array literals (section [4.6](#4.6)) may be used to create values of tuple types. + +An example: ```TypeScript -var t: [number, string] = [1, "one"]; +var t: [number, string] = [3, "three"]; +var n = t[0]; // Type of n is number +var s = t[1]; // Type of s is string +var i: number; +var x = t[i]; // Type of x is number | string ``` -### 3.3.4 Function Types +### 3.3.4 Union Types -An object type containing one or more call signatures is said to be a ***function type***. Function types may be written using function type literals (section [3.6.6](#3.6.6)) or by including call signatures in object type literals. +***Union types*** represent values that may have one of several disjoint representations. A value of a union type *A* | *B* is a value that is *either* of type *A* or type *B*. Union types are written using union type literals (section [3.6.6](#3.6.6)). -### 3.3.5 Constructor Types +A union type encompasses an unordered set of unrelated types (that is, types that aren't subtypes of each other). The following rules govern union types: -An object type containing one or more construct signatures is said to be a ***constructor type***. Constructor types may be written using constructor type literals (section [3.6.7](#3.6.7)) or by including construct signatures in object type literals. +* *A* | *B* is equivalent to *A* if *B* is a subtype of *A*. +* *A* | *B* is equivalent to *B* | *A*. +* *AB* | *C* is equivalent to *A* | *BC*, where *AB* is *A* | *B* and *BC* is *B* | *C*. -### 3.3.6 Members +Union types are reduced to the smallest possible set of constituent types using these rules. + +Union types have the following subtype relationships: + +* A union type *U* is a subtype of a type *T* if each type in *U* is a subtype of *T*. +* A type *T* is a subtype of a union type *U* if *T* is a subtype of any type in *U*. + +Similarly, union types have the following assignability relationships: + +* A union type *U* is assignable to a type *T* if each type in *U* is assignable to *T*. +* A type *T* is assignable to a union type *U* if *T* is assignable to any type in *U*. + +For purposes of property access (section [4.10](#4.10)) and function calls ([4.12](#4.12)), a union type *U* has those members that are present in every one of its constituent types, with types that are unions of the respective members in the constituent types. Specifically: + +* If each type in *U* has a property *P*, *U* has a property *P* of a union type of the types of *P* from each type in *U*. +* If each type in *U* has call signatures and the sets of call signatures are identical ignoring return types, *U* has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in *U*. +* If each type in *U* has construct signatures and the sets of construct signatures are identical ignoring return types, *U* has the same set of construct signatures, but with return types that are unions of the return types of the respective construct signatures from each type in *U*. +* If each type in *U* has a string index signature, *U* has a string index signature of a union type of the types of the string index signatures from each type in *U*. +* If each type in *U* has a numeric index signature, *U* has a numeric index signature of a union type of the types of the numeric index signatures from each type in *U*. + +When used as a contextual type (section [4.19](#4.19)), a union type *U* has those members that are present in any of its constituent types, with types that are unions of the respective members in the constituent types. Specifically: + +* Let *S* be the set of types in *U* that has a property *P*. If *S* is not empty, *U* has a property *P* of a union type of the types of *P* from each type in *S*. +* Let *S* be the set of types in *U* that have call signatures. If *S* is not empty and the sets of call signatures of the types in *S* are identical ignoring return types, *U* has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in *S*. +* Let *S* be the set of types in *U* that have construct signatures. If *S* is not empty and the sets of construct signatures of the types in *S* are identical ignoring return types, *U* has the same set of construct signatures, but with return types that are unions of the return types of the respective construct signatures from each type in *S*. +* Let *S* be the set of types in *U* that has a string index signature. If *S* is not empty, *U* has a string index signature of a union type of the types of the string index signatures from each type in *S*. +* Let *S* be the set of types in *U* that has a numeric index signature. If *S* is not empty, *U* has a numeric index signature of a union type of the types of the numeric index signatures from each type in *S*. + +The || and conditional operators (section [4.15.7](#4.15.7) and [4.16](#4.16)) may produce values of union types, and array literals (section [4.6](#4.6)) may produce array values that have union types as their element types. + +Type guards (section [4.20](#4.20)) may be used to narrow a union type to a more specific type. In particular, type guards are useful for narrowing union type values to a non-union type values. + +In the example + +```TypeScript +var x: string | number; +var test: boolean; +x = "hello"; // Ok +x = 42; // Ok +x = test; // Error, boolean not assignable +x = test ? 5 : "five"; // Ok +x = test ? 0 : false; // Error, number | boolean not asssignable +``` + +it is possible to assign 'x' a value of type string, number, or the union type string | number, but not any other type. To access a value in 'x', a type guard can be used to first narrow the type of 'x' to either string or number: + +```TypeScript +var n = typeof x === "string" ? x.length : x; // Type of n is number +``` + +The following example illustrates the merging of member types that occurs when union types are created from object types. + +```TypeScript +interface A { + a: string; + b: number; +} + +interface B { + a: number; + b: number; + c: number; +} + +var x: A | B; +var a = x.a; // a has type string | number +var b = x.b; // b has type number +var c = x.c; // Error, no property c in union type +``` + +Note that 'x.a' has a union type because the type of 'a' is different in 'A' and 'B', whereas 'x.b' simply has type number because that is the type of 'b' in both 'A' and 'B'. Also note that there is no property 'x.c' because only 'A' has a property 'c'. + +### 3.3.5 Function Types + +An object type containing one or more call signatures is said to be a ***function type***. Function types may be written using function type literals (section [3.6.7](#3.6.7)) or by including call signatures in object type literals. + +### 3.3.6 Constructor Types + +An object type containing one or more construct signatures is said to be a ***constructor type***. Constructor types may be written using constructor type literals (section [3.6.8](#3.6.8)) or by including construct signatures in object type literals. + +### 3.3.7 Members Every object type is composed from zero or more of the following kinds of members: @@ -1168,9 +1259,9 @@ Each type parameter has an associated type parameter ***constraint*** that estab The ***base constraint*** of a type parameter *T* is defined as follows: -* If *T* has no declared constraint, *T*’s base constraint is the empty object type `{}`. -* If *T*’s declared constraint is a type parameter, *T*’s base constraint is that of the type parameter. -* Otherwise, *T*’s base constraint is *T*’s declared constraint. +* If *T* has no declared constraint, *T*'s base constraint is the empty object type `{}`. +* If *T*'s declared constraint is a type parameter, *T*'s base constraint is that of the type parameter. +* Otherwise, *T*'s base constraint is *T*'s declared constraint. In the example @@ -1180,7 +1271,7 @@ interface G { } ``` -the base constraint of ‘T’ is the empty object type, and the base constraint of ‘U’ and ‘V’ is ‘Function’. +the base constraint of 'T' is the empty object type, and the base constraint of 'U' and 'V' is 'Function'. For purposes of determining type relationships (section [3.8](#3.8)), type parameters appear to be subtypes of their base constraint. Likewise, in property accesses (section [4.10](#4.10)), `new` operations (section [4.11](#4.11)), and function calls (section [4.12](#4.12)), type parameters appear to have the members of their base constraint, but no other members. @@ -1206,7 +1297,7 @@ Given the declaration interface G { } ``` -a type reference of the form ‘G<A, B>’ places no requirements on ‘A’ but requires ‘B’ to be assignable to ‘Function’. +a type reference of the form 'G<A, B>' places no requirements on 'A' but requires 'B' to be assignable to 'Function'. The process of substituting type arguments for type parameters in a generic type or generic signature is known as ***instantiating*** the generic type or signature. Instantiation of a generic type or signature can fail if the supplied type arguments do not satisfy the constraints of their corresponding type parameters. @@ -1214,11 +1305,11 @@ The process of substituting type arguments for type parameters in a generic type Class, interface, and enum types are ***named types*** that are introduced through class declarations (section [8.1](#8.1)), interface declarations (section [7.1](#7.1)), and enum declarations ([9.1](#9.1)). Class and interface types may have type parameters and are then called ***generic types***. Conversely, named types without type parameters are called ***non-generic types***. -Interface declarations only introduce named types, whereas class declarations introduce named types *and* constructor functions that create instances of implementations of those named types. The named types introduced by class and interface declarations have only minor differences (classes can’t declare optional members and interfaces can’t declare private or protected members) and are in most contexts interchangeable. In particular, class declarations with only public members introduce named types that function exactly like those created by interface declarations. +Interface declarations only introduce named types, whereas class declarations introduce named types *and* constructor functions that create instances of implementations of those named types. The named types introduced by class and interface declarations have only minor differences (classes can't declare optional members and interfaces can't declare private or protected members) and are in most contexts interchangeable. In particular, class declarations with only public members introduce named types that function exactly like those created by interface declarations. Named types are referenced through ***type references*** (section [3.6.2](#3.6.2)) that specify a type name and, if applicable, the type arguments to be substituted for the type parameters of the named type. -Named types are technically not types—only *references* to named types are. This distinction is particularly evident with generic types: Generic types are “templates” from which multiple *actual* types can be created by writing type references that supply type arguments to substitute in place of the generic type’s type parameters. This substitution process is known as ***instantiating*** a generic type. Only once a generic type is instantiated does it denote an actual type. +Named types are technically not types—only *references* to named types are. This distinction is particularly evident with generic types: Generic types are "templates" from which multiple *actual* types can be created by writing type references that supply type arguments to substitute in place of the generic type's type parameters. This substitution process is known as ***instantiating*** a generic type. Only once a generic type is instantiated does it denote an actual type. TypeScript has a structural type system, and therefore an instantiation of a generic type is indistinguishable from an equivalent manually written expansion. For example, given the declaration @@ -1240,7 +1331,7 @@ is indistinguishable from the type ### 3.5.1 Instance Types -Each named type has an associated actual type known as the ***instance type***. For a non-generic type, the instance type is simply a type reference to the non-generic type. For a generic type, the instance type is an instantiation of the generic type where each of the type arguments is the corresponding type parameter. Since the instance type uses the type parameters it can be used only where the type parameters are in scope—that is, inside the declaration of the generic type. Within the constructor and instance member functions of a class, the type of `this` is the instance type of the class. +Each named type has an associated actual type known as the ***instance type***. For a non-generic type, the instance type is simply a type reference to the non-generic type. For a generic type, the instance type is an instantiation of the generic type where each of the type arguments is the corresponding type parameter. Since the instance type uses the type parameters it can be used only where the type parameters are in scope—that is, inside the declaration of the generic type. Within the constructor and instance member functions of a class, the type of `this` is the instance type of the class. The following example illustrates the concept of an instance type: @@ -1258,15 +1349,33 @@ class G { // Introduce type parameter T Types are specified either by referencing their keyword or name, or by writing object type literals, array type literals, tuple type literals, function type literals, constructor type literals, or type queries.   *Type:* +   *PrimaryOrUnionType* +   *FunctionType* +   *ConstructorType* + +  *PrimaryOrUnionType:* +   *PrimaryType* +   *UnionType* + +  *PrimaryType:* +   *ParenthesizedType*    *PredefinedType*    *TypeReference*    *ObjectType*    *ArrayType*    *TupleType* -   *FunctionType* -   *ConstructorType*    *TypeQuery* +  *ParenthesizedType:* +   `(` *Type* `)` + +Parentheses are required around union, function, or constructor types when they are used as array element types, and parentheses are required around function or constructor types in union types. For example: + +```TypeScript +(string | number)[] +((x: string) => string) | (x: number) => number) +``` + The different forms of type notations are described in the following sections. ### 3.6.1 Predefined Types @@ -1330,9 +1439,9 @@ var v6: G; // Error, wrong number of arguments var v7: G; // Error, no arguments ``` -A type argument is simply a *Type* and may itself be a type reference to a generic type, as demonstrated by ‘v4’ in the example above. +A type argument is simply a *Type* and may itself be a type reference to a generic type, as demonstrated by 'v4' in the example above. -As described in section [3.5](#3.5), a type reference to a generic type *G* designates a type wherein all occurrences of *G*’s type parameters have been replaced with the actual type arguments supplied in the type reference. For example, the declaration of ‘v1’ above is equivalent to: +As described in section [3.5](#3.5), a type reference to a generic type *G* designates a type wherein all occurrences of *G*'s type parameters have been replaced with the actual type arguments supplied in the type reference. For example, the declaration of 'v1' above is equivalent to: ```TypeScript var v1: { @@ -1369,36 +1478,24 @@ The members of an object type literal are specified as a combination of property An array type literal is written as an element type followed by an open and close square bracket.   *ArrayType:* -   *ElementType* *[no LineTerminator here]* `[` `]` +   *PrimaryType* *[no LineTerminator here]* `[` `]` -  *ElementType:* -   *PredefinedType* -   *TypeReference* -   *ObjectType* -   *ArrayType* -   *TupleType* -   *TypeQuery* +An array type literal references an array type (section [3.3.2](#3.3.2)) with the given element type. An array type literal is simply shorthand notation for a reference to the generic interface type 'Array' in the global module with the element type as a type argument. -An array type literal references an array type (section [3.3.2](#3.3.2)) with the given element type. An array type literal is simply shorthand notation for a reference to the generic interface type ‘Array’ in the global module with the element type as a type argument. - -In order to avoid grammar ambiguities, array type literals permit only a restricted set of notations for the element type. Specifically, an *ArrayType* cannot start with a *FunctionType* or *ConstructorType*. To use one of those forms for the element type, an array type must be written using the ‘Array<T>’ notation. For example, the type +When union, function, or constructor types are used as array element types they must be enclosed in parentheses. For example: ```TypeScript -() => string[] +(string | number)[] +(() => string))[] ``` -denotes a function returning a string array, not an array of functions returning string. The latter can be expressed using ‘Array<T>’ notation +Alternatively, array types can be written using the 'Array<T>' notation. For example, the types above are equivalent to ```TypeScript +Array Array<() => string> ``` -or by writing the element type as an object type literal - -```TypeScript -{ (): string }[] -``` - ### 3.6.5 Tuple Type Literals A tuple type literal is written as a sequence of element types, separated by commas and enclosed in square brackets. @@ -1415,7 +1512,28 @@ A tuple type literal is written as a sequence of element types, separated by com A tuple type literal references a tuple type (section [3.3.3](#3.3.3)). -### 3.6.6 Function Type Literals +### 3.6.6 Union Type Literals + +A union type literal is written as a sequence of types separated by vertical bars. + +  *UnionType:* +   *PrimaryOrUnionType* `|` *PrimaryType* + +A union typle literal references a union type (section [3.3.4](#3.3.4)). + +When function or constructor types are included in union types they must be enclosed in parentheses. For example: + +```TypeScript +((x: string) => string) | ((x: number) => number) +``` + +Alternatively, function or constructor types in union types can be written using object literals: + +```TypeScript +{ (x: string): string } | { (x: number): number } +``` + +### 3.6.7 Function Type Literals A function type literal specifies the type parameters, regular parameters, and return type of a call signature. @@ -1436,7 +1554,7 @@ is exactly equivalent to the object type literal Note that function types with multiple call or construct signatures cannot be written as function type literals but must instead be written as object type literals. -### 3.6.7 Constructor Type Literals +### 3.6.8 Constructor Type Literals A constructor type literal specifies the type parameters, regular parameters, and return type of a construct signature. @@ -1457,7 +1575,7 @@ is exactly equivalent to the object type literal Note that constructor types with multiple construct signatures cannot be written as constructor type literals but must instead be written as object type literals. -### 3.6.8 Type Queries +### 3.6.9 Type Queries A type query obtains the type of an expression. @@ -1477,7 +1595,7 @@ var a = { x: 10, y: 20 }; var b: typeof a; ``` -Above, ‘b’ is given the same type as ‘a’, namely ‘{ x: number; y: number; }’. +Above, 'b' is given the same type as 'a', namely '{ x: number; y: number; }'. If a declaration includes a type annotation that references the entity being declared through a circular path of type queries or type references containing type queries, the resulting type is the Any type. For example, all of the following variables are given the type Any: @@ -1495,7 +1613,7 @@ var g: { x: typeof g; }; var h: () => typeof h; ``` -Here, ‘g’ and ‘g.x’ have the same recursive type, and likewise ‘h’ and ‘h()’ have the same recursive type. +Here, 'g' and 'g.x' have the same recursive type, and likewise 'h' and 'h()' have the same recursive type. ## 3.7 Specifying Members @@ -1554,7 +1672,7 @@ A function taking two values of the same type, returning an array of that type: (x: T, y: T): T[] ``` -A function taking two arguments of different types, returning an object with properties ‘x’ and ‘y’ of those types: +A function taking two arguments of different types, returning an object with properties 'x' and 'y' of those types: ```TypeScript (x: T, y: U): { x: T; y: U; } @@ -1568,7 +1686,7 @@ A function taking an array of one type and a function argument, returning an arr #### 3.7.2.2 Parameter List -A signature’s parameter list consists of zero or more required parameters, followed by zero or more optional parameters, finally followed by an optional rest parameter. +A signature's parameter list consists of zero or more required parameters, followed by zero or more optional parameters, finally followed by an optional rest parameter.   *ParameterList:*    *RequiredParameterList* @@ -1618,7 +1736,7 @@ A parameter can be marked optional by following its name with a question mark (` #### 3.7.2.3 Return Type -If present, a call signature’s return type annotation specifies the type of the value computed and returned by a call operation. A `void` return type annotation is used to indicate that a function has no return value. +If present, a call signature's return type annotation specifies the type of the value computed and returned by a call operation. A `void` return type annotation is used to indicate that a function has no return value. When a call signature with no return type annotation occurs in a context without a function body, the return type is assumed to be the Any type. @@ -1637,11 +1755,11 @@ interface Document { } ``` -states that calls to ‘createElement’ with the string literals “div”, “span”, and “canvas” return values of type ‘HTMLDivElement’, ‘HTMLSpanElement’, and ‘HTMLCanvasElement’ respectively, and that calls with all other string expressions return values of type ‘HTMLElement’. +states that calls to 'createElement' with the string literals "div", "span", and "canvas" return values of type 'HTMLDivElement', 'HTMLSpanElement', and 'HTMLCanvasElement' respectively, and that calls with all other string expressions return values of type 'HTMLElement'. When writing overloaded declarations such as the one above it is important to list the non-specialized signature last. This is because overload resolution (section [4.12.1](#4.12.1)) processes the candidates in declaration order and picks the first one that matches. -Every specialized call or construct signature in an object type must be assignable to at least one non-specialized call or construct signature in the same object type (where a call signature *A* is considered assignable to another call signature *B* if an object type containing only *A* would be assignable to an object type containing only *B*). For example, the ‘createElement’ property in the example above is of a type that contains three specialized signatures, all of which are assignable to the non-specialized signature in the type. +Every specialized call or construct signature in an object type must be assignable to at least one non-specialized call or construct signature in the same object type (where a call signature *A* is considered assignable to another call signature *B* if an object type containing only *A* would be assignable to an object type containing only *B*). For example, the 'createElement' property in the example above is of a type that contains three specialized signatures, all of which are assignable to the non-specialized signature in the type. ### 3.7.3 Construct Signatures @@ -1722,7 +1840,7 @@ In the following example of an object type } ``` -the properties ‘func1’, ‘func2’, and ‘func3’ are all of the same type, namely an object type with a single call signature taking a number and returning a number. Likewise, in the object type +the properties 'func1', 'func2', and 'func3' are all of the same type, namely an object type with a single call signature taking a number and returning a number. Likewise, in the object type ```TypeScript { @@ -1735,29 +1853,29 @@ the properties } ``` -the properties ‘func4’ and ‘func5’ are of the same type, namely an object type with two call signatures taking and returning number and string respectively. +the properties 'func4' and 'func5' are of the same type, namely an object type with two call signatures taking and returning number and string respectively. ## 3.8 Type Relationships Types in TypeScript have identity, subtype, supertype, and assignment compatibility relationships as defined in the following sections. -For purposes of determining type relationships, all object types appear to have the members of the ‘Object’ interface unless those members are hidden by members with the same name in the object types, and object types with one or more call or construct signatures appear to have the members of the ‘Function’ interface unless those members are hidden by members with the same name in the object types. Apparent types (section [3.8.1](#3.8.1)) that are object types appear to have these extra members as well. +For purposes of determining type relationships, all object types appear to have the members of the 'Object' interface unless those members are hidden by members with the same name in the object types, and object types with one or more call or construct signatures appear to have the members of the 'Function' interface unless those members are hidden by members with the same name in the object types. Apparent types (section [3.8.1](#3.8.1)) that are object types appear to have these extra members as well. ### 3.8.1 Apparent Type -In certain contexts a type appears to have the characteristics of a related type called the type’s ***apparent type***. Specifically, a type’s apparent type is used when determining subtype, supertype, and assignment compatibility relationships, as well as in the type checking of property accesses (section [4.10](#4.10)), `new` operations (section [4.11](#4.11)), and function calls (section [4.12](#4.12)). +In certain contexts a type appears to have the characteristics of a related type called the type's ***apparent type***. Specifically, a type's apparent type is used when determining subtype, supertype, and assignment compatibility relationships, as well as in the type checking of property accesses (section [4.10](#4.10)), `new` operations (section [4.11](#4.11)), and function calls (section [4.12](#4.12)). The apparent type of a type *T* is defined as follows: -* If *T* is the primitive type Number, Boolean, or String, the apparent type of *T* is the augmented form (as defined below) of the global interface type ‘Number’, ‘Boolean’, or ‘String’. -* if *T* is an enum type, the apparent type of *T* is the augmented form of the global interface type ‘Number’. +* If *T* is the primitive type Number, Boolean, or String, the apparent type of *T* is the augmented form (as defined below) of the global interface type 'Number', 'Boolean', or 'String'. +* if *T* is an enum type, the apparent type of *T* is the augmented form of the global interface type 'Number'. * If *T* is an object type, the apparent type of *T* is the augmented form of *T*. -* If *T* is a type parameter, the apparent type of *T* is the apparent type of *T*’s base constraint (section [3.4.1](#3.4.1)). +* If *T* is a type parameter, the apparent type of *T* is the apparent type of *T*'s base constraint (section [3.4.1](#3.4.1)). * Otherwise, the apparent type of *T* is *T* itself. -The augmented form of an object type *T* adds to *T* those properties of the global interface type ‘Object’ that aren’t hidden by properties in *T*. Furthermore, if *T* has one or more call or construct signatures, the augmented form of *T* adds to *T* the properties of the global interface type ‘Function’ that aren’t hidden by properties in *T*. Properties in *T* hide ‘Object’ or ‘Function’ interface properties with the same name. +The augmented form of an object type *T* adds to *T* those properties of the global interface type 'Object' that aren't hidden by properties in *T*. Furthermore, if *T* has one or more call or construct signatures, the augmented form of *T* adds to *T* the properties of the global interface type 'Function' that aren't hidden by properties in *T*. Properties in *T* hide 'Object' or 'Function' interface properties with the same name. -In effect, a type’s apparent type is a subtype of the ‘Object’ or ‘Function’ interface unless the type defines members that are incompatible with those of the ‘Object’ or ‘Function’ interface—which, for example, occurs if the type defines a property with the same name as a property in the ‘Object’ or ‘Function’ interface but with a type that isn’t a subtype of that in the ‘Object’ or ‘Function’ interface. +In effect, a type's apparent type is a subtype of the 'Object' or 'Function' interface unless the type defines members that are incompatible with those of the 'Object' or 'Function' interface—which, for example, occurs if the type defines a property with the same name as a property in the 'Object' or 'Function' interface but with a type that isn't a subtype of that in the 'Object' or 'Function' interface. Some examples: @@ -1767,7 +1885,7 @@ var f: Function = (x: number) => x * x; // Ok var err: Object = { toString: 0 }; // Error ``` -The last assignment is an error because the apparent type of the object literal has a ‘toString’ method that isn’t compatible with that of ‘Object’. +The last assignment is an error because the apparent type of the object literal has a 'toString' method that isn't compatible with that of 'Object'. ### 3.8.2 Type and Member Identity @@ -1775,8 +1893,9 @@ Two types are considered ***identical*** when * they are both the Any type, * they are the same primitive type, -* they are the same type parameter, or -* they are object types with identical sets of members. +* they are the same type parameter, +* they are union types with identical sets of constituent types, or +* they are non-union object types with identical sets of members. Two members are considered identical when @@ -1803,11 +1922,11 @@ var a: C; var b: C; ``` -the variables ‘a’ and ‘b’ are of identical types because the two type references to ‘C’ create types with a private member ‘x’ that originates in the same declaration, and because the two private ‘x’ members have types with identical sets of members once the type arguments ‘X’ and ‘Y’ are substituted. +the variables 'a' and 'b' are of identical types because the two type references to 'C' create types with a private member 'x' that originates in the same declaration, and because the two private 'x' members have types with identical sets of members once the type arguments 'X' and 'Y' are substituted. ### 3.8.3 Subtypes and Supertypes -*S* is a ***subtype*** of a type *T*, and *T* is a ***supertype*** of *S*, if one of the following is true, where *S*’ denotes the apparent type (section [3.8.1](#3.8.1)) of *S*: +*S* is a ***subtype*** of a type *T*, and *T* is a ***supertype*** of *S*, if one of the following is true, where *S*' denotes the apparent type (section [3.8.1](#3.8.1)) of *S*: * *S* and *T* are identical types. * *T* is the Any type. @@ -1816,20 +1935,22 @@ the variables * *S* is an enum type and *T* is the primitive type Number. * *S* is a string literal type and *T* is the primitive type String. * *S* and *T* are type parameters, and *S* is directly or indirectly constrained to *T*. -* *S’* and *T* are object types and, for each member *M* in *T*, one of the following is true: - * *M* is a property and *S’* contains a property *N* where +* *S* is a union type and each constituent type of *S* is a subtype of *T*. +* *T* is a union type and *S* is a subtype of at least one constituent type of *T*. +* *S'* and *T* are object types and, for each member *M* in *T*, one of the following is true: + * *M* is a property and *S'* contains a property *N* where * *M* and *N* have the same name, * the type of *N* is a subtype of that of *M*, * if *M* is a required property, *N* is also a required property, and * *M* and *N* are both public, *M* and *N* are both private and originate in the same declaration, *M* and *N* are both protected and originate in the same declaration, or *M* is protected and *N* is declared in a class derived from the class in which *M* is declared. - * *M* is an optional property and *S’* contains no property of the same name as *M*. - * *M* is a non-specialized call or construct signature and *S*’ contains a call or construct signature *N* where, when *M* and *N* are instantiated using type Any as the type argument for all type parameters declared by *M* and *N* (if any), + * *M* is an optional property and *S'* contains no property of the same name as *M*. + * *M* is a non-specialized call or construct signature and *S*' contains a call or construct signature *N* where, when *M* and *N* are instantiated using type Any as the type argument for all type parameters declared by *M* and *N* (if any), * the signatures are of the same kind (call or construct), * *M* has a rest parameter or the number of non-optional parameters in *N* is less than or equal to the total number of parameters in *M*, * for parameter positions that are present in both signatures, each parameter type in *N* is a subtype or supertype of the corresponding parameter type in *M*, and * the result type of *M* is Void, or the result type of *N* is a subtype of that of *M*. - * *M* is a string index signature of type *U* and *S’* contains a string index signature of a type that is a subtype of *U*. - * *M* is a numeric index signature of type *U* and *S’* contains a string or numeric index signature of a type that is a subtype of *U*. + * *M* is a string index signature of type *U* and *S'* contains a string index signature of a type that is a subtype of *U*. + * *M* is a numeric index signature of type *U* and *S'* contains a string or numeric index signature of a type that is a subtype of *U*. When comparing call or construct signatures, parameter names are ignored and rest parameters correspond to an unbounded expansion of optional parameters of the rest parameter element type. @@ -1841,7 +1962,7 @@ Also note that type parameters are not considered object types. Thus, the only s Types are required to be assignment compatible in certain circumstances, such as expression and variable types in assignment statements and argument and parameter types in function calls. -*S* is ***assignable to*** a type *T*, and *T* is ***assignable from*** *S*, if one of the following is true, where *S*’ denotes the apparent type (section [3.8.1](#3.8.1)) of *S*: +*S* is ***assignable to*** a type *T*, and *T* is ***assignable from*** *S*, if one of the following is true, where *S*' denotes the apparent type (section [3.8.1](#3.8.1)) of *S*: * *S* and *T* are identical types. * *S* or *T* is the Any type. @@ -1850,20 +1971,22 @@ Types are required to be assignment compatible in certain circumstances, such as * *S* or *T* is an enum type and* *the other is the primitive type Number. * *S* is a string literal type and *T* is the primitive type String. * *S* and *T* are type parameters, and *S* is directly or indirectly constrained to *T*. -* *S’* and *T* are object types and, for each member *M* in *T*, one of the following is true: - * *M* is a property and *S’* contains a property *N* where +* *S* is a union type and each constituent type of *S* is assignable to *T*. +* *T* is a union type and *S* is assignable to at least one constituent type of *T*. +* *S'* and *T* are object types and, for each member *M* in *T*, one of the following is true: + * *M* is a property and *S'* contains a property *N* where * *M* and *N* have the same name, * the type of *N* is assignable to that of *M*, * if *M* is a required property, *N* is also a required property, and * *M* and *N* are both public, *M* and *N* are both private and originate in the same declaration, *M* and *N* are both protected and originate in the same declaration, or *M* is protected and *N* is declared in a class derived from the class in which *M* is declared. - * *M* is an optional property and *S’* contains no property of the same name as *M*. - * *M* is a non-specialized call or construct signature and *S*’ contains a call or construct signature *N* where, when *M* and *N* are instantiated using type Any as the type argument for all type parameters declared by *M* and *N* (if any), + * *M* is an optional property and *S'* contains no property of the same name as *M*. + * *M* is a non-specialized call or construct signature and *S*' contains a call or construct signature *N* where, when *M* and *N* are instantiated using type Any as the type argument for all type parameters declared by *M* and *N* (if any), * the signatures are of the same kind (call or construct), * *M* has a rest parameter or the number of non-optional parameters in *N* is less than or equal to the total number of parameters in *M*, * for parameter positions that are present in both signatures, each parameter type in *N* is assignable to or from the corresponding parameter type in *M*, and * the result type of *M* is Void, or the result type of *N* is assignable to that of *M*. - * *M* is a string index signature of type *U* and *S’* contains a string index signature of a type that is assignable to *U*. - * *M* is a numeric index signature of type *U* and *S’* contains a string or numeric index signature of a type that is assignable to *U*. + * *M* is a string index signature of type *U* and *S'* contains a string index signature of a type that is assignable to *U*. + * *M* is a numeric index signature of type *U* and *S'* contains a string or numeric index signature of a type that is assignable to *U*. When comparing call or construct signatures, parameter names are ignored and rest parameters correspond to an unbounded expansion of optional parameters of the rest parameter element type. @@ -1889,14 +2012,19 @@ foo({ name: "hello" }); // Error, id required but missing During type argument inference in a function call (section [4.12.2](#4.12.2)) it is in certain circumstances necessary to instantiate a generic call signature of an argument expression in the context of a non-generic call signature of a parameter such that further inferences can be made. A generic call signature *A* is ***instantiated in the context of*** non-generic call signature *B* as follows: -* Using the process described in [3.8.6](#3.8.6), inferences for *A*’s type parameters are made from each parameter type in *B* to the corresponding parameter type in *A* for those parameter positions that are present in both signatures, where rest parameters correspond to an unbounded expansion of optional parameters of the rest parameter element type. -* The inferred type argument for each type parameter is the best common type (section [3.10](#3.10)) of the set of inferences made for that type parameter. However, if the best common type does not satisfy the constraint of the type parameter, the inferred type argument is instead the constraint. +* Using the process described in [3.8.6](#3.8.6), inferences for *A*'s type parameters are made from each parameter type in *B* to the corresponding parameter type in *A* for those parameter positions that are present in both signatures, where rest parameters correspond to an unbounded expansion of optional parameters of the rest parameter element type. +* The inferred type argument for each type parameter is the union type of the set of inferences made for that type parameter. However, if the union type does not satisfy the constraint of the type parameter, the inferred type argument is instead the constraint. ### 3.8.6 Type Inference In certain contexts, inferences for a given set of type parameters are made *from* a type *S*, in which those type parameters do not occur, *to* another type *T*, in which those type parameters do occur. Inferences consist of a set of candidate type arguments collected for each of the type parameters. The inference process recursively relates *S* and *T* to gather as many inferences as possible: * If *T* is one of the type parameters for which inferences are being made, *S* is added to the set of inferences for that type parameter. +* Otherwise, if *S* and *T* are references to the same generic type, inferences are made from each type argument in *S* to each corresponding type argument in *T*. +* Otherwise, if *T* is a union type: + * First, inferences are made from *S* to each constituent type in *T* that isn't simply one of the type parameters for which inferences are being made. + * If the first step produced no inferences and exactly one constituent type in *T* is simply a type parameter for which inferences are being made, inferences are made from *S* to that type parameter. +* Otherwise, if *S* is a union type, inferences are made from each constituent type in *S* to *T*. * Otherwise, if *S* and *T* are object types, then for each member *M* in *T*: * If *M* is a property and *S* contains a property *N* with the same name as *M*, inferences are made from the type of *N* to the type of *M*. * If *M* is a call signature and a corresponding call signature *N* exists in *S*, *N* is instantiated with the Any type as an argument for each type parameter (if any) and inferences are made from parameter types in *N* to the corresponding parameter types in *M* for positions that are present in both signatures, and from the return type of *N* to the return type of *M*. @@ -1915,7 +2043,7 @@ Classes and interfaces can reference themselves in their internal structure, in interface A { next: A; } ``` -contains an infinitely nested sequence of ‘next’ properties. Types such as this are perfectly valid but require special treatment when determining type relationships. Specifically, when comparing types *S* and *T* for a given relationship (identity, subtype, or assignability), the relationship in question is assumed to be true for every directly or indirectly nested occurrence of the same *S* and the same *T* (where same means originating in the same declaration and, if applicable, having identical type arguments). For example, consider the identity relationship between ‘A’ above and ‘B’ below: +contains an infinitely nested sequence of 'next' properties. Types such as this are perfectly valid but require special treatment when determining type relationships. Specifically, when comparing types *S* and *T* for a given relationship (identity, subtype, or assignability), the relationship in question is assumed to be true for every directly or indirectly nested occurrence of the same *S* and the same *T* (where same means originating in the same declaration and, if applicable, having identical type arguments). For example, consider the identity relationship between 'A' above and 'B' below: ```TypeScript interface B { next: C; } @@ -1925,7 +2053,7 @@ interface C { next: D; } interface D { next: B; } ``` -To determine whether ‘A’ and ‘B’ are identical, first the ‘next’ properties of type ‘A’ and ‘C’ are compared. That leads to comparing the ‘next’ properties of type ‘A’ and ‘D’, which leads to comparing the ‘next’ properties of type ‘A’ and ‘B’. Since ‘A’ and ‘B’ are already being compared this relationship is by definition true. That in turn causes the other comparisons to be true, and therefore the final result is true. +To determine whether 'A' and 'B' are identical, first the 'next' properties of type 'A' and 'C' are compared. That leads to comparing the 'next' properties of type 'A' and 'D', which leads to comparing the 'next' properties of type 'A' and 'B'. Since 'A' and 'B' are already being compared this relationship is by definition true. That in turn causes the other comparisons to be true, and therefore the final result is true. When this same technique is used to compare generic type references, two type references are considered the same when they originate in the same declaration and have identical type arguments. @@ -1939,7 +2067,7 @@ interface List { } ``` -‘List<T>’ has a member ‘owner’ of type ‘List<List<T>>’, which has a member ‘owner’ of type ‘List<List<List<T>>>’, which has a member ‘owner’ of type ‘List<List<List<List<T>>>>’ and so on, ad infinitum. Since type relationships are determined structurally, possibly exploring the constituent types to their full depth, in order to determine type relationships involving infinitely expanding generic types it may be necessary for the compiler to terminate the recursion at some point with the assumption that no further exploration will change the outcome. +'List<T>' has a member 'owner' of type 'List<List<T>>', which has a member 'owner' of type 'List<List<List<T>>>', which has a member 'owner' of type 'List<List<List<List<T>>>>' and so on, ad infinitum. Since type relationships are determined structurally, possibly exploring the constituent types to their full depth, in order to determine type relationships involving infinitely expanding generic types it may be necessary for the compiler to terminate the recursion at some point with the assumption that no further exploration will change the outcome. ## 3.9 Widened Types @@ -1949,41 +2077,24 @@ In several situations TypeScript infers types from context, alleviating the need var name = "Steve"; ``` -infers the type of ‘name’ to be the String primitive type since that is the type of the value used to initialize it. When inferring the type of a variable, property or function result from an expression, the ***widened*** form of the source type is used as the inferred type of the target. The widened form of a type is the type in which all occurrences of the Null and Undefined types have been replaced with the type `any`. +infers the type of 'name' to be the String primitive type since that is the type of the value used to initialize it. When inferring the type of a variable, property or function result from an expression, the ***widened*** form of the source type is used as the inferred type of the target. The widened form of a type is the type in which all occurrences of the Null and Undefined types have been replaced with the type `any`. The following example shows the results of widening types to produce inferred variable types. ```TypeScript -var a = null; // var a: any -var b = undefined; // var b: any -var c = { x: 0, y: null }; // var c: { x: number, y: any } -var d = [ null, undefined ]; // var d: any[] +var a = null; // var a: any +var b = undefined; // var b: any +var c = { x: 0, y: null }; // var c: { x: number, y: any } +var d = [ null, undefined ]; // var d: any[] ``` -## 3.10 Best Common Type - -In several situations a ***best common type*** needs to be inferred from a set of types. In particular, return types of functions with multiple return statements and element types of array literals are found this way. The determination of a best common type may in some cases factor in a contextual type. - -Given a set of types { *T1*, *T2*, …, *Tn* } and a contextual type *C*, the best common type is determined as follows: - -* If the set of types is empty, the best common type is *C*. -* Otherwise, if C is a supertype of every *Tn*, the best common type is C. -* Otherwise, if one exists, the first *Tx* that is a supertype of every *Tn* is the best common type. -* Otherwise, the best common type is an empty object type (the type `{}`). - -Given a set of types { *T1*, *T2*, …, *Tn* } and no contextual type, the best common type is determined as follows: - -* If the set of types is empty, the best common type is an empty object type. -* Otherwise, if one exists, the first *Tx* that is a supertype of every *Tn* is the best common type. -* Otherwise, the best common type is an empty object type (the type `{}`). -
#
4 Expressions -This chapter describes the manner in which TypeScript provides type inference and type checking for JavaScript expressions. TypeScript’s type analysis occurs entirely at compile-time and adds no run-time overhead to expression evaluation. +This chapter describes the manner in which TypeScript provides type inference and type checking for JavaScript expressions. TypeScript's type analysis occurs entirely at compile-time and adds no run-time overhead to expression evaluation. -TypeScript’s typing rules define a type for every expression construct. For example, the type of the literal 123 is the Number primitive type, and the type of the object literal { a: 10, b: "hello" } is { a: number; b: string; }. The sections in this chapter describe these rules in detail. +TypeScript's typing rules define a type for every expression construct. For example, the type of the literal 123 is the Number primitive type, and the type of the object literal { a: 10, b: "hello" } is { a: number; b: string; }. The sections in this chapter describe these rules in detail. In addition to type inference and type checking, TypeScript augments JavaScript expressions with the following constructs: @@ -2033,7 +2144,7 @@ Literals are typed as follows: * The type of the literals `true` and `false` is the Boolean primitive type. * The type of numeric literals is the Number primitive type. * The type of string literals is the String primitive type. -* The type of regular expression literals is the global interface type ‘RegExp’. +* The type of regular expression literals is the global interface type 'RegExp'. ## 4.5 Object Literals @@ -2068,7 +2179,7 @@ f : function ( ... ) { ... } Each property assignment in an object literal is processed as follows: * If the object literal is contextually typed and the contextual type contains a property with a matching name, the property assignment is contextually typed by the type of that property. -* Otherwise, if the object literal is contextually typed, the contextual type contains a numeric index signature, and the property assignment specifies a numeric property name, the property assignment is contextually typed by the type of the numeric index signature. +* Otherwise, if the object literal is contextually typed, if the contextual type contains a numeric index signature, and if the property assignment specifies a numeric property name, the property assignment is contextually typed by the type of the numeric index signature. * Otherwise, if the object literal is contextually typed and the contextual type contains a string index signature, the property assignment is contextually typed by the type of the string index signature. * Otherwise, the property assignment is processed without a contextual type. @@ -2082,14 +2193,14 @@ A get accessor declaration is processed in the same manner as an ordinary functi If a get accessor is declared for a property, the return type of the get accessor becomes the type of the property. If only a set accessor is declared for a property, the parameter type (which may be type Any if no type annotation is present) of the set accessor becomes the type of the property. -When an object literal is contextually typed by a type that includes a string index signature of type *T*, the resulting type of the object literal includes a string index signature with the widened form of the best common type of the contextual type *T* and the types of the properties declared in the object literal. Likewise, when an object literal is contextually typed by a type that includes a numeric index signature of type *T*, the resulting type of the object literal includes a numeric index signature with the widened form of the best common type of the contextual type *T* and the types of the numerically named properties (section [3.7.4](#3.7.4)) declared in the object literal. +When an object literal is contextually typed by a type that includes a string index signature, the resulting type of the object literal includes a string index signature with the union type of the types of the properties declared in the object literal, or the Undefined type if the object literal is empty. Likewise, when an object literal is contextually typed by a type that includes a numeric index signature, the resulting type of the object literal includes a numeric index signature with the union type of the types of the numerically named properties (section [3.7.4](#3.7.4)) declared in the object literal, or the Undefined type if the object literal declares no numerically named properties. ## 4.6 Array Literals An array literal ```TypeScript -[expr1, expr2, ..., exprN] +[ expr1, expr2, ..., exprN ] ``` denotes a value of an array type (section [3.3.2](#3.3.2)) or a tuple type (section [3.3.3](#3.3.3)) depending on context. @@ -2100,22 +2211,17 @@ Each element expression in a non-empty array literal is processed as follows: * Otherwise, if the array literal is contextually typed by a type *T* with a numeric index signature, the element expression is contextually typed by the type of the numeric index signature. * Otherwise, the element expression is not contextually typed. -The resulting type of a non-empty array literal expression is determined as follows: +The resulting type an array literal expression is determined as follows: -* If the array literal is contextually typed by a type *T* and *T* has at least one property with a numeric name that matches the index of an element expression in the array literal, the resulting type is a tuple type constructed from the types of the element expressions. -* Otherwise, if the array literal is contextually typed by a type T with a numeric index signature of type *S*, the resulting type is an array type where the element type is the best common type of the contextual type *S* and the types of the element expressions. -* Otherwise, if the array literal is not contextually typed, the resulting type is an array type where the element type is the best common type of the types of the element expressions. - -The resulting type of an empty array literal expression is determined as follows: - -* If the array literal is contextually typed by a type *T* with a numeric index signature of type *S*, the resulting type is an array type with element type *S*. -* Otherwise, the resulting type is an array type with the element type Undefined. +* If the array literal is empty, the resulting type is an array type with the element type Undefined. +* Otherwise, if the array literal is contextually typed by a type that has a property with the numeric name '0', the resulting type is a tuple type constructed from the types of the element expressions. +* Otherwise, the resulting type is an array type with an element type that is the union of the types of the element expressions. The rules above mean that an array literal is always of an array type, unless it is contextually typed by a type with numerically named properties (such as a tuple type). For example ```TypeScript var a = [1, 2]; // number[] -var b = ["hello", true]; // {}[] +var b = ["hello", true]; // (string | boolean)[] var c: [number, string] = [3, "three"]; // [number, string] ``` @@ -2134,7 +2240,7 @@ has the same type and classification as the contained expression itself. Specifi The `super` keyword can be used in expressions to reference base class properties and the base class constructor.   *CallExpression:* *( Modified )* -   … +   …    `super` `(` *ArgumentListopt* `)`    `super` `.` *IdentifierName* @@ -2169,7 +2275,7 @@ Function expressions are extended from JavaScript to optionally include paramete    `function` *Identifieropt* *CallSignature* `{` *FunctionBody* `}`   *AssignmentExpression:* *( Modified )* -   … +   …    *ArrowFunctionExpression*   *ArrowFunctionExpression:* @@ -2182,7 +2288,7 @@ Function expressions are extended from JavaScript to optionally include paramete The terms ***standard function expression*** and ***arrow function expression*** are used to refer to the *FunctionExpression* and *ArrowFunctionExpression* forms respectively. When referring to either, the generic term ***function expression*** is used. -The type of a function expression is an object type containing a single call signature with parameter and return types inferred from the function expression’s signature and body. +The type of a function expression is an object type containing a single call signature with parameter and return types inferred from the function expression's signature and body. The descriptions of function declarations provided in section [6.1](#6.1) apply to function expressions as well, except that function expressions do not support overloading. @@ -2247,7 +2353,7 @@ var messenger = new Messenger(); messenger.start(); ``` -the use of an arrow function expression causes the callback to have the same `this` as the surrounding ‘start’ method. Writing the callback as a standard function expression it becomes necessary to manually arrange access to the surrounding `this`, for example by copying it into a local variable: +the use of an arrow function expression causes the callback to have the same `this` as the surrounding 'start' method. Writing the callback as a standard function expression it becomes necessary to manually arrange access to the surrounding `this`, for example by copying it into a local variable: ```TypeScript class Messenger { @@ -2282,13 +2388,13 @@ Function expressions with no type parameters and no parameter type annotations ( When a function expression is contextually typed by a function type *T*, the function expression is processed as if it had explicitly specified parameter type annotations as they exist in *T*. Parameters are matched by position and need not have matching names. If the function expression has fewer parameters than *T*, the additional parameters in *T* are ignored. If the function expression has more parameters than *T*, the additional parameters are all considered to have type Any. -Furthermore, when a function expression has no return type annotation and is contextually typed by a function type *T*, expressions in contained return statements (section [5.7](#5.7)) are contextually typed by *T*’s return type. +Furthermore, when a function expression has no return type annotation and is contextually typed by a function type *T*, expressions in contained return statements (section [5.7](#5.7)) are contextually typed by *T*'s return type. ## 4.10 Property Access A property access uses either dot notation or bracket notation. A property access expression is always classified as a reference. -A property access uses an object’s apparent type (section [3.8.1](#3.8.1)) to determine its properties. Furthermore, in a property access, an object’s apparent type includes the properties that originate in the ‘Object’ or ‘Function’ global interface types, as described in section [3.3](#3.3). +A property access uses an object's apparent type (section [3.8.1](#3.8.1)) to determine its properties. Furthermore, in a property access, an object's apparent type includes the properties that originate in the 'Object' or 'Function' global interface types, as described in section [3.3](#3.3). A dot notation property access of the form @@ -2310,9 +2416,9 @@ object [ index ] where *object* and *index* are expressions, is used to access the property with the name computed by the index expression on the given object. A bracket notation property access is processed as follows at compile-time: -* If *index* is a string literal or a numeric literal and *object*’s apparent type has a property with the name given by that literal (converted to its string representation in the case of a numeric literal), the property access is of the type of that property. -* Otherwise, if *object*’s apparent type has a numeric index signature and *index* is of type Any, the Number primitive type, or an enum type, the property access is of the type of that index signature. -* Otherwise, if *object*’s apparent type has a string index signature and *index* is of type Any, the String or Number primitive type, or an enum type, the property access is of the type of that index signature. +* If *index* is a string literal or a numeric literal and *object*'s apparent type has a property with the name given by that literal (converted to its string representation in the case of a numeric literal), the property access is of the type of that property. +* Otherwise, if *object*'s apparent type has a numeric index signature and *index* is of type Any, the Number primitive type, or an enum type, the property access is of the type of that index signature. +* Otherwise, if *object*'s apparent type has a string index signature and *index* is of type Any, the String or Number primitive type, or an enum type, the property access is of the type of that index signature. * Otherwise, if *index* is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. * Otherwise, the property access is invalid and a compile-time error occurs. @@ -2336,7 +2442,7 @@ var s = data[0]; // string var n = data[1]; // number ``` -## 4.11 The new Operator +## 4.11 The new Operator A `new` operation has one of the following forms: @@ -2349,8 +2455,8 @@ new C < ... > ( ... ) where *C* is an expression. The first form is equivalent to supplying an empty argument list. *C* must be of type Any or of an object type with one or more construct or call signatures. The operation is processed as follows at compile-time: * If *C* is of type Any, any argument list is permitted and the result of the operation is of type Any. -* If *C*’s apparent type (section [3.8.1](#3.8.1)) is an object type with one or more construct signatures, the expression is processed in the same manner as a function call, but using the construct signatures as the initial set of candidate signatures for overload resolution. The result type of the function call becomes the result type of the operation. -* If *C*’s apparent type is an object type with no construct signatures but one or more call signatures, the expression is processed as a function call. A compile-time error occurs if the result of the function call is not Void. The type of the result of the operation is Any. +* If *C*'s apparent type (section [3.8.1](#3.8.1)) is an object type with one or more construct signatures, the expression is processed in the same manner as a function call, but using the construct signatures as the initial set of candidate signatures for overload resolution. The result type of the function call becomes the result type of the operation. +* If *C*'s apparent type is an object type with no construct signatures but one or more call signatures, the expression is processed as a function call. A compile-time error occurs if the result of the function call is not Void. The type of the result of the operation is Any. ## 4.12 Function Calls @@ -2370,11 +2476,11 @@ where *func* is an expression of a function type or of type Any. The function ex If *func* is of type Any, or of an object type that has no call or construct signatures but is a subtype of the Function interface, the call is an ***untyped function call***. In an untyped function call no type arguments are permitted, argument expressions can be of any type and number, no contextual types are provided for the argument expressions, and the result is always of type Any. -If *func*’s apparent type (section [3.8.1](#3.8.1)) is a function type, the call is a ***typed function call***. TypeScript employs ***overload resolution*** in typed function calls in order to support functions with multiple call signatures. Furthermore, TypeScript may perform ***type argument inference*** to automatically determine type arguments in generic function calls. +If *func*'s apparent type (section [3.8.1](#3.8.1)) is a function type, the call is a ***typed function call***. TypeScript employs ***overload resolution*** in typed function calls in order to support functions with multiple call signatures. Furthermore, TypeScript may perform ***type argument inference*** to automatically determine type arguments in generic function calls. ### 4.12.1 Overload Resolution -The purpose of overload resolution in a function call is to ensure that at least one signature is applicable, to provide contextual types for the arguments, and to determine the result type of the function call, which could differ between the multiple applicable signatures. Overload resolution has no impact on the run-time behavior of a function call. Since JavaScript doesn’t support function overloading, all that matters at run-time is the name of the function. +The purpose of overload resolution in a function call is to ensure that at least one signature is applicable, to provide contextual types for the arguments, and to determine the result type of the function call, which could differ between the multiple applicable signatures. Overload resolution has no impact on the run-time behavior of a function call. Since JavaScript doesn't support function overloading, all that matters at run-time is the name of the function. The compile-time processing of a typed function call consists of the following steps: @@ -2383,8 +2489,7 @@ The compile-time processing of a typed function call consists of the following s * the function call has no type arguments, and * the signature is applicable with respect to the argument list of the function call. * A generic signature is a candidate in a function call without type arguments when - * type inference (section [4.12.2](#4.12.2)) succeeds in inferring a list of type arguments, - * the inferred type arguments satisfy their constraints, and + * type inference (section [4.12.2](#4.12.2)) succeeds for each type parameter, * once the inferred type arguments are substituted for their associated type parameters, the signature is applicable with respect to the argument list of the function call. * A generic signature is a candidate in a function call with type arguments when * The signature has the same number of type parameters as were supplied in the type argument list, @@ -2402,12 +2507,13 @@ A signature is said to be an ***applicable signature*** with respect to an argum ### 4.12.2 Type Argument Inference -Given a signature < *T1* , *T2* , … , *Tn* > ( *p1* : *P1* , *p2* : *P2* , … , *pm* : *Pm* ), where each parameter type *P* references zero or more of the type parameters *T*, and an argument list ( *e1* , *e2* , … , *em* ), the task of type argument inference is to find a set of type arguments *A1*…*An* to substitute for *T1*…*Tn* such that the argument list becomes an applicable signature. +Given a signature < *T1* , *T2* , … , *Tn* > ( *p1* : *P1* , *p2* : *P2* , … , *pm* : *Pm* ), where each parameter type *P* references zero or more of the type parameters *T*, and an argument list ( *e1* , *e2* , … , *em* ), the task of type argument inference is to find a set of type arguments *A1*…*An* to substitute for *T1*…*Tn* such that the argument list becomes an applicable signature. -The inferred type argument for a particular type parameter is determined from a set of candidate types. Given a type parameter *T*, let *C* denote the widened form (section [3.9](#3.9)) of the best common type (section [3.10](#3.10)) of the set of candidate types *T*. Then, +Type argument inference produces a set of candidate types for each type parameter. Given a type parameter *T* and set of candidate types, the actual inferred type argument is determined as follows: -* If *C* satisfies *T*’s constraint, the inferred type argument for *T* is *C*. -* Otherwise, the inferred type argument for *T* is *T*’s constraint. +* If the set of candidate argument types is empty, the inferred type argument for *T* is *T*'s constraint. +* Otherwise, if at least one of the candidate types is a supertype of all of the other candidate types, let *C* denote the first such candidate type. If *C* satisfies *T*'s constraint, the inferred type argument for *T* is *C*. Otherwise, the inferred type argument for *T* is *T*'s constraint. +* Otherwise, if no candidate type is a supertype of all of the other candidate types, type inference has fails and no type argument is inferred for *T*. In order to compute candidate types, the argument list is processed as follows: @@ -2417,27 +2523,27 @@ In order to compute candidate types, the argument list is processed as follows: The process of inferentially typing an expression *e* by a type *T* is the same as that of contextually typing *e* by *T*, with the following exceptions: * Where expressions contained within *e* would be contextually typed, they are instead inferentially typed. -* Where a contextual type would be included in a best common type determination (such as when inferentially typing an object or array literal), an inferential type is not. * When a function expression is inferentially typed (section [4.9.3](#4.9.3)) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, the corresponding inferred type arguments to become ***fixed*** and no further candidate inferences are made for them. -* If *e* is an expression of a function type that contains exactly one generic call signature and no other members, and *T* is a function type with exactly one non-generic call signature and no other members, then any inferences made for type parameters referenced by the parameters of *T*’s call signature are ***fixed***, and *e*’s type is changed to a function type with *e*’s call signature instantiated in the context of *T*’s call signature (section [3.8.5](#3.8.5)). +* If *e* is an expression of a function type that contains exactly one generic call signature and no other members, and *T* is a function type with exactly one non-generic call signature and no other members, then any inferences made for type parameters referenced by the parameters of *T*'s call signature are ***fixed***, and *e*'s type is changed to a function type with *e*'s call signature instantiated in the context of *T*'s call signature (section [3.8.5](#3.8.5)). -In the example +An example: ```TypeScript function choose(x: T, y: T): T { return Math.random() < 0.5 ? x : y; } -var x = choose("Five", 5); +var x = choose(10, 20); // Ok, x of type number +var y = choose("Five", 5); // Error ``` -inferences for ‘T’ in the call to ‘choose’ are made as follows: For the first parameter, an inference is made from type ‘string’ to ‘T’. For the second parameter, an inference is made from type ‘number’ to ‘T’. Since the best common type (section [3.10](#3.10)) of ‘string’ and ‘number’ is the empty object type, the call to ‘choose’ is equivalent to +In the first call to 'choose', two inferences are made from 'number' to 'T', one for each parameter. Thus, 'number' is inferred for 'T' and the call is equivalent to ```TypeScript -var x = choose<{}>("Five", 5); +var x = choose(10, 20); ``` -and the resulting type of ‘x’ is therefore the empty object type. Note that had both arguments been of type ‘string’ or ‘number’, ‘x’ would have been of that type. +In the second call to 'choose', an inference is made from type 'string' to 'T' for the first parameter and an inference is made from type 'number' to 'T' for the second parameter. Since neither 'string' nor 'number' is a supertype of the other, type inference fails. That in turn means there are no applicable signatures and the function call is an error. In the example @@ -2452,13 +2558,13 @@ var names = ["Peter", "Paul", "Mary"]; var lengths = map(names, s => s.length); ``` -inferences for ‘T’ and ‘U’ in the call to ‘map’ are made as follows: For the first parameter, inferences are made from the type ‘string[]’ (the type of ‘names’) to the type ‘T[]’, inferring ‘string’ for ‘T’. For the second parameter, inferential typing of the arrow expression ‘s => s.length’ causes ‘T’ to become fixed such that the inferred type ‘string’ can be used for the parameter ‘s’. The return type of the arrow expression can then be determined, and inferences are made from the type ‘(s: string) => number’ to the type ‘(x: T) => U’, inferring ‘number’ for ‘U’. Thus the call to ‘map’ is equivalent to +inferences for 'T' and 'U' in the call to 'map' are made as follows: For the first parameter, inferences are made from the type 'string[]' (the type of 'names') to the type 'T[]', inferring 'string' for 'T'. For the second parameter, inferential typing of the arrow expression 's => s.length' causes 'T' to become fixed such that the inferred type 'string' can be used for the parameter 's'. The return type of the arrow expression can then be determined, and inferences are made from the type '(s: string) => number' to the type '(x: T) => U', inferring 'number' for 'U'. Thus the call to 'map' is equivalent to ```TypeScript var lengths = map(names, s => s.length); ``` -and the resulting type of ‘lengths’ is therefore ‘number[]’. +and the resulting type of 'lengths' is therefore 'number[]'. In the example @@ -2475,14 +2581,14 @@ var ages = [7, 9, 12]; var pairs = zip(names, ages, s => n => ({ name: s, age: n })); ``` -inferences for ‘S’, ‘T’ and ‘U’ in the call to ‘zip’ are made as follows: Using the first two parameters, inferences of ‘string’ for ‘S’ and ‘number’ for ‘T’ are made. For the third parameter, inferential typing of the outer arrow expression causes ‘S’ to become fixed such that the inferred type ‘string’ can be used for the parameter ‘s’. When a function expression is inferentially typed, its return expression(s) are also inferentially typed. Thus, the inner arrow function is inferentially typed, causing ‘T’ to become fixed such that the inferred type ‘number’ can be used for the parameter ‘n’. The return type of the inner arrow function can then be determined, which in turn determines the return type of the function returned from the outer arrow function, and inferences are made from the type ‘(s: string) => (n: number) => { name: string; age: number }’ to the type ‘(x: S) => (y: T) => R’, inferring ‘{ name: string; age: number }’ for ‘R’. Thus the call to ‘zip’ is equivalent to +inferences for 'S', 'T' and 'U' in the call to 'zip' are made as follows: Using the first two parameters, inferences of 'string' for 'S' and 'number' for 'T' are made. For the third parameter, inferential typing of the outer arrow expression causes 'S' to become fixed such that the inferred type 'string' can be used for the parameter 's'. When a function expression is inferentially typed, its return expression(s) are also inferentially typed. Thus, the inner arrow function is inferentially typed, causing 'T' to become fixed such that the inferred type 'number' can be used for the parameter 'n'. The return type of the inner arrow function can then be determined, which in turn determines the return type of the function returned from the outer arrow function, and inferences are made from the type '(s: string) => (n: number) => { name: string; age: number }' to the type '(x: S) => (y: T) => R', inferring '{ name: string; age: number }' for 'R'. Thus the call to 'zip' is equivalent to ```TypeScript var pairs = zip( names, ages, s => n => ({ name: s, age: n })); ``` -and the resulting type of ‘pairs’ is therefore ‘{ name: string; age: number }[]’. +and the resulting type of 'pairs' is therefore '{ name: string; age: number }[]'. ### 4.12.3 Grammar Ambiguities @@ -2492,32 +2598,32 @@ The inclusion of type arguments in the *Arguments* production (section [4.12](#4 f(g(7)); ``` -could be interpreted as a call to ‘f’ with two arguments, ‘g < A’ and ‘B > (7)’. Alternatively, it could be interpreted as a call to ‘f’ with one argument, which is a call to a generic function ‘g’ with two type arguments and one regular argument. +could be interpreted as a call to 'f' with two arguments, 'g < A' and 'B > (7)'. Alternatively, it could be interpreted as a call to 'f' with one argument, which is a call to a generic function 'g' with two type arguments and one regular argument. -The grammar ambiguity is resolved as follows: In a context where one possible interpretation of a sequence of tokens is an *Arguments* production, if the initial sequence of tokens forms a syntactically correct *TypeArguments* production and is followed by a ‘`(`‘ token, then the sequence of tokens is processed an *Arguments* production, and any other possible interpretation is discarded. Otherwise, the sequence of tokens is not considered an *Arguments* production. +The grammar ambiguity is resolved as follows: In a context where one possible interpretation of a sequence of tokens is an *Arguments* production, if the initial sequence of tokens forms a syntactically correct *TypeArguments* production and is followed by a '`(`' token, then the sequence of tokens is processed an *Arguments* production, and any other possible interpretation is discarded. Otherwise, the sequence of tokens is not considered an *Arguments* production. -This rule means that the call to ‘f’ above is interpreted as a call with one argument, which is a call to a generic function ‘g’ with two type arguments and one regular argument. However, the statements +This rule means that the call to 'f' above is interpreted as a call with one argument, which is a call to a generic function 'g' with two type arguments and one regular argument. However, the statements ```TypeScript f(g < A, B > 7); f(g < A, B > +(7)); ``` -are both interpreted as calls to ‘f’ with two arguments. +are both interpreted as calls to 'f' with two arguments. ## 4.13 Type Assertions TypeScript extends the JavaScript expression grammar with the ability to assert a type for an expression:   *UnaryExpression:* *( Modified )* -   … +   …    `<` *Type* `>` *UnaryExpression* A type assertion expression consists of a type enclosed in `<` and `>` followed by a unary expression. Type assertion expressions are purely a compile-time construct. Type assertions are *not* checked at run-time and have no impact on the emitted JavaScript (and therefore no run-time cost). The type and the enclosing `<` and `>` are simply removed from the generated code. In a type assertion expression of the form `<` *T* `>` *e*, *e* is contextually typed (section [4.19](#4.19)) by *T* and the resulting type of* e* is required to be assignable to *T*, or *T* is required to be assignable to the widened form of the resulting type of *e*, or otherwise a compile-time error occurs. The type of the result is *T*. -Type assertions check for assignment compatibility in both directions. Thus, type assertions allow type conversions that *might* be correct, but aren’t *known* to be correct. In the example +Type assertions check for assignment compatibility in both directions. Thus, type assertions allow type conversions that *might* be correct, but aren't *known* to be correct. In the example ```TypeScript class Shape { ... } @@ -2532,7 +2638,7 @@ function createShape(kind: string): Shape { var circle = createShape("circle"); ``` -the type annotations indicate that the ‘createShape’ function *might* return a ‘Circle’ (because ‘Circle’ is a subtype of ‘Shape’), but isn’t *known* to do so (because its return type is ‘Shape’). Therefore, a type assertion is needed to treat the result as a ‘Circle’. +the type annotations indicate that the 'createShape' function *might* return a 'Circle' (because 'Circle' is a subtype of 'Shape'), but isn't *known* to do so (because its return type is 'Shape'). Therefore, a type assertion is needed to treat the result as a 'Circle'. As mentioned above, type assertions are not checked at run-time and it is up to the programmer to guard against errors, for example using the `instanceof` operator: @@ -2552,7 +2658,7 @@ The subsections that follow specify the compile-time processing rules of the una These operators, in prefix or postfix form, require their operand to be of type Any, the Number primitive type, or an enum type, and classified as a reference (section [4.1](#4.1)). They produce a result of the Number primitive type. -### 4.14.2 The +, –, and ~ operators +### 4.14.2 The +, –, and ~ operators These operators permit their operand to be of any type and produce a result of the Number primitive type. @@ -2564,7 +2670,7 @@ function getValue() { ... } var n = +getValue(); ``` -The example above converts the result of ‘getValue()’ to a number if it isn’t a number already. The type inferred for ‘n’ is the Number primitive type regardless of the return type of ‘getValue’. +The example above converts the result of 'getValue()' to a number if it isn't a number already. The type inferred for 'n' is the Number primitive type regardless of the return type of 'getValue'. ### 4.14.3 The ! operator @@ -2578,19 +2684,19 @@ function getValue() { ... } var b = !!getValue(); ``` -The example above converts the result of ‘getValue()’ to a Boolean if it isn’t a Boolean already. The type inferred for ‘b’ is the Boolean primitive type regardless of the return type of ‘getValue’. +The example above converts the result of 'getValue()' to a Boolean if it isn't a Boolean already. The type inferred for 'b' is the Boolean primitive type regardless of the return type of 'getValue'. ### 4.14.4 The delete Operator -The ‘delete’ operator takes an operand of any type and produces a result of the Boolean primitive type. +The 'delete' operator takes an operand of any type and produces a result of the Boolean primitive type. ### 4.14.5 The void Operator -The ‘void’ operator takes an operand of any type and produces the value ‘undefined’. The type of the result is the Undefined type ([3.2.6](#3.2.6)). +The 'void' operator takes an operand of any type and produces the value 'undefined'. The type of the result is the Undefined type ([3.2.6](#3.2.6)). ### 4.14.6 The typeof Operator -The ‘typeof’ operator takes an operand of any type and produces a value of the String primitive type. In positions where a type is expected, ‘typeof’ can also be used in a type query (section [3.6.8](#3.6.8)) to produce the type of an expression. +The 'typeof' operator takes an operand of any type and produces a value of the String primitive type. In positions where a type is expected, 'typeof' can also be used in a type query (section [3.6.9](#3.6.9)) to produce the type of an expression. ```TypeScript var x = 5; @@ -2598,13 +2704,13 @@ var y = typeof x; // Use in an expression var z: typeof x; // Use in a type query ``` -In the example above, ‘x’ is of type ‘number’, ‘y’ is of type ‘string’ because when used in an expression, ‘typeof’ produces a value of type string (in this case the string “number”), and ‘z’ is of type ‘number’ because when used in a type query, ‘typeof’ obtains the type of an expression. +In the example above, 'x' is of type 'number', 'y' is of type 'string' because when used in an expression, 'typeof' produces a value of type string (in this case the string "number"), and 'z' is of type 'number' because when used in a type query, 'typeof' obtains the type of an expression. ## 4.15 Binary Operators The subsections that follow specify the compile-time processing rules of the binary operators. In general, if the operands of a binary operator do not meet the stated requirements, a compile-time error occurs and the result of the operation defaults to type any in further processing. Tables that summarize the compile-time processing rules for operands of the Any type, the Boolean, Number, and String primitive types, and all object types and type parameters (the Object column in the tables) are provided. -### 4.15.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators +### 4.15.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators These operators require their operands to be of type Any, the Number primitive type, or an enum type. Operands of an enum type are treated as having the primitive type Number. If one operand is the `null` or `undefined` value, it is treated as having the type of the other operand. The result is always of the Number primitive type. @@ -2636,7 +2742,7 @@ function getValue() { ... } var s = getValue() + ""; ``` -The example above converts the result of ‘getValue()’ to a string if it isn’t a string already. The type inferred for ‘s’ is the String primitive type regardless of the return type of ‘getValue’. +The example above converts the result of 'getValue()' to a string if it isn't a string already. The type inferred for 's' is the String primitive type regardless of the return type of 'getValue'. ### 4.15.3 The <, >, <=, >=, ==, !=, ===, and !== operators @@ -2652,9 +2758,9 @@ These operators require one operand type to be identical to or a subtype of the ### 4.15.4 The instanceof operator -The `instanceof` operator requires the left operand to be of type Any, an object type, or a type parameter type, and the right operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the Boolean primitive type. +The `instanceof` operator requires the left operand to be of type Any, an object type, or a type parameter type, and the right operand to be of type Any or a subtype of the 'Function' interface type. The result is always of the Boolean primitive type. -Note that object types containing one or more call or construct signatures are automatically subtypes of the ‘Function’ interface type, as described in section [3.3](#3.3). +Note that object types containing one or more call or construct signatures are automatically subtypes of the 'Function' interface type, as described in section [3.3](#3.3). ### 4.15.5 The in operator @@ -2676,9 +2782,9 @@ The && operator permits the operands to be of any type and produces a result of The || operator permits the operands to be of any type. -If the || expression is contextually typed (section [4.19](#4.19)), the operands are contextually typed by the same type and the result is of the best common type (section [3.10](#3.10)) of the contextual type and the two operand types. +If the || expression is contextually typed (section [4.19](#4.19)), the operands are contextually typed by the same type. Otherwise, the left operand is not contextually typed and the right operand is contextually typed by the type of the left operand. -If the || expression is not contextually typed, the right operand is contextually typed by the type of the left operand and the result is of the best common type of the two operand types. +The type of the result is the union type of the two operand types. ||Any|Boolean|Number|String|Object| |:---:|:---:|:---:|:---:|:---:|:---:| @@ -2698,9 +2804,9 @@ test ? expr1 : expr2 the *test* expression may be of any type. -If the conditional expression is contextually typed (section [4.19](#4.19)), *expr1* and *expr2* are contextually typed by the same type and the result is of the best common type (section [3.10](#3.10)) of the contextual type and the types of *expr1* and *expr2*. An error occurs if the best common type is not identical to at least one of the three candidate types. +If the conditional expression is contextually typed (section [4.19](#4.19)), *expr1* and *expr2* are contextually typed by the same type. Otherwise, *expr1* and *expr2* are not contextually typed. -If the conditional expression is not contextually typed, the result is of the best common type of the types of *Expr1* and *Expr2*. An error occurs if the best common type is not identical to at least one of the two candidate types. +The type of the result is the union type of the types of *expr1* and *expr2*. ## 4.17 Assignment Operators @@ -2744,10 +2850,10 @@ the assignment f = function(s) { return s.toLowerCase(); } ``` -infers the type of the ‘s’ parameter to be the String primitive type even though there is no type annotation to that effect. The function expression is said to be ***contextually typed*** by the variable to which it is being assigned. Contextual typing occurs in the following situations: +infers the type of the 's' parameter to be the String primitive type even though there is no type annotation to that effect. The function expression is said to be ***contextually typed*** by the variable to which it is being assigned. Contextual typing occurs in the following situations: * In variable, parameter, and member declarations with a type annotation and an initializer, the initializer expression is contextually typed by the type of the variable, parameter, or property. -* In return statements, if the containing function includes a return type annotation, return expressions are contextually typed by that return type. Otherwise, if the containing function is contextually typed by a type *T*, return expressions are contextually typed by *T*’s return type. +* In return statements, if the containing function includes a return type annotation, return expressions are contextually typed by that return type. Otherwise, if the containing function is contextually typed by a type *T*, return expressions are contextually typed by *T*'s return type. * In typed function calls, argument expressions are contextually typed by their parameter types. * In type assertions, the expression is contextually typed by the indicated type. * In || operator expressions without a contextual type, the right hand expression is contextually typed by the type of the left hand expression. @@ -2761,24 +2867,24 @@ Contextual typing of an expression *e* by a type *T* proceeds as follows: * If *e* is an *ObjectLiteral* and *T* is an object type, *e* is processed with the contextual type *T*, as described in section [4.5](#4.5). * If *e* is an *ArrayLiteral* and *T* is an object type with a numeric index signature, *e* is processed with the contextual type *T*, as described in section [4.6](#4.6). -* If *e* is a *FunctionExpression* or *ArrowFunctionExpression* with no type parameters and no parameter type annotations, *T* is a function type with exactly one call signature and *T*’s call signature is non-generic, then any inferences made for type parameters referenced by the parameters of *T*’s call signature are fixed (section [4.12.2](#4.12.2)) and *e* is processed with the contextual type *T*, as described in section [4.9.3](#4.9.3). +* If *e* is a *FunctionExpression* or *ArrowFunctionExpression* with no type parameters and no parameter type annotations, *T* is a function type with exactly one call signature and *T*'s call signature is non-generic, then any inferences made for type parameters referenced by the parameters of *T*'s call signature are fixed (section [4.12.2](#4.12.2)) and *e* is processed with the contextual type *T*, as described in section [4.9.3](#4.9.3). * If *e* is a || operator expression and *T* is an object type, *e* is processed with the contextual type *T*, as described in section [4.15.7](#4.15.7). * If *e* is a conditional operator expression and *T* is an object type, *e* is processed with the contextual type *T*, as described in section [4.16](#4.16). * Otherwise, *e* is processed without a contextual type. -The rules above require expressions be of the exact syntactic forms specified in order to be processed as contextually typed constructs. For example, given the declaration of the variable ‘f’ above, the assignment +The rules above require expressions be of the exact syntactic forms specified in order to be processed as contextually typed constructs. For example, given the declaration of the variable 'f' above, the assignment ```TypeScript f = s => s.toLowerCase(); ``` -causes the function expression to be contextually typed, inferring the String primitive type for ‘s’. However, simply enclosing the construct in parentheses +causes the function expression to be contextually typed, inferring the String primitive type for 's'. However, simply enclosing the construct in parentheses ```TypeScript f = (s => s.toLowerCase()); ``` -causes the function expression to be processed without a contextual type, now inferring ‘s’ and the result of the function to be of type Any as no type annotations are present. +causes the function expression to be processed without a contextual type, now inferring 's' and the result of the function to be of type Any as no type annotations are present. In the following example @@ -2802,7 +2908,113 @@ setEventHandlers({ }); ``` -the object literal passed to ‘setEventHandlers’ is contextually typed to the ‘EventHandlers’ type. This causes the two property assignments to be contextually typed to the unnamed function type ‘(event: EventObject) => void’, which in turn causes the ‘e’ parameters in the arrow function expressions to automatically be typed as ‘EventObject’. +the object literal passed to 'setEventHandlers' is contextually typed to the 'EventHandlers' type. This causes the two property assignments to be contextually typed to the unnamed function type '(event: EventObject) => void', which in turn causes the 'e' parameters in the arrow function expressions to automatically be typed as 'EventObject'. + +## 4.20 Type Guards + +Type guards are particular expression patterns involving the 'typeof' and 'instanceof' operators that cause the types of variables or parameters to be ***narrowed*** to more specific types. For example, in the code below, knowledge of the static type of 'x' in combination with a 'typeof' check makes it safe to narrow the type of 'x' to string in the first branch of the 'if' statement and number in the second branch of the 'if' statement. + +```TypeScript +function foo(x: number | string) { + if (typeof x === "string") { + return x.length; // x has type string here + } + else { + return x + 1; // x has type number here + } +} +``` + +The type of a variable or parameter is narrowed in the following situations: + +* In the true branch statement of an 'if' statement, the type of a variable or parameter is *narrowed* by any type guard in the 'if' condition *when true*, provided the true branch statement contains no assignments to the variable or parameter. +* In the false branch statement of an 'if' statement, the type of a variable or parameter is *narrowed* by any type guard in the 'if' condition *when false*, provided the false branch statement contains no assignments to the variable or parameter. +* In the true expression of a conditional expression, the type of a variable or parameter is *narrowed* by any type guard in the condition *when true*, provided the true expression contains no assignments to the variable or parameter. +* In the false expression of a conditional expression, the type of a variable or parameter is *narrowed* by any type guard in the condition *when false*, provided the false expression contains no assignments to the variable or parameter. +* In the right operand of a && operation, the type of a variable or parameter is *narrowed* by any type guard in the left operand *when true*, provided the right operand contains no assignments to the variable or parameter. +* In the right operand of a || operation, the type of a variable or parameter is *narrowed* by any type guard in the left operand *when false*, provided the right operand contains no assignments to the variable or parameter. + +A type guard is simply an expression that follows a particular pattern. The process of narrowing the type of a variable *x* by a type guard *when true* or *when false* depends on the type guard as follows: + +* A type guard of the form `x instanceof C`, where *C* is of a subtype of the global type 'Function' and *C* has a property named 'prototype' + * *when true*, narrows the type of *x* to the type of the 'prototype' property in *C* provided it is a subtype of the type of *x*, or + * *when false*, has no effect on the type of *x*. +* A type guard of the form `typeof x === s`, where *s* is a string literal with the value 'string', 'number', or 'boolean', + * *when true*, narrows the type of *x* to the given primitive type, or + * *when false*, removes the primitive type from the type of *x*. +* A type guard of the form `typeof x === s`, where *s* is a string literal with any value but 'string', 'number', or 'boolean', + * *when true*, removes the primitive types string, number, and boolean from the type of *x*, or + * *when false*, has no effect on the type of *x*. +* A type guard of the form `typeof x !== s`, where *s* is a string literal, + * *when true*, narrows the type of x by `typeof x === s` *when false*, or + * *when false*, narrows the type of x by `typeof x === s` *when true*. +* A type guard of the form `!expr` + * *when true*, narrows the type of *x* by *expr* *when false*, or + * *when false*, narrows the type of *x* by *expr* *when true*. +* A type guard of the form `expr1 && expr2` + * *when true*, narrows the type of *x* by *expr1* *when true* and then by *expr2* *when true*, or + * *when false*, narrows the type of *x* to *T1* | *T2*, where *T1* is the type of *x* narrowed by *expr1* *when false*, and *T2* is the type of *x* narrowed by *expr1* *when true* and then by *expr2* *when false*. +* A type guard of the form `expr1 || expr2` + * *when true*, narrows the type of *x* to *T1* | *T2*, where *T1* is the type of *x* narrowed by *expr1* *when true*, and *T2* is the type of *x* narrowed by *expr1* *when false* and then by *expr2* *when true*, or + * *when false*, narrows the type of *x* by *expr1* *when false* and then by *expr2* *when false*. +* A type guard of any other form has no effect on the type of *x*. + +A primitive type *P* is removed from a type *T* as follows: + +* If *T* is a union type *P* | *T1* | *T2* | … | *Tn*, the result is the type *T1* | *T2* | … | *Tn*. +* Otherwise, the result is *T*. + +Note that type guards affect types of variables and parameters only and have no effect on members of objects such as properties. Also note that it is possible to defeat a type guard by calling a function that changes the type of the guarded variable. + +In the example + +```TypeScript +function isLongString(obj: any) { + return typeof obj === "string" && obj.length > 100; +} +``` + +the 'obj' parameter has type string in the right operand of the && operator. + +In the example + +```TypeScript +function f(x: string | number | boolean) { + if (typeof x === "string" || typeof x === "number") { + var y = x; // Type of y is string | number + } + else { + var z = x; // Type of z is boolean + } +} +``` + +the type of 'x' is string | number | boolean in left operand of the || operator, number | boolean in the right operand of the || operator, string | number in the first branch of the 'if' statement, and boolean in the second branch of the 'if' statement. + +In the example + +```TypeScript +function processData(data: string | { (): string }) { + var d = typeof data !== "string" ? data() : data; + // Process string in d +} +``` + +the inferred type of 'd' is string. + +In the example + +```TypeScript +class NamedItem { + name: string; +} + +function getName(obj: any) { + return obj instanceof NamedItem ? obj.name : "unknown"; +} +``` + +the inferred type of the 'getName' function is string.
@@ -2826,7 +3038,7 @@ Variable statements are extended to include optional type annotations. A variable declaration introduces a variable with the given name in the containing declaration space. The type associated with a variable is determined as follows: * If the declaration includes a type annotation, the stated type becomes the type of the variable. If an initializer is present, the initializer expression is contextually typed (section [4.19](#4.19)) by the stated type and must be assignable to the stated type, or otherwise a compile-time error occurs. -* If the declaration includes an initializer but no type annotation, and if the initializer doesn’t directly or indirectly reference the variable, the widened type (section [3.9](#3.9)) of the initializer expression becomes the type of the variable. If the initializer directly or indirectly references the variable, the type of the variable becomes the Any type. +* If the declaration includes an initializer but no type annotation, and if the initializer doesn't directly or indirectly reference the variable, the widened type (section [3.9](#3.9)) of the initializer expression becomes the type of the variable. If the initializer directly or indirectly references the variable, the type of the variable becomes the Any type. * If the declaration includes neither a type annotation nor an initializer, the type of the variable becomes the Any type. Multiple declarations for the same variable name in the same declaration space are permitted, provided that each declaration associates the same type with the variable. @@ -2841,7 +3053,7 @@ var d = { x: 1, y: "hello" }; // { x: number; y: string; } var e: any = "test"; // any ``` -The following is permitted because all declarations of the single variable ‘x’ associate the same type (Number) with ‘x’. +The following is permitted because all declarations of the single variable 'x' associate the same type (Number) with 'x'. ```TypeScript var x = 1; @@ -2851,7 +3063,7 @@ if (x == 1) { } ``` -In the following example, all five variables are of the same type, ‘{ x: number; y: number; }’. +In the following example, all five variables are of the same type, '{ x: number; y: number; }'. ```TypeScript interface Point { x: number; y: number; } @@ -2865,15 +3077,15 @@ var e = <{ x: number; y: number; }> { x: 0, y: undefined }; ##
5.2 If, Do, and While Statements -Expressions controlling ‘if’, ‘do’, and ‘while’ statements can be of any type (and not just type Boolean). +Expressions controlling 'if', 'do', and 'while' statements can be of any type (and not just type Boolean). ## 5.3 For Statements -Variable declarations in ‘for’ statements are extended in the same manner as variable declarations in variable statements (section [5.1](#5.1)). +Variable declarations in 'for' statements are extended in the same manner as variable declarations in variable statements (section [5.1](#5.1)). ## 5.4 For-In Statements -In a ‘for-in’ statement of the form +In a 'for-in' statement of the form ```TypeScript for (v in expr) statement @@ -2881,7 +3093,7 @@ for (v in expr) statement *v* must be an expression classified as a reference of type Any or the String primitive type, and *expr* must be an expression of type Any, an object type, or a type parameter type. -In a ‘for-in’ statement of the form +In a 'for-in' statement of the form ```TypeScript for (var v in expr) statement @@ -2891,21 +3103,21 @@ for (var v in expr) statement ## 5.5 Continue Statements -A ‘continue’ statement is required to be nested, directly or indirectly (but not crossing function boundaries), within an iteration (‘do’, ‘while’, ‘for’, or ‘for-in’) statement. When a ‘continue’ statement includes a target label, that target label must appear in the label set of an enclosing (but not crossing function boundaries) iteration statement. +A 'continue' statement is required to be nested, directly or indirectly (but not crossing function boundaries), within an iteration ('do', 'while', 'for', or 'for-in') statement. When a 'continue' statement includes a target label, that target label must appear in the label set of an enclosing (but not crossing function boundaries) iteration statement. ## 5.6 Break Statements -A ‘break’ statement is required to be nested, directly or indirectly (but not crossing function boundaries), within an iteration (‘do’, ‘while’, ‘for’, or ‘for-in’) or ‘switch’ statement. When a ‘break’ statement includes a target label, that target label must appear in the label set of an enclosing (but not crossing function boundaries) statement. +A 'break' statement is required to be nested, directly or indirectly (but not crossing function boundaries), within an iteration ('do', 'while', 'for', or 'for-in') or 'switch' statement. When a 'break' statement includes a target label, that target label must appear in the label set of an enclosing (but not crossing function boundaries) statement. ## 5.7 Return Statements -It is an error for a ‘return’ statement to occur outside a function body. Specifically, ‘return’ statements are not permitted at the global level or in module bodies. +It is an error for a 'return' statement to occur outside a function body. Specifically, 'return' statements are not permitted at the global level or in module bodies. -A ‘return’ statement without an expression returns the value ‘undefined’ and is permitted in the body of any function, regardless of the return type of the function. +A 'return' statement without an expression returns the value 'undefined' and is permitted in the body of any function, regardless of the return type of the function. -When a ‘return’ statement includes an expression, if the containing function includes a return type annotation, the return expression is contextually typed (section [4.19](#4.19)) by that return type and must be of a type that is assignable to the return type. Otherwise, if the containing function is contextually typed by a type *T*, *Expr* is contextually typed by *T*’s return type. +When a 'return' statement includes an expression, if the containing function includes a return type annotation, the return expression is contextually typed (section [4.19](#4.19)) by that return type and must be of a type that is assignable to the return type. Otherwise, if the containing function is contextually typed by a type *T*, *Expr* is contextually typed by *T*'s return type. -In a function implementation without a return type annotation, the return type is inferred from the ‘return’ statements in the function body, as described in section [6.3](#6.3). +In a function implementation without a return type annotation, the return type is inferred from the 'return' statements in the function body, as described in section [6.3](#6.3). In the example @@ -2915,23 +3127,23 @@ function f(): (x: string) => number { } ``` -the arrow expression in the ‘return’ statement is contextually typed by the return type of ‘f’, thus giving type ‘string’ to ‘s’. +the arrow expression in the 'return' statement is contextually typed by the return type of 'f', thus giving type 'string' to 's'. ## 5.8 With Statements -Use of the ‘with’ statement in TypeScript is an error, as is the case in ECMAScript 5’s strict mode. Furthermore, within the body of a ‘with’ statement, TypeScript considers every identifier occurring in an expression (section [4.3](#4.3)) to be of the Any type regardless of its declared type. Because the ‘with’ statement puts a statically unknown set of identifiers in scope in front of those that are statically known, it is not possible to meaningfully assign a static type to any identifier. +Use of the 'with' statement in TypeScript is an error, as is the case in ECMAScript 5's strict mode. Furthermore, within the body of a 'with' statement, TypeScript considers every identifier occurring in an expression (section [4.3](#4.3)) to be of the Any type regardless of its declared type. Because the 'with' statement puts a statically unknown set of identifiers in scope in front of those that are statically known, it is not possible to meaningfully assign a static type to any identifier. ## 5.9 Switch Statements -In a ‘switch’ statement, each ‘case’ expression must be of a type that is assignable to or from (section [3.8.4](#3.8.4)) the type of the ‘switch’ expression. +In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from (section [3.8.4](#3.8.4)) the type of the 'switch' expression. ## 5.10 Throw Statements -The expression specified in a ‘throw’ statement can be of any type. +The expression specified in a 'throw' statement can be of any type. ## 5.11 Try Statements -The variable introduced by a ‘catch’ clause of a ‘try’ statement is always of type Any. It is not possible to include a type annotation in a ‘catch’ clause. +The variable introduced by a 'catch' clause of a 'try' statement is always of type Any. It is not possible to include a type annotation in a 'catch' clause.
@@ -2960,7 +3172,7 @@ A function declaration introduces a function with the given name in the containi ##
6.2 Function Overloads -Function overloads allow a more accurate specification of the patterns of invocation supported by a function than is possible with a single signature. The compile-time processing of a call to an overloaded function chooses the best candidate overload for the particular arguments and the return type of that overload becomes the result type the function call expression. Thus, using overloads it is possible to statically describe the manner in which a function’s return type varies based on its arguments. Overload resolution in function calls is described further in section [4.12](#4.12). +Function overloads allow a more accurate specification of the patterns of invocation supported by a function than is possible with a single signature. The compile-time processing of a call to an overloaded function chooses the best candidate overload for the particular arguments and the return type of that overload becomes the result type the function call expression. Thus, using overloads it is possible to statically describe the manner in which a function's return type varies based on its arguments. Overload resolution in function calls is described further in section [4.12](#4.12). Function overloads are purely a compile-time construct. They have no impact on the emitted JavaScript and thus no run-time cost. @@ -2982,7 +3194,7 @@ function attr(nameOrMap: any, value?: string): any { } ``` -Note that each overload and the final implementation specify the same identifier. The type of the local variable ‘attr’ introduced by this declaration is +Note that each overload and the final implementation specify the same identifier. The type of the local variable 'attr' introduced by this declaration is ```TypeScript var attr: { @@ -2998,9 +3210,10 @@ Note that the signature of the actual function implementation is not included in A function implementation without a return type annotation is said to be an ***implicitly typed function***. The return type of an implicitly typed function *f* is inferred from its function body as follows: -* If there are no return statements with expressions in *f*’s function body, the inferred return type is Void. -* Otherwise, if *f*’s function body directly references *f* or references any implicitly typed functions that through this same analysis reference *f*, the inferred return type is Any. -* Otherwise, the inferred return type is the widened form (section [3.9](#3.9)) of the best common type (section [3.10](#3.10)) of the types of the return statement expression in the function body, ignoring return statements with no expressions. A compile-time error occurs if the best common type isn’t one of the return statement expression types (i.e. if the best common type is an empty type). +* If there are no return statements with expressions in *f*'s function body, the inferred return type is Void. +* Otherwise, if *f*'s function body directly references *f* or references any implicitly typed functions that through this same analysis reference *f*, the inferred return type is Any. +* Otherwise, if *f* is a contextually typed function expression (section [4.9.3](#4.9.3)), the inferred return type is the union type (section [3.3.4](#3.3.4)) of the types of the return statement expressions in the function body, ignoring return statements with no expressions. +* Otherwise, the inferred return type is the first of the types of the return statement expressions in the function body that is a supertype (section [3.8.3](#3.8.3)) of each of the others, ignoring return statements with no expressions. A compile-time error occurs if no return statement expression has a type that is a supertype of each of the others. In the example @@ -3015,11 +3228,11 @@ function g(x: number) { } ``` -the inferred return type for ‘f’ and ‘g’ is Any because the functions reference themselves through a cycle with no return type annotations. Adding an explicit return type ‘number’ to either breaks the cycle and causes the return type ‘number’ to be inferred for the other. +the inferred return type for 'f' and 'g' is Any because the functions reference themselves through a cycle with no return type annotations. Adding an explicit return type 'number' to either breaks the cycle and causes the return type 'number' to be inferred for the other. -An explicitly typed function whose return type isn’t the Void or the Any type must have at least one return statement somewhere in its body. An exception to this rule is if the function implementation consists of a single ‘throw’ statement. +An explicitly typed function whose return type isn't the Void or the Any type must have at least one return statement somewhere in its body. An exception to this rule is if the function implementation consists of a single 'throw' statement. -The type of ‘this’ in a function implementation is the Any type. +The type of 'this' in a function implementation is the Any type. In the signature of a function implementation, a parameter can be marked optional by following it with an initializer. When a parameter declaration includes both a type annotation and an initializer, the initializer expression is contextually typed (section [4.19](#4.19)) by the stated type and must be assignable to the stated type, or otherwise a compile-time error occurs. When a parameter declaration has no type annotation but includes an initializer, the type of the parameter is the widened form (section [3.9](#3.9)) of the type of the initializer expression. @@ -3052,11 +3265,11 @@ function f(a = x) { } ``` -the local variable ‘x’ is in scope in the parameter initializer (thus hiding the outer ‘x’), but it is an error to reference it because it will always be uninitialized at the time the parameter initializer is evaluated. +the local variable 'x' is in scope in the parameter initializer (thus hiding the outer 'x'), but it is an error to reference it because it will always be uninitialized at the time the parameter initializer is evaluated. ## 6.4 Generic Functions -A function implementation may include type parameters in its signature (section [3.7.2.1](#3.7.2.1)) and is then called a ***generic function***. Type parameters provide a mechanism for expressing relationships between parameter and return types in call operations. Type parameters have no run-time representation—they are purely a compile-time construct. +A function implementation may include type parameters in its signature (section [3.7.2.1](#3.7.2.1)) and is then called a ***generic function***. Type parameters provide a mechanism for expressing relationships between parameter and return types in call operations. Type parameters have no run-time representation—they are purely a compile-time construct. Type parameters declared in the signature of a function implementation are in scope in the signature and body of that function implementation. @@ -3074,7 +3287,7 @@ function compare(x: T, y: T): number { } ``` -Note that the ‘x’ and ‘y’ parameters are known to be subtypes of the constraint ‘Comparable’ and therefore have a ‘compareTo’ member. This is described further in section [3.4.1](#3.4.1). +Note that the 'x' and 'y' parameters are known to be subtypes of the constraint 'Comparable' and therefore have a 'compareTo' member. This is described further in section [3.4.1](#3.4.1). The type arguments of a call to a generic function may be explicitly specified in a call operation or may, when possible, be inferred (section [4.12.2](#4.12.2)) from the types of the regular arguments in the call. In the example @@ -3087,7 +3300,7 @@ class Person { } ``` -the type argument to ‘compare’ is automatically inferred to be the String type because the two arguments are strings. +the type argument to 'compare' is automatically inferred to be the String type because the two arguments are strings. ## 6.5 Code Generation @@ -3102,7 +3315,7 @@ function () { *FunctionName* is the name of the function (or nothing in the case of a function expression). -*FunctionParameters* is a comma separated list of the function’s parameter names. +*FunctionParameters* is a comma separated list of the function's parameter names. *DefaultValueAssignments* is a sequence of default property value assignments, one for each parameter with a default value, in the order they are declared, of the form @@ -3120,7 +3333,7 @@ where *Parameter* is the parameter name and *Default* is the default value expre Interfaces provide the ability to name and parameterize object types and to compose existing named object types into new ones. -Interfaces have no run-time representation—they are purely a compile-time construct. Interfaces are particularly useful for documenting and validating the required shape of properties, objects passed as parameters, and objects returned from functions. +Interfaces have no run-time representation—they are purely a compile-time construct. Interfaces are particularly useful for documenting and validating the required shape of properties, objects passed as parameters, and objects returned from functions. Because TypeScript has a structural type system, an interface type with a particular set of members is considered identical to, and can be substituted for, another interface type or object type literal with an identical set of members (see section [3.8.2](#3.8.2)). @@ -3149,7 +3362,7 @@ An interface may optionally have type parameters (section [3.4.1](#3.4.1)) that An interface can inherit from zero or more ***base types*** which are specified in the *InterfaceExtendsClause*. The base types must be type references to class or interface types. -An interface has the members specified in the *ObjectType* of its declaration and furthermore inherits all base type members that aren’t hidden by declarations in the interface: +An interface has the members specified in the *ObjectType* of its declaration and furthermore inherits all base type members that aren't hidden by declarations in the interface: * A property declaration hides a public base type property with the same name. * A string index signature declaration hides a base type string index signature. @@ -3179,7 +3392,7 @@ interface Shaker { } ``` -An interface that extends ‘Mover’ and ‘Shaker’ must declare a new ‘getStatus’ property as it would otherwise inherit two ‘getStatus’ properties with different types. The new ‘getStatus’ property must be declared such that the resulting ‘MoverShaker’ is a subtype of both ‘Mover’ and ‘Shaker’: +An interface that extends 'Mover' and 'Shaker' must declare a new 'getStatus' property as it would otherwise inherit two 'getStatus' properties with different types. The new 'getStatus' property must be declared such that the resulting 'MoverShaker' is a subtype of both 'Mover' and 'Shaker': ```TypeScript interface MoverShaker extends Mover, Shaker { @@ -3193,11 +3406,11 @@ Since function and constructor types are just object types containing call and c interface StringComparer { (a: string, b: string): number; } ``` -This declares type ‘StringComparer’ to be a function type taking two strings and returning a number. +This declares type 'StringComparer' to be a function type taking two strings and returning a number. ## 7.2 Declaration Merging -Interfaces are “open-ended” and interface declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) contribute to a single interface. +Interfaces are "open-ended" and interface declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) contribute to a single interface. When a generic interface has multiple declarations, all declarations must have identical type parameter lists, i.e. identical type parameter names with identical constraints in identical order. @@ -3264,13 +3477,13 @@ class Location { } ``` -In the above example, ‘SelectableControl’ contains all of the members of ‘Control’, including the private ‘state’ property. Since ‘state’ is a private member it is only possible for descendants of ‘Control’ to implement ‘SelectableControl’. This is because only descendants of ‘Control’ will have a ‘state’ private member that originates in the same declaration, which is a requirement for private members to be compatible (section [3.8](#3.8)). +In the above example, 'SelectableControl' contains all of the members of 'Control', including the private 'state' property. Since 'state' is a private member it is only possible for descendants of 'Control' to implement 'SelectableControl'. This is because only descendants of 'Control' will have a 'state' private member that originates in the same declaration, which is a requirement for private members to be compatible (section [3.8](#3.8)). -Within the ‘Control’ class it is possible to access the ‘state’ private member through an instance of ‘SelectableControl’. Effectively, a ‘SelectableControl’ acts like a ‘Control’ that is known to have a ‘select’ method. The ‘Button’ and ‘TextBox’ classes are subtypes of ‘SelectableControl’ (because they both inherit from ‘Control’ and have a ‘select’ method), but the ‘Image’ and ‘Location’ classes are not. +Within the 'Control' class it is possible to access the 'state' private member through an instance of 'SelectableControl'. Effectively, a 'SelectableControl' acts like a 'Control' that is known to have a 'select' method. The 'Button' and 'TextBox' classes are subtypes of 'SelectableControl' (because they both inherit from 'Control' and have a 'select' method), but the 'Image' and 'Location' classes are not. ## 7.4 Dynamic Type Checks -TypeScript does not provide a direct mechanism for dynamically testing whether an object implements a particular interface. Instead, TypeScript code can use the JavaScript technique of checking whether an appropriate set of members are present on the object. For example, given the declarations in section [7.1](#7.1), the following is a dynamic check for the ‘MoverShaker’ interface: +TypeScript does not provide a direct mechanism for dynamically testing whether an object implements a particular interface. Instead, TypeScript code can use the JavaScript technique of checking whether an appropriate set of members are present on the object. For example, given the declarations in section [7.1](#7.1), the following is a dynamic check for the 'MoverShaker' interface: ```TypeScript var obj: any = getSomeObject(); @@ -3294,7 +3507,7 @@ function asMoverShaker(obj: any): MoverShaker { TypeScript supports classes that are closely aligned with those proposed for ECMAScript 6, and includes extensions for instance and static member declarations and properties declared and initialized from constructor parameters. -*NOTE: TypeScript currently doesn’t support class expressions or nested class declarations from the ECMAScript 6 proposal*. +*NOTE: TypeScript currently doesn't support class expressions or nested class declarations from the ECMAScript 6 proposal*. ## 8.1 Class Declarations @@ -3309,7 +3522,7 @@ The *Identifier* of a class declaration may not be one of the predefined type na A class may optionally have type parameters (section [3.4.1](#3.4.1)) that serve as placeholders for actual types to be provided when the class is referenced in type references. A class with type parameters is called a ***generic class***. The type parameters of a generic class declaration are in scope in the entire declaration and may be referenced in the *ClassHeritage* and *ClassBody*. -The following example introduces both a named type called ‘Point’ (the class type) and a member called ‘Point’ (the constructor function) in the containing module. +The following example introduces both a named type called 'Point' (the class type) and a member called 'Point' (the constructor function) in the containing module. ```TypeScript class Point { @@ -3319,7 +3532,7 @@ class Point { } ``` -The ‘Point’ type is exactly equivalent to +The 'Point' type is exactly equivalent to ```TypeScript interface Point { @@ -3329,7 +3542,7 @@ interface Point { } ``` -The ‘Point’ member is a constructor function whose type corresponds to the declaration +The 'Point' member is a constructor function whose type corresponds to the declaration ```TypeScript var Point: { @@ -3344,7 +3557,7 @@ The context in which a class is referenced distinguishes between the class insta var p: Point = new Point(10, 20); ``` -the identifier ‘Point’ in the type annotation refers to the class instance type, whereas the identifier ‘Point’ in the `new` expression refers to the constructor function object. +the identifier 'Point' in the type annotation refers to the class instance type, whereas the identifier 'Point' in the `new` expression refers to the constructor function object. ### 8.1.1 Class Heritage Specification @@ -3362,7 +3575,7 @@ The heritage specification of a class consists of optional `extends` and `implem   *ImplementsClause:*    `implements` *ClassOrInterfaceTypeList* -A class that includes an `extends` clause is called a ***derived class***, and the class specified in the `extends` clause is called the ***base class*** of the derived class. When a class heritage specification omits the `extends` clause, the class does not have a base class. However, as is the case with every object type, type references (section [3.3.1](#3.3.1)) to the class will appear to have the members of the global interface type named ‘Object’ unless those members are hidden by members with the same name in the class. +A class that includes an `extends` clause is called a ***derived class***, and the class specified in the `extends` clause is called the ***base class*** of the derived class. When a class heritage specification omits the `extends` clause, the class does not have a base class. However, as is the case with every object type, type references (section [3.3.1](#3.3.1)) to the class will appear to have the members of the global interface type named 'Object' unless those members are hidden by members with the same name in the class. The following constraints must be satisfied by the class heritage specification or otherwise a compile-time error occurs: @@ -3382,15 +3595,15 @@ module Foo { } ``` -When evaluated as an expression, the type reference ‘A’ in the `extends` clause doesn’t reference the class constructor function of ‘A’ (instead it references the local variable ‘A’). +When evaluated as an expression, the type reference 'A' in the `extends` clause doesn't reference the class constructor function of 'A' (instead it references the local variable 'A'). The only situation in which the last two constraints above are violated is when a class overrides one or more base class members with incompatible new members. -Note that because TypeScript has a structural type system, a class doesn’t need to explicitly state that it implements an interface—it suffices for the class to simply contain the appropriate set of instance members. The `implements` clause of a class provides a mechanism to assert and validate that the class contains the appropriate sets of instance members, but otherwise it has no effect on the class type. +Note that because TypeScript has a structural type system, a class doesn't need to explicitly state that it implements an interface—it suffices for the class to simply contain the appropriate set of instance members. The `implements` clause of a class provides a mechanism to assert and validate that the class contains the appropriate sets of instance members, but otherwise it has no effect on the class type. ### 8.1.2 Class Body -The class body consists of zero or more constructor or member declarations. Statements are not allowed in the body of a class—they must be placed in the constructor or in members. +The class body consists of zero or more constructor or member declarations. Statements are not allowed in the body of a class—they must be placed in the constructor or in members.   *ClassBody:*    *ClassElementsopt* @@ -3432,7 +3645,7 @@ Private property members can be accessed only within their declaring class. Spec Protected property members can be accessed only within their declaring class and classes derived from their declaring class, and a protected instance property member must be accessed *through* an instance of the enclosing class. Specifically, a protected member *M* declared in a class *C* can be accessed only within the class body of *C* or the class body of a class derived from *C*. Furthermore, when a protected instance member *M* is accessed in a property access *E*`.`*M* within the body of a class *D*, the type of *E* is required to be *D* or a type that directly or indirectly has *D* as a base type, regardless of type arguments. -Private and protected accessibility is enforced only at compile-time and serves as no more than an *indication of intent*. Since JavaScript provides no mechanism to create private and protected properties on an object, it is not possible to enforce the private and protected modifiers in dynamic code at run-time. For example, private and protected accessibility can be defeated by changing an object’s static type to Any and accessing the member dynamically. +Private and protected accessibility is enforced only at compile-time and serves as no more than an *indication of intent*. Since JavaScript provides no mechanism to create private and protected properties on an object, it is not possible to enforce the private and protected modifiers in dynamic code at run-time. For example, private and protected accessibility can be defeated by changing an object's static type to Any and accessing the member dynamically. The following example demonstrates private and protected accessibility: @@ -3458,11 +3671,11 @@ class B extends A { } ``` -In class ‘A’, the accesses to ‘x’ are permitted because ‘x’ is declared in ‘A’, and the accesses to ‘y’ are permitted because both take place through an instance of ‘A’ or a type derived from ‘A’. In class ‘B’, access to ‘x’ is not permitted, and the first access to ‘y’ is an error because it takes place through an instance of ‘A’, which is not derived from the enclosing class ‘B’. +In class 'A', the accesses to 'x' are permitted because 'x' is declared in 'A', and the accesses to 'y' are permitted because both take place through an instance of 'A' or a type derived from 'A'. In class 'B', access to 'x' is not permitted, and the first access to 'y' is an error because it takes place through an instance of 'A', which is not derived from the enclosing class 'B'. ### 8.2.3 Inheritance and Overriding -A derived class ***inherits*** all members from its base class it doesn’t ***override***. Inheritance means that a derived class implicitly contains all non-overridden members of the base class. Only public and protected property members can be overridden. +A derived class ***inherits*** all members from its base class it doesn't ***override***. Inheritance means that a derived class implicitly contains all non-overridden members of the base class. Only public and protected property members can be overridden. A property member in a derived class is said to override a property member in a base class when the derived class property member has the same name and kind (instance or static) as the base class property member. The type of an overriding property member must be assignable (section [3.8.4](#3.8.4)) to the type of the overridden property member, or otherwise a compile-time error occurs. @@ -3503,7 +3716,7 @@ class B extends A { } ``` -the instance type of ‘A’ is +the instance type of 'A' is ```TypeScript interface A { @@ -3513,7 +3726,7 @@ interface A { } ``` -and the instance type of ‘B’ is +and the instance type of 'B' is ```TypeScript interface B { @@ -3524,7 +3737,7 @@ interface B { } ``` -Note that static declarations in a class do not contribute to the class type and its instance type—rather, static declarations introduce properties on the constructor function object. Also note that the declaration of ‘g’ in ‘B’ overrides the member inherited from ‘A’. +Note that static declarations in a class do not contribute to the class type and its instance type—rather, static declarations introduce properties on the constructor function object. Also note that the declaration of 'g' in 'B' overrides the member inherited from 'A'. ### 8.2.5 Constructor Function Types @@ -3537,10 +3750,10 @@ The type of the constructor function introduced by a class declaration is called * A property for each static member variable declaration in the class body. * A property of a function type for each static member function declaration in the class body. * A property for each uniquely named static member accessor declaration in the class body. -* A property named ‘prototype’, the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. +* A property named 'prototype', the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. * All base class constructor function type properties that are not overridden in the class. -Every class automatically contains a static property member named ‘prototype’, the type of which is the containing class with type Any substituted for each type parameter. +Every class automatically contains a static property member named 'prototype', the type of which is the containing class with type Any substituted for each type parameter. The example @@ -3578,7 +3791,7 @@ var TwoArrays: { } ``` -Note that the construct signatures in the constructor function types have the same type parameters as their class and return the instance type of their class. Also note that when a derived class doesn’t declare a constructor, type arguments from the base class reference are substituted before construct signatures are propagated from the base constructor function type to the derived constructor function type. +Note that the construct signatures in the constructor function types have the same type parameters as their class and return the instance type of their class. Also note that when a derived class doesn't declare a constructor, type arguments from the base class reference are substituted before construct signatures are propagated from the base constructor function type to the derived constructor function type. ## 8.3 Constructor Declarations @@ -3689,7 +3902,7 @@ Note that the declaration spaces of instance and static property members are sep Except for overrides, as described in section [8.2.3](#8.2.3), it is an error for a derived class to declare a property member with the same name and kind (instance or static) as a base class member. -Every class automatically contains a static property member named ‘prototype’, the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. It is an error to explicitly declare a static property member with the name ‘prototype’. +Every class automatically contains a static property member named 'prototype', the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. It is an error to explicitly declare a static property member with the name 'prototype'. Below is an example of a class containing both instance and static property member declarations: @@ -3706,7 +3919,7 @@ class Point { } ``` -The class instance type ‘Point’ has the members: +The class instance type 'Point' has the members: ```TypeScript interface Point { @@ -3716,7 +3929,7 @@ interface Point { } ``` -and the constructor function ‘Point’ has a type corresponding to the declaration: +and the constructor function 'Point' has a type corresponding to the declaration: ```TypeScript var Point: { @@ -3815,7 +4028,7 @@ class ColoredPoint extends Point { } ``` -In a static member function, `this` represents the constructor function object on which the static member function was invoked. Thus, a call to ‘new this()’ may actually invoke a derived class constructor: +In a static member function, `this` represents the constructor function object on which the static member function was invoked. Thus, a call to 'new this()' may actually invoke a derived class constructor: ```TypeScript class A { @@ -3833,7 +4046,7 @@ var x = A.create(); // new A() var y = B.create(); // new B() ``` -Note that TypeScript doesn’t require or verify that derived constructor functions are subtypes of base constructor functions. In other words, changing the declaration of ‘B’ to +Note that TypeScript doesn't require or verify that derived constructor functions are subtypes of base constructor functions. In other words, changing the declaration of 'B' to ```TypeScript class B extends A { @@ -3843,7 +4056,7 @@ class B extends A { } ``` -does not cause errors in the example, even though the call to the constructor from the ‘create’ function doesn’t specify an argument (thus giving the value ‘undefined’ to ‘b’). +does not cause errors in the example, even though the call to the constructor from the 'create' function doesn't specify an argument (thus giving the value 'undefined' to 'b'). ### 8.4.3 Member Accessor Declarations @@ -3861,7 +4074,7 @@ An instance member accessor declaration declares a property in the class instanc A static member accessor declaration declares a property in the constructor function type and defines a property on the constructor function object of the class with a get or set accessor. In the body of a static member accessor declaration, the type of `this` is the constructor function type. -Get and set accessors are emitted as calls to ‘Object.defineProperty’ in the generated JavaScript, as described in section [8.6.1](#8.6.1). +Get and set accessors are emitted as calls to 'Object.defineProperty' in the generated JavaScript, as described in section [8.6.1](#8.6.1). ## 8.5 Index Member Declarations @@ -3902,7 +4115,7 @@ var = (function () { *ClassName* is the name of the class. -*ConstructorParameters* is a comma separated list of the constructor’s parameter names. +*ConstructorParameters* is a comma separated list of the constructor's parameter names. *DefaultValueAssignments* is a sequence of default property value assignments corresponding to those generated for a regular function declaration, as described in section [6.5](#6.5). @@ -3976,7 +4189,7 @@ Object.defineProperty(, "", { }; ``` -where *MemberName* is the name of the member accessor, *GetAccessorStatements* is the code generated for the statements in the get acessor’s function body, *ParameterName* is the name of the set accessor parameter, and *SetAccessorStatements* is the code generated for the statements in the set accessor’s function body. The ‘get’ property is included only if a get accessor is declared and the ‘set’ property is included only if a set accessor is declared. +where *MemberName* is the name of the member accessor, *GetAccessorStatements* is the code generated for the statements in the get acessor's function body, *ParameterName* is the name of the set accessor parameter, and *SetAccessorStatements* is the code generated for the statements in the set accessor's function body. The 'get' property is included only if a get accessor is declared and the 'set' property is included only if a set accessor is declared. *StaticVariableAssignments* is a sequence of statements, one for each static member variable declaration with an initializer, in the order they are declared, of the form @@ -4006,7 +4219,7 @@ var = (function (_super) { })(); ``` -In addition, the ‘__extends’ function below is emitted at the beginning of the JavaScript source file. It copies all properties from the base constructor function object to the derived constructor function object (in order to inherit static members), and appropriately establishes the ‘prototype’ property of the derived constructor function object. +In addition, the '__extends' function below is emitted at the beginning of the JavaScript source file. It copies all properties from the base constructor function object to the derived constructor function object (in order to inherit static members), and appropriately establishes the 'prototype' property of the derived constructor function object. ```TypeScript var __extends = this.__extends || function(d, b) { @@ -4074,7 +4287,7 @@ An enum declaration declares an ***enum type*** and an ***enum object*** in the   *EnumDeclaration:*    `enum` *Identifier* `{` *EnumBodyopt* `}` -The enum type and enum object declared by an *EnumDeclaration* both have the name given by the *Identifier* of the declaration. The enum type is a distinct subtype of the Number primitive type. The enum object is a variable of an anonymous object type containing a set of properties, all of the enum type, corresponding to the values declared for the enum type in the body of the declaration. The enum object’s type furthermore includes a numeric index signature with the signature ‘[x: number]: string’. +The enum type and enum object declared by an *EnumDeclaration* both have the name given by the *Identifier* of the declaration. The enum type is a distinct subtype of the Number primitive type. The enum object is a variable of an anonymous object type containing a set of properties, all of the enum type, corresponding to the values declared for the enum type in the body of the declaration. The enum object's type furthermore includes a numeric index signature with the signature '[x: number]: string'. The *Identifier* of an enum declaration may not be one of the predefined type names (section [3.6.1](#3.6.1)). @@ -4084,7 +4297,7 @@ The example enum Color { Red, Green, Blue } ``` -declares a subtype of the Number primitive type called ‘Color’ and introduces a variable ‘Color’ with a type that corresponds to the declaration +declares a subtype of the Number primitive type called 'Color' and introduces a variable 'Color' with a type that corresponds to the declaration ```TypeScript var Color: { @@ -4095,7 +4308,7 @@ var Color: { }; ``` -The numeric index signature reflects a “reverse mapping” that is automatically generated in every enum object, as described in section [9.4](#9.4). The reverse mapping provides a convenient way to obtain the string representation of an enum value. For example +The numeric index signature reflects a "reverse mapping" that is automatically generated in every enum object, as described in section [9.4](#9.4). The reverse mapping provides a convenient way to obtain the string representation of an enum value. For example ```TypeScript var c = Color.Red; @@ -4156,7 +4369,7 @@ enum Test { } ``` -‘A’, ‘B’, ‘D’, and ‘E’ are constant members with values 0, 1, 10, and 11 respectively, and ‘C’ is a computed member. +'A', 'B', 'D', and 'E' are constant members with values 0, 1, 10, and 11 respectively, and 'C' is a computed member. In the example @@ -4175,9 +4388,9 @@ the first four members are constant members and the last two are computed member ## 9.3 Declaration Merging -Enums are “open-ended” and enum declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) define a single enum type and contribute to a single enum object. +Enums are "open-ended" and enum declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) define a single enum type and contribute to a single enum object. -It isn’t possible for one enum declaration to continue the automatic numbering sequence of another, and when an enum type has multiple declarations, only one declaration is permitted to omit a value for the first member. +It isn't possible for one enum declaration to continue the automatic numbering sequence of another, and when an enum type has multiple declarations, only one declaration is permitted to omit a value for the first member. ## 9.4 Code Generation @@ -4200,7 +4413,7 @@ var ; where *MemberName* is the name of the enum member and *Value* is the assigned constant value or the code generated for the computed value expression. -For example, the ‘Color’ enum example from section [9.1](#9.1) generates the following JavaScript: +For example, the 'Color' enum example from section [9.1](#9.1) generates the following JavaScript: ```TypeScript var Color; @@ -4215,7 +4428,7 @@ var Color; # 10 Internal Modules -An internal module is a named container of statements and declarations. An internal module represents both a namespace and a singleton module instance. The namespace contains named types and other namespaces, and the singleton module instance contains properties for the module’s exported members. The body of an internal module corresponds to a function that is executed once, thereby providing a mechanism for maintaining local state with assured isolation. +An internal module is a named container of statements and declarations. An internal module represents both a namespace and a singleton module instance. The namespace contains named types and other namespaces, and the singleton module instance contains properties for the module's exported members. The body of an internal module corresponds to a function that is executed once, thereby providing a mechanism for maintaining local state with assured isolation. ## 10.1 Module Declarations @@ -4228,7 +4441,7 @@ An internal module declaration declares a namespace name and, in the case of an    *Identifier*    *IdentifierPath* `.` *Identifier* -Internal modules are either ***instantiated*** or ***non-instantiated***. A non-instantiated module is an internal module containing only interface types and other non-instantiated modules. An instantiated module is an internal module that doesn’t meet this definition. In intuitive terms, an instantiated module is one for which a module object instance is created, whereas a non-instantiated module is one for which no code is generated. +Internal modules are either ***instantiated*** or ***non-instantiated***. A non-instantiated module is an internal module containing only interface types and other non-instantiated modules. An instantiated module is an internal module that doesn't meet this definition. In intuitive terms, an instantiated module is one for which a module object instance is created, whereas a non-instantiated module is one for which no code is generated. When a module identifier is referenced as a *ModuleName* (section [3.6.2](#3.6.2)) it denotes a container of module and type names, and when a module identifier is referenced as a *PrimaryExpression* (section [4.3](#4.3)) it denotes the singleton module instance. For example: @@ -4245,9 +4458,9 @@ var x2 = m.a; // Same as M.a var q: m.P; // Error ``` -Above, when ‘M’ is used as a *PrimaryExpression* it denotes an object instance with a single member ‘a’ and when ‘M’ is used as a *ModuleName* it denotes a container with a single type member ‘P’. The final line in the example is an error because ‘m’ is a variable which cannot be referenced in a type name. +Above, when 'M' is used as a *PrimaryExpression* it denotes an object instance with a single member 'a' and when 'M' is used as a *ModuleName* it denotes a container with a single type member 'P'. The final line in the example is an error because 'm' is a variable which cannot be referenced in a type name. -If the declaration of ‘M’ above had excluded the exported variable ‘a’, ‘M’ would be a non-instantiated module and it would be an error to reference ‘M’ as a *PrimaryExpression*. +If the declaration of 'M' above had excluded the exported variable 'a', 'M' would be a non-instantiated module and it would be an error to reference 'M' as a *PrimaryExpression*. An internal module declaration that specifies an *IdentifierPath* with more than one identifier is equivalent to a series of nested single-identifier internal module declarations where all but the outermost are automatically exported. For example: @@ -4306,7 +4519,7 @@ Import declarations are used to create local aliases for entities in other modul An *EntityName* consisting of a single identifier is resolved as a *ModuleName* and is thus required to reference an internal module. The resulting local alias references the given internal module and is itself classified as an internal module. -An *EntityName* consisting of more than one identifier is resolved as a *ModuleName* followed by an identifier that names one or more exported entities in the given module. The resulting local alias has all the meanings and classifications of the referenced entity or entities. (As many as three distinct meanings are possible for an entity name—namespace, type, and member.) In effect, it is as if the imported entity or entities were declared locally with the local alias name. +An *EntityName* consisting of more than one identifier is resolved as a *ModuleName* followed by an identifier that names one or more exported entities in the given module. The resulting local alias has all the meanings and classifications of the referenced entity or entities. (As many as three distinct meanings are possible for an entity name—namespace, type, and member.) In effect, it is as if the imported entity or entities were declared locally with the local alias name. In the example @@ -4324,7 +4537,7 @@ module B { } ``` -within ‘B’, ‘Y’ is an alias only for module ‘A’ and not the local interface ‘A’, whereas ‘Z’ is an alias for all exported meanings of ‘A.X’, thus denoting both an interface type and a variable. +within 'B', 'Y' is an alias only for module 'A' and not the local interface 'A', whereas 'Z' is an alias for all exported meanings of 'A.X', thus denoting both an interface type and a variable. If the *ModuleName* portion of an *EntityName* references an instantiated module, the *ModuleName* is required to reference the module instance when evaluated as an expression. In the example @@ -4339,7 +4552,7 @@ module B { } ``` -‘Y’ is a local alias for the non-instantiated module ‘A’. If the declaration of ‘A’ is changed such that ‘A’ becomes an instantiated module, for example by including a variable declaration in ‘A’, the import statement in ‘B’ above would be an error because the expression ‘A’ doesn’t reference the module instance of module ‘A’. +'Y' is a local alias for the non-instantiated module 'A'. If the declaration of 'A' is changed such that 'A' becomes an instantiated module, for example by including a variable declaration in 'A', the import statement in 'B' above would be an error because the expression 'A' doesn't reference the module instance of module 'A'. When an import statement includes an export modifier, all meanings of the local alias are exported. @@ -4349,7 +4562,7 @@ An export declaration declares an externally accessible module member. An export Exported class, interface, and enum types can be accessed as a *TypeName* (section [3.6.2](#3.6.2)) of the form *M.T*, where *M* is a reference to the containing module and *T* is the exported type name. Likewise, as part of a *TypeName*, exported modules can be accessed as a *ModuleName* of the form *M.N*, where *M* is a reference to the containing module and *N* is the exported module. -Exported variable, function, class, enum, module, and import alias declarations become properties on the module instance and together establish the module’s ***instance type***. This unnamed type has the following members: +Exported variable, function, class, enum, module, and import alias declarations become properties on the module instance and together establish the module's ***instance type***. This unnamed type has the following members: * A property for each exported variable declaration. * A property of a function type for each exported function declaration. @@ -4383,15 +4596,15 @@ interface A { x: string; } module M { export interface B { x: A; } export interface C { x: B; } - export function foo(c: C) { … } + export function foo(c: C) { … } } ``` -the ‘foo’ function depends upon the named types ‘A’, ‘B’, and ‘C’. In order to export ‘foo’ it is necessary to also export ‘B’ and ‘C’ as they otherwise would not be at least as accessible as ‘foo’. The ‘A’ interface is already at least as accessible as ‘foo’ because it is declared in a parent module of foo’s module. +the 'foo' function depends upon the named types 'A', 'B', and 'C'. In order to export 'foo' it is necessary to also export 'B' and 'C' as they otherwise would not be at least as accessible as 'foo'. The 'A' interface is already at least as accessible as 'foo' because it is declared in a parent module of foo's module. ## 10.5 Declaration Merging -Internal modules are “open-ended” and internal module declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) contribute to a single module. For example, the following two declarations of a module outer might be located in separate source files. +Internal modules are "open-ended" and internal module declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) contribute to a single module. For example, the following two declarations of a module outer might be located in separate source files. File a.ts: @@ -4438,7 +4651,7 @@ Declaration merging also extends to internal module declarations with the same q * When merging a class and an internal module, the type of the constructor function object is merged with the instance type of the module. In effect, the overloads or implementation of the class constructor provide the construct signatures, and the static members of the class and exported members of the module provide the properties of the combined type. It is an error to have static class members and exported module members with the same name. * When merging an enum and an internal module, the type of the enum object is merged with the instance type of the module. In effect, the members of the enum and the exported members of the module provide the properties of the combined type. It is an error to have enum members and exported module members with the same name. -When merging a non-ambient function or class declaration and a non-ambient internal module declaration, the function or class declaration must be located prior to the internal module declaration in the same source file. This ensures that the shared object instance is created as a function object. (While it is possible to add properties to an object after its creation, it is not possible to make an object “callable” after the fact.) +When merging a non-ambient function or class declaration and a non-ambient internal module declaration, the function or class declaration must be located prior to the internal module declaration in the same source file. This ensures that the shared object instance is created as a function object. (While it is possible to add properties to an object after its creation, it is not possible to make an object "callable" after the fact.) The example @@ -4464,7 +4677,7 @@ var p2 = point.origin; var b = point.equals(p1, p2); ``` -declares ‘point’ as a function object with two properties, ‘origin’ and ‘equals’. Note that the module declaration for ‘point’ is located after the function declaration. +declares 'point' as a function object with two properties, 'origin' and 'equals'. Note that the module declaration for 'point' is located after the function declaration. ## 10.6 Code Generation @@ -4477,7 +4690,7 @@ var ; })(||(={})); ``` -where *ModuleName* is the name of the module and *ModuleStatements* is the code generated for the statements in the module body. The *ModuleName* function parameter may be prefixed with one or more underscore characters to ensure the name is unique within the function body. Note that the entire module is emitted as an anonymous function that is immediately executed. This ensures that local variables are in their own lexical environment isolated from the surrounding context. Also note that the generated function doesn’t create and return a module instance, but rather it extends the existing instance (which may have just been created in the function call). This ensures that internal modules can extend each other. +where *ModuleName* is the name of the module and *ModuleStatements* is the code generated for the statements in the module body. The *ModuleName* function parameter may be prefixed with one or more underscore characters to ensure the name is unique within the function body. Note that the entire module is emitted as an anonymous function that is immediately executed. This ensures that local variables are in their own lexical environment isolated from the surrounding context. Also note that the generated function doesn't create and return a module instance, but rather it extends the existing instance (which may have just been created in the function call). This ensures that internal modules can extend each other. An import statement generates code of the form @@ -4509,11 +4722,11 @@ This copies a reference to the entity into a property on the module instance. TypeScript implements external modules that are closely aligned with those proposed for ECMAScript 6 and supports code generation targeting CommonJS and AMD module systems. -*NOTE: TypeScript currently doesn’t support the full proposed capabilities of the ECMAScript 6 import and export syntax. We expect to align more closely on the syntax as the ECMAScript 6 specification evolves*. +*NOTE: TypeScript currently doesn't support the full proposed capabilities of the ECMAScript 6 import and export syntax. We expect to align more closely on the syntax as the ECMAScript 6 specification evolves*. ## 11.1 Source Files -A TypeScript ***program*** consists of one or more source files that are either ***implementation source files*** or ***declaration source files***. Source files with extension ‘.ts’ are *ImplementationSourceFiles* containing statements and declarations. Source files with extension ‘.d.ts’ are *DeclarationSourceFiles* containing declarations only. Declaration source files are a strict subset of implementation source files. +A TypeScript ***program*** consists of one or more source files that are either ***implementation source files*** or ***declaration source files***. Source files with extension '.ts' are *ImplementationSourceFiles* containing statements and declarations. Source files with extension '.d.ts' are *DeclarationSourceFiles* containing declarations only. Declaration source files are a strict subset of implementation source files.   *SourceFile:*    *ImplementationSourceFile* @@ -4547,9 +4760,9 @@ A TypeScript ***program*** consists of one or more source files that are either    `export`*opt* *AmbientDeclaration*    `export`*opt* *ExternalImportDeclaration* -When a TypeScript program is compiled, all of the program’s source files are processed together. Statements and declarations in different source files can depend on each other, possibly in a circular fashion. By default, a JavaScript output file is generated for each implementation source file in a compilation, but no output is generated from declaration source files. +When a TypeScript program is compiled, all of the program's source files are processed together. Statements and declarations in different source files can depend on each other, possibly in a circular fashion. By default, a JavaScript output file is generated for each implementation source file in a compilation, but no output is generated from declaration source files. -The source elements permitted in a TypeScript implementation source file are a superset of those supported by JavaScript. Specifically, TypeScript extends the JavaScript grammar’s existing *VariableDeclaration* (section [5.1](#5.1)) and *FunctionDeclaration* (section [6.1](#6.1)) productions, and adds *InterfaceDeclaration* (section [7.1](#7.1)), *ClassDeclaration* (section [8.1](#8.1)), *EnumDeclaration* (section [9.1](#9.1)), *ModuleDeclaration* (section [10.1](#10.1)), *ImportDeclaration* (section [10.3](#10.3)), *ExternalImportDeclaration* (section [11.2.2](#11.2.2)), *ExportAssignment* (section [11.2.4](#11.2.4)), *AmbientDeclaration* (section [12.1](#12.1)), and *AmbientExternalModuleDeclaration* (section [12.2](#12.2)) productions. +The source elements permitted in a TypeScript implementation source file are a superset of those supported by JavaScript. Specifically, TypeScript extends the JavaScript grammar's existing *VariableDeclaration* (section [5.1](#5.1)) and *FunctionDeclaration* (section [6.1](#6.1)) productions, and adds *InterfaceDeclaration* (section [7.1](#7.1)), *ClassDeclaration* (section [8.1](#8.1)), *EnumDeclaration* (section [9.1](#9.1)), *ModuleDeclaration* (section [10.1](#10.1)), *ImportDeclaration* (section [10.3](#10.3)), *ExternalImportDeclaration* (section [11.2.2](#11.2.2)), *ExportAssignment* (section [11.2.4](#11.2.4)), *AmbientDeclaration* (section [12.1](#12.1)), and *AmbientExternalModuleDeclaration* (section [12.2](#12.2)) productions. Declaration source files are restricted to contain declarations only. Declaration source files can be used to declare the static type information associated with existing JavaScript code in an adjunct manner. They are entirely optional but enable the TypeScript compiler and tools to provide better verification and assistance when integrating existing JavaScript code and libraries in a TypeScript application. @@ -4561,11 +4774,11 @@ External modules can additionally be declared using *AmbientExternalModuleDeclar ### 11.1.1 Source Files Dependencies -The TypeScript compiler automatically determines a source file’s dependencies and includes those dependencies in the program being compiled. The determination is made from “reference comments” and external import declarations as follows: +The TypeScript compiler automatically determines a source file's dependencies and includes those dependencies in the program being compiled. The determination is made from "reference comments" and external import declarations as follows: -* A comment of the form /// <reference path="…"/> adds a dependency on the source file specified in the path argument. The path is resolved relative to the directory of the containing source file. -* An external import declaration that specifies a relative external module name (section [11.2.1](#11.2.1)) resolves the name relative to the directory of the containing source file. If a source file with the resulting path and file extension ‘.ts’ exists, that file is added as a dependency. Otherwise, if a source file with the resulting path and file extension ‘.d.ts’ exists, that file is added as a dependency. -* An external import declaration that specifies a top-level external module name (section [11.2.1](#11.2.1)) resolves the name in a host dependent manner (typically by resolving the name relative to a module name space root or searching for the name in a series of directories). If a source file with extension ‘.ts’ or ‘.d.ts’ corresponding to the reference is located, that file is added as a dependency. +* A comment of the form /// <reference path="…"/> adds a dependency on the source file specified in the path argument. The path is resolved relative to the directory of the containing source file. +* An external import declaration that specifies a relative external module name (section [11.2.1](#11.2.1)) resolves the name relative to the directory of the containing source file. If a source file with the resulting path and file extension '.ts' exists, that file is added as a dependency. Otherwise, if a source file with the resulting path and file extension '.d.ts' exists, that file is added as a dependency. +* An external import declaration that specifies a top-level external module name (section [11.2.1](#11.2.1)) resolves the name in a host dependent manner (typically by resolving the name relative to a module name space root or searching for the name in a series of directories). If a source file with extension '.ts' or '.d.ts' corresponding to the reference is located, that file is added as a dependency. Any files included as dependencies in turn have their references analyzed in a transitive manner until all dependencies have been determined. @@ -4605,7 +4818,7 @@ export function message(s: string) { } ``` -The import declaration in the ‘main’ module references the ‘log’ module and compiling the ‘main.ts’ file causes the ‘log.ts’ file to also be compiled as part of the program. At run-time, the import declaration loads the ‘log’ module and produces a reference to its module instance through which it is possible to reference the exported function. +The import declaration in the 'main' module references the 'log' module and compiling the 'main.ts' file causes the 'log.ts' file to also be compiled as part of the program. At run-time, the import declaration loads the 'log' module and produces a reference to its module instance through which it is possible to reference the exported function. TypeScript supports two patterns of JavaScript code generation for external modules: The CommonJS Modules pattern (section [11.2.5](#11.2.5)), typically used by server frameworks such as node.js, and the Asynchronous Module Definition (AMD) pattern (section [11.2.6](#11.2.6)), an extension to CommonJS Modules that permits asynchronous module loading, as is typical in browsers. The desired module code generation pattern is selected through a compiler option and does not affect the TypeScript source code. Indeed, it is possible to author external modules that can be compiled for use both on the server side (e.g. using node.js) and on the client side (using an AMD compliant loader) with no changes to the TypeScript source code. @@ -4614,16 +4827,16 @@ TypeScript supports two patterns of JavaScript code generation for external modu External modules are identified and referenced using external module names. The following definition is aligned with that provided in the CommonJS Modules 1.0 specification. * An external module name is a string of terms delimited by forward slashes. -* External module names may not have file-name extensions like “.js”. -* External module names may be relative or top-level. An external module name is relative if the first term is “.” or “..”. +* External module names may not have file-name extensions like ".js". +* External module names may be relative or top-level. An external module name is relative if the first term is "." or "..". * Top-level names are resolved off the conceptual module name space root. * Relative names are resolved relative to the name of the module in which they occur. -For purposes of resolving external module references, TypeScript associates a file path with every external module. The file path is simply the path of the module’s source file without the file extension. For example, an external module contained in the source file ‘C:\src\lib\io.ts’ has the file path ‘C:/src/lib/io’ and an external module contained in the source file ‘C:\src\ui\editor.d.ts’ has the file path ‘C:/src/ui/editor’. +For purposes of resolving external module references, TypeScript associates a file path with every external module. The file path is simply the path of the module's source file without the file extension. For example, an external module contained in the source file 'C:\src\lib\io.ts' has the file path 'C:/src/lib/io' and an external module contained in the source file 'C:\src\ui\editor.d.ts' has the file path 'C:/src/ui/editor'. An external module name in an import declaration is resolved as follows: -* If the import declaration specifies a relative external module name, the name is resolved relative to the directory of the referencing module’s file path. The program must contain a module with the resulting file path or otherwise an error occurs. For example, in a module with the file path ‘C:/src/ui/main’, the external module names ‘./editor’ and ‘../lib/io’ reference modules with the file paths ‘C:/src/ui/editor’ and ‘C:/src/lib/io’. +* If the import declaration specifies a relative external module name, the name is resolved relative to the directory of the referencing module's file path. The program must contain a module with the resulting file path or otherwise an error occurs. For example, in a module with the file path 'C:/src/ui/main', the external module names './editor' and '../lib/io' reference modules with the file paths 'C:/src/ui/editor' and 'C:/src/lib/io'. * If the import declaration specifies a top-level external module name and the program contains an *AmbientExternalModuleDeclaration* (section [12.2](#12.2)) with a string literal that specifies that exact name, then the import declaration references that ambient external module. * If the import declaration specifies a top-level external module name and the program contains no *AmbientExternalModuleDeclaration* (section [12.2](#12.2)) with a string literal that specifies that exact name, the name is resolved in a host dependent manner (for example by considering the name relative to a module name space root). If a matching module cannot be found an error occurs. @@ -4660,7 +4873,7 @@ When an external module containing an export assignment is imported, the local a It is an error for an external module to contain more than one export assignment. -Assume the following example resides in the file ‘point.ts’: +Assume the following example resides in the file 'point.ts': ```TypeScript export = Point; @@ -4671,7 +4884,7 @@ class Point { } ``` -When ‘point.ts’ is imported in another external module, the import alias references the exported class and can be used both as a type and as a constructor function: +When 'point.ts' is imported in another external module, the import alias references the exported class and can be used both as a type and as a constructor function: ```TypeScript import Pt = require("./point"); @@ -4684,9 +4897,9 @@ Note that there is no requirement that the import alias use the same name as the ### 11.2.5 CommonJS Modules -The CommonJS Modules definition specifies a methodology for writing JavaScript modules with implied privacy, the ability to import other modules, and the ability to explicitly export members. A CommonJS compliant system provides a ‘require’ function that can be used to synchronously load other external modules to obtain their singleton module instance, as well as an ‘exports’ variable to which a module can add properties to define its external API. +The CommonJS Modules definition specifies a methodology for writing JavaScript modules with implied privacy, the ability to import other modules, and the ability to explicitly export members. A CommonJS compliant system provides a 'require' function that can be used to synchronously load other external modules to obtain their singleton module instance, as well as an 'exports' variable to which a module can add properties to define its external API. -The ‘main’ and ‘log’ example from section [11.2](#11.2) above generates the following JavaScript code when compiled for the CommonJS Modules pattern: +The 'main' and 'log' example from section [11.2](#11.2) above generates the following JavaScript code when compiled for the CommonJS Modules pattern: File main.js: @@ -4703,7 +4916,7 @@ exports.message = function(s) { } ``` -An external import declaration is represented in the generated JavaScript as a variable initialized by a call to the ‘require’ function provided by the module system host. A variable declaration and ‘require’ call is emitted for a particular imported module only if the imported module, or a local alias (section [10.3](#10.3)) that references the imported module, is referenced as a *PrimaryExpression* somewhere in the body of the importing module. If an imported module is referenced only as a *ModuleName* or *TypeQueryExpression*, nothing is emitted. +An external import declaration is represented in the generated JavaScript as a variable initialized by a call to the 'require' function provided by the module system host. A variable declaration and 'require' call is emitted for a particular imported module only if the imported module, or a local alias (section [10.3](#10.3)) that references the imported module, is referenced as a *PrimaryExpression* somewhere in the body of the importing module. If an imported module is referenced only as a *ModuleName* or *TypeQueryExpression*, nothing is emitted. An example: @@ -4724,21 +4937,21 @@ import g = require("./geometry"); var p = g.point(10, 20); ``` -The ‘game’ module references the imported ‘geometry’ module in an expression (through its alias ‘g’) and a ‘require’ call is therefore included in the emitted JavaScript: +The 'game' module references the imported 'geometry' module in an expression (through its alias 'g') and a 'require' call is therefore included in the emitted JavaScript: ```TypeScript var g = require("./geometry"); var p = g.point(10, 20); ``` -Had the ‘game’ module instead been written to only reference ‘geometry’ in a type position +Had the 'game' module instead been written to only reference 'geometry' in a type position ```TypeScript import g = require("./geometry"); var p: g.Point = { x: 10, y: 20 }; ``` -the emitted JavaScript would have no dependency on the ‘geometry’ module and would simply be +the emitted JavaScript would have no dependency on the 'geometry' module and would simply be ```TypeScript var p = { x: 10, y: 20 }; @@ -4746,9 +4959,9 @@ var p = { x: 10, y: 20 }; ### 11.2.6 AMD Modules -The Asynchronous Module Definition (AMD) specification extends the CommonJS Modules specification with a pattern for authoring asynchronously loadable modules with associated dependencies. Using the AMD pattern, modules are emitted as calls to a global ‘define’ function taking an array of dependencies, specified as external module names, and a callback function containing the module body. The global ‘define’ function is provided by including an AMD compliant loader in the application. The loader arranges to asynchronously load the module’s dependencies and, upon completion, calls the callback function passing resolved module instances as arguments in the order they were listed in the dependency array. +The Asynchronous Module Definition (AMD) specification extends the CommonJS Modules specification with a pattern for authoring asynchronously loadable modules with associated dependencies. Using the AMD pattern, modules are emitted as calls to a global 'define' function taking an array of dependencies, specified as external module names, and a callback function containing the module body. The global 'define' function is provided by including an AMD compliant loader in the application. The loader arranges to asynchronously load the module's dependencies and, upon completion, calls the callback function passing resolved module instances as arguments in the order they were listed in the dependency array. -The “main” and “log” example from above generates the following JavaScript code when compiled for the AMD pattern. +The "main" and "log" example from above generates the following JavaScript code when compiled for the AMD pattern. File main.js: @@ -4768,13 +4981,13 @@ define(["require", "exports"], function(require, exports) { } ``` -The special ‘require’ and ‘exports’ dependencies are always present. Additional entries are added to the dependencies array and the parameter list as required to represent imported external modules. Similar to the code generation for CommonJS Modules, a dependency entry is generated for a particular imported module only if the imported module is referenced as a *PrimaryExpression* somewhere in the body of the importing module. If an imported module is referenced only as a *ModuleName*, no dependency is generated for that module. +The special 'require' and 'exports' dependencies are always present. Additional entries are added to the dependencies array and the parameter list as required to represent imported external modules. Similar to the code generation for CommonJS Modules, a dependency entry is generated for a particular imported module only if the imported module is referenced as a *PrimaryExpression* somewhere in the body of the importing module. If an imported module is referenced only as a *ModuleName*, no dependency is generated for that module.
#
12 Ambients -Ambient declarations are used to provide static typing over existing JavaScript code. Ambient declarations differ from regular declarations in that no JavaScript code is emitted for them. Instead of introducing new variables, functions, classes, enums, or modules, ambient declarations provide type information for entities that exist “ambiently” and are included in a program by external means, for example by referencing a JavaScript library in a <script/> tag. +Ambient declarations are used to provide static typing over existing JavaScript code. Ambient declarations differ from regular declarations in that no JavaScript code is emitted for them. Instead of introducing new variables, functions, classes, enums, or modules, ambient declarations provide type information for entities that exist "ambiently" and are included in a program by external means, for example by referencing a JavaScript library in a <script/> tag. ## 12.1 Ambient Declarations @@ -4903,7 +5116,7 @@ An *ExternalImportDeclaration* in an *AmbientExternalModuleDeclaration* may refe If an ambient external module declaration includes an export assignment, it is an error for any of the declarations within the module to specify an `export` modifier. If an ambient external module declaration contains no export assignment, entities declared in the module are exported regardless of whether their declarations include the optional `export` modifier. -Ambient external modules are “open-ended” and ambient external module declarations with the same string literal name contribute to a single external module. For example, the following two declarations of an external module ‘io’ might be located in separate source files. +Ambient external modules are "open-ended" and ambient external module declarations with the same string literal name contribute to a single external module. For example, the following two declarations of an external module 'io' might be located in separate source files. ```TypeScript declare module "io" { @@ -4956,15 +5169,26 @@ This appendix contains a summary of the grammar found in the main document. As d    *Type*   *Type:* +   *PrimaryOrUnionType* +   *FunctionType* +   *ConstructorType* + +  *PrimaryOrUnionType:* +   *PrimaryType* +   *UnionType* + +  *PrimaryType:* +   *ParenthesizedType*    *PredefinedType*    *TypeReference*    *ObjectType*    *ArrayType*    *TupleType* -   *FunctionType* -   *ConstructorType*    *TypeQuery* +  *ParenthesizedType:* +   `(` *Type* `)` +   *PredefinedType:*    `any`    `number` @@ -5001,15 +5225,7 @@ This appendix contains a summary of the grammar found in the main document. As d    *MethodSignature*   *ArrayType:* -   *ElementType* *[no LineTerminator here]* `[` `]` - -  *ElementType:* -   *PredefinedType* -   *TypeReference* -   *ObjectType* -   *ArrayType* -   *TupleType* -   *TypeQuery* +   *PrimaryType* *[no LineTerminator here]* `[` `]`   *TupleType:*    `[` *TupleElementTypes* `]` @@ -5021,6 +5237,9 @@ This appendix contains a summary of the grammar found in the main document. As d   *TupleElementType:*    *Type* +  *UnionType:* +   *PrimaryOrUnionType* `|` *PrimaryType* +   *FunctionType:*    *TypeParametersopt* `(` *ParameterListopt* `)` `=>` *Type* @@ -5104,7 +5323,7 @@ This appendix contains a summary of the grammar found in the main document. As d    `set` *PropertyName* `(` *Identifier* *TypeAnnotationopt* `)` `{` *FunctionBody* `}`   *CallExpression:* *( Modified )* -   … +   …    `super` `(` *ArgumentListopt* `)`    `super` `.` *IdentifierName* @@ -5112,7 +5331,7 @@ This appendix contains a summary of the grammar found in the main document. As d    `function` *Identifieropt* *CallSignature* `{` *FunctionBody* `}`   *AssignmentExpression:* *( Modified )* -   … +   …    *ArrowFunctionExpression*   *ArrowFunctionExpression:* @@ -5127,7 +5346,7 @@ This appendix contains a summary of the grammar found in the main document. As d    *TypeArgumentsopt* `(` *ArgumentListopt* `)`   *UnaryExpression:* *( Modified )* -   … +   …    `<` *Type* `>` *UnaryExpression* ## A.3 Statements diff --git a/scripts/ior.ts b/scripts/ior.ts new file mode 100644 index 00000000000..f0c142a266c --- /dev/null +++ b/scripts/ior.ts @@ -0,0 +1,123 @@ +/// + +import fs = require('fs'); +import path = require('path'); + +interface IOLog { + filesRead: { + path: string; + result: { contents: string; }; + }[]; + arguments: string[]; +} + +module Commands { + export function dir(obj: IOLog) { + obj.filesRead.filter(f => f.result !== undefined).forEach(f => { + console.log(f.path); + }); + } + dir['description'] = ': displays a list of files'; + + export function find(obj: IOLog, str: string) { + obj.filesRead.filter(f => f.result !== undefined).forEach(f => { + var lines = f.result.contents.split('\n'); + var printedHeader = false; + lines.forEach(line => { + if (line.indexOf(str) >= 0) { + if (!printedHeader) { + console.log(' === ' + f.path + ' ==='); + printedHeader = true; + } + console.log(line); + } + }); + }); + } + find['description'] = ' string: finds text in files'; + + export function grab(obj: IOLog, filename: string) { + obj.filesRead.filter(f => f.result !== undefined).forEach(f => { + if (path.basename(f.path) === filename) { + fs.writeFile(filename, f.result.contents); + } + }); + } + grab['description'] = ' filename.ts: writes out the specified file to disk'; + + export function extract(obj: IOLog, outputFolder: string) { + var directorySeparator = "/"; + function directoryExists(path: string): boolean { + return fs.existsSync(path) && fs.statSync(path).isDirectory(); + } + function getDirectoryPath(path: string) { + return path.substr(0, Math.max(getRootLength(path), path.lastIndexOf(directorySeparator))); + } + function getRootLength(path: string): number { + if (path.charAt(0) === directorySeparator) { + if (path.charAt(1) !== directorySeparator) return 1; + var p1 = path.indexOf(directorySeparator, 2); + if (p1 < 0) return 2; + var p2 = path.indexOf(directorySeparator, p1 + 1); + if (p2 < 0) return p1 + 1; + return p2 + 1; + } + if (path.charAt(1) === ":") { + if (path.charAt(2) === directorySeparator) return 3; + return 2; + } + return 0; + } + function ensureDirectoriesExist(directoryPath: string) { + if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { + var parentDirectory = getDirectoryPath(directoryPath); + ensureDirectoriesExist(parentDirectory); + console.log("creating directory: " + directoryPath); + fs.mkdirSync(directoryPath); + } + } + function transalatePath(outputFolder:string, path: string): string { + return outputFolder + directorySeparator + path.replace(":", ""); + } + function fileExists(path: string): boolean { + return fs.existsSync(path); + } + obj.filesRead.forEach(f => { + var filename = transalatePath(outputFolder, f.path); + ensureDirectoriesExist(getDirectoryPath(filename)); + console.log("writing filename: " + filename); + fs.writeFile(filename, f.result.contents, (err) => { }); + }); + + console.log("Command: tsc "); + obj.arguments.forEach(a => { + if (getRootLength(a) > 0) { + console.log(transalatePath(outputFolder, a)); + } + else { + console.log(a); + } + console.log(" "); + }); + } + extract['description'] = ' outputFolder: extract all input files to '; +} + +var args = process.argv.slice(2); +if (args.length < 2) { + console.log('Usage: node ior.js path_to_file.json [command]'); + console.log('List of commands: '); + Object.keys(Commands).forEach(k => console.log(' ' + k + Commands[k]['description'])); +} else { + var cmd: Function = Commands[args[1]]; + if (cmd === undefined) { + console.log('Unknown command ' + args[1]); + } else { + fs.readFile(args[0], 'utf-8', (err, data) => { + if (err) throw err; + var json = JSON.parse(data); + cmd.apply(undefined, [json].concat(args.slice(2))); + }); + } +} + diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index 6a4aaad9f93..eccfb821bb2 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -3,6 +3,7 @@ interface DiagnosticDetails { category: string; code: number; + isEarly?: boolean; } interface InputDiagnosticMessageTable { @@ -63,8 +64,9 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: ' ' + convertPropertyName(nameMap[name]) + ': { code: ' + diagnosticDetails.code + ', category: DiagnosticCategory.' + diagnosticDetails.category + - ', key: "' + name.replace('"', '\\"') + - '" },\r\n'; + ', key: "' + name.replace('"', '\\"') + '"' + + (diagnosticDetails.isEarly ? ', isEarly: true' : '') + + ' },\r\n'; } result += ' };\r\n}'; diff --git a/scripts/word2md.js b/scripts/word2md.js index 8f9cd276f95..0645acbb143 100644 --- a/scripts/word2md.js +++ b/scripts/word2md.js @@ -1,4 +1,8 @@ var sys = (function () { + var fileStream = new ActiveXObject("ADODB.Stream"); + fileStream.Type = 2; + var binaryStream = new ActiveXObject("ADODB.Stream"); + binaryStream.Type = 1; var args = []; for (var i = 0; i < WScript.Arguments.length; i++) { args[i] = WScript.Arguments.Item(i); @@ -6,7 +10,24 @@ var sys = (function () { return { args: args, createObject: function (typeName) { return new ActiveXObject(typeName); }, - write: function (s) { return WScript.StdOut.Write(s); } + write: function (s) { + WScript.StdOut.Write(s); + }, + writeFile: function (fileName, data) { + fileStream.Open(); + binaryStream.Open(); + try { + fileStream.Charset = "utf-8"; + fileStream.WriteText(data); + fileStream.Position = 3; + fileStream.CopyTo(binaryStream); + binaryStream.SaveToFile(fileName, 2); + } + finally { + binaryStream.Close(); + fileStream.Close(); + } + } }; })(); function convertDocumentToMarkdown(doc) { @@ -149,6 +170,10 @@ function convertDocumentToMarkdown(doc) { lastInTable = inTable; } function writeDocument() { + var title = doc.builtInDocumentProperties.item(1) + ""; + if (title.length) { + write("# " + title + "\n\n"); + } for (var p = doc.paragraphs.first; p; p = p.next()) { writeParagraph(p); } @@ -168,16 +193,19 @@ function convertDocumentToMarkdown(doc) { findReplace("^19 REF", {}, "[^&](#^&)", {}); doc.fields.toggleShowCodes(); writeDocument(); + result = result.replace(/\x85/g, "\u2026"); + result = result.replace(/\x96/g, "\u2013"); + result = result.replace(/\x97/g, "\u2014"); return result; } function main(args) { - if (args.length !== 1) { - sys.write("Syntax: word2md \n"); + if (args.length !== 2) { + sys.write("Syntax: word2md \n"); return; } var app = sys.createObject("Word.Application"); var doc = app.documents.open(args[0]); - sys.write(convertDocumentToMarkdown(doc)); + sys.writeFile(args[1], convertDocumentToMarkdown(doc)); doc.close(false); app.quit(); } diff --git a/scripts/word2md.ts b/scripts/word2md.ts index b1bc50b0cb9..65b39d6e4f6 100644 --- a/scripts/word2md.ts +++ b/scripts/word2md.ts @@ -103,6 +103,7 @@ module Word { export interface Document { fields: Fields; paragraphs: Paragraphs; + builtInDocumentProperties: Collection; close(saveChanges: boolean): void; range(): Range; } @@ -118,6 +119,10 @@ module Word { } var sys = (function () { + var fileStream = new ActiveXObject("ADODB.Stream"); + fileStream.Type = 2 /*text*/; + var binaryStream = new ActiveXObject("ADODB.Stream"); + binaryStream.Type = 1 /*binary*/; var args: string[] = []; for (var i = 0; i < WScript.Arguments.length; i++) { args[i] = WScript.Arguments.Item(i); @@ -125,7 +130,26 @@ var sys = (function () { return { args: args, createObject: (typeName: string) => new ActiveXObject(typeName), - write: (s: string) => WScript.StdOut.Write(s) + write(s: string): void { + WScript.StdOut.Write(s); + }, + writeFile: (fileName: string, data: string): void => { + fileStream.Open(); + binaryStream.Open(); + try { + // Write characters in UTF-8 encoding + fileStream.Charset = "utf-8"; + fileStream.WriteText(data); + // We don't want the BOM, skip it by setting the starting location to 3 (size of BOM). + fileStream.Position = 3; + fileStream.CopyTo(binaryStream); + binaryStream.SaveToFile(fileName, 2 /*overwrite*/); + } + finally { + binaryStream.Close(); + fileStream.Close(); + } + } }; })(); @@ -298,6 +322,10 @@ function convertDocumentToMarkdown(doc: Word.Document): string { } function writeDocument() { + var title = doc.builtInDocumentProperties.item(1) + ""; + if (title.length) { + write("# " + title + "\n\n"); + } for (var p = doc.paragraphs.first; p; p = p.next()) { writeParagraph(p); } @@ -321,17 +349,21 @@ function convertDocumentToMarkdown(doc: Word.Document): string { writeDocument(); + result = result.replace(/\x85/g, "\u2026"); + result = result.replace(/\x96/g, "\u2013"); + result = result.replace(/\x97/g, "\u2014"); + return result; } function main(args: string[]) { - if (args.length !== 1) { - sys.write("Syntax: word2md \n"); + if (args.length !== 2) { + sys.write("Syntax: word2md \n"); return; } var app: Word.Application = sys.createObject("Word.Application"); var doc = app.documents.open(args[0]); - sys.write(convertDocumentToMarkdown(doc)); + sys.writeFile(args[1], convertDocumentToMarkdown(doc)); doc.close(false); app.quit(); } diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index c9f9d6bf6e3..accb46504dc 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -31,13 +31,14 @@ module ts { var parent: Node; var container: Declaration; + var blockScopeContainer: Node; var lastContainer: Declaration; var symbolCount = 0; var Symbol = objectAllocator.getSymbolConstructor(); if (!file.locals) { file.locals = {}; - container = file; + container = blockScopeContainer = file; bind(file); file.symbolCount = symbolCount; } @@ -86,10 +87,11 @@ module ts { } // Report errors every position with duplicate declaration // Report errors on previous encountered declarations + var message = symbol.flags & SymbolFlags.BlockScopedVariable ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; forEach(symbol.declarations, (declaration) => { - file.semanticErrors.push(createDiagnosticForNode(declaration.name, Diagnostics.Duplicate_identifier_0, getDisplayName(declaration))); + file.semanticErrors.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration))); }); - file.semanticErrors.push(createDiagnosticForNode(node.name, Diagnostics.Duplicate_identifier_0, getDisplayName(node))); + file.semanticErrors.push(createDiagnosticForNode(node.name, message, getDisplayName(node))); symbol = createSymbol(0, name); } @@ -167,12 +169,13 @@ module ts { // All container nodes are kept on a linked list in declaration order. This list is used by the getLocalNameOfContainer function // in the type checker to validate that the local name used for a container is unique. - function bindChildren(node: Declaration, symbolKind: SymbolFlags) { + function bindChildren(node: Declaration, symbolKind: SymbolFlags, isBlockScopeContainer: boolean) { if (symbolKind & SymbolFlags.HasLocals) { node.locals = {}; } var saveParent = parent; var saveContainer = container; + var savedBlockScopeContainer = blockScopeContainer; parent = node; if (symbolKind & SymbolFlags.IsContainer) { container = node; @@ -184,12 +187,16 @@ module ts { lastContainer = container; } } + if (isBlockScopeContainer) { + blockScopeContainer = node; + } forEachChild(node, bind); container = saveContainer; parent = saveParent; + blockScopeContainer = savedBlockScopeContainer; } - function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) { + function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) { switch (container.kind) { case SyntaxKind.ModuleDeclaration: declareModuleMember(node, symbolKind, symbolExcludes); @@ -225,121 +232,159 @@ module ts { declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } - bindChildren(node, symbolKind); + bindChildren(node, symbolKind, isBlockScopeContainer); } function bindConstructorDeclaration(node: ConstructorDeclaration) { - bindDeclaration(node, SymbolFlags.Constructor, 0); + bindDeclaration(node, SymbolFlags.Constructor, 0, /*isBlockScopeContainer*/ true); forEach(node.parameters, p => { if (p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) { - bindDeclaration(p, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + bindDeclaration(p, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); } }); } function bindModuleDeclaration(node: ModuleDeclaration) { if (node.name.kind === SyntaxKind.StringLiteral) { - bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes); + bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); } else if (isInstantiated(node)) { - bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes); + bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); } else { - bindDeclaration(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes); + bindDeclaration(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes, /*isBlockScopeContainer*/ true); } } - function bindAnonymousDeclaration(node: Node, symbolKind: SymbolFlags, name: string) { + function bindAnonymousDeclaration(node: Node, symbolKind: SymbolFlags, name: string, isBlockScopeContainer: boolean) { var symbol = createSymbol(symbolKind, name); addDeclarationToSymbol(symbol, node, symbolKind); - bindChildren(node, symbolKind); + bindChildren(node, symbolKind, isBlockScopeContainer); } function bindCatchVariableDeclaration(node: CatchBlock) { - var symbol = createSymbol(SymbolFlags.Variable, node.variable.text || "__missing"); - addDeclarationToSymbol(symbol, node, SymbolFlags.Variable); + var symbol = createSymbol(SymbolFlags.FunctionScopedVariable, node.variable.text || "__missing"); + addDeclarationToSymbol(symbol, node, SymbolFlags.FunctionScopedVariable); var saveParent = parent; - parent = node; + var savedBlockScopeContainer = blockScopeContainer; + parent = blockScopeContainer = node; forEachChild(node, bind); parent = saveParent; + blockScopeContainer = savedBlockScopeContainer; + } + + function bindBlockScopedVariableDeclaration(node: Declaration) { + switch (blockScopeContainer.kind) { + case SyntaxKind.ModuleDeclaration: + declareModuleMember(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); + break; + case SyntaxKind.SourceFile: + if (isExternalModule(container)) { + declareModuleMember(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); + break; + } + default: + if (!blockScopeContainer.locals) { + blockScopeContainer.locals = {}; + } + declareSymbol(blockScopeContainer.locals, undefined, node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); + } + + bindChildren(node, SymbolFlags.BlockScopedVariable, /*isBlockScopeContainer*/ false); } function bind(node: Node) { node.parent = parent; switch (node.kind) { case SyntaxKind.TypeParameter: - bindDeclaration(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); + bindDeclaration(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.Parameter: - bindDeclaration(node, SymbolFlags.Variable, SymbolFlags.ParameterExcludes); + bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.VariableDeclaration: - bindDeclaration(node, SymbolFlags.Variable, SymbolFlags.VariableExcludes); + if (node.flags & NodeFlags.BlockScoped) { + bindBlockScopedVariableDeclaration(node); + } + else { + bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes, /*isBlockScopeContainer*/ false); + } break; case SyntaxKind.Property: case SyntaxKind.PropertyAssignment: - bindDeclaration(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + bindDeclaration(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.EnumMember: - bindDeclaration(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes); + bindDeclaration(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.CallSignature: - bindDeclaration(node, SymbolFlags.CallSignature, 0); + bindDeclaration(node, SymbolFlags.CallSignature, 0, /*isBlockScopeContainer*/ false); break; case SyntaxKind.Method: - bindDeclaration(node, SymbolFlags.Method, SymbolFlags.MethodExcludes); + bindDeclaration(node, SymbolFlags.Method, SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.ConstructSignature: - bindDeclaration(node, SymbolFlags.ConstructSignature, 0); + bindDeclaration(node, SymbolFlags.ConstructSignature, 0, /*isBlockScopeContainer*/ true); break; case SyntaxKind.IndexSignature: - bindDeclaration(node, SymbolFlags.IndexSignature, 0); + bindDeclaration(node, SymbolFlags.IndexSignature, 0, /*isBlockScopeContainer*/ false); break; case SyntaxKind.FunctionDeclaration: - bindDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes); + bindDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.Constructor: bindConstructorDeclaration(node); break; case SyntaxKind.GetAccessor: - bindDeclaration(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes); + bindDeclaration(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.SetAccessor: - bindDeclaration(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes); + bindDeclaration(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.TypeLiteral: - bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type"); + bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type", /*isBlockScopeContainer*/ false); break; case SyntaxKind.ObjectLiteral: - bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object"); + bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object", /*isBlockScopeContainer*/ false); break; case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - bindAnonymousDeclaration(node, SymbolFlags.Function, "__function"); + bindAnonymousDeclaration(node, SymbolFlags.Function, "__function", /*isBlockScopeContainer*/ true); break; case SyntaxKind.CatchBlock: bindCatchVariableDeclaration(node); break; case SyntaxKind.ClassDeclaration: - bindDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes); + bindDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.InterfaceDeclaration: - bindDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes); + bindDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.EnumDeclaration: - bindDeclaration(node, SymbolFlags.Enum, SymbolFlags.EnumExcludes); + bindDeclaration(node, SymbolFlags.Enum, SymbolFlags.EnumExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.ModuleDeclaration: bindModuleDeclaration(node); break; case SyntaxKind.ImportDeclaration: - bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes); + bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.SourceFile: if (isExternalModule(node)) { - bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((node).filename) + '"'); + bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((node).filename) + '"', /*isBlockScopeContainer*/ true); break; } + + case SyntaxKind.Block: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.SwitchStatement: + bindChildren(node, 0 , true); + break; + default: var saveParent = parent; parent = node; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8a240eae3c1..7a959c0dbfc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33,10 +33,16 @@ module ts { if (stringWriters.length == 0) { var str = ""; + var writeText: (text: string) => void = text => str += text; return { string: () => str, - writeKind: text => str += text, - writeSymbol: text => str += text, + writeKeyword: writeText, + writeOperator: writeText, + writePunctuation: writeText, + writeSpace: writeText, + writeStringLiteral: writeText, + writeParameter: writeText, + writeSymbol: writeText, // Completely ignore indentation for string writers. And map newlines to // a single space. @@ -88,12 +94,10 @@ module ts { getSymbolsInScope: getSymbolsInScope, getSymbolInfo: getSymbolInfo, getTypeOfNode: getTypeOfNode, - getApparentType: getApparentType, typeToString: typeToString, - writeType: writeType, + getSymbolDisplayBuilder: getSymbolDisplayBuilder, symbolToString: symbolToString, - writeSymbol: writeSymbol, - getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType, + getAugmentedPropertiesOfType: getAugmentedPropertiesOfType, getRootSymbols: getRootSymbols, getContextualType: getContextualType, getFullyQualifiedName: getFullyQualifiedName, @@ -101,13 +105,11 @@ module ts { getEnumMemberValue: getEnumMemberValue, isValidPropertyAccess: isValidPropertyAccess, getSignatureFromDeclaration: getSignatureFromDeclaration, - writeSignature: writeSignature, - writeTypeParameter: writeTypeParameter, - writeTypeParametersOfSymbol: writeTypeParametersOfSymbol, isImplementationOfOverload: isImplementationOfOverload, getAliasedSymbol: resolveImport, isUndefinedSymbol: symbol => symbol === undefinedSymbol, - isArgumentsSymbol: symbol => symbol === argumentsSymbol + isArgumentsSymbol: symbol => symbol === argumentsSymbol, + hasEarlyErrors: hasEarlyErrors }; var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined"); @@ -175,7 +177,8 @@ module ts { function getExcludedSymbolFlags(flags: SymbolFlags): SymbolFlags { var result: SymbolFlags = 0; - if (flags & SymbolFlags.Variable) result |= SymbolFlags.VariableExcludes; + if (flags & SymbolFlags.BlockScopedVariable) result |= SymbolFlags.BlockScopedVariableExcludes; + if (flags & SymbolFlags.FunctionScopedVariable) result |= SymbolFlags.FunctionScopedVariableExcludes; if (flags & SymbolFlags.Property) result |= SymbolFlags.PropertyExcludes; if (flags & SymbolFlags.EnumMember) result |= SymbolFlags.EnumMemberExcludes; if (flags & SymbolFlags.Function) result |= SymbolFlags.FunctionExcludes; @@ -225,8 +228,13 @@ module ts { recordMergedSymbol(target, source); } else { + var message = target.flags & SymbolFlags.BlockScopedVariable || source.flags & SymbolFlags.BlockScopedVariable + ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; forEach(source.declarations, node => { - error(node.name ? node.name : node, Diagnostics.Duplicate_identifier_0, symbolToString(source)); + error(node.name ? node.name : node, message, symbolToString(source)); + }); + forEach(target.declarations, node => { + error(node.name ? node.name : node, message, symbolToString(source)); }); } } @@ -317,6 +325,25 @@ module ts { if (!s && nameNotFoundMessage) { error(errorLocation, nameNotFoundMessage, nameArg); } + + if (s && s.flags & SymbolFlags.BlockScopedVariable) { + // Block-scoped variables can not be used before their definition + var declaration = forEach(s.declarations, d => d.flags & NodeFlags.BlockScoped ? d : undefined); + Debug.assert(declaration, "Block-scoped variable declaration is undefined"); + var declarationSourceFile = getSourceFileOfNode(declaration); + var referenceSourceFile = getSourceFileOfNode(errorLocation); + if (declarationSourceFile === referenceSourceFile) { + if (declaration.pos > errorLocation.pos) { + error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, identifierToString(declaration.name)); + } + } + else if (compilerOptions.out) { + var sourceFiles = program.getSourceFiles(); + if (sourceFiles.indexOf(referenceSourceFile) < sourceFiles.indexOf(declarationSourceFile)) { + error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, identifierToString(declaration.name)); + } + } + } return s; } @@ -609,6 +636,12 @@ module ts { } function symbolIsValue(symbol: Symbol): boolean { + // If it is an instantiated symbol, then it is a value if the symbol it is an + // instantiation of is a value. + if (symbol.flags & SymbolFlags.Instantiated) { + return symbolIsValue(getSymbolLinks(symbol).target); + } + // If the symbol has the value flag, it is trivially a value. if (symbol.flags & SymbolFlags.Value) { return true; @@ -619,12 +652,6 @@ module ts { return (resolveImport(symbol).flags & SymbolFlags.Value) !== 0; } - // If it is an instantiated symbol, then it is a value if the symbol it is an - // instantiation of is a value. - if (symbol.flags & SymbolFlags.Instantiated) { - return (getSymbolLinks(symbol).target.flags & SymbolFlags.Value) !== 0; - } - return false; } @@ -677,17 +704,17 @@ module ts { return result || emptyArray; } - function setObjectTypeMembers(type: ObjectType, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedObjectType { - (type).members = members; - (type).properties = getNamedMembers(members); - (type).callSignatures = callSignatures; - (type).constructSignatures = constructSignatures; - if (stringIndexType) (type).stringIndexType = stringIndexType; - if (numberIndexType) (type).numberIndexType = numberIndexType; - return type; + function setObjectTypeMembers(type: ObjectType, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedType { + (type).members = members; + (type).properties = getNamedMembers(members); + (type).callSignatures = callSignatures; + (type).constructSignatures = constructSignatures; + if (stringIndexType) (type).stringIndexType = stringIndexType; + if (numberIndexType) (type).numberIndexType = numberIndexType; + return type; } - function createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedObjectType { + function createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedType { return setObjectTypeMembers(createObjectType(TypeFlags.Anonymous, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } @@ -948,24 +975,24 @@ module ts { } function writeKeyword(writer: SymbolWriter, kind: SyntaxKind) { - writer.writeKind(tokenToString(kind), SymbolDisplayPartKind.keyword); + writer.writeKeyword(tokenToString(kind)); } function writePunctuation(writer: SymbolWriter, kind: SyntaxKind) { - writer.writeKind(tokenToString(kind), SymbolDisplayPartKind.punctuation); + writer.writePunctuation(tokenToString(kind)); } function writeOperator(writer: SymbolWriter, kind: SyntaxKind) { - writer.writeKind(tokenToString(kind), SymbolDisplayPartKind.operator); + writer.writeOperator(tokenToString(kind)); } function writeSpace(writer: SymbolWriter) { - writer.writeKind(" ", SymbolDisplayPartKind.space); + writer.writeSpace(" "); } function symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string { var writer = getSingleLineStringWriter(); - writeSymbol(symbol, writer, enclosingDeclaration, meaning); + getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning); var result = writer.string(); releaseStringWriter(writer); @@ -973,93 +1000,9 @@ module ts { return result; } - // Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope - // Meaning needs to be specified if the enclosing declaration is given - function writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void { - var parentSymbol: Symbol; - function writeSymbolName(symbol: Symbol): void { - if (parentSymbol) { - // Write type arguments of instantiated class/interface here - if (flags & SymbolFormatFlags.WriteTypeParametersOrArguments) { - if (symbol.flags & SymbolFlags.Instantiated) { - writeTypeArguments(getTypeParametersOfClassOrInterface(parentSymbol), - (symbol).mapper, writer, enclosingDeclaration); - } - else { - writeTypeParametersOfSymbol(parentSymbol, writer, enclosingDeclaration); - } - } - writePunctuation(writer, SyntaxKind.DotToken); - } - parentSymbol = symbol; - if (symbol.declarations && symbol.declarations.length > 0) { - var declaration = symbol.declarations[0]; - if (declaration.name) { - writer.writeSymbol(identifierToString(declaration.name), symbol); - return; - } - } - - writer.writeSymbol(symbol.name, symbol); - } - - // Let the writer know we just wrote out a symbol. The declaration emitter writer uses - // this to determine if an import it has previously seen (and not written out) needs - // to be written to the file once the walk of the tree is complete. - // - // NOTE(cyrusn): This approach feels somewhat unfortunate. A simple pass over the tree - // up front (for example, during checking) could determine if we need to emit the imports - // and we could then access that data during declaration emit. - writer.trackSymbol(symbol, enclosingDeclaration, meaning); - function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void { - if (symbol) { - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing)); - - if (!accessibleSymbolChain || - needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { - - // Go up and add our parent. - walkSymbol( - getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), - getQualifiedLeftMeaning(meaning)); - } - - if (accessibleSymbolChain) { - for (var i = 0, n = accessibleSymbolChain.length; i < n; i++) { - writeSymbolName(accessibleSymbolChain[i]); - } - } - else { - // If we didn't find accessible symbol chain for this symbol, break if this is external module - if (!parentSymbol && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) { - return; - } - - // if this is anonymous type break - if (symbol.flags & SymbolFlags.TypeLiteral || symbol.flags & SymbolFlags.ObjectLiteral) { - return; - } - - writeSymbolName(symbol); - } - } - } - - // Get qualified name - if (enclosingDeclaration && - // TypeParameters do not need qualification - !(symbol.flags & SymbolFlags.TypeParameter)) { - - walkSymbol(symbol, meaning); - return; - } - - return writeSymbolName(symbol); - } - function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string { var writer = getSingleLineStringWriter(); - writeType(type, writer, enclosingDeclaration, flags); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); var result = writer.string(); releaseStringWriter(writer); @@ -1072,316 +1015,453 @@ module ts { return result; } - function writeType(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { - return writeType(type, flags | TypeFormatFlags.WriteArrowStyleSignature); - - function writeType(type: Type, flags: TypeFormatFlags) { - // Write undefined/null type as any - if (type.flags & TypeFlags.Intrinsic) { - // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving - writer.writeKind(!(flags & TypeFormatFlags.WriteOwnNameForAnyLike) && - (type.flags & TypeFlags.Any) ? "any" : (type).intrinsicName, SymbolDisplayPartKind.keyword); - } - else if (type.flags & TypeFlags.Reference) { - writeTypeReference(type); - } - else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { - writeSymbol(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type); - } - else if (type.flags & TypeFlags.Tuple) { - writeTupleType(type); - } - else if (type.flags & TypeFlags.Union) { - writeUnionType(type); - } - else if (type.flags & TypeFlags.Anonymous) { - writeAnonymousType(type, flags); - } - else if (type.flags & TypeFlags.StringLiteral) { - writer.writeKind((type).text, SymbolDisplayPartKind.stringLiteral); - } - else { - // Should never get here - // { ... } - writePunctuation(writer, SyntaxKind.OpenBraceToken); - writeSpace(writer); - writePunctuation(writer, SyntaxKind.DotDotDotToken); - writeSpace(writer); - writePunctuation(writer, SyntaxKind.CloseBraceToken); - } - } - - function writeTypeList(types: Type[], union: boolean) { - for (var i = 0; i < types.length; i++) { - if (i > 0) { - if (union) { - writeSpace(writer); - } - writePunctuation(writer, union ? SyntaxKind.BarToken : SyntaxKind.CommaToken); - writeSpace(writer); - } - // Don't output function type literals in unions because '() => string | () => number' would be parsed - // as a function type that returns a union type. Instead output '{ (): string; } | { (): number; }'. - writeType(types[i], union ? flags & ~TypeFormatFlags.WriteArrowStyleSignature : flags | TypeFormatFlags.WriteArrowStyleSignature); - } - } - - function writeTypeReference(type: TypeReference) { - if (type.target === globalArrayType && !(flags & TypeFormatFlags.WriteArrayAsGenericType) && !(type.typeArguments[0].flags & TypeFlags.Union)) { - // If we are writing array element type the arrow style signatures are not allowed as - // we need to surround it by curlies, e.g. { (): T; }[]; as () => T[] would mean something different - writeType(type.typeArguments[0], flags & ~TypeFormatFlags.WriteArrowStyleSignature); - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - } - else { - writeSymbol(type.target.symbol, writer, enclosingDeclaration, SymbolFlags.Type); - writePunctuation(writer, SyntaxKind.LessThanToken); - writeTypeList(type.typeArguments, /*union*/ false); - writePunctuation(writer, SyntaxKind.GreaterThanToken); - } - } - - function writeTupleType(type: TupleType) { - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writeTypeList(type.elementTypes, /*union*/ false); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - } - - function writeUnionType(type: UnionType) { - writeTypeList(type.types, /*union*/ true); - } - - function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) { - // Always use 'typeof T' for type of class, enum, and module objects - if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { - writeTypeofSymbol(type); - } - // Use 'typeof T' for types of functions and methods that circularly reference themselves - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type); - } - else if (typeStack && contains(typeStack, type)) { - // Recursive usage, use any - writeKeyword(writer, SyntaxKind.AnyKeyword); - } - else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); - writeLiteralType(type, flags); - typeStack.pop(); - } - - function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & SymbolFlags.Method && // typeof static method - ts.forEach(type.symbol.declarations, declaration => declaration.flags & NodeFlags.Static)); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & SymbolFlags.Function) && - (type.symbol.parent || // is exported function symbol - ts.forEach(type.symbol.declarations, declaration => - declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); - - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - // typeof is allowed only for static/non local functions - return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it - (typeStack && contains(typeStack, type)); // it is type of the symbol uses itself recursively - } - } - } - } - - function writeTypeofSymbol(type: ObjectType) { - writeKeyword(writer, SyntaxKind.TypeOfKeyword); - writeSpace(writer); - writeSymbol(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value); - } - - function writeLiteralType(type: ObjectType, flags: TypeFormatFlags) { - var resolved = resolveObjectTypeMembers(type); - if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { - if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { - writePunctuation(writer, SyntaxKind.OpenBraceToken); - writePunctuation(writer, SyntaxKind.CloseBraceToken); + // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. + var _displayBuilder: SymbolDisplayBuilder; + function getSymbolDisplayBuilder(): SymbolDisplayBuilder { + /** + * Writes only the name of the symbol out to the writer. Uses the original source text + * for the name of the symbol if it is available to match how the user inputted the name. + */ + function appendSymbolNameOnly(symbol: Symbol, writer: SymbolWriter): void { + if (symbol.declarations && symbol.declarations.length > 0) { + var declaration = symbol.declarations[0]; + if (declaration.name) { + writer.writeSymbol(identifierToString(declaration.name), symbol); return; } + } + + writer.writeSymbol(symbol.name, symbol); + } + + /** + * Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope + * Meaning needs to be specified if the enclosing declaration is given + */ + function buildSymbolDisplay(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void { + var parentSymbol: Symbol; + function appendParentTypeArgumentsAndSymbolName(symbol: Symbol): void { + if (parentSymbol) { + // Write type arguments of instantiated class/interface here + if (flags & SymbolFormatFlags.WriteTypeParametersOrArguments) { + if (symbol.flags & SymbolFlags.Instantiated) { + buildDisplayForTypeArgumentsAndDelimiters(getTypeParametersOfClassOrInterface(parentSymbol), + (symbol).mapper, writer, enclosingDeclaration); + } + else { + buildTypeParameterDisplayFromSymbol(parentSymbol, writer, enclosingDeclaration); + } + } + writePunctuation(writer, SyntaxKind.DotToken); + } + parentSymbol = symbol; + appendSymbolNameOnly(symbol, writer); + } + + // Let the writer know we just wrote out a symbol. The declaration emitter writer uses + // this to determine if an import it has previously seen (and not written out) needs + // to be written to the file once the walk of the tree is complete. + // + // NOTE(cyrusn): This approach feels somewhat unfortunate. A simple pass over the tree + // up front (for example, during checking) could determine if we need to emit the imports + // and we could then access that data during declaration emit. + writer.trackSymbol(symbol, enclosingDeclaration, meaning); + function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void { + if (symbol) { + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing)); + + if (!accessibleSymbolChain || + needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { + + // Go up and add our parent. + walkSymbol( + getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), + getQualifiedLeftMeaning(meaning)); + } + + if (accessibleSymbolChain) { + for (var i = 0, n = accessibleSymbolChain.length; i < n; i++) { + appendParentTypeArgumentsAndSymbolName(accessibleSymbolChain[i]); + } + } + else { + // If we didn't find accessible symbol chain for this symbol, break if this is external module + if (!parentSymbol && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) { + return; + } + + // if this is anonymous type break + if (symbol.flags & SymbolFlags.TypeLiteral || symbol.flags & SymbolFlags.ObjectLiteral) { + return; + } + + appendParentTypeArgumentsAndSymbolName(symbol); + } + } + } + + // Get qualified name + if (enclosingDeclaration && + // TypeParameters do not need qualification + !(symbol.flags & SymbolFlags.TypeParameter)) { + + walkSymbol(symbol, meaning); + return; + } + + return appendParentTypeArgumentsAndSymbolName(symbol); + } + + function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, typeStack?: Type[]) { + var globalFlagsToPass = globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike; + return writeType(type, globalFlags); + + function writeType(type: Type, flags: TypeFormatFlags) { + // Write undefined/null type as any + if (type.flags & TypeFlags.Intrinsic) { + // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving + writer.writeKeyword(!(globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike) && + (type.flags & TypeFlags.Any) ? "any" : (type).intrinsicName); + } + else if (type.flags & TypeFlags.Reference) { + writeTypeReference(type, flags); + } + else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type); + } + else if (type.flags & TypeFlags.Tuple) { + writeTupleType(type); + } + else if (type.flags & TypeFlags.Union) { + writeUnionType(type, flags); + } + else if (type.flags & TypeFlags.Anonymous) { + writeAnonymousType(type, flags); + } + else if (type.flags & TypeFlags.StringLiteral) { + writer.writeStringLiteral((type).text); + } + else { + // Should never get here + // { ... } + writePunctuation(writer, SyntaxKind.OpenBraceToken); + writeSpace(writer); + writePunctuation(writer, SyntaxKind.DotDotDotToken); + writeSpace(writer); + writePunctuation(writer, SyntaxKind.CloseBraceToken); + } + } + + function writeTypeList(types: Type[], union: boolean) { + for (var i = 0; i < types.length; i++) { + if (i > 0) { + if (union) { + writeSpace(writer); + } + writePunctuation(writer, union ? SyntaxKind.BarToken : SyntaxKind.CommaToken); + writeSpace(writer); + } + writeType(types[i], union ? TypeFormatFlags.InElementType : TypeFormatFlags.None); + } + } + + function writeTypeReference(type: TypeReference, flags: TypeFormatFlags) { + if (type.target === globalArrayType && !(flags & TypeFormatFlags.WriteArrayAsGenericType)) { + writeType(type.typeArguments[0], TypeFormatFlags.InElementType); + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + } + else { + buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, SymbolFlags.Type); + writePunctuation(writer, SyntaxKind.LessThanToken); + writeTypeList(type.typeArguments, /*union*/ false); + writePunctuation(writer, SyntaxKind.GreaterThanToken); + } + } + + function writeTupleType(type: TupleType) { + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writeTypeList(type.elementTypes, /*union*/ false); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + } + + function writeUnionType(type: UnionType, flags: TypeFormatFlags) { + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.OpenParenToken); + } + writeTypeList(type.types, /*union*/ true); + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.CloseParenToken); + } + } + + function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) { + // Always use 'typeof T' for type of class, enum, and module objects + if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { + writeTypeofSymbol(type); + } + // Use 'typeof T' for types of functions and methods that circularly reference themselves + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type); + } + else if (typeStack && contains(typeStack, type)) { + // Recursive usage, use any + writeKeyword(writer, SyntaxKind.AnyKeyword); + } + else { + if (!typeStack) { + typeStack = []; + } + typeStack.push(type); + writeLiteralType(type, flags); + typeStack.pop(); + } + + function shouldWriteTypeOfFunctionSymbol() { + if (type.symbol) { + var isStaticMethodSymbol = !!(type.symbol.flags & SymbolFlags.Method && // typeof static method + ts.forEach(type.symbol.declarations, declaration => declaration.flags & NodeFlags.Static)); + var isNonLocalFunctionSymbol = !!(type.symbol.flags & SymbolFlags.Function) && + (type.symbol.parent || // is exported function symbol + ts.forEach(type.symbol.declarations, declaration => + declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); + + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + // typeof is allowed only for static/non local functions + return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it + (typeStack && contains(typeStack, type)); // it is type of the symbol uses itself recursively + } + } + } + } + + function writeTypeofSymbol(type: ObjectType) { + writeKeyword(writer, SyntaxKind.TypeOfKeyword); + writeSpace(writer); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value); + } + + function writeLiteralType(type: ObjectType, flags: TypeFormatFlags) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { + if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { + writePunctuation(writer, SyntaxKind.OpenBraceToken); + writePunctuation(writer, SyntaxKind.CloseBraceToken); + return; + } - if (flags & TypeFormatFlags.WriteArrowStyleSignature) { if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) { - writeSignature(resolved.callSignatures[0], writer, enclosingDeclaration, flags, typeStack); + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.OpenParenToken); + } + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature , typeStack); + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.CloseParenToken); + } return; } if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) { + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.OpenParenToken); + } writeKeyword(writer, SyntaxKind.NewKeyword); writeSpace(writer); - writeSignature(resolved.constructSignatures[0], writer, enclosingDeclaration, flags, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, typeStack); + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.CloseParenToken); + } return; } } - } - writePunctuation(writer, SyntaxKind.OpenBraceToken); - writer.writeLine(); - writer.increaseIndent(); - for (var i = 0; i < resolved.callSignatures.length; i++) { - writeSignature(resolved.callSignatures[i], writer, enclosingDeclaration, flags & ~TypeFormatFlags.WriteArrowStyleSignature, typeStack); - writePunctuation(writer, SyntaxKind.SemicolonToken); + writePunctuation(writer, SyntaxKind.OpenBraceToken); writer.writeLine(); - } - for (var i = 0; i < resolved.constructSignatures.length; i++) { - writeKeyword(writer, SyntaxKind.NewKeyword); - writeSpace(writer); + writer.increaseIndent(); + for (var i = 0; i < resolved.callSignatures.length; i++) { + buildSignatureDisplay(resolved.callSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + for (var i = 0; i < resolved.constructSignatures.length; i++) { + writeKeyword(writer, SyntaxKind.NewKeyword); + writeSpace(writer); - writeSignature(resolved.constructSignatures[i], writer, enclosingDeclaration, flags & ~TypeFormatFlags.WriteArrowStyleSignature, typeStack); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } - if (resolved.stringIndexType) { - // [x: string]: - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writer.writeKind("x", SymbolDisplayPartKind.parameterName); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeKeyword(writer, SyntaxKind.StringKeyword); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeType(resolved.stringIndexType, flags | TypeFormatFlags.WriteArrowStyleSignature); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } - if (resolved.numberIndexType) { - // [x: number]: - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writer.writeKind("x", SymbolDisplayPartKind.parameterName); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeKeyword(writer, SyntaxKind.NumberKeyword); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeType(resolved.numberIndexType, flags | TypeFormatFlags.WriteArrowStyleSignature); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } - for (var i = 0; i < resolved.properties.length; i++) { - var p = resolved.properties[i]; - var t = getTypeOfSymbol(p); - if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfType(t).length) { - var signatures = getSignaturesOfType(t, SignatureKind.Call); - for (var j = 0; j < signatures.length; j++) { - writeSymbol(p, writer); + buildSignatureDisplay(resolved.constructSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + if (resolved.stringIndexType) { + // [x: string]: + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writer.writeParameter("x"); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeKeyword(writer, SyntaxKind.StringKeyword); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeType(resolved.stringIndexType, TypeFormatFlags.None); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + if (resolved.numberIndexType) { + // [x: number]: + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writer.writeParameter("x"); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeKeyword(writer, SyntaxKind.NumberKeyword); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeType(resolved.numberIndexType, TypeFormatFlags.None); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + for (var i = 0; i < resolved.properties.length; i++) { + var p = resolved.properties[i]; + var t = getTypeOfSymbol(p); + if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) { + var signatures = getSignaturesOfType(t, SignatureKind.Call); + for (var j = 0; j < signatures.length; j++) { + buildSymbolDisplay(p, writer); + if (isOptionalProperty(p)) { + writePunctuation(writer, SyntaxKind.QuestionToken); + } + buildSignatureDisplay(signatures[j], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + } + else { + buildSymbolDisplay(p, writer); if (isOptionalProperty(p)) { writePunctuation(writer, SyntaxKind.QuestionToken); } - writeSignature(signatures[j], writer, enclosingDeclaration, flags & ~TypeFormatFlags.WriteArrowStyleSignature, typeStack); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeType(t, TypeFormatFlags.None); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } } - else { - writeSymbol(p, writer); - if (isOptionalProperty(p)) { - writePunctuation(writer, SyntaxKind.QuestionToken); - } - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeType(t, flags | TypeFormatFlags.WriteArrowStyleSignature); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } + writer.decreaseIndent(); + writePunctuation(writer, SyntaxKind.CloseBraceToken); } - writer.decreaseIndent(); - writePunctuation(writer, SyntaxKind.CloseBraceToken); } - } - function writeTypeParameter(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { - writeSymbol(tp.symbol, writer); - var constraint = getConstraintOfTypeParameter(tp); - if (constraint) { - writeSpace(writer); - writeKeyword(writer, SyntaxKind.ExtendsKeyword); - writeSpace(writer); - writeType(constraint, writer, enclosingDeclaration, flags, typeStack); - } - } - - function writeTypeParameters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { - if (typeParameters && typeParameters.length) { - writePunctuation(writer, SyntaxKind.LessThanToken); - for (var i = 0; i < typeParameters.length; i++) { - if (i > 0) { - writePunctuation(writer, SyntaxKind.CommaToken); - writeSpace(writer); - } - writeTypeParameter(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + function buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags) { + var targetSymbol = getTargetSymbol(symbol); + if (targetSymbol.flags & SymbolFlags.Class || targetSymbol.flags & SymbolFlags.Interface) { + buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } - writePunctuation(writer, SyntaxKind.GreaterThanToken); } - } - function writeTypeArguments(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { - if (typeParameters && typeParameters.length) { - writePunctuation(writer, SyntaxKind.LessThanToken); - for (var i = 0; i < typeParameters.length; i++) { - if (i > 0) { - writePunctuation(writer, SyntaxKind.CommaToken); - writeSpace(writer); - } - writeType(mapper(typeParameters[i]), writer, enclosingDeclaration, TypeFormatFlags.WriteArrowStyleSignature); - } - writePunctuation(writer, SyntaxKind.GreaterThanToken); - } - } - - function writeTypeParametersOfSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags) { - var rootSymbol = getRootSymbol(symbol); - if (rootSymbol.flags & SymbolFlags.Class || rootSymbol.flags & SymbolFlags.Interface) { - writeTypeParameters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); - } - } - - function writeSignature(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { - if (signature.target && (flags & TypeFormatFlags.WriteTypeArgumentsOfSignature)) { - // Instantiated signature, write type arguments instead - writeTypeArguments(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); - } - else { - writeTypeParameters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); - } - writePunctuation(writer, SyntaxKind.OpenParenToken); - for (var i = 0; i < signature.parameters.length; i++) { - if (i > 0) { - writePunctuation(writer, SyntaxKind.CommaToken); + function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + appendSymbolNameOnly(tp.symbol, writer); + var constraint = getConstraintOfTypeParameter(tp); + if (constraint) { writeSpace(writer); + writeKeyword(writer, SyntaxKind.ExtendsKeyword); + writeSpace(writer); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); } - var p = signature.parameters[i]; + } + + function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { if (getDeclarationFlagsFromSymbol(p) & NodeFlags.Rest) { writePunctuation(writer, SyntaxKind.DotDotDotToken); } - writeSymbol(p, writer); + appendSymbolNameOnly(p, writer); if (p.valueDeclaration.flags & NodeFlags.QuestionMark || (p.valueDeclaration).initializer) { writePunctuation(writer, SyntaxKind.QuestionToken); } writePunctuation(writer, SyntaxKind.ColonToken); writeSpace(writer); - writeType(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); } - writePunctuation(writer, SyntaxKind.CloseParenToken); - if (flags & TypeFormatFlags.WriteArrowStyleSignature) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, SyntaxKind.LessThanToken); + for (var i = 0; i < typeParameters.length; i++) { + if (i > 0) { + writePunctuation(writer, SyntaxKind.CommaToken); + writeSpace(writer); + } + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + } + writePunctuation(writer, SyntaxKind.GreaterThanToken); + } + } + + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, SyntaxKind.LessThanToken); + for (var i = 0; i < typeParameters.length; i++) { + if (i > 0) { + writePunctuation(writer, SyntaxKind.CommaToken); + writeSpace(writer); + } + buildTypeDisplay(mapper(typeParameters[i]), writer, enclosingDeclaration, TypeFormatFlags.None); + } + writePunctuation(writer, SyntaxKind.GreaterThanToken); + } + } + + function buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + writePunctuation(writer, SyntaxKind.OpenParenToken); + for (var i = 0; i < parameters.length; i++) { + if (i > 0) { + writePunctuation(writer, SyntaxKind.CommaToken); + writeSpace(writer); + } + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + } + writePunctuation(writer, SyntaxKind.CloseParenToken); + } + + function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + if (flags & TypeFormatFlags.WriteArrowStyleSignature) { + writeSpace(writer); + writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken); + } + else { + writePunctuation(writer, SyntaxKind.ColonToken); + } writeSpace(writer); - writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); } - else { - writePunctuation(writer, SyntaxKind.ColonToken); - } - writeSpace(writer); + + function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + if (signature.target && (flags & TypeFormatFlags.WriteTypeArgumentsOfSignature)) { + // Instantiated signature, write type arguments instead + // This is achieved by passing in the mapper separately + buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); + } + else { + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + } - writeType(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + } + + return _displayBuilder || (_displayBuilder = { + symbolToString: symbolToString, + typeToString: typeToString, + buildSymbolDisplay: buildSymbolDisplay, + buildTypeDisplay: buildTypeDisplay, + buildTypeParameterDisplay: buildTypeParameterDisplay, + buildParameterDisplay: buildParameterDisplay, + buildDisplayForParametersAndDelimiters: buildDisplayForParametersAndDelimiters, + buildDisplayForTypeParametersAndDelimiters: buildDisplayForTypeParametersAndDelimiters, + buildDisplayForTypeArgumentsAndDelimiters: buildDisplayForTypeArgumentsAndDelimiters, + buildTypeParameterDisplayFromSymbol: buildTypeParameterDisplayFromSymbol, + buildSignatureDisplay: buildSignatureDisplay, + buildReturnTypeDisplay: buildReturnTypeDisplay + }); } function isDeclarationVisible(node: Declaration): boolean { @@ -1497,25 +1577,6 @@ module ts { } } - function getApparentType(type: Type): ApparentType { - if (type.flags & TypeFlags.TypeParameter) { - do { - type = getConstraintOfTypeParameter(type); - } while (type && type.flags & TypeFlags.TypeParameter); - if (!type) type = emptyObjectType; - } - if (type.flags & TypeFlags.StringLike) { - type = globalStringType; - } - else if (type.flags & TypeFlags.NumberLike) { - type = globalNumberType; - } - else if (type.flags & TypeFlags.Boolean) { - type = globalBooleanType; - } - return type; - } - function getTypeOfPrototypeProperty(prototype: Symbol): Type { // TypeScript 1.0 spec (April 2014): 8.4 // Every class automatically contains a static property member named 'prototype', @@ -1731,16 +1792,10 @@ module ts { return links.type; } - function getTypeOfUnionProperty(symbol: Symbol): Type { - var links = getSymbolLinks(symbol); - if (!links.type) { - var types = map(links.unionType.types, t => getTypeOfSymbol(getPropertyOfType(getApparentType(t), symbol.name))); - links.type = getUnionType(types); - } - return links.type; - } - function getTypeOfSymbol(symbol: Symbol): Type { + if (symbol.flags & SymbolFlags.Instantiated) { + return getTypeOfInstantiatedSymbol(symbol); + } if (symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) { return getTypeOfVariableOrParameterOrProperty(symbol); } @@ -1756,12 +1811,6 @@ module ts { if (symbol.flags & SymbolFlags.Import) { return getTypeOfImport(symbol); } - if (symbol.flags & SymbolFlags.Instantiated) { - return getTypeOfInstantiatedSymbol(symbol); - } - if (symbol.flags & SymbolFlags.UnionProperty) { - return getTypeOfUnionProperty(symbol); - } return unknownType; } @@ -1916,6 +1965,7 @@ module ts { } function getDeclaredTypeOfSymbol(symbol: Symbol): Type { + Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0); if (symbol.flags & SymbolFlags.Class) { return getDeclaredTypeOfClass(symbol); } @@ -1931,7 +1981,6 @@ module ts { if (symbol.flags & SymbolFlags.Import) { return getDeclaredTypeOfImport(symbol); } - Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0); return unknownType; } @@ -1979,7 +2028,7 @@ module ts { if (type.baseTypes.length) { members = createSymbolTable(type.declaredProperties); forEach(type.baseTypes, baseType => { - addInheritedMembers(members, getPropertiesOfType(baseType)); + addInheritedMembers(members, getPropertiesOfObjectType(baseType)); callSignatures = concatenate(callSignatures, getSignaturesOfType(baseType, SignatureKind.Call)); constructSignatures = concatenate(constructSignatures, getSignaturesOfType(baseType, SignatureKind.Construct)); stringIndexType = stringIndexType || getIndexTypeOfType(baseType, IndexKind.String); @@ -1999,7 +2048,7 @@ module ts { var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined; forEach(target.baseTypes, baseType => { var instantiatedBaseType = instantiateType(baseType, mapper); - addInheritedMembers(members, getPropertiesOfType(instantiatedBaseType)); + addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); callSignatures = concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Call)); constructSignatures = concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Construct)); stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, IndexKind.String); @@ -2052,7 +2101,7 @@ module ts { } function resolveTupleTypeMembers(type: TupleType) { - var arrayType = resolveObjectTypeMembers(createArrayType(getUnionType(type.elementTypes))); + var arrayType = resolveObjectOrUnionTypeMembers(createArrayType(getUnionType(type.elementTypes))); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); @@ -2109,42 +2158,13 @@ module ts { } function resolveUnionTypeMembers(type: UnionType) { - var types: Type[] = []; - forEach(type.types, t => { - var apparentType = getApparentType(t); - if (!contains(types, apparentType)) { - types.push(apparentType); - } - }); - if (types.length <= 1) { - var resolved = types.length ? resolveObjectTypeMembers(types[0]) : emptyObjectType; - setObjectTypeMembers(type, resolved.members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexType, resolved.numberIndexType); - return; - } - var members: SymbolTable = {}; - forEach(getPropertiesOfType(types[0]), prop => { - for (var i = 1; i < types.length; i++) { - if (!getPropertyOfType(types[i], prop.name)) { - return; - } - } - var symbol = createSymbol(SymbolFlags.UnionProperty | SymbolFlags.Transient, prop.name); - symbol.unionType = type; - - symbol.declarations = []; - for (var i = 0; i < types.length; i++) { - var s = getPropertyOfType(types[i], prop.name); - if (s.declarations) - symbol.declarations.push.apply(symbol.declarations, s.declarations); - } - - members[prop.name] = symbol; - }); - var callSignatures = getUnionSignatures(types, SignatureKind.Call); - var constructSignatures = getUnionSignatures(types, SignatureKind.Construct); - var stringIndexType = getUnionIndexType(types, IndexKind.String); - var numberIndexType = getUnionIndexType(types, IndexKind.Number); - setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + // The members and properties collections are empty for union types. To get all properties of a union + // type use getPropertiesOfType (only the language service uses this). + var callSignatures = getUnionSignatures(type.types, SignatureKind.Call); + var constructSignatures = getUnionSignatures(type.types, SignatureKind.Construct); + var stringIndexType = getUnionIndexType(type.types, IndexKind.String); + var numberIndexType = getUnionIndexType(type.types, IndexKind.Number); + setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); } function resolveAnonymousTypeMembers(type: ObjectType) { @@ -2175,7 +2195,7 @@ module ts { } if (classType.baseTypes.length) { members = createSymbolTable(getNamedMembers(members)); - addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); + addInheritedMembers(members, getPropertiesOfObjectType(getTypeOfSymbol(classType.baseTypes[0].symbol))); } } var stringIndexType: Type = undefined; @@ -2184,8 +2204,8 @@ module ts { setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } - function resolveObjectTypeMembers(type: ObjectType): ResolvedObjectType { - if (!(type).members) { + function resolveObjectOrUnionTypeMembers(type: ObjectType): ResolvedType { + if (!(type).members) { if (type.flags & (TypeFlags.Class | TypeFlags.Interface)) { resolveClassOrInterfaceMembers(type); } @@ -2202,60 +2222,173 @@ module ts { resolveTypeReferenceMembers(type); } } - return type; + return type; } - function getPropertiesOfType(type: Type): Symbol[] { + // Return properties of an object type or an empty array for other types + function getPropertiesOfObjectType(type: Type): Symbol[] { if (type.flags & TypeFlags.ObjectType) { - return resolveObjectTypeMembers(type).properties; + return resolveObjectOrUnionTypeMembers(type).properties; } return emptyArray; } + // If the given type is an object type and that type has a property by the given name, return + // the symbol for that property. Otherwise return undefined. + function getPropertyOfObjectType(type: Type, name: string): Symbol { + if (type.flags & TypeFlags.ObjectType) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; + } + } + } + } + + function getPropertiesOfUnionType(type: UnionType): Symbol[] { + var result: Symbol[] = []; + forEach(getPropertiesOfType(type.types[0]), prop => { + var unionProp = getPropertyOfUnionType(type, prop.name); + if (unionProp) { + result.push(unionProp); + } + }); + return result; + } + + function getPropertiesOfType(type: Type): Symbol[] { + if (type.flags & TypeFlags.Union) { + return getPropertiesOfUnionType(type); + } + return getPropertiesOfObjectType(getApparentType(type)); + } + + // For a type parameter, return the base constraint of the type parameter. For the string, number, and + // boolean primitive types, return the corresponding object types.Otherwise return the type itself. + // Note that the apparent type of a union type is the union type itself. + function getApparentType(type: Type): Type { + if (type.flags & TypeFlags.TypeParameter) { + do { + type = getConstraintOfTypeParameter(type); + } while (type && type.flags & TypeFlags.TypeParameter); + if (!type) { + type = emptyObjectType; + } + } + if (type.flags & TypeFlags.StringLike) { + type = globalStringType; + } + else if (type.flags & TypeFlags.NumberLike) { + type = globalNumberType; + } + else if (type.flags & TypeFlags.Boolean) { + type = globalBooleanType; + } + return type; + } + + function createUnionProperty(unionType: UnionType, name: string): Symbol { + var types = unionType.types; + var props: Symbol[]; + for (var i = 0; i < types.length; i++) { + var type = getApparentType(types[i]); + if (type !== unknownType) { + var prop = getPropertyOfType(type, name); + if (!prop) { + return undefined; + } + if (!props) { + props = [prop]; + } + else { + props.push(prop); + } + } + } + var propTypes: Type[] = []; + var declarations: Declaration[] = []; + for (var i = 0; i < props.length; i++) { + var prop = props[i]; + if (prop.declarations) { + declarations.push.apply(declarations, prop.declarations); + } + propTypes.push(getTypeOfSymbol(prop)); + } + var result = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | SymbolFlags.UnionProperty, name); + result.unionType = unionType; + result.declarations = declarations; + result.type = getUnionType(propTypes); + return result; + } + + function getPropertyOfUnionType(type: UnionType, name: string): Symbol { + var properties = type.resolvedProperties || (type.resolvedProperties = {}); + if (hasProperty(properties, name)) { + return properties[name]; + } + var property = createUnionProperty(type, name); + if (property) { + properties[name] = property; + } + return property; + } + + // Return the symbol for the property with the given name in the given type. Creates synthetic union properties when + // necessary, maps primtive types and type parameters are to their apparent types, and augments with properties from + // Object and Function as appropriate. function getPropertyOfType(type: Type, name: string): Symbol { - if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + if (type.flags & TypeFlags.Union) { + return getPropertyOfUnionType(type, name); + } + if (!(type.flags & TypeFlags.ObjectType)) { + type = getApparentType(type); + if (!(type.flags & TypeFlags.ObjectType)) { + return undefined; } } - } - - function getPropertyOfApparentType(type: ApparentType, name: string): Symbol { - if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + var resolved = resolveObjectOrUnionTypeMembers(type); + if (hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; } - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - var symbol = getPropertyOfType(globalFunctionType, name); - if (symbol) return symbol; - } - return getPropertyOfType(globalObjectType, name); } + if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { + var symbol = getPropertyOfObjectType(globalFunctionType, name); + if (symbol) return symbol; + } + return getPropertyOfObjectType(globalObjectType, name); } - function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] { - if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + function getSignaturesOfObjectOrUnionType(type: Type, kind: SignatureKind): Signature[] { + if (type.flags & (TypeFlags.ObjectType | TypeFlags.Union)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === SignatureKind.Call ? resolved.callSignatures : resolved.constructSignatures; } return emptyArray; } - function getIndexTypeOfType(type: Type, kind: IndexKind): Type { - if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + // Return the signatures of the given kind in the given type. Creates synthetic union signatures when necessary and + // maps primtive types and type parameters are to their apparent types. + function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] { + return getSignaturesOfObjectOrUnionType(getApparentType(type), kind); + } + + function getIndexTypeOfObjectOrUnionType(type: Type, kind: IndexKind): Type { + if (type.flags & (TypeFlags.ObjectType | TypeFlags.Union)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === IndexKind.String ? resolved.stringIndexType : resolved.numberIndexType; } } + // Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and + // maps primtive types and type parameters are to their apparent types. + function getIndexTypeOfType(type: Type, kind: IndexKind): Type { + return getIndexTypeOfObjectOrUnionType(getApparentType(type), kind); + } + // Return list of type parameters with duplicates removed (duplicate identifier errors are generated in the actual // type checking functions). function getTypeParametersFromDeclaration(typeParameterDeclarations: TypeParameterDeclaration[]): TypeParameter[] { @@ -2417,7 +2550,7 @@ module ts { // will result in a different declaration kind. if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === SyntaxKind.Constructor || signature.declaration.kind === SyntaxKind.ConstructSignature; - var type = createObjectType(TypeFlags.Anonymous | TypeFlags.FromSignature); + var type = createObjectType(TypeFlags.Anonymous | TypeFlags.FromSignature); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -2813,6 +2946,8 @@ module ts { return getTypeFromTupleTypeNode(node); case SyntaxKind.UnionType: return getTypeFromUnionTypeNode(node); + case SyntaxKind.ParenType: + return getTypeFromTypeNode((node).type); case SyntaxKind.TypeLiteral: return getTypeFromTypeLiteralNode(node); // This function assumes that an identifier or qualified name is a type expression @@ -2937,7 +3072,7 @@ module ts { // Keep the flags from the symbol we're instantiating. Mark that is instantiated, and // also transient so that we can just store data on it directly. - var result = createSymbol(SymbolFlags.Instantiated | SymbolFlags.Transient, symbol.name); + var result = createSymbol(SymbolFlags.Instantiated | SymbolFlags.Transient | symbol.flags, symbol.name); result.declarations = symbol.declarations; result.parent = symbol.parent; result.target = symbol; @@ -2950,8 +3085,8 @@ module ts { } function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType { - var result = createObjectType(TypeFlags.Anonymous, type.symbol); - result.properties = instantiateList(getPropertiesOfType(type), mapper, instantiateSymbol); + var result = createObjectType(TypeFlags.Anonymous, type.symbol); + result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, SignatureKind.Call), mapper, instantiateSignature); result.constructSignatures = instantiateList(getSignaturesOfType(type, SignatureKind.Construct), mapper, instantiateSignature); @@ -3008,9 +3143,9 @@ module ts { function getTypeWithoutConstructors(type: Type): Type { if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.constructSignatures.length) { - var result = createObjectType(TypeFlags.Anonymous, type.symbol); + var result = createObjectType(TypeFlags.Anonymous, type.symbol); result.members = resolved.members; result.properties = resolved.properties; result.callSignatures = resolved.callSignatures; @@ -3072,7 +3207,7 @@ module ts { for (var i = 0, len = type.baseTypes.length; i < len; ++i) { var base = type.baseTypes[i]; - var properties = getPropertiesOfType(base); + var properties = getPropertiesOfObjectType(base); for (var j = 0, proplen = properties.length; j < proplen; ++j) { var prop = properties[j]; if (!hasProperty(seen, prop.name)) { @@ -3333,13 +3468,13 @@ module ts { if (relation === identityRelation) { return propertiesIdenticalTo(source, target, reportErrors); } - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfApparentType(source, targetProp.name); + var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { - if (!isOptionalProperty(targetProp)) { + if (relation === subtypeRelation || !isOptionalProperty(targetProp)) { if (reportErrors) { reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } @@ -3410,14 +3545,14 @@ module ts { } function propertiesIdenticalTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { - var sourceProperties = getPropertiesOfType(source); - var targetProperties = getPropertiesOfType(target); + var sourceProperties = getPropertiesOfObjectType(source); + var targetProperties = getPropertiesOfObjectType(target); if (sourceProperties.length !== targetProperties.length) { return false; } for (var i = 0, len = sourceProperties.length; i < len; ++i) { var sourceProp = sourceProperties[i]; - var targetProp = getPropertyOfType(target, sourceProp.name); + var targetProp = getPropertyOfObjectType(target, sourceProp.name); if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { return false; } @@ -3628,10 +3763,6 @@ module ts { return forEach(types, t => isSupertypeOfEach(t, types) ? t : undefined); } - function getBestCommonType(types: Type[], contextualType: Type): Type { - return contextualType && isSupertypeOfEach(contextualType, types) ? contextualType : getUnionType(types); - } - function isTypeOfObjectLiteral(type: Type): boolean { return (type.flags & TypeFlags.Anonymous) && type.symbol && (type.symbol.flags & SymbolFlags.ObjectLiteral) ? true : false; } @@ -3668,7 +3799,7 @@ module ts { } function getWidenedTypeOfObjectLiteral(type: Type): Type { - var properties = getPropertiesOfType(type); + var properties = getPropertiesOfObjectType(type); if (properties.length) { var widenedTypes: Type[] = []; var propTypeWasWidened: boolean = false; @@ -3687,7 +3818,7 @@ module ts { var members: SymbolTable = {}; var index = 0; forEach(properties, p => { - var symbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, p.name); + var symbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | p.flags, p.name); symbol.declarations = p.declarations; symbol.parent = p.parent; symbol.type = widenedTypes[index++]; @@ -3740,11 +3871,12 @@ module ts { } } - function createInferenceContext(typeParameters: TypeParameter[]): InferenceContext { + function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext { var inferences: Type[][] = []; for (var i = 0; i < typeParameters.length; i++) inferences.push([]); return { typeParameters: typeParameters, + inferUnionTypes: inferUnionTypes, inferenceCount: 0, inferences: inferences, inferredTypes: new Array(typeParameters.length), @@ -3849,10 +3981,10 @@ module ts { } function inferFromProperties(source: Type, target: Type) { - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfType(source, targetProp.name); + var sourceProp = getPropertyOfObjectType(source, targetProp.name); if (sourceProp) { inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } @@ -3891,10 +4023,9 @@ module ts { if (!result) { var inferences = context.inferences[index]; if (inferences.length) { - // Find type that is supertype of all others - var supertype = getCommonSupertype(inferences); - // Infer widened supertype, or the undefined type for no common supertype - var inferredType = supertype ? getWidenedType(supertype) : undefinedType; + // Infer widened union or supertype, or the undefined type for no common supertype + var unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences); + var inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : undefinedType; } else { // Infer the empty object type when no inferences were made @@ -4038,8 +4169,8 @@ module ts { // Get the narrowed type of a given symbol at a given location function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) { var type = getTypeOfSymbol(symbol); - // Only narrow when symbol is variable of a non-primitive type - if (symbol.flags & SymbolFlags.Variable && isTypeAnyOrObjectOrTypeParameter(type)) { + // Only narrow when symbol is variable of a structured type + if (symbol.flags & SymbolFlags.Variable && type.flags & TypeFlags.Structured) { while (true) { var child = node; node = node.parent; @@ -4150,7 +4281,7 @@ module ts { if (!isTypeSubtypeOf(rightType, globalFunctionType)) { return type; } - var prototypeProperty = getPropertyOfType(getApparentType(rightType), "prototype"); + var prototypeProperty = getPropertyOfType(rightType, "prototype"); if (!prototypeProperty) { return type; } @@ -4506,23 +4637,23 @@ module ts { function getTypeOfPropertyOfContextualType(type: Type, name: string) { return applyToContextualType(type, t => { - var prop = getPropertyOfType(t, name); + var prop = getPropertyOfObjectType(t, name); return prop ? getTypeOfSymbol(prop) : undefined; }); } function getIndexTypeOfContextualType(type: Type, kind: IndexKind) { - return applyToContextualType(type, t => getIndexTypeOfType(t, kind)); + return applyToContextualType(type, t => getIndexTypeOfObjectOrUnionType(t, kind)); } // Return true if the given contextual type is a tuple-like type function contextualTypeIsTupleType(type: Type): boolean { - return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getPropertyOfType(t, "0")) : getPropertyOfType(type, "0")); + return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getPropertyOfObjectType(t, "0")) : getPropertyOfObjectType(type, "0")); } // Return true if the given contextual type provides an index signature of the given kind function contextualTypeHasIndexSignature(type: Type, kind: IndexKind): boolean { - return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getIndexTypeOfType(t, kind)) : getIndexTypeOfType(type, kind)); + return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getIndexTypeOfObjectOrUnionType(t, kind)) : getIndexTypeOfObjectOrUnionType(type, kind)); } // In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of @@ -4596,17 +4727,16 @@ module ts { return undefined; } - // Return the single non-generic signature in the given type, or undefined if none exists + // If the given type is an object or union type, if that type has a single signature, and if + // that signature is non-generic, return the signature. Otherwise return undefined. function getNonGenericSignature(type: Type): Signature { - var signatures = getSignaturesOfType(type, SignatureKind.Call); - if (signatures.length !== 1) { - return undefined; + var signatures = getSignaturesOfObjectOrUnionType(type, SignatureKind.Call); + if (signatures.length === 1) { + var signature = signatures[0]; + if (!signature.typeParameters) { + return signature; + } } - var signature = signatures[0]; - if (signature.typeParameters) { - return undefined; - } - return signature; } // Return the contextual signature for a given expression node. A contextual type provides a @@ -4657,7 +4787,28 @@ module ts { } function isNumericName(name: string) { - return (name !== "") && !isNaN(name); + // The intent of numeric names is that + // - they are names with text in a numeric form, and that + // - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit', + // acquired by applying the abstract 'ToNumber' operation on the name's text. + // + // The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name. + // In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold. + // + // Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)' + // according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'. + // Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names + // because their 'ToString' representation is not equal to their original text. + // This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1. + // + // Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'. + // The '+' prefix operator is equivalent here to applying the abstract ToNumber operation. + // Applying the 'toString()' method on a number gives us the abstract ToString operation on a number. + // + // Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional. + // This is desired behavior, because when indexing with them as numeric entities, you are indexing + // with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively. + return (+name).toString() === name; } function checkObjectLiteral(node: ObjectLiteral, contextualMapper?: TypeMapper): Type { @@ -4669,7 +4820,7 @@ module ts { var member = members[id]; if (member.flags & SymbolFlags.Property) { var type = checkExpression((member.declarations[0]).initializer, contextualMapper); - var prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, member.name); + var prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); prop.declarations = member.declarations; prop.parent = member.parent; if (member.valueDeclaration) prop.valueDeclaration = member.valueDeclaration; @@ -4707,7 +4858,9 @@ module ts { if (hasProperty(properties, id)) { if (kind === IndexKind.String || isNumericName(id)) { var type = getTypeOfSymbol(properties[id]); - if (!contains(propTypes, type)) propTypes.push(type); + if (!contains(propTypes, type)) { + propTypes.push(type); + } } } } @@ -4770,11 +4923,11 @@ module ts { if (type === unknownType) return type; if (type !== anyType) { var apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { + if (apparentType === unknownType) { // handle cases when type is Type parameter with invalid constraint return unknownType; } - var prop = getPropertyOfApparentType(apparentType, node.right.text); + var prop = getPropertyOfType(apparentType, node.right.text); if (!prop) { if (node.right.text) { error(node.right, Diagnostics.Property_0_does_not_exist_on_type_1, identifierToString(node.right), typeToString(type)); @@ -4805,8 +4958,7 @@ module ts { function isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean { var type = checkExpression(node.left); if (type !== unknownType && type !== anyType) { - var apparentType = getApparentType(getWidenedType(type)); - var prop = getPropertyOfApparentType(apparentType, propertyName); + var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) { if (node.left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) { return false; @@ -4822,8 +4974,10 @@ module ts { } function checkIndexedAccess(node: IndexedAccess): Type { - var objectType = checkExpression(node.object); + // Obtain base constraint such that we can bail out if the constraint is an unknown type + var objectType = getApparentType(checkExpression(node.object)); var indexType = checkExpression(node.index); + if (objectType === unknownType) return unknownType; // TypeScript 1.0 spec (April 2014): 4.10 Property Access @@ -4836,14 +4990,9 @@ module ts { // - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. // See if we can index as a property. - var apparentType = getApparentType(objectType); - if (apparentType === unknownType) { - // handle cases when objectType is type parameter with invalid type - return unknownType; - } if (node.index.kind === SyntaxKind.StringLiteral || node.index.kind === SyntaxKind.NumericLiteral) { var name = (node.index).text; - var prop = getPropertyOfApparentType(apparentType, name); + var prop = getPropertyOfType(objectType, name); if (prop) { return getTypeOfSymbol(prop); } @@ -4854,14 +5003,14 @@ module ts { // Try to use a number indexer. if (indexType.flags & (TypeFlags.Any | TypeFlags.NumberLike)) { - var numberIndexType = getIndexTypeOfType(apparentType, IndexKind.Number); + var numberIndexType = getIndexTypeOfType(objectType, IndexKind.Number); if (numberIndexType) { return numberIndexType; } } // Try to use string indexing. - var stringIndexType = getIndexTypeOfType(apparentType, IndexKind.String); + var stringIndexType = getIndexTypeOfType(objectType, IndexKind.String); if (stringIndexType) { return stringIndexType; } @@ -4924,7 +5073,7 @@ module ts { // If type has a single call signature and no other members, return that signature. Otherwise, return undefined. function getSingleCallSignature(type: Type): Signature { if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 && resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) { return resolved.callSignatures[0]; @@ -4935,7 +5084,7 @@ module ts { // Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec) function instantiateSignatureInContextOf(signature: Signature, contextualSignature: Signature, contextualMapper: TypeMapper): Signature { - var context = createInferenceContext(signature.typeParameters); + var context = createInferenceContext(signature.typeParameters, /*inferUnionTypes*/ true); forEachMatchingParameterType(contextualSignature, signature, (source, target) => { // Type parameters from outer context referenced by source type are fixed by instantiation of the source type inferTypes(context, instantiateType(source, contextualMapper), target); @@ -4945,7 +5094,7 @@ module ts { function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument?: boolean[]): Type[] { var typeParameters = signature.typeParameters; - var context = createInferenceContext(typeParameters); + var context = createInferenceContext(typeParameters, /*inferUnionTypes*/ false); var mapper = createInferenceMapper(context); // First infer from arguments that are not context sensitive for (var i = 0; i < args.length; i++) { @@ -5146,18 +5295,13 @@ module ts { } var funcType = checkExpression(node.func); - if (funcType === unknownType) { + var apparentType = getApparentType(funcType); + + if (apparentType === unknownType) { // Another error has already been reported return resolveErrorCall(node); } - var apparentType = getApparentType(funcType); - if (apparentType === unknownType) { - // handler cases when funcType is type parameter with invalid constraint - // Another error was already reported - return resolveErrorCall(node); - } - // Technically, this signatures list may be incomplete. We are taking the apparent type, // but we are not including call signatures that may have been added to the Object or // Function interface, since they have none by default. This is a bit of a leap of faith @@ -5195,10 +5339,7 @@ module ts { function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature { var expressionType = checkExpression(node.func); - if (expressionType === unknownType) { - // Another error has already been reported - return resolveErrorCall(node); - } + // TS 1.0 spec: 4.11 // If ConstructExpr is of type Any, Args can be any argument // list and the result of the operation is of type Any. @@ -5206,7 +5347,6 @@ module ts { if (node.typeArguments) { error(node, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } - return resolveUntypedCall(node); } @@ -5216,9 +5356,8 @@ module ts { // signatures for overload resolution.The result type of the function call becomes // the result type of the operation. expressionType = getApparentType(expressionType); - if (expressionType === unknownType) { - // handler cases when original expressionType is a type parameter with invalid constraint - // another error has already been reported + if (expressionType === unknownType) { + // Another error has already been reported return resolveErrorCall(node); } @@ -5484,7 +5623,7 @@ module ts { return true; } - function checkReferenceExpression(n: Node, message: DiagnosticMessage): boolean { + function checkReferenceExpression(n: Node, invalidReferenceMessage: DiagnosticMessage, constantVarianleMessage: DiagnosticMessage): boolean { function findSymbol(n: Node): Symbol { var symbol = getNodeLinks(n).resolvedSymbol; // Because we got the symbol from the resolvedSymbol property, it might be of kind @@ -5523,8 +5662,34 @@ module ts { } } + function isConstVariableReference(n: Node): boolean { + switch (n.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.PropertyAccess: + var symbol = findSymbol(n); + return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0; + case SyntaxKind.IndexedAccess: + var index = (n).index; + var symbol = findSymbol((n).object); + if (symbol && index.kind === SyntaxKind.StringLiteral) { + var name = (index).text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name); + return prop && (prop.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Const) !== 0; + } + return false; + case SyntaxKind.ParenExpression: + return isConstVariableReference((n).expression); + default: + return false; + } + } + if (!isReferenceOrErrorExpression(n)) { - error(n, message); + error(n, invalidReferenceMessage); + return false; + } + if (isConstVariableReference(n)) { + error(n, constantVarianleMessage); return false; } return true; @@ -5549,7 +5714,9 @@ module ts { var ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors - checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer); + checkReferenceExpression(node.operand, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); } return numberType; } @@ -5561,13 +5728,19 @@ module ts { var ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors - checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer); + checkReferenceExpression(node.operand, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); } return numberType; } - function isTypeAnyOrObjectOrTypeParameter(type: Type): boolean { - return (type.flags & (TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) !== 0; + // Return true if type is any, an object type, a type parameter, or a union type composed of only those kinds of types + function isStructuredType(type: Type): boolean { + if (type.flags & TypeFlags.Union) { + return !forEach((type).types, t => !isStructuredType(t)); + } + return (type.flags & TypeFlags.Structured) !== 0; } function checkInstanceOfExpression(node: BinaryExpression, leftType: Type, rightType: Type): Type { @@ -5576,7 +5749,7 @@ module ts { // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (leftType !== unknownType && !isTypeAnyOrObjectOrTypeParameter(leftType)) { + if (leftType !== unknownType && !isStructuredType(leftType)) { error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported @@ -5594,7 +5767,7 @@ module ts { if (leftType !== anyType && leftType !== stringType && leftType !== numberType) { error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number); } - if (!isTypeAnyOrObjectOrTypeParameter(rightType)) { + if (!isStructuredType(rightType)) { error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -5695,7 +5868,7 @@ module ts { case SyntaxKind.GreaterThanToken: case SyntaxKind.LessThanEqualsToken: case SyntaxKind.GreaterThanEqualsToken: - if (!isTypeSubtypeOf(leftType, rightType) && !isTypeSubtypeOf(rightType, leftType)) { + if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) { reportOperatorError(); } return booleanType; @@ -5738,7 +5911,7 @@ module ts { // requires VarExpr to be classified as a reference // A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1) // and the type of the non - compound operation to be assignable to the type of VarExpr. - var ok = checkReferenceExpression(node.left, Diagnostics.Invalid_left_hand_side_of_assignment_expression); + var ok = checkReferenceExpression(node.left, Diagnostics.Invalid_left_hand_side_of_assignment_expression, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); // Use default messages if (ok) { // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported @@ -6712,6 +6885,38 @@ module ts { } } + function checkCollisionWithConstDeclarations(node: VariableDeclaration) { + // Variable declarations are hoisted to the top of their function scope. They can shadow + // block scoped declarations, which bind tighter. this will not be flagged as duplicate definition + // by the binder as the declaration scope is different. + // A non-initialized declaration is a no-op as the block declaration will resolve before the var + // declaration. the problem is if the declaration has an initializer. this will act as a write to the + // block declared value. this is fine for let, but not const. + // + // Only consider declarations with initializers, uninitialized var declarations will not + // step on a const variable. + // Do not consider let and const declarations, as duplicate block-scoped declarations + // are handled by the binder. + // We are only looking for var declarations that step on const declarations from a + // different scope. e.g.: + // var x = 0; + // { + // const x = 0; + // var x = 0; + // } + if (node.initializer && (node.flags & NodeFlags.BlockScoped) === 0) { + var symbol = getSymbolOfNode(node); + if (symbol.flags & SymbolFlags.FunctionScopedVariable) { + var localDeclarationSymbol = resolveName(node, node.name.text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); + if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) { + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.Const) { + error(node, Diagnostics.Cannot_redeclare_block_scoped_variable_0, symbolToString(localDeclarationSymbol)); + } + } + } + } + } + function checkVariableDeclaration(node: VariableDeclaration) { checkSourceElement(node.type); checkExportsOnMergedDeclarations(node); @@ -6735,6 +6940,7 @@ module ts { // Use default messages checkTypeAssignableTo(checkAndMarkExpression(node.initializer), type, node, /*chainedMessage*/ undefined, /*terminalMessage*/ undefined); } + checkCollisionWithConstDeclarations(node); } checkCollisionWithCapturedSuperVariable(node, node.name); @@ -6808,14 +7014,14 @@ module ts { } else { // run check only former check succeeded to avoid cascading errors - checkReferenceExpression(node.variable, Diagnostics.Invalid_left_hand_side_in_for_in_statement); + checkReferenceExpression(node.variable, Diagnostics.Invalid_left_hand_side_in_for_in_statement, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); } } var exprType = checkExpression(node.expression); // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!isTypeAnyOrObjectOrTypeParameter(exprType) && exprType !== unknownType) { + if (!isStructuredType(exprType) && exprType !== unknownType) { error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } @@ -6920,7 +7126,7 @@ module ts { // for interfaces property and indexer might be inherited from different bases // check if any base class already has both property and indexer. // check should be performed only if 'type' is the first type that brings property\indexer together - var someBaseClassHasBothPropertyAndIndexer = forEach((type).baseTypes, base => getPropertyOfType(base, prop.name) && getIndexTypeOfType(base, indexKind)); + var someBaseClassHasBothPropertyAndIndexer = forEach((type).baseTypes, base => getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind)); errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : type.symbol.declarations[0]; } @@ -6940,7 +7146,7 @@ module ts { var numberIndexType = getIndexTypeOfType(type, IndexKind.Number); if (stringIndexType || numberIndexType) { - forEach(getPropertiesOfType(type), prop => { + forEach(getPropertiesOfObjectType(type), prop => { var propType = getTypeOfSymbol(prop); checkIndexConstraintForProperty(prop, propType, declaredStringIndexer, stringIndexType, IndexKind.String); checkIndexConstraintForProperty(prop, propType, declaredNumberIndexer, numberIndexType, IndexKind.Number); @@ -7072,7 +7278,7 @@ module ts { // derived class instance member variables and accessors, but not by other kinds of members. // NOTE: assignability is checked in checkClassDeclaration - var baseProperties = getPropertiesOfType(baseType); + var baseProperties = getPropertiesOfObjectType(baseType); for (var i = 0, len = baseProperties.length; i < len; ++i) { var base = getTargetSymbol(baseProperties[i]); @@ -7080,7 +7286,7 @@ module ts { continue; } - var derived = getTargetSymbol(getPropertyOfType(type, base.name)); + var derived = getTargetSymbol(getPropertyOfObjectType(type, base.name)); if (derived) { var baseDeclarationFlags = getDeclarationFlagsFromSymbol(base); var derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived); @@ -7439,6 +7645,8 @@ module ts { return checkTupleType(node); case SyntaxKind.UnionType: return checkUnionType(node); + case SyntaxKind.ParenType: + return checkSourceElement((node).type); case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); case SyntaxKind.Block: @@ -7737,77 +7945,6 @@ module ts { return node.parent && node.parent.kind === SyntaxKind.TypeReference; } - function isExpression(node: Node): boolean { - switch (node.kind) { - case SyntaxKind.ThisKeyword: - case SyntaxKind.SuperKeyword: - case SyntaxKind.NullKeyword: - case SyntaxKind.TrueKeyword: - case SyntaxKind.FalseKeyword: - case SyntaxKind.RegularExpressionLiteral: - case SyntaxKind.ArrayLiteral: - case SyntaxKind.ObjectLiteral: - case SyntaxKind.PropertyAccess: - case SyntaxKind.IndexedAccess: - case SyntaxKind.CallExpression: - case SyntaxKind.NewExpression: - case SyntaxKind.TypeAssertion: - case SyntaxKind.ParenExpression: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - case SyntaxKind.PrefixOperator: - case SyntaxKind.PostfixOperator: - case SyntaxKind.BinaryExpression: - case SyntaxKind.ConditionalExpression: - case SyntaxKind.OmittedExpression: - return true; - case SyntaxKind.QualifiedName: - while (node.parent.kind === SyntaxKind.QualifiedName) node = node.parent; - return node.parent.kind === SyntaxKind.TypeQuery; - case SyntaxKind.Identifier: - if (node.parent.kind === SyntaxKind.TypeQuery) { - return true; - } - // Fall through - case SyntaxKind.NumericLiteral: - case SyntaxKind.StringLiteral: - var parent = node.parent; - switch (parent.kind) { - case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: - case SyntaxKind.Property: - case SyntaxKind.EnumMember: - case SyntaxKind.PropertyAssignment: - return (parent).initializer === node; - case SyntaxKind.ExpressionStatement: - case SyntaxKind.IfStatement: - case SyntaxKind.DoStatement: - case SyntaxKind.WhileStatement: - case SyntaxKind.ReturnStatement: - case SyntaxKind.WithStatement: - case SyntaxKind.SwitchStatement: - case SyntaxKind.CaseClause: - case SyntaxKind.ThrowStatement: - case SyntaxKind.SwitchStatement: - return (parent).expression === node; - case SyntaxKind.ForStatement: - return (parent).initializer === node || - (parent).condition === node || - (parent).iterator === node; - case SyntaxKind.ForInStatement: - return (parent).variable === node || - (parent).expression === node; - case SyntaxKind.TypeAssertion: - return node === (parent).operand; - default: - if (isExpression(parent)) { - return true; - } - } - } - return false; - } - function isTypeNode(node: Node): boolean { if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) { return true; @@ -8001,8 +8138,8 @@ module ts { var objectType = checkExpression((node.parent).object); if (objectType === unknownType) return undefined; var apparentType = getApparentType(objectType); - if (apparentType === unknownType) return undefined; - return getPropertyOfApparentType(apparentType, (node).text); + if (apparentType === unknownType) return undefined; + return getPropertyOfType(apparentType, (node).text); } break; } @@ -8061,53 +8198,27 @@ module ts { return checkExpression(expr); } - function getAugmentedPropertiesOfApparentType(type: Type): Symbol[]{ - var apparentType = getApparentType(type); - - if (apparentType.flags & TypeFlags.ObjectType) { - // Augment the apparent type with Function and Object members as applicable - var propertiesByName: Map = {}; - var results: Symbol[] = []; - - forEach(getPropertiesOfType(apparentType), s => { - propertiesByName[s.name] = s; - results.push(s); - }); - - var resolved = resolveObjectTypeMembers(type); - forEachValue(resolved.members, s => { - if (symbolIsValue(s) && !propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); + // Return the list of properties of the given type, augmented with properties from Function + // if the type has call or construct signatures + function getAugmentedPropertiesOfType(type: Type): Symbol[] { + var type = getApparentType(type); + var propsByName = createSymbolTable(getPropertiesOfType(type)); + if (getSignaturesOfType(type, SignatureKind.Call).length || getSignaturesOfType(type, SignatureKind.Construct).length) { + forEach(getPropertiesOfType(globalFunctionType), p => { + if (!hasProperty(propsByName, p.name)) { + propsByName[p.name] = p; } }); - - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - forEach(getPropertiesOfType(globalFunctionType), s => { - if (!propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); - } - }); - } - - return results; - } - else { - return getPropertiesOfType(apparentType); } + return getNamedMembers(propsByName); } - function getRootSymbol(symbol: Symbol): Symbol { - return symbol.flags & SymbolFlags.Transient && getSymbolLinks(symbol).target || symbol; - } - - function getRootSymbols(symbol: Symbol): Symbol[] { + function getRootSymbols(symbol: Symbol): Symbol[]{ if (symbol.flags & SymbolFlags.UnionProperty) { var symbols: Symbol[] = []; var name = symbol.name; forEach(getSymbolLinks(symbol).unionType.types, t => { - symbols.push(getPropertyOfType(getApparentType(t), name)); + symbols.push(getPropertyOfType(t, name)); }); return symbols; } @@ -8205,6 +8316,10 @@ module ts { return getDiagnostics().length > 0 || getGlobalDiagnostics().length > 0; } + function hasEarlyErrors(sourceFile?: SourceFile): boolean { + return forEach(getDiagnostics(sourceFile), d => d.isEarly); + } + function isReferencedImportDeclaration(node: ImportDeclaration): boolean { var symbol = getSymbolOfNode(node); if (getSymbolLinks(symbol).referenced) { @@ -8269,12 +8384,12 @@ module ts { var symbol = getSymbolOfNode(location); var type = symbol && !(symbol.flags & SymbolFlags.TypeLiteral) ? getTypeOfSymbol(symbol) : getTypeFromTypeNode(location); - writeType(type, writer, enclosingDeclaration, flags); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } function writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) { var signature = getSignatureFromDeclaration(signatureDeclaration); - writeType(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); + getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); } function invokeEmitter(targetSourceFile?: SourceFile) { @@ -8288,6 +8403,7 @@ module ts { getEnumMemberValue: getEnumMemberValue, isTopLevelValueImportedViaEntityName: isTopLevelValueImportedViaEntityName, hasSemanticErrors: hasSemanticErrors, + hasEarlyErrors: hasEarlyErrors, isDeclarationVisible: isDeclarationVisible, isImplementationOfOverload: isImplementationOfOverload, writeTypeAtLocation: writeTypeAtLocation, diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 0e48953eaa7..a7993484c64 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -102,10 +102,10 @@ module ts { { name: "target", shortName: "t", - type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 }, - description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5, + type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 , "es6": ScriptTarget.ES6 }, + description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental, paramType: Diagnostics.VERSION, - error: Diagnostics.Argument_for_target_option_must_be_es3_or_es5 + error: Diagnostics.Argument_for_target_option_must_be_es3_es5_or_es6 }, { name: "version", diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ee7f4701d19..ae2cf053123 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -232,7 +232,8 @@ module ts { messageText: text, category: message.category, - code: message.code + code: message.code, + isEarly: message.isEarly }; } @@ -251,7 +252,8 @@ module ts { messageText: text, category: message.category, - code: message.code + code: message.code, + isEarly: message.isEarly }; } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index ac2a79c603d..a5dda0b1f4b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -114,7 +114,12 @@ module ts { Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile external modules unless the '--module' flag is provided." }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, - An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." }, + var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." }, + let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." }, + const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." }, + const_declarations_must_be_initialized: { code: 1155, category: DiagnosticCategory.Error, key: "'const' declarations must be initialized" }, + const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block." }, + let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -261,6 +266,11 @@ module ts { Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." }, Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." }, The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: DiagnosticCategory.Error, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." }, + Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration.", isEarly: true }, + The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant: { code: 2449, category: DiagnosticCategory.Error, key: "The operand of an increment or decrement operator cannot be a constant.", isEarly: true }, + Left_hand_side_of_assignment_expression_cannot_be_a_constant: { code: 2450, category: DiagnosticCategory.Error, key: "Left-hand side of assignment expression cannot be a constant.", isEarly: true }, + Cannot_redeclare_block_scoped_variable_0: { code: 2451, category: DiagnosticCategory.Error, key: "Cannot redeclare block-scoped variable '{0}'.", isEarly: true }, + An_enum_member_cannot_have_a_numeric_name: { code: 2452, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, @@ -355,7 +365,7 @@ module ts { Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, - Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), or 'ES5'" }, + Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." }, @@ -377,7 +387,7 @@ module ts { Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, Argument_for_module_option_must_be_commonjs_or_amd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." }, - Argument_for_target_option_must_be_es3_or_es5: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." }, + Argument_for_target_option_must_be_es3_es5_or_es6: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3', 'es5', or 'es6'." }, Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, Unable_to_open_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d8895d15144..1336af21aaf 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -447,9 +447,29 @@ "category": "Error", "code": 1150 }, - "An enum member cannot have a numeric name.": { + "'var', 'let' or 'const' expected.": { "category": "Error", - "code": 1151 + "code": 1152 + }, + "'let' declarations are only available when targeting ECMAScript 6 and higher.": { + "category": "Error", + "code": 1153 + }, + "'const' declarations are only available when targeting ECMAScript 6 and higher.": { + "category": "Error", + "code": 1154 + }, + "'const' declarations must be initialized": { + "category": "Error", + "code": 1155 + }, + "'const' declarations can only be declared inside a block.": { + "category": "Error", + "code": 1156 + }, + "'let' declarations can only be declared inside a block.": { + "category": "Error", + "code": 1157 }, "Duplicate identifier '{0}'.": { @@ -1036,6 +1056,30 @@ "category": "Error", "code": 2447 }, + "Block-scoped variable '{0}' used before its declaration.": { + "category": "Error", + "code": 2448, + "isEarly": true + }, + "The operand of an increment or decrement operator cannot be a constant.": { + "category": "Error", + "code": 2449, + "isEarly": true + }, + "Left-hand side of assignment expression cannot be a constant.": { + "category": "Error", + "code": 2450, + "isEarly": true + }, + "Cannot redeclare block-scoped variable '{0}'.": { + "category": "Error", + "code": 2451, + "isEarly": true + }, + "An enum member cannot have a numeric name.": { + "category": "Error", + "code": 2452 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -1416,7 +1460,7 @@ "category": "Message", "code": 6009 }, - "Specify ECMAScript target version: 'ES3' (default), or 'ES5'": { + "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)": { "category": "Message", "code": 6015 }, @@ -1504,7 +1548,7 @@ "category": "Error", "code": 6046 }, - "Argument for '--target' option must be 'es3' or 'es5'.": { + "Argument for '--target' option must be 'es3', 'es5', or 'es6'.": { "category": "Error", "code": 6047 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e8e80b9898b..d24e3687f53 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4,8 +4,11 @@ /// module ts { - interface EmitTextWriter extends SymbolWriter { + interface EmitTextWriter { write(s: string): void; + writeLine(): void; + increaseIndent(): void; + decreaseIndent(): void; getText(): string; rawWrite(s: string): void; writeLiteral(s: string): void; @@ -15,6 +18,9 @@ module ts { getIndent(): number; } + interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter{ + } + var indentStrings: string[] = ["", " "]; export function getIndentString(level: number) { if (indentStrings[level] === undefined) { @@ -103,7 +109,7 @@ module ts { }; } - function createTextWriter(trackSymbol: (symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags)=> void): EmitTextWriter { + function createTextWriter(): EmitTextWriter { var output = ""; var indent = 0; var lineStart = true; @@ -149,17 +155,8 @@ module ts { } } - function writeKind(text: string, kind: SymbolDisplayPartKind) { - write(text); - } - function writeSymbol(text: string, symbol: Symbol) { - write(text); - } return { write: write, - trackSymbol: trackSymbol, - writeKind: writeKind, - writeSymbol: writeSymbol, rawWrite: rawWrite, writeLiteral: writeLiteral, writeLine: writeLine, @@ -170,7 +167,6 @@ module ts { getLine: () => lineCount + 1, getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1, getText: () => output, - clear: () => { } }; } @@ -318,7 +314,7 @@ module ts { } function emitJavaScript(jsFilePath: string, root?: SourceFile) { - var writer = createTextWriter(trackSymbol); + var writer = createTextWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -374,8 +370,6 @@ module ts { /** Sourcemap data that will get encoded */ var sourceMapData: SourceMapData; - function trackSymbol(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags) { } - function initializeEmitterWithSourceMaps() { var sourceMapDir: string; // The directory in which sourcemap will be @@ -1149,7 +1143,15 @@ module ts { write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); if (node.declarations) { - emitToken(SyntaxKind.VarKeyword, endPos); + if (node.declarations[0] && node.declarations[0].flags & NodeFlags.Let) { + emitToken(SyntaxKind.LetKeyword, endPos); + } + else if (node.declarations[0] && node.declarations[0].flags & NodeFlags.Const) { + emitToken(SyntaxKind.ConstKeyword, endPos); + } + else { + emitToken(SyntaxKind.VarKeyword, endPos); + } write(" "); emitCommaList(node.declarations, /*includeTrailingComma*/ false); } @@ -1169,7 +1171,12 @@ module ts { write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); if (node.declaration) { - emitToken(SyntaxKind.VarKeyword, endPos); + if (node.declaration.flags & NodeFlags.Let) { + emitToken(SyntaxKind.LetKeyword, endPos); + } + else { + emitToken(SyntaxKind.VarKeyword, endPos); + } write(" "); emit(node.declaration); } @@ -1298,7 +1305,17 @@ module ts { function emitVariableStatement(node: VariableStatement) { emitLeadingComments(node); - if (!(node.flags & NodeFlags.Export)) write("var "); + if (!(node.flags & NodeFlags.Export)) { + if (node.flags & NodeFlags.Let) { + write("let "); + } + else if (node.flags & NodeFlags.Const) { + write("const "); + } + else { + write("var "); + } + } emitCommaList(node.declarations, /*includeTrailingComma*/ false); write(";"); emitTrailingComments(node); @@ -2314,7 +2331,7 @@ module ts { } function emitDeclarations(jsFilePath: string, root?: SourceFile) { - var writer = createTextWriter(trackSymbol); + var writer = createTextWriterWithSymbolWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -2338,11 +2355,24 @@ module ts { typeName?: Identifier } + function createTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter { + var writer = createTextWriter(); + writer.trackSymbol = trackSymbol; + writer.writeKeyword = writer.write; + writer.writeOperator = writer.write; + writer.writePunctuation = writer.write; + writer.writeSpace = writer.write; + writer.writeStringLiteral = writer.writeLiteral; + writer.writeParameter = writer.write; + writer.writeSymbol = writer.write; + return writer; + } + function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) { var oldWriter = writer; forEach(importDeclarations, aliasToWrite => { var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined); - writer = createTextWriter(trackSymbol); + writer = createTextWriterWithSymbolWriter(); for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { writer.increaseIndent(); } @@ -2822,7 +2852,15 @@ module ts { if (hasDeclarationWithEmit) { emitJsDocComments(node); emitDeclarationFlags(node); - write("var "); + if (node.flags & NodeFlags.Let) { + write("let "); + } + else if (node.flags & NodeFlags.Const) { + write("const "); + } + else { + write("var "); + } emitCommaList(node.declarations, emitVariableDeclaration); write(";"); writeLine(); @@ -2861,7 +2899,7 @@ module ts { } return { diagnosticMessage: diagnosticMessage, - errorNode: node.parameters[0], + errorNode: node.parameters[0], typeName: node.name }; } @@ -2882,7 +2920,7 @@ module ts { } return { diagnosticMessage: diagnosticMessage, - errorNode: node.name, + errorNode: node.name, typeName: undefined }; } @@ -3233,11 +3271,14 @@ module ts { } var hasSemanticErrors = resolver.hasSemanticErrors(); + var hasEarlyErrors = resolver.hasEarlyErrors(targetSourceFile); function emitFile(jsFilePath: string, sourceFile?: SourceFile) { - emitJavaScript(jsFilePath, sourceFile); - if (!hasSemanticErrors && compilerOptions.declaration) { - emitDeclarations(jsFilePath, sourceFile); + if (!hasEarlyErrors) { + emitJavaScript(jsFilePath, sourceFile); + if (!hasSemanticErrors && compilerOptions.declaration) { + emitDeclarations(jsFilePath, sourceFile); + } } } @@ -3277,7 +3318,9 @@ module ts { // Check and update returnCode for syntactic and semantic var returnCode: EmitReturnStatus; - if (hasEmitterError) { + if (hasEarlyErrors) { + returnCode = EmitReturnStatus.AllOutputGenerationSkipped; + } else if (hasEmitterError) { returnCode = EmitReturnStatus.EmitErrorsEncountered; } else if (hasSemanticErrors && compilerOptions.declaration) { returnCode = EmitReturnStatus.DeclarationGenerationSkipped; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index cd08aaa0914..1694d30fa53 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -67,6 +67,77 @@ module ts { return identifier.kind === SyntaxKind.Missing ? "(Missing)" : getTextOfNode(identifier); } + export function isExpression(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ThisKeyword: + case SyntaxKind.SuperKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + case SyntaxKind.RegularExpressionLiteral: + case SyntaxKind.ArrayLiteral: + case SyntaxKind.ObjectLiteral: + case SyntaxKind.PropertyAccess: + case SyntaxKind.IndexedAccess: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.TypeAssertion: + case SyntaxKind.ParenExpression: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.PrefixOperator: + case SyntaxKind.PostfixOperator: + case SyntaxKind.BinaryExpression: + case SyntaxKind.ConditionalExpression: + case SyntaxKind.OmittedExpression: + return true; + case SyntaxKind.QualifiedName: + while (node.parent.kind === SyntaxKind.QualifiedName) node = node.parent; + return node.parent.kind === SyntaxKind.TypeQuery; + case SyntaxKind.Identifier: + if (node.parent.kind === SyntaxKind.TypeQuery) { + return true; + } + // Fall through + case SyntaxKind.NumericLiteral: + case SyntaxKind.StringLiteral: + var parent = node.parent; + switch (parent.kind) { + case SyntaxKind.VariableDeclaration: + case SyntaxKind.Parameter: + case SyntaxKind.Property: + case SyntaxKind.EnumMember: + case SyntaxKind.PropertyAssignment: + return (parent).initializer === node; + case SyntaxKind.ExpressionStatement: + case SyntaxKind.IfStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: + case SyntaxKind.ReturnStatement: + case SyntaxKind.WithStatement: + case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseClause: + case SyntaxKind.ThrowStatement: + case SyntaxKind.SwitchStatement: + return (parent).expression === node; + case SyntaxKind.ForStatement: + return (parent).initializer === node || + (parent).condition === node || + (parent).iterator === node; + case SyntaxKind.ForInStatement: + return (parent).variable === node || + (parent).expression === node; + case SyntaxKind.TypeAssertion: + return node === (parent).operand; + default: + if (isExpression(parent)) { + return true; + } + } + } + return false; + } + export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic { node = getErrorSpanForNode(node); var file = getSourceFileOfNode(node); @@ -227,6 +298,8 @@ module ts { return children((node).elementTypes); case SyntaxKind.UnionType: return children((node).types); + case SyntaxKind.ParenType: + return child((node).type); case SyntaxKind.ArrayLiteral: return children((node).elements); case SyntaxKind.ObjectLiteral: @@ -1076,7 +1149,7 @@ module ts { return isParameter(); case ParsingContext.TypeArguments: case ParsingContext.TupleElementTypes: - return isType(); + return token === SyntaxKind.CommaToken || isType(); } Debug.fail("Non-exhaustive case in 'isListElement'."); @@ -1658,6 +1731,14 @@ module ts { return finishNode(node); } + function parseParenType(): ParenTypeNode { + var node = createNode(SyntaxKind.ParenType); + parseExpected(SyntaxKind.OpenParenToken); + node.type = parseType(); + parseExpected(SyntaxKind.CloseParenToken); + return finishNode(node); + } + function parseFunctionType(signatureKind: SyntaxKind): TypeLiteralNode { var node = createNode(SyntaxKind.TypeLiteral); var member = createNode(signatureKind); @@ -1691,10 +1772,7 @@ module ts { case SyntaxKind.OpenBracketToken: return parseTupleType(); case SyntaxKind.OpenParenToken: - case SyntaxKind.LessThanToken: - return parseFunctionType(SyntaxKind.CallSignature); - case SyntaxKind.NewKeyword: - return parseFunctionType(SyntaxKind.ConstructSignature); + return parseParenType(); default: if (isIdentifier()) { return parseTypeReference(); @@ -1718,18 +1796,18 @@ module ts { case SyntaxKind.NewKeyword: return true; case SyntaxKind.OpenParenToken: - // Only consider an ( as the start of a type if we have () or (id - // We don't want to consider things like (1) as a function type. + // Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier, + // or something that starts a type. We don't want to consider things like '(1)' a type. return lookAhead(() => { nextToken(); - return token === SyntaxKind.CloseParenToken || isParameter(); + return token === SyntaxKind.CloseParenToken || isParameter() || isType(); }); default: return isIdentifier(); } } - function parseNonUnionType(): TypeNode { + function parsePrimaryType(): TypeNode { var type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) { parseExpected(SyntaxKind.CloseBracketToken); @@ -1740,13 +1818,13 @@ module ts { return type; } - function parseType(): TypeNode { - var type = parseNonUnionType(); + function parseUnionType(): TypeNode { + var type = parsePrimaryType(); if (token === SyntaxKind.BarToken) { var types = >[type]; types.pos = type.pos; while (parseOptional(SyntaxKind.BarToken)) { - types.push(parseNonUnionType()); + types.push(parsePrimaryType()); } types.end = getNodeEnd(); var node = createNode(SyntaxKind.UnionType, type.pos); @@ -1756,6 +1834,48 @@ module ts { return type; } + function isFunctionType(): boolean { + return token === SyntaxKind.LessThanToken || token === SyntaxKind.OpenParenToken && lookAhead(() => { + nextToken(); + if (token === SyntaxKind.CloseParenToken || token === SyntaxKind.DotDotDotToken) { + // ( ) + // ( ... + return true; + } + if (isIdentifier() || isModifier(token)) { + nextToken(); + if (token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken || + token === SyntaxKind.QuestionToken || token === SyntaxKind.EqualsToken || + isIdentifier() || isModifier(token)) { + // ( id : + // ( id , + // ( id ? + // ( id = + // ( modifier id + return true; + } + if (token === SyntaxKind.CloseParenToken) { + nextToken(); + if (token === SyntaxKind.EqualsGreaterThanToken) { + // ( id ) => + return true; + } + } + } + return false; + }); + } + + function parseType(): TypeNode { + if (isFunctionType()) { + return parseFunctionType(SyntaxKind.CallSignature); + } + if (token === SyntaxKind.NewKeyword) { + return parseFunctionType(SyntaxKind.ConstructSignature); + } + return parseUnionType(); + } + function parseTypeAnnotation(): TypeNode { return parseOptional(SyntaxKind.ColonToken) ? parseType() : undefined; } @@ -2342,13 +2462,29 @@ module ts { function parseTypeArguments(): NodeArray { var typeArgumentListStart = scanner.getTokenPos(); var errorCountBeforeTypeParameterList = file.syntacticErrors.length; - var result = parseBracketedList(ParsingContext.TypeArguments, parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); + // We pass parseSingleTypeArgument instead of parseType as the element parser + // because parseSingleTypeArgument knows how to parse a missing type argument. + // This is useful for signature help. parseType has the disadvantage that when + // it sees a missing type, it changes the LookAheadMode to Error, and the result + // is a broken binary expression, which breaks signature help. + var result = parseBracketedList(ParsingContext.TypeArguments, parseSingleTypeArgument, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) { grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, Diagnostics.Type_argument_list_cannot_be_empty); } return result; } + function parseSingleTypeArgument(): TypeNode { + if (token === SyntaxKind.CommaToken) { + var errorStart = scanner.getTokenPos(); + var errorLength = scanner.getTextPos() - errorStart; + grammarErrorAtPos(errorStart, errorLength, Diagnostics.Type_expected); + return createNode(SyntaxKind.Missing); + } + + return parseType(); + } + function parsePrimaryExpression(): Expression { switch (token) { case SyntaxKind.ThisKeyword: @@ -2558,11 +2694,14 @@ module ts { } // STATEMENTS + function parseStatementAllowingLetDeclaration() { + return parseStatement(/*allowLetAndConstDeclarations*/ true); + } function parseBlock(ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean): Block { var node = createNode(SyntaxKind.Block); if (parseExpected(SyntaxKind.OpenBraceToken) || ignoreMissingOpenBrace) { - node.statements = parseList(ParsingContext.BlockStatements,checkForStrictMode, parseStatement); + node.statements = parseList(ParsingContext.BlockStatements, checkForStrictMode, parseStatementAllowingLetDeclaration); parseExpected(SyntaxKind.CloseBraceToken); } else { @@ -2608,8 +2747,8 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); - node.thenStatement = parseStatement(); - node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement() : undefined; + node.thenStatement = parseStatement(/*allowLetAndConstDeclarations*/ false); + node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement(/*allowLetAndConstDeclarations*/ false) : undefined; return finishNode(node); } @@ -2619,7 +2758,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - node.statement = parseStatement(); + node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); inIterationStatement = saveInIterationStatement; parseExpected(SyntaxKind.WhileKeyword); @@ -2644,7 +2783,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - node.statement = parseStatement(); + node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); inIterationStatement = saveInIterationStatement; return finishNode(node); @@ -2656,11 +2795,29 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); if (token !== SyntaxKind.SemicolonToken) { if (parseOptional(SyntaxKind.VarKeyword)) { - var declarations = parseVariableDeclarationList(0, true); + var declarations = parseVariableDeclarationList(0, /*noIn*/ true); if (!declarations.length) { error(Diagnostics.Variable_declaration_list_cannot_be_empty); } } + else if (parseOptional(SyntaxKind.LetKeyword)) { + var declarations = parseVariableDeclarationList(NodeFlags.Let, /*noIn*/ true); + if (!declarations.length) { + error(Diagnostics.Variable_declaration_list_cannot_be_empty); + } + if (languageVersion < ScriptTarget.ES6) { + grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } + else if (parseOptional(SyntaxKind.ConstKeyword)) { + var declarations = parseVariableDeclarationList(NodeFlags.Const, /*noIn*/ true); + if (!declarations.length) { + error(Diagnostics.Variable_declaration_list_cannot_be_empty); + } + if (languageVersion < ScriptTarget.ES6) { + grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } else { var varOrInit = parseExpression(true); } @@ -2699,7 +2856,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - forOrForInStatement.statement = parseStatement(); + forOrForInStatement.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); inIterationStatement = saveInIterationStatement; return finishNode(forOrForInStatement); @@ -2810,7 +2967,7 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); - node.statement = parseStatement(); + node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); node = finishNode(node); if (isInStrictMode) { // Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such @@ -2825,7 +2982,7 @@ module ts { parseExpected(SyntaxKind.CaseKeyword); node.expression = parseExpression(); parseExpected(SyntaxKind.ColonToken); - node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement); + node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatementAllowingLetDeclaration); return finishNode(node); } @@ -2833,7 +2990,7 @@ module ts { var node = createNode(SyntaxKind.DefaultClause); parseExpected(SyntaxKind.DefaultKeyword); parseExpected(SyntaxKind.ColonToken); - node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement); + node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatementAllowingLetDeclaration); return finishNode(node); } @@ -2940,9 +3097,9 @@ module ts { return token === SyntaxKind.WhileKeyword || token === SyntaxKind.DoKeyword || token === SyntaxKind.ForKeyword; } - function parseStatementWithLabelSet(): Statement { + function parseStatementWithLabelSet(allowLetAndConstDeclarations: boolean): Statement { labelledStatementInfo.pushCurrentLabelSet(isIterationStatementStart()); - var statement = parseStatement(); + var statement = parseStatement(allowLetAndConstDeclarations); labelledStatementInfo.pop(); return statement; } @@ -2951,7 +3108,7 @@ module ts { return isIdentifier() && lookAhead(() => nextToken() === SyntaxKind.ColonToken); } - function parseLabelledStatement(): LabeledStatement { + function parseLabeledStatement(allowLetAndConstDeclarations: boolean): LabeledStatement { var node = createNode(SyntaxKind.LabeledStatement); node.label = parseIdentifier(); parseExpected(SyntaxKind.ColonToken); @@ -2963,7 +3120,7 @@ module ts { // We only want to call parseStatementWithLabelSet when the label set is complete // Therefore, keep parsing labels until we know we're done. - node.statement = isLabel() ? parseLabelledStatement() : parseStatementWithLabelSet(); + node.statement = isLabel() ? parseLabeledStatement(allowLetAndConstDeclarations) : parseStatementWithLabelSet(allowLetAndConstDeclarations); return finishNode(node); } @@ -2986,6 +3143,8 @@ module ts { return !inErrorRecovery; case SyntaxKind.OpenBraceToken: case SyntaxKind.VarKeyword: + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: case SyntaxKind.FunctionKeyword: case SyntaxKind.IfKeyword: case SyntaxKind.DoKeyword: @@ -3027,12 +3186,14 @@ module ts { } } - function parseStatement(): Statement { + function parseStatement(allowLetAndConstDeclarations: boolean): Statement { switch (token) { case SyntaxKind.OpenBraceToken: return parseBlock(/* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false); case SyntaxKind.VarKeyword: - return parseVariableStatement(); + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: + return parseVariableStatement(allowLetAndConstDeclarations); case SyntaxKind.FunctionKeyword: return parseFunctionDeclaration(); case SyntaxKind.SemicolonToken: @@ -3066,16 +3227,12 @@ module ts { return parseDebuggerStatement(); default: if (isLabel()) { - return parseLabelledStatement(); + return parseLabeledStatement(allowLetAndConstDeclarations); } return parseExpressionStatement(); } } - function parseStatementOrFunction(): Statement { - return token === SyntaxKind.FunctionKeyword ? parseFunctionDeclaration() : parseStatement(); - } - function parseAndCheckFunctionBody(isConstructor: boolean): Block { var initialPosition = scanner.getTokenPos(); var errorCountBeforeBody = file.syntacticErrors.length; @@ -3111,6 +3268,9 @@ module ts { if (inAmbientContext && node.initializer && errorCountBeforeVariableDeclaration === file.syntacticErrors.length) { grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } + if (!inAmbientContext && !node.initializer && flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized); + } if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { // It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code // and its Identifier is eval or arguments @@ -3124,17 +3284,42 @@ module ts { () => parseVariableDeclaration(flags, noIn), /*allowTrailingComma*/ false); } - function parseVariableStatement(pos?: number, flags?: NodeFlags): VariableStatement { + function parseVariableStatement(allowLetAndConstDeclarations: boolean, pos?: number, flags?: NodeFlags): VariableStatement { var node = createNode(SyntaxKind.VariableStatement, pos); if (flags) node.flags = flags; var errorCountBeforeVarStatement = file.syntacticErrors.length; - parseExpected(SyntaxKind.VarKeyword); - node.declarations = parseVariableDeclarationList(flags, /*noIn*/false); + if (token === SyntaxKind.LetKeyword) { + node.flags |= NodeFlags.Let; + } + else if (token === SyntaxKind.ConstKeyword) { + node.flags |= NodeFlags.Const; + } + else if (token !== SyntaxKind.VarKeyword) { + error(Diagnostics.var_let_or_const_expected); + } + nextToken(); + node.declarations = parseVariableDeclarationList(node.flags, /*noIn*/false); parseSemicolon(); finishNode(node); if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) { grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty); } + if (languageVersion < ScriptTarget.ES6) { + if (node.flags & NodeFlags.Let) { + grammarErrorOnNode(node, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + else if (node.flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } + else if (!allowLetAndConstDeclarations) { + if (node.flags & NodeFlags.Let) { + grammarErrorOnNode(node, Diagnostics.let_declarations_can_only_be_declared_inside_a_block); + } + else if (node.flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_declarations_can_only_be_declared_inside_a_block); + } + } return node; } @@ -3713,6 +3898,8 @@ module ts { function isDeclaration(): boolean { switch (token) { case SyntaxKind.VarKeyword: + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: case SyntaxKind.FunctionKeyword: return true; case SyntaxKind.ClassKeyword: @@ -3763,7 +3950,9 @@ module ts { var result: Declaration; switch (token) { case SyntaxKind.VarKeyword: - result = parseVariableStatement(pos, flags); + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: + result = parseVariableStatement(/*allowLetAndConstDeclarations*/ true, pos, flags); break; case SyntaxKind.FunctionKeyword: result = parseFunctionDeclaration(pos, flags); @@ -3811,7 +4000,7 @@ module ts { var statementStart = scanner.getTokenPos(); var statementFirstTokenLength = scanner.getTextPos() - statementStart; var errorCountBeforeStatement = file.syntacticErrors.length; - var statement = parseStatement(); + var statement = parseStatement(/*allowLetAndConstDeclarations*/ true); if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) { grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 2f5ff604df3..d685a30d959 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -1,4 +1,3 @@ -/// interface System { args: string[]; @@ -68,7 +67,7 @@ var sys: System = (function () { return fileStream.ReadText(); } catch (e) { - throw e.number === -2147024809 ? new Error(ts.Diagnostics.Unsupported_file_encoding.key) : e; + throw e; } finally { fileStream.Close(); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index c8cccd2da1c..15f231bc74e 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -142,14 +142,19 @@ module ts { // otherwise use toLowerCase as a canonical form. return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); } - + + // returned by CScript sys environment + var unsupportedFileEncodingErrorCode = -2147024809; + function getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile { try { var text = sys.readFile(filename, options.charset); } catch (e) { if (onError) { - onError(e.message); + onError(e.number === unsupportedFileEncodingErrorCode ? + getDiagnosticText(Diagnostics.Unsupported_file_encoding) : + e.message); } text = ""; } @@ -356,13 +361,18 @@ module ts { else { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); var checkStart = new Date().getTime(); - var semanticErrors = checker.getDiagnostics(); - var emitStart = new Date().getTime(); - var emitOutput = checker.emitFiles(); - var emitErrors = emitOutput.errors; - exitStatus = emitOutput.emitResultStatus; - var reportStart = new Date().getTime(); - errors = concatenate(semanticErrors, emitErrors); + errors = checker.getDiagnostics(); + if (!checker.hasEarlyErrors()) { + var emitStart = new Date().getTime(); + var emitOutput = checker.emitFiles(); + var emitErrors = emitOutput.errors; + exitStatus = emitOutput.emitResultStatus; + var reportStart = new Date().getTime(); + errors = concatenate(errors, emitErrors); + } + else { + exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; + } } reportDiagnostics(errors); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index fdb49d8dfdd..1f8e10f619b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -155,6 +155,7 @@ module ts { ArrayType, TupleType, UnionType, + ParenType, // Expression ArrayLiteral, ObjectLiteral, @@ -225,7 +226,7 @@ module ts { FirstFutureReservedWord = ImplementsKeyword, LastFutureReservedWord = YieldKeyword, FirstTypeNode = TypeReference, - LastTypeNode = UnionType, + LastTypeNode = ParenType, FirstPunctuation = OpenBraceToken, LastPunctuation = CaretEqualsToken, FirstToken = EndOfFileToken, @@ -250,9 +251,12 @@ module ts { MultiLine = 0x00000100, // Multi-line array or object literal Synthetic = 0x00000200, // Synthetic node (for full fidelity) DeclarationFile = 0x00000400, // Node is a .d.ts file + Let = 0x00000800, // Variable declaration + Const = 0x00001000, // Variable declaration Modifier = Export | Ambient | Public | Private | Protected | Static, - AccessibilityModifier = Public | Private | Protected + AccessibilityModifier = Public | Private | Protected, + BlockScoped = Let | Const } export interface Node extends TextRange { @@ -346,6 +350,10 @@ module ts { types: NodeArray; } + export interface ParenTypeNode extends TypeNode { + type: TypeNode; + } + export interface StringLiteralTypeNode extends TypeNode { text: string; } @@ -644,30 +652,26 @@ module ts { getParentOfSymbol(symbol: Symbol): Symbol; getTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; - getPropertyOfType(type: Type, propetyName: string): Symbol; + getPropertyOfType(type: Type, propertyName: string): Symbol; getSignaturesOfType(type: Type, kind: SignatureKind): Signature[]; getIndexTypeOfType(type: Type, kind: IndexKind): Type; getReturnTypeOfSignature(signature: Signature): Type; getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]; getSymbolInfo(node: Node): Symbol; getTypeOfNode(node: Node): Type; - getApparentType(type: Type): ApparentType; typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string; - writeType(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string; - writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void; + getSymbolDisplayBuilder(): SymbolDisplayBuilder; getFullyQualifiedName(symbol: Symbol): string; - getAugmentedPropertiesOfApparentType(type: Type): Symbol[]; + getAugmentedPropertiesOfType(type: Type): Symbol[]; getRootSymbols(symbol: Symbol): Symbol[]; getContextualType(node: Node): Type; getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature; getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature; - writeSignature(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; - writeTypeParameter(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; - writeTypeParametersOfSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void; isImplementationOfOverload(node: FunctionDeclaration): boolean; isUndefinedSymbol(symbol: Symbol): boolean; isArgumentsSymbol(symbol: Symbol): boolean; + hasEarlyErrors(sourceFile?: SourceFile): boolean; // Returns the constant value of this enum member, or 'undefined' if the enum member has a // computed value. @@ -677,8 +681,25 @@ module ts { getAliasedSymbol(symbol: Symbol): Symbol; } + export interface SymbolDisplayBuilder { + buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildSymbolDisplay(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void; + buildSignatureDisplay(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildParameterDisplay(parameter: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void; + buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + } + export interface SymbolWriter { - writeKind(text: string, kind: SymbolDisplayPartKind): void; + writeKeyword(text: string): void; + writeOperator(text: string): void; + writePunctuation(text: string): void; + writeSpace(text: string): void; + writeStringLiteral(text: string): void; + writeParameter(text: string): void; writeSymbol(text: string, symbol: Symbol): void; writeLine(): void; increaseIndent(): void; @@ -699,6 +720,7 @@ module ts { WriteArrowStyleSignature = 0x00000008, // Write arrow style signature WriteOwnNameForAnyLike = 0x00000010, // Write symbol's own name instead of 'any' for any like types (eg. unknown, __resolving__ etc) WriteTypeArgumentsOfSignature = 0x00000020, // Write the type arguments instead of type parameters of the signature + InElementType = 0x00000040, // Writing an array or union element type } export enum SymbolFormatFlags { @@ -745,52 +767,62 @@ module ts { // Returns the constant value this property access resolves to, or 'undefined' if it does // resolve to a constant. getConstantValue(node: PropertyAccess): number; + hasEarlyErrors(sourceFile?: SourceFile): boolean; } export enum SymbolFlags { - Variable = 0x00000001, // Variable or parameter - Property = 0x00000002, // Property or enum member - EnumMember = 0x00000004, // Enum member - Function = 0x00000008, // Function - Class = 0x00000010, // Class - Interface = 0x00000020, // Interface - Enum = 0x00000040, // Enum - ValueModule = 0x00000080, // Instantiated module - NamespaceModule = 0x00000100, // Uninstantiated module - TypeLiteral = 0x00000200, // Type Literal - ObjectLiteral = 0x00000400, // Object Literal - Method = 0x00000800, // Method - Constructor = 0x00001000, // Constructor - GetAccessor = 0x00002000, // Get accessor - SetAccessor = 0x00004000, // Set accessor - CallSignature = 0x00008000, // Call signature - ConstructSignature = 0x00010000, // Construct signature - IndexSignature = 0x00020000, // Index signature - TypeParameter = 0x00040000, // Type parameter - UnionProperty = 0x00080000, // Property in union type + FunctionScopedVariable = 0x00000001, // Variable (var) or parameter + Property = 0x00000002, // Property or enum member + EnumMember = 0x00000004, // Enum member + Function = 0x00000008, // Function + Class = 0x00000010, // Class + Interface = 0x00000020, // Interface + Enum = 0x00000040, // Enum + ValueModule = 0x00000080, // Instantiated module + NamespaceModule = 0x00000100, // Uninstantiated module + TypeLiteral = 0x00000200, // Type Literal + ObjectLiteral = 0x00000400, // Object Literal + Method = 0x00000800, // Method + Constructor = 0x00001000, // Constructor + GetAccessor = 0x00002000, // Get accessor + SetAccessor = 0x00004000, // Set accessor + CallSignature = 0x00008000, // Call signature + ConstructSignature = 0x00010000, // Construct signature + IndexSignature = 0x00020000, // Index signature + TypeParameter = 0x00040000, // Type parameter // Export markers (see comment in declareModuleMember in binder) - ExportValue = 0x00100000, // Exported value marker - ExportType = 0x00200000, // Exported type marker - ExportNamespace = 0x00400000, // Exported namespace marker + ExportValue = 0x00080000, // Exported value marker + ExportType = 0x00100000, // Exported type marker + ExportNamespace = 0x00200000, // Exported namespace marker - Import = 0x00800000, // Import - Instantiated = 0x01000000, // Instantiated symbol - Merged = 0x02000000, // Merged symbol (created during program binding) - Transient = 0x04000000, // Transient symbol (created during type check) - Prototype = 0x08000000, // Prototype property (no source representation) - Undefined = 0x10000000, // Symbol for the undefined + Import = 0x00400000, // Import + Instantiated = 0x00800000, // Instantiated symbol + Merged = 0x01000000, // Merged symbol (created during program binding) + Transient = 0x02000000, // Transient symbol (created during type check) + Prototype = 0x04000000, // Prototype property (no source representation) + UnionProperty = 0x08000000, // Property in union type - Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor | UnionProperty, - + BlockScopedVariable = 0x10000000, // A block-scoped variable (let ot const) + + Variable = FunctionScopedVariable | BlockScopedVariable, + Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor, Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter, Namespace = ValueModule | NamespaceModule, Module = ValueModule | NamespaceModule, Accessor = GetAccessor | SetAccessor, Signature = CallSignature | ConstructSignature | IndexSignature, + + // Variables can be redeclared, but can not redeclare a block-scoped declaration with the + // same name, or any other value that is not a variable, e.g. ValueModule or Class + FunctionScopedVariableExcludes = Value & ~FunctionScopedVariable, + + // Block-scoped declarations are not allowed to be re-declared + // they can not merge with anything in the value space + BlockScopedVariableExcludes = Value, + ParameterExcludes = Value, - VariableExcludes = Value & ~Variable, PropertyExcludes = Value, EnumMemberExcludes = Value, FunctionExcludes = Value & ~(Function | ValueModule), @@ -804,8 +836,9 @@ module ts { SetAccessorExcludes = Value & ~GetAccessor, TypeParameterExcludes = Type & ~TypeParameter, + // Imports collide with all other imports with the same name. - ImportExcludes = Import, + ImportExcludes = Import, ModuleMember = Variable | Function | Class | Interface | Enum | Module | Import, @@ -896,7 +929,8 @@ module ts { Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null, StringLike = String | StringLiteral, NumberLike = Number | Enum, - ObjectType = Class | Interface | Reference | Tuple | Union | Anonymous, + ObjectType = Class | Interface | Reference | Tuple | Anonymous, + Structured = Any | ObjectType | Union | TypeParameter } // Properties common to all types @@ -919,12 +953,6 @@ module ts { // Object types (TypeFlags.ObjectType) export interface ObjectType extends Type { } - export interface ApparentType extends Type { - // This property is not used. It is just to make the type system think ApparentType - // is a strict subtype of Type. - _apparentTypeBrand: any; - } - // Class and interface types (TypeFlags.Class and TypeFlags.Interface) export interface InterfaceType extends ObjectType { typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic) @@ -954,12 +982,13 @@ module ts { baseArrayType: TypeReference; // Array where T is best common type of element types } - export interface UnionType extends ObjectType { - types: Type[]; // Constituent types + export interface UnionType extends Type { + types: Type[]; // Constituent types + resolvedProperties: SymbolTable; // Cache of resolved properties } - // Resolved object type - export interface ResolvedObjectType extends ObjectType { + // Resolved object or union type + export interface ResolvedType extends ObjectType, UnionType { members: SymbolTable; // Properties by name properties: Symbol[]; // Properties callSignatures: Signature[]; // Call signatures of type @@ -1006,6 +1035,7 @@ module ts { export interface InferenceContext { typeParameters: TypeParameter[]; // Type parameters for which inferences are made + inferUnionTypes: boolean; // Infer union types for disjoint candidates (otherwise undefinedType) inferenceCount: number; // Incremented for every inference made (whether new or not) inferences: Type[][]; // Inferences made for each type parameter inferredTypes: Type[]; // Inferred type for each type parameter @@ -1015,6 +1045,7 @@ module ts { key: string; category: DiagnosticCategory; code: number; + isEarly?: boolean; } // A linked list of formatted diagnostic messages to be used as part of a multiline message. @@ -1035,6 +1066,7 @@ module ts { messageText: string; category: DiagnosticCategory; code: number; + isEarly?: boolean; } export enum DiagnosticCategory { @@ -1087,6 +1119,8 @@ module ts { export enum ScriptTarget { ES3, ES5, + ES6, + Latest = ES6, } export interface ParsedCommandLine { @@ -1237,32 +1271,7 @@ module ts { tab = 0x09, // \t verticalTab = 0x0B, // \v } - - export enum SymbolDisplayPartKind { - aliasName, - className, - enumName, - fieldName, - interfaceName, - keyword, - lineBreak, - numericLiteral, - stringLiteral, - localName, - methodName, - moduleName, - operator, - parameterName, - propertyName, - punctuation, - space, - text, - typeParameterName, - enumMemberName, - functionName, - regularExpressionLiteral, - } - + export interface CancellationToken { isCancellationRequested(): boolean; } diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 31d009c4765..6e211892437 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -61,9 +61,11 @@ class CompilerBaselineRunner extends RunnerBase { var otherFiles: { unitName: string; content: string }[]; var harnessCompiler: Harness.Compiler.HarnessCompiler; - var declToBeCompiled: { unitName: string; content: string }[] = []; - var declOtherFiles: { unitName: string; content: string }[] = []; - var declResult: Harness.Compiler.CompilerResult; + var declFileCompilationResult: { + declInputFiles: { unitName: string; content: string }[]; + declOtherFiles: { unitName: string; content: string }[]; + declResult: Harness.Compiler.CompilerResult; + }; var createNewInstance = false; @@ -147,9 +149,7 @@ class CompilerBaselineRunner extends RunnerBase { toBeCompiled = undefined; otherFiles = undefined; harnessCompiler = undefined; - declToBeCompiled = undefined; - declOtherFiles = undefined; - declResult = undefined; + declFileCompilationResult = undefined; }); function getByteOrderMarkText(file: Harness.Compiler.GeneratedFile): string { @@ -173,61 +173,18 @@ class CompilerBaselineRunner extends RunnerBase { // Source maps? it('Correct sourcemap content for ' + fileName, () => { - if (result.sourceMapRecord) { + if (options.sourceMap) { Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.ts$/, '.sourcemap.txt'), () => { - return result.sourceMapRecord; + return result.getSourceMapRecord(); }); } }); // Compile .d.ts files it('Correct compiler generated.d.ts for ' + fileName, () => { - if (options.declaration && result.errors.length === 0 && result.declFilesCode.length !== result.files.length) { - throw new Error('There were no errors and declFiles generated did not match number of js files generated'); - } - - // if the .d.ts is non-empty, confirm it compiles correctly as well - if (options.declaration && result.errors.length === 0 && result.declFilesCode.length > 0) { - function addDtsFile(file: { unitName: string; content: string }, dtsFiles: { unitName: string; content: string }[]) { - if (Harness.Compiler.isDTS(file.unitName)) { - dtsFiles.push(file); - } - else { - var declFile = findResultCodeFile(file.unitName); - // Look if there is --out file corresponding to this ts file - if (!declFile && options.out) { - declFile = findResultCodeFile(options.out); - if (!declFile || findUnit(declFile.fileName, declToBeCompiled) || - findUnit(declFile.fileName, declOtherFiles)) { - return; - } - } - - if (declFile) { - dtsFiles.push({ unitName: declFile.fileName, content: declFile.code }); - return; - } - } - - function findResultCodeFile(fileName: string) { - return ts.forEach(result.declFilesCode, - declFile => declFile.fileName === (fileName.substr(0, fileName.length - ".ts".length) + ".d.ts") - ? declFile : undefined); - } - - function findUnit(fileName: string, units: { unitName: string; content: string }[]) { - return ts.forEach(units, unit => unit.unitName === fileName ? unit : undefined); - } - } - - ts.forEach(toBeCompiled, file => addDtsFile(file, declToBeCompiled)); - ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles)); - harnessCompiler.compileFiles(declToBeCompiled, declOtherFiles, function (compileResult) { - declResult = compileResult; - }, function (settings) { - harnessCompiler.setCompilerSettings(tcSettings); - }); - } + declFileCompilationResult = harnessCompiler.compileDeclarationFiles(toBeCompiled, otherFiles, result, function (settings) { + harnessCompiler.setCompilerSettings(tcSettings); + }, options); }); @@ -267,10 +224,10 @@ class CompilerBaselineRunner extends RunnerBase { } } - if (declResult && declResult.errors.length) { + if (declFileCompilationResult && declFileCompilationResult.declResult.errors.length) { jsCode += '\r\n\r\n//// [DtsFileErrors]\r\n'; jsCode += '\r\n\r\n'; - jsCode += getErrorBaseline(declToBeCompiled, declOtherFiles, declResult); + jsCode += getErrorBaseline(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles, declFileCompilationResult.declResult); } if (jsCode.length > 0) { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 6a4e13b22e3..145d639bcaf 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -146,7 +146,7 @@ module FourSlash { function convertGlobalOptionsToCompilationSettings(globalOptions: { [idx: string]: string }): ts.CompilationSettings { var settings: ts.CompilationSettings = {}; - // Convert all property in globalOptions into ts.CompilationSettings + // Convert all property in globalOptions into ts.CompilationSettings for (var prop in globalOptions) { if (globalOptions.hasOwnProperty(prop)) { switch (prop) { @@ -985,15 +985,85 @@ module FourSlash { return item.parameters[currentParam]; } + private alignmentForExtraInfo = 50; + + private spanInfoToString(pos: number, spanInfo: TypeScript.TextSpan, prefixString: string) { + var resultString = "SpanInfo: " + JSON.stringify(spanInfo); + if (spanInfo) { + var spanString = this.activeFile.content.substr(spanInfo.start(), spanInfo.length()); + var spanLineMap = ts.computeLineStarts(spanString); + for (var i = 0; i < spanLineMap.length; i++) { + if (!i) { + resultString += "\n"; + } + resultString += prefixString + spanString.substring(spanLineMap[i], spanLineMap[i + 1]); + } + resultString += "\n" + prefixString + ":=> (" + this.getLineColStringAtPosition(spanInfo.start()) + ") to (" + this.getLineColStringAtPosition(spanInfo.end()) + ")"; + } + + return resultString; + } + + private baselineCurrentFileLocations(getSpanAtPos: (pos: number) => TypeScript.TextSpan): string { + var fileLineMap = ts.computeLineStarts(this.activeFile.content); + var nextLine = 0; + var resultString = ""; + var currentLine: string; + var previousSpanInfo: string; + var startColumn: number; + var length: number; + var prefixString = " >"; + + var addSpanInfoString = () => { + if (previousSpanInfo) { + resultString += currentLine; + var thisLineMarker = repeatString(startColumn, " ") + repeatString(length, "~"); + thisLineMarker += repeatString(this.alignmentForExtraInfo - thisLineMarker.length - prefixString.length + 1, " "); + resultString += thisLineMarker; + resultString += "=> Pos: (" + (pos - length) + " to " + (pos - 1) + ") "; + resultString += " " + previousSpanInfo; + previousSpanInfo = undefined; + } + }; + + for (var pos = 0; pos < this.activeFile.content.length; pos++) { + if (pos === 0 || pos === fileLineMap[nextLine]) { + nextLine++; + addSpanInfoString(); + if (resultString.length) { + resultString += "\n--------------------------------"; + } + currentLine = "\n" + nextLine.toString() + repeatString(3 - nextLine.toString().length, " ") + ">" + this.activeFile.content.substring(pos, fileLineMap[nextLine]) + "\n "; + startColumn = 0; + length = 0; + } + var spanInfo = this.spanInfoToString(pos, getSpanAtPos(pos), prefixString); + if (previousSpanInfo && previousSpanInfo !== spanInfo) { + addSpanInfoString(); + previousSpanInfo = spanInfo; + startColumn = startColumn + length; + length = 1; + } + else { + previousSpanInfo = spanInfo; + length++; + } + } + addSpanInfoString(); + return resultString; + + function repeatString(count: number, char: string) { + var result = ""; + for (var i = 0; i < count; i++) { + result += char; + } + return result; + } + } + public getBreakpointStatementLocation(pos: number) { this.taoInvalidReason = 'getBreakpointStatementLocation NYI'; - - var spanInfo = this.languageService.getBreakpointStatementAtPosition(this.activeFile.fileName, pos); - var resultString = "\n**Pos: " + pos + " SpanInfo: " + JSON.stringify(spanInfo) + "\n** Statement: "; - if (spanInfo !== null) { - resultString = resultString + this.activeFile.content.substr(spanInfo.start(), spanInfo.length()); - } - return resultString; + return this.languageService.getBreakpointStatementAtPosition(this.activeFile.fileName, pos); } public baselineCurrentFileBreakpointLocations() { @@ -1003,12 +1073,7 @@ module FourSlash { "Breakpoint Locations for " + this.activeFile.fileName, this.testData.globalOptions[testOptMetadataNames.baselineFile], () => { - var fileLength = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getLength(); - var resultString = ""; - for (var pos = 0; pos < fileLength; pos++) { - resultString = resultString + this.getBreakpointStatementLocation(pos); - } - return resultString; + return this.baselineCurrentFileLocations(pos => this.getBreakpointStatementLocation(pos)); }, true /* run immediately */); } @@ -1056,7 +1121,7 @@ module FourSlash { } public printBreakpointLocation(pos: number) { - Harness.IO.log(this.getBreakpointStatementLocation(pos)); + Harness.IO.log("\n**Pos: " + pos + " " + this.spanInfoToString(pos, this.getBreakpointStatementLocation(pos), " ")); } public printBreakpointAtCurrentLocation() { @@ -1502,7 +1567,7 @@ module FourSlash { throw new Error('verifyCaretAtMarker failed - expected to be in file "' + pos.fileName + '", but was in file "' + this.activeFile.fileName + '"'); } if (pos.position !== this.currentCaretPosition) { - throw new Error('verifyCaretAtMarker failed - expected to be at marker "/*' + markerName + '*/, but was at position ' + this.currentCaretPosition + '(' + this.getLineColStringAtCaret() + ')'); + throw new Error('verifyCaretAtMarker failed - expected to be at marker "/*' + markerName + '*/, but was at position ' + this.currentCaretPosition + '(' + this.getLineColStringAtPosition(this.currentCaretPosition) + ')'); } } @@ -1566,10 +1631,10 @@ module FourSlash { this.taoInvalidReason = 'verifyCurrentNameOrDottedNameSpanText NYI'; var span = this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, this.currentCaretPosition, this.currentCaretPosition); - if (span === null) { + if (!span) { this.raiseError('verifyCurrentNameOrDottedNameSpanText\n' + '\tExpected: "' + text + '"\n' + - '\t Actual: null'); + '\t Actual: undefined'); } var actual = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getText(span.start(), span.end()); @@ -1581,12 +1646,8 @@ module FourSlash { } private getNameOrDottedNameSpan(pos: number) { - var spanInfo = this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, pos, pos); - var resultString = "\n**Pos: " + pos + " SpanInfo: " + JSON.stringify(spanInfo) + "\n** Statement: "; - if (spanInfo !== null) { - resultString = resultString + this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getText(spanInfo.start(), spanInfo.end()); - } - return resultString; + this.taoInvalidReason = 'getNameOrDottedNameSpan NYI'; + return this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, pos, pos); } public baselineCurrentFileNameOrDottedNameSpans() { @@ -1596,23 +1657,21 @@ module FourSlash { "Name OrDottedNameSpans for " + this.activeFile.fileName, this.testData.globalOptions[testOptMetadataNames.baselineFile], () => { - var fileLength = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getLength(); - var resultString = ""; - for (var pos = 0; pos < fileLength; pos++) { - resultString = resultString + this.getNameOrDottedNameSpan(pos); - } - return resultString; + return this.baselineCurrentFileLocations(pos => + this.getNameOrDottedNameSpan(pos)); }, true /* run immediately */); } public printNameOrDottedNameSpans(pos: number) { - Harness.IO.log(this.getNameOrDottedNameSpan(pos)); + Harness.IO.log(this.spanInfoToString(pos, this.getNameOrDottedNameSpan(pos), "**")); } - private verifyClassifications(expected: { classificationType: string; text: string }[], actual: ts.ClassifiedSpan[]) { + private verifyClassifications(expected: { classificationType: string; text: string; textSpan?: TextSpan }[], actual: ts.ClassifiedSpan[]) { if (actual.length !== expected.length) { - this.raiseError('verifyClassifications failed - expected total classifications to be ' + expected.length + ', but was ' + actual.length); + this.raiseError('verifyClassifications failed - expected total classifications to be ' + expected.length + + ', but was ' + actual.length + + jsonMismatchString()); } for (var i = 0; i < expected.length; i++) { @@ -1623,17 +1682,38 @@ module FourSlash { if (expectedType !== actualClassification.classificationType) { this.raiseError('verifyClassifications failed - expected classifications type to be ' + expectedType + ', but was ' + - actualClassification.classificationType); + actualClassification.classificationType + + jsonMismatchString()); } + var expectedSpan = expectedClassification.textSpan; var actualSpan = actualClassification.textSpan; + + if (expectedSpan) { + var expectedLength = expectedSpan.end - expectedSpan.start; + + if (expectedSpan.start !== actualSpan.start() || expectedLength !== actualSpan.length()) { + this.raiseError("verifyClassifications failed - expected span of text to be " + + "{start=" + expectedSpan.start + ", length=" + expectedLength + "}, but was " + + "{start=" + actualSpan.start() + ", length=" + actualSpan.length() + "}" + + jsonMismatchString()); + } + } + var actualText = this.activeFile.content.substr(actualSpan.start(), actualSpan.length()); if (expectedClassification.text !== actualText) { - this.raiseError('verifyClassifications failed - expected classificatied text to be ' + + this.raiseError('verifyClassifications failed - expected classified text to be ' + expectedClassification.text + ', but was ' + - actualText); + actualText + + jsonMismatchString()); } } + + function jsonMismatchString() { + return sys.newLine + + "expected: '" + sys.newLine + JSON.stringify(expected, (k,v) => v, 2) + "'" + sys.newLine + + "actual: '" + sys.newLine + JSON.stringify(actual, (k, v) => v, 2) + "'"; + } } public verifySemanticClassifications(expected: { classificationType: string; text: string }[]) { @@ -1984,7 +2064,8 @@ module FourSlash { var newlinePos = text.indexOf('\n'); if (newlinePos === -1) { return text; - } else { + } + else { if (text.charAt(newlinePos - 1) === '\r') { newlinePos--; } @@ -2090,8 +2171,8 @@ module FourSlash { return this.languageServiceShimHost.positionToZeroBasedLineCol(this.activeFile.fileName, this.currentCaretPosition).line + 1; } - private getLineColStringAtCaret() { - var pos = this.languageServiceShimHost.positionToZeroBasedLineCol(this.activeFile.fileName, this.currentCaretPosition); + private getLineColStringAtPosition(position: number) { + var pos = this.languageServiceShimHost.positionToZeroBasedLineCol(this.activeFile.fileName, position); return 'line ' + (pos.line + 1) + ', col ' + pos.character; } @@ -2139,7 +2220,7 @@ module FourSlash { var host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFilename, content: undefined }, { unitName: fileName, content: content }], (fn, contents) => result = contents, - ts.ScriptTarget.ES5, + ts.ScriptTarget.Latest, sys.useCaseSensitiveFileNames); var program = ts.createProgram([Harness.Compiler.fourslashFilename, fileName], { out: "fourslashTestOutput.js" }, host); var checker = ts.createTypeChecker(program, /*fullTypeCheckMode*/ true); diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 8bfaeb5800f..cfabc3436d6 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -139,6 +139,7 @@ module Harness { deleteFile(filename: string): void; listFiles(path: string, filter: RegExp, options?: { recursive?: boolean }): string[]; log(text: string): void; + getMemoryUsage? (): number; } module IOImpl { @@ -275,6 +276,13 @@ module Harness { return filesInFolder(path); } + + export var getMemoryUsage: typeof IO.getMemoryUsage = () => { + if (global.gc) { + global.gc(); + } + return process.memoryUsage().heapUsed; + } } export module Network { @@ -532,7 +540,7 @@ module Harness { } export var defaultLibFileName = 'lib.d.ts'; - export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.ES5, /*version:*/ "0"); + export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*version:*/ "0"); // Cache these between executions so we don't have to re-parse them for every test export var fourslashFilename = 'fourslash.ts'; @@ -685,6 +693,8 @@ module Harness { options.target = ts.ScriptTarget.ES3; } else if (setting.value.toLowerCase() === 'es5') { options.target = ts.ScriptTarget.ES5; + } else if (setting.value.toLowerCase() === 'es6') { + options.target = ts.ScriptTarget.ES6; } else { throw new Error('Unknown compile target ' + setting.value); } @@ -791,9 +801,11 @@ module Harness { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); checker.checkProgram(); + var hasEarlyErrors = checker.hasEarlyErrors(); + // only emit if there weren't parse errors var emitResult: ts.EmitResult; - if (!hadParseErrors) { + if (!hadParseErrors && !hasEarlyErrors) { emitResult = checker.emitFiles(); } @@ -804,15 +816,81 @@ module Harness { }); this.lastErrors = errors; - var result = new CompilerResult(fileOutputs, errors, []); - // Covert the source Map data into the baseline - result.updateSourceMapRecord(program, emitResult ? emitResult.sourceMaps : undefined); + var result = new CompilerResult(fileOutputs, errors, program, sys.getCurrentDirectory(), emitResult ? emitResult.sourceMaps : undefined); onComplete(result, checker); // reset what newline means in case the last test changed it sys.newLine = '\r\n'; return options; } + + public compileDeclarationFiles(inputFiles: { unitName: string; content: string; }[], + otherFiles: { unitName: string; content: string; }[], + result: CompilerResult, + settingsCallback?: (settings: ts.CompilerOptions) => void, + options?: ts.CompilerOptions) { + if (options.declaration && result.errors.length === 0 && result.declFilesCode.length !== result.files.length) { + throw new Error('There were no errors and declFiles generated did not match number of js files generated'); + } + + // if the .d.ts is non-empty, confirm it compiles correctly as well + if (options.declaration && result.errors.length === 0 && result.declFilesCode.length > 0) { + var declInputFiles: { unitName: string; content: string }[] = []; + var declOtherFiles: { unitName: string; content: string }[] = []; + var declResult: Harness.Compiler.CompilerResult; + + ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles)); + ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles)); + this.compileFiles(declInputFiles, declOtherFiles, function (compileResult) { + declResult = compileResult; + }, settingsCallback, options); + + return { declInputFiles: declInputFiles, declOtherFiles: declOtherFiles, declResult: declResult }; + } + + function addDtsFile(file: { unitName: string; content: string }, dtsFiles: { unitName: string; content: string }[]) { + if (isDTS(file.unitName)) { + dtsFiles.push(file); + } + else if (isTS(file.unitName)) { + var declFile = findResultCodeFile(file.unitName); + if (!findUnit(declFile.fileName, declInputFiles) && !findUnit(declFile.fileName, declOtherFiles)) { + dtsFiles.push({ unitName: declFile.fileName, content: declFile.code }); + } + } + + function findResultCodeFile(fileName: string) { + var dTsFileName = ts.forEach(result.program.getSourceFiles(), sourceFile => { + if (sourceFile.filename === fileName) { + // Is this file going to be emitted separately + var sourceFileName: string; + if (ts.isExternalModule(sourceFile) || !options.out) { + if (options.outDir) { + var sourceFilePath = ts.getNormalizedPathFromPathComponents(ts.getNormalizedPathComponents(sourceFile.filename, result.currentDirectoryForProgram)); + sourceFilePath = sourceFilePath.replace(result.program.getCommonSourceDirectory(), ""); + sourceFileName = ts.combinePaths(options.outDir, sourceFilePath); + } + else { + sourceFileName = sourceFile.filename; + } + } + else { + // Goes to single --out file + sourceFileName = options.out; + } + + return ts.removeFileExtension(sourceFileName) + ".d.ts"; + } + }); + + return ts.forEach(result.declFilesCode, declFile => declFile.fileName === dTsFileName ? declFile : undefined); + } + + function findUnit(fileName: string, units: { unitName: string; content: string; }[]) { + return ts.forEach(units, unit => unit.unitName === fileName ? unit : undefined); + } + } + } } export function getMinimalDiagnostic(err: ts.Diagnostic): HarnessDiagnostic { @@ -948,10 +1026,6 @@ module Harness { } */ - /** Recreate the harness compiler instance to its default settings */ - export function recreate(options?: { useMinimalDefaultLib: boolean; noImplicitAny: boolean; }) { - } - /** The harness' compiler instance used when tests are actually run. Reseting or changing settings of this compiler instance must be done within a test case (i.e., describe/it) */ var harnessCompiler: HarnessCompiler; @@ -991,6 +1065,10 @@ module Harness { return str.substr(str.length - end.length) === end; } + export function isTS(fileName: string) { + return stringEndsWith(fileName, '.ts'); + } + export function isDTS(fileName: string) { return stringEndsWith(fileName, '.d.ts'); } @@ -1009,10 +1087,10 @@ module Harness { public errors: HarnessDiagnostic[] = []; public declFilesCode: GeneratedFile[] = []; public sourceMaps: GeneratedFile[] = []; - public sourceMapRecord: string; /** @param fileResults an array of strings for the fileName and an ITextWriter with its code */ - constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], sourceMapRecordLines: string[]) { + constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], public program: ts.Program, + public currentDirectoryForProgram: string, private sourceMapData: ts.SourceMapData[]) { var lines: string[] = []; fileResults.forEach(emittedFile => { @@ -1030,12 +1108,11 @@ module Harness { }); this.errors = errors; - this.sourceMapRecord = sourceMapRecordLines.join('\r\n'); } - public updateSourceMapRecord(program: ts.Program, sourceMapData: ts.SourceMapData[]) { - if (sourceMapData) { - this.sourceMapRecord = Harness.SourceMapRecoder.getSourceMapRecord(sourceMapData, program, this.files); + public getSourceMapRecord() { + if (this.sourceMapData) { + return Harness.SourceMapRecoder.getSourceMapRecord(this.sourceMapData, this.program, this.files); } } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 647d0729cbb..6307c4d1e78 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -260,7 +260,7 @@ module Harness.LanguageService { /** Parse file given its source text */ public parseSourceText(fileName: string, sourceText: TypeScript.IScriptSnapshot): TypeScript.SourceUnitSyntax { - return TypeScript.Parser.parse(fileName, TypeScript.SimpleText.fromScriptSnapshot(sourceText), ts.ScriptTarget.ES5, TypeScript.isDTSFile(fileName)).sourceUnit(); + return TypeScript.Parser.parse(fileName, TypeScript.SimpleText.fromScriptSnapshot(sourceText), ts.ScriptTarget.Latest, TypeScript.isDTSFile(fileName)).sourceUnit(); } /** Parse a file on disk given its fileName */ diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 2886c43f091..797bc12a42b 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -419,6 +419,16 @@ class ProjectRunner extends RunnerBase { // }) //}); } + + after(() => { + // Mocha holds onto the closure environment of the describe callback even after the test is done. + // Therefore we have to clean out large objects after the test is done. + nodeCompilerResult = undefined; + amdCompilerResult = undefined; + testCase = undefined; + testFileText = undefined; + testCaseJustName = undefined; + }); }); } } \ No newline at end of file diff --git a/src/harness/runner.ts b/src/harness/runner.ts index 331a19819b3..38e23bb10c5 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -18,7 +18,6 @@ // /// /// /// -/// function runTests(runners: RunnerBase[]) { if (reverse) { @@ -67,9 +66,6 @@ if (testConfigFile !== '') { case 'fourslash-generated': runners.push(new GeneratedFourslashRunner()); break; - case 'unittests': - runners.push(new UnitTestRunner()); - break; case 'rwc': runners.push(new RWCRunner()); break; @@ -93,9 +89,6 @@ if (runners.length === 0) { // language services runners.push(new FourslashRunner()); //runners.push(new GeneratedFourslashRunner()); - - // unittests - runners.push(new UnitTestRunner()); } sys.newLine = '\r\n'; diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index f7cc699c075..6590344a8dd 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -46,144 +46,171 @@ module RWC { } export function runRWCTest(jsonPath: string) { - var harnessCompiler = Harness.Compiler.getCompiler(); - var opts: ts.ParsedCommandLine; + describe("Testing a RWC project: " + jsonPath, () => { + var inputFiles: { unitName: string; content: string; }[] = []; + var otherFiles: { unitName: string; content: string; }[] = []; + var compilerResult: Harness.Compiler.CompilerResult; + var compilerOptions: ts.CompilerOptions; + var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' }; + var baseName = /(.*)\/(.*).json/.exec(Harness.Path.switchToForwardSlashes(jsonPath))[2]; + // Compile .d.ts files + var declFileCompilationResult: { + declInputFiles: { unitName: string; content: string }[]; + declOtherFiles: { unitName: string; content: string }[]; + declResult: Harness.Compiler.CompilerResult; + }; - var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath)); - var errors = ''; - - it('has parsable options', () => { - runWithIOLog(ioLog, () => { - opts = ts.parseCommandLine(ioLog.arguments); - assert.equal(opts.errors.length, 0); - }); - }); - - var inputFiles: { unitName: string; content: string; }[] = []; - var otherFiles: { unitName: string; content: string; }[] = []; - var compilerResult: Harness.Compiler.CompilerResult; - it('can compile', () => { - runWithIOLog(ioLog, () => { - harnessCompiler.reset(); - - // Load the files - ts.forEach(opts.filenames, fileName => { - inputFiles.push(getHarnessCompilerInputUnit(fileName)); - }); - - if (!opts.options.noLib) { - // Find the lib.d.ts file in the input file and add it to the input files list - var libFile = ts.forEach(ioLog.filesRead, fileRead=> Harness.isLibraryFile(fileRead.path) ? fileRead.path : undefined); - if (libFile) { - inputFiles.push(getHarnessCompilerInputUnit(libFile)); - } - } - - ts.forEach(ioLog.filesRead, fileRead => { - var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileRead.path)); - var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath); - if (!inInputList) { - // Add the file to other files - otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); - } - }); - - // do not use lib since we already read it in above - opts.options.noLib = true; - - // Emit the results - harnessCompiler.compileFiles(inputFiles, otherFiles, compileResult => { - compilerResult = compileResult; - }, /*settingsCallback*/ undefined, opts.options); + after(() => { + // Mocha holds onto the closure environment of the describe callback even after the test is done. + // Therefore we have to clean out large objects after the test is done. + inputFiles = undefined; + otherFiles = undefined; + compilerResult = undefined; + compilerOptions = undefined; + baselineOpts = undefined; + baseName = undefined; + declFileCompilationResult = undefined; }); - function getHarnessCompilerInputUnit(fileName: string) { - var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileName)); - try { - var content = sys.readFile(resolvedPath); + it('can compile', () => { + var harnessCompiler = Harness.Compiler.getCompiler(); + var opts: ts.ParsedCommandLine; + + var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath)); + runWithIOLog(ioLog, () => { + opts = ts.parseCommandLine(ioLog.arguments); + assert.equal(opts.errors.length, 0); + }); + + runWithIOLog(ioLog, () => { + harnessCompiler.reset(); + + // Load the files + ts.forEach(opts.filenames, fileName => { + inputFiles.push(getHarnessCompilerInputUnit(fileName)); + }); + + if (!opts.options.noLib) { + // Find the lib.d.ts file in the input file and add it to the input files list + var libFile = ts.forEach(ioLog.filesRead, fileRead=> Harness.isLibraryFile(fileRead.path) ? fileRead.path : undefined); + if (libFile) { + inputFiles.push(getHarnessCompilerInputUnit(libFile)); + } + } + + ts.forEach(ioLog.filesRead, fileRead => { + var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileRead.path)); + var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath); + if (!inInputList) { + // Add the file to other files + otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); + } + }); + + // do not use lib since we already read it in above + opts.options.noLib = true; + + // Emit the results + compilerOptions = harnessCompiler.compileFiles(inputFiles, otherFiles, compileResult => { + compilerResult = compileResult; + }, /*settingsCallback*/ undefined, opts.options); + }); + + function getHarnessCompilerInputUnit(fileName: string) { + var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileName)); + try { + var content = sys.readFile(resolvedPath); + } + catch (e) { + // Leave content undefined. + } + return { unitName: resolvedPath, content: content }; } - catch (e) { - // Leave content undefined. - } - return { unitName: resolvedPath, content: content }; - } - }); + }); - // Baselines - var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' }; - var baseName = /(.*)\/(.*).json/.exec(Harness.Path.switchToForwardSlashes(jsonPath))[2]; + // Baselines + it('Correct compiler generated.d.ts', () => { + declFileCompilationResult = Harness.Compiler.getCompiler().compileDeclarationFiles(inputFiles, otherFiles, compilerResult, /*settingscallback*/ undefined, compilerOptions); + }); - it('has the expected emitted code', () => { - Harness.Baseline.runBaseline('has the expected emitted code', baseName + '.output.js', () => { - return collateOutputs(compilerResult.files, s => SyntacticCleaner.clean(s)); - }, false, baselineOpts); - }); - it('has the expected declaration file content', () => { - Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => { - if (compilerResult.errors.length || !compilerResult.declFilesCode.length) { - return null; - } - return collateOutputs(compilerResult.declFilesCode); - }, false, baselineOpts); - }); - - it('has the expected source maps', () => { - Harness.Baseline.runBaseline('has the expected source maps', baseName + '.map', () => { - if (!compilerResult.sourceMaps.length) { - return null; - } - - return collateOutputs(compilerResult.sourceMaps); - }, false, baselineOpts); - }); - - it('has correct source map record', () => { - if (compilerResult.sourceMapRecord) { - Harness.Baseline.runBaseline('has correct source map record', baseName + '.sourcemap.txt', () => { - return compilerResult.sourceMapRecord; + it('has the expected emitted code', () => { + Harness.Baseline.runBaseline('has the expected emitted code', baseName + '.output.js', () => { + return collateOutputs(compilerResult.files, s => SyntacticCleaner.clean(s)); }, false, baselineOpts); - } - }); + }); - it('has the expected errors', () => { - Harness.Baseline.runBaseline('has the expected errors', baseName + '.errors.txt', () => { - if (compilerResult.errors.length === 0) { - return null; + it('has the expected declaration file content', () => { + Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => { + if (compilerResult.errors.length || !compilerResult.declFilesCode.length) { + return null; + } + return collateOutputs(compilerResult.declFilesCode); + }, false, baselineOpts); + }); + + it('has the expected source maps', () => { + Harness.Baseline.runBaseline('has the expected source maps', baseName + '.map', () => { + if (!compilerResult.sourceMaps.length) { + return null; + } + + return collateOutputs(compilerResult.sourceMaps); + }, false, baselineOpts); + }); + + //it('has correct source map record', () => { + // if (compilerOptions.sourceMap) { + // Harness.Baseline.runBaseline('has correct source map record', baseName + '.sourcemap.txt', () => { + // return compilerResult.getSourceMapRecord(); + // }, false, baselineOpts); + // } + //}); + + it('has the expected errors', () => { + Harness.Baseline.runBaseline('has the expected errors', baseName + '.errors.txt', () => { + if (compilerResult.errors.length === 0) { + return null; + } + + return Harness.Compiler.getErrorBaseline(inputFiles.concat(otherFiles), compilerResult.errors); + }, false, baselineOpts); + }); + + it('has no errors in generated declaration files', () => { + if (compilerOptions.declaration && !compilerResult.errors.length) { + Harness.Baseline.runBaseline('has no errors in generated declaration files', baseName + '.dts.errors.txt', () => { + if (declFileCompilationResult.declResult.errors.length === 0) { + return null; + } + + return Harness.Compiler.minimalDiagnosticsToString(declFileCompilationResult.declResult.errors) + + sys.newLine + sys.newLine + + Harness.Compiler.getErrorBaseline(declFileCompilationResult.declInputFiles.concat(declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.errors); + }, false, baselineOpts); } + }); - return Harness.Compiler.getErrorBaseline(inputFiles.concat(otherFiles), compilerResult.errors); - }, false, baselineOpts); + // TODO: Type baselines (need to refactor out from compilerRunner) }); - - // TODO: Type baselines (need to refactor out from compilerRunner) } } class RWCRunner extends RunnerBase { - private runnerPath = "tests/runners/rwc"; - private sourcePath = "tests/cases/rwc/"; - - private harnessCompiler: Harness.Compiler.HarnessCompiler; + private static sourcePath = "tests/cases/rwc/"; /** Setup the runner's tests so that they are ready to be executed by the harness * The first test should be a describe/it block that sets up the harness's compiler instance appropriately */ public initializeTests(): void { - // Recreate the compiler with the default lib - Harness.Compiler.recreate({ useMinimalDefaultLib: false, noImplicitAny: false }); - this.harnessCompiler = Harness.Compiler.getCompiler(); - // Read in and evaluate the test list - var testList = Harness.IO.listFiles(this.sourcePath, /.+\.json$/); + var testList = Harness.IO.listFiles(RWCRunner.sourcePath, /.+\.json$/); for (var i = 0; i < testList.length; i++) { this.runTest(testList[i]); } } private runTest(jsonFilename: string) { - describe("Testing a RWC project: " + jsonFilename, () => { - RWC.runRWCTest(jsonFilename); - }); + RWC.runRWCTest(jsonFilename); } } \ No newline at end of file diff --git a/src/harness/unittestrunner.ts b/src/harness/unittestrunner.ts deleted file mode 100644 index 95c90415409..00000000000 --- a/src/harness/unittestrunner.ts +++ /dev/null @@ -1,73 +0,0 @@ -/// -/// - -class UnitTestRunner extends RunnerBase { - constructor() { - super(); - } - - public initializeTests() { - this.tests = this.enumerateFiles('tests/cases/unittests/services', /\.ts/i); - - var outfile = new Harness.Compiler.WriterAggregator() - var outerr = new Harness.Compiler.WriterAggregator(); - // note this is running immediately to generate tests to be run later inside describe/it - // need a fresh instance so that the previous runner's last test is not hanging around - var harnessCompiler = Harness.Compiler.getCompiler({ useExistingInstance: false }); - - var toBeAdded = this.tests.map(test => { - return { unitName: test, content: Harness.IO.readFile(test) } - }); - harnessCompiler.addInputFiles(toBeAdded); - harnessCompiler.setCompilerOptions({ noResolve: true }); - - var stdout = new Harness.Compiler.EmitterIOHost(); - var emitDiagnostics = harnessCompiler.emitAll(stdout); - var results = stdout.toArray(); - var lines: string[] = []; - results.forEach(v => lines = lines.concat(v.file.lines)); - var code = lines.join("\n") - - var nodeContext: any = undefined; - if (Utils.getExecutionEnvironment() === Utils.ExecutionEnvironment.Node) { - nodeContext = { - require: require, - process: process, - describe: describe, - it: it, - assert: assert, - beforeEach: beforeEach, - afterEach: afterEach, - before: before, - after: after, - Harness: Harness, - IO: Harness.IO, - ts: ts, - TypeScript: TypeScript - // FourSlash: FourSlash - }; - } - - describe("Setup compiler for compiler unittests", () => { - // ensures a clean compiler instance when tests are eventually executed following this describe block - harnessCompiler = Harness.Compiler.getCompiler({ - useExistingInstance: false, - optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false } - }); - }); - - // this generated code is a series of top level describe/it blocks that will run in between the setup and cleanup blocks in this file - Utils.evalFile(code, "generated_test_code.js", nodeContext); - - describe("Cleanup after unittests", () => { - var harnessCompiler = Harness.Compiler.getCompiler({ - useExistingInstance: false, - optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false } - }); - }); - - // note this runs immediately (ie before this same code in the describe block above) - // to make sure the next runner doesn't include the previous one's stuff - harnessCompiler = Harness.Compiler.getCompiler({ useExistingInstance: false }); - } -} \ No newline at end of file diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 923458c144d..3a72ee9bfa6 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -1,1085 +1,503 @@ // Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. -module TypeScript.Services.Breakpoints { - function createBreakpointSpanInfo(parentElement: TypeScript.ISyntaxElement, ...childElements: TypeScript.ISyntaxElement[]): TextSpan { - if (!parentElement) { - return null; +/// + +module ts.BreakpointResolver { + /** + * Get the breakpoint span in given sourceFile + */ + export function spanInSourceFileAtLocation(sourceFile: SourceFile, position: number) { + // Cannot set breakpoint in dts file + if (sourceFile.flags & NodeFlags.DeclarationFile) { + return undefined; } - if (childElements.length == 0) { - return TextSpan.fromBounds(TypeScript.start(parentElement), TypeScript.end(parentElement)); - } + var tokenAtLocation = getTokenAtPosition(sourceFile, position); + var lineOfPosition = sourceFile.getLineAndCharacterFromPosition(position).line; + if (sourceFile.getLineAndCharacterFromPosition(tokenAtLocation.getStart()).line > lineOfPosition) { + // Get previous token if the token is returned starts on new line + // eg: var x =10; |--- curser is here + // var y = 10; + // token at position will return var keyword on second line as the token but we would like to use + // token on same line if trailing trivia (comments or white spaces on same line) part of the last token on that line + tokenAtLocation = findPrecedingToken(tokenAtLocation.pos, sourceFile); - var start: number; - var end: number; - for (var i = 0; i < childElements.length; i++) { - var element = childElements[i]; - if (element && !isShared(element)) { - if (start == undefined) { - start = TypeScript.start(element); - } - end = TypeScript.end(element); + // Its a blank line + if (!tokenAtLocation || sourceFile.getLineAndCharacterFromPosition(tokenAtLocation.getEnd()).line !== lineOfPosition) { + return undefined; } } - return TextSpan.fromBounds(start, end); - } - - function createBreakpointSpanInfoWithLimChar(startElement: TypeScript.ISyntaxElement, limChar: number): TextSpan { - return TextSpan.fromBounds(start(startElement), limChar); - } - - class BreakpointResolver { - constructor(private posLine: number, private lineMap: TypeScript.LineMap) { + // Cannot set breakpoint in ambient declarations + if (isInAmbientContext(tokenAtLocation)) { + return undefined; } - private breakpointSpanOfToken(positionedToken: TypeScript.ISyntaxToken): TextSpan { - switch (positionedToken.kind()) { - case TypeScript.SyntaxKind.OpenBraceToken: - return this.breakpointSpanOfOpenBrace(positionedToken); + // Get the span in the node based on its syntax + return spanInNode(tokenAtLocation); - case TypeScript.SyntaxKind.CloseBraceToken: - return this.breakpointSpanOfCloseBrace(positionedToken); + function textSpan(startNode: Node, endNode?: Node) { + return TypeScript.TextSpan.fromBounds(startNode.getStart(), (endNode || startNode).getEnd()); + } - case TypeScript.SyntaxKind.CommaToken: - return this.breakpointSpanOfComma(positionedToken); + function spanInNodeIfStartsOnSameLine(node: Node, otherwiseOnNode?: Node): TypeScript.TextSpan { + if (node && lineOfPosition === sourceFile.getLineAndCharacterFromPosition(node.getStart()).line) { + return spanInNode(node); + } + return spanInNode(otherwiseOnNode); + } - case TypeScript.SyntaxKind.SemicolonToken: - case TypeScript.SyntaxKind.EndOfFileToken: - return this.breakpointSpanIfStartsOnSameLine(previousToken(positionedToken)); + function spanInPreviousNode(node: Node): TypeScript.TextSpan { + return spanInNode(findPrecedingToken(node.pos, sourceFile)); + } - case TypeScript.SyntaxKind.CloseParenToken: - return this.breakpointSpanOfCloseParen(positionedToken); + function spanInNextNode(node: Node): TypeScript.TextSpan { + return spanInNode(findNextToken(node, node.parent)); + } - case TypeScript.SyntaxKind.DoKeyword: - var parentElement = positionedToken.parent; - if (parentElement && parentElement.kind() == TypeScript.SyntaxKind.DoStatement) { - return this.breakpointSpanIfStartsOnSameLine(nextToken(positionedToken)); + function spanInNode(node: Node): TypeScript.TextSpan { + if (node) { + if (isExpression(node)) { + if (node.parent.kind === SyntaxKind.DoStatement) { + // Set span as if on while keyword + return spanInPreviousNode(node); } - break; - } - return this.breakpointSpanOfContainingNode(positionedToken); - } + if (node.parent.kind === SyntaxKind.ForStatement) { + // For now lets set the span on this expression, fix it later + return textSpan(node); + } - private breakpointSpanOfOpenBrace(openBraceToken: TypeScript.ISyntaxToken): TextSpan { - var container = Syntax.containingNode(openBraceToken); - if (container) { - var originalContainer = container; - if (container && container.kind() == TypeScript.SyntaxKind.Block) { - // We have to check the parent and decide what to do with the breakpoint - container = Syntax.containingNode(container); - if (!container) { - container = originalContainer; + if (node.parent.kind === SyntaxKind.BinaryExpression && (node.parent).operator === SyntaxKind.CommaToken) { + // if this is comma expression, the breakpoint is possible in this expression + return textSpan(node); + } + + if (node.parent.kind == SyntaxKind.ArrowFunction && (node.parent).body == node) { + // If this is body of arrow function, it is allowed to have the breakpoint + return textSpan(node); } } - switch (container.kind()) { - case TypeScript.SyntaxKind.Block: - if (!this.canHaveBreakpointInBlock(container)) { - return null; - } - return this.breakpointSpanOfFirstStatementInBlock(container); - break; + switch (node.kind) { + case SyntaxKind.VariableStatement: + // Span on first variable declaration + return spanInVariableDeclaration((node).declarations[0]); - case TypeScript.SyntaxKind.ModuleDeclaration: - case TypeScript.SyntaxKind.ClassDeclaration: - case TypeScript.SyntaxKind.FunctionDeclaration: - case TypeScript.SyntaxKind.ConstructorDeclaration: - case TypeScript.SyntaxKind.MemberFunctionDeclaration: - case TypeScript.SyntaxKind.GetAccessor: - case TypeScript.SyntaxKind.SetAccessor: - case TypeScript.SyntaxKind.FunctionExpression: - case TypeScript.SyntaxKind.ParenthesizedArrowFunctionExpression: - case TypeScript.SyntaxKind.SimpleArrowFunctionExpression: - if (!this.canHaveBreakpointInDeclaration(container)) { - return null; + case SyntaxKind.VariableDeclaration: + case SyntaxKind.Property: + return spanInVariableDeclaration(node); + + case SyntaxKind.Parameter: + return spanInParameterDeclaration(node); + + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.Method: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Constructor: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + return spanInFunctionDeclaration(node); + + case SyntaxKind.FunctionBlock: + return spanInFunctionBlock(node); + + case SyntaxKind.Block: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: + case SyntaxKind.ModuleBlock: + return spanInBlock(node); + + case SyntaxKind.ExpressionStatement: + // span on the expression + return textSpan((node).expression); + + case SyntaxKind.ReturnStatement: + // span on return keyword and expression if present + return textSpan(node.getChildAt(0), (node).expression); + + case SyntaxKind.WhileStatement: + // Span on while(...) + return textSpan(node, findNextToken((node).expression, node)); + + case SyntaxKind.DoStatement: + // span in statement of the do statement + return spanInNode((node).statement); + + case SyntaxKind.DebuggerStatement: + // span on debugger keyword + return textSpan(node.getChildAt(0)); + + case SyntaxKind.IfStatement: + // set on if(..) span + return textSpan(node, findNextToken((node).expression, node)); + + case SyntaxKind.LabeledStatement: + // span in statement + return spanInNode((node).statement); + + case SyntaxKind.BreakStatement: + case SyntaxKind.ContinueStatement: + // On break or continue keyword and label if present + return textSpan(node.getChildAt(0), (node).label); + + case SyntaxKind.ForStatement: + return spanInForStatement(node); + + case SyntaxKind.ForInStatement: + // span on for (a in ...) + return textSpan(node, findNextToken((node).expression, node)); + + case SyntaxKind.SwitchStatement: + // span on switch(...) + return textSpan(node, findNextToken((node).expression, node)); + + case SyntaxKind.CaseClause: + case SyntaxKind.DefaultClause: + // span in first statement of the clause + return spanInNode((node).statements[0]); + + case SyntaxKind.TryStatement: + // span in try block + return spanInBlock((node).tryBlock); + + case SyntaxKind.ThrowStatement: + // span in throw ... + return textSpan(node, (node).expression); + + case SyntaxKind.ExportAssignment: + // span on export = id + return textSpan(node, (node).exportName); + + case SyntaxKind.ImportDeclaration: + // import statement without including semicolon + return textSpan(node, (node).entityName || (node).externalModuleName); + + case SyntaxKind.ModuleDeclaration: + // span on complete module if it is instantiated + if (!isInstantiated(node)) { + return undefined; } - if (this.posLine != this.lineMap.getLineNumberFromPosition(start(container))) { - return this.breakpointSpanOfFirstChildOfSyntaxList(this.getSyntaxListOfDeclarationWithElements(container)); + + case SyntaxKind.ClassDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.EnumMember: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + // span on complete node + return textSpan(node); + + case SyntaxKind.WithStatement: + // span in statement + return spanInNode((node).statement); + + // No breakpoint in interface + case SyntaxKind.InterfaceDeclaration: + return undefined; + + // Tokens: + case SyntaxKind.SemicolonToken: + case SyntaxKind.EndOfFileToken: + return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile)); + + case SyntaxKind.CommaToken: + return spanInPreviousNode(node) + + case SyntaxKind.OpenBraceToken: + return spanInOpenBraceToken(node); + + case SyntaxKind.CloseBraceToken: + return spanInCloseBraceToken(node); + + case SyntaxKind.OpenParenToken: + return spanInOpenParenToken(node); + + case SyntaxKind.CloseParenToken: + return spanInCloseParenToken(node); + + case SyntaxKind.ColonToken: + return spanInColonToken(node); + + case SyntaxKind.GreaterThanToken: + case SyntaxKind.LessThanToken: + return spanInGreaterThanOrLessThanToken(node); + + // Keywords: + case SyntaxKind.WhileKeyword: + return spanInWhileKeyword(node); + + case SyntaxKind.ElseKeyword: + case SyntaxKind.CatchKeyword: + case SyntaxKind.FinallyKeyword: + return spanInNextNode(node); + + default: + // If this is name of property assignment, set breakpoint in the initializer + if (node.parent.kind === SyntaxKind.PropertyAssignment && (node.parent).name === node) { + return spanInNode((node.parent).initializer); + } + + // Breakpoint in type assertion goes to its operand + if (node.parent.kind === SyntaxKind.TypeAssertion && (node.parent).type === node) { + return spanInNode((node.parent).operand); + } + + // return type of function go to previous token + if (isAnyFunction(node.parent) && (node.parent).type === node) { + return spanInPreviousNode(node); + } + + // Default go to parent to set the breakpoint + return spanInNode(node.parent); + } + } + + function spanInVariableDeclaration(variableDeclaration: VariableDeclaration): TypeScript.TextSpan { + // If declaration of for in statement, just set the span in parent + if (variableDeclaration.parent.kind === SyntaxKind.ForInStatement) { + return spanInNode(variableDeclaration.parent); + } + + var isParentVariableStatement = variableDeclaration.parent.kind === SyntaxKind.VariableStatement; + var isDeclarationOfForStatement = variableDeclaration.parent.kind === SyntaxKind.ForStatement && contains((variableDeclaration.parent).declarations, variableDeclaration); + var declarations = isParentVariableStatement + ? (variableDeclaration.parent).declarations + : isDeclarationOfForStatement + ? (variableDeclaration.parent).declarations + : undefined; + + // Breakpoint is possible in variableDeclaration only if there is initialization + if (variableDeclaration.initializer || (variableDeclaration.flags & NodeFlags.Export)) { + if (declarations && declarations[0] === variableDeclaration) { + if (isParentVariableStatement) { + // First declaration - include var keyword + return textSpan(variableDeclaration.parent, variableDeclaration); } else { - return this.breakpointSpanOf(container); + Debug.assert(isDeclarationOfForStatement); + // Include var keyword from for statement declarations in the span + return textSpan(findPrecedingToken(variableDeclaration.pos, sourceFile, variableDeclaration.parent), variableDeclaration); } - - case TypeScript.SyntaxKind.EnumDeclaration: - if (!this.canHaveBreakpointInDeclaration(container)) { - return null; - } - if (this.posLine != this.lineMap.getLineNumberFromPosition(start(container))) { - return this.breakpointSpanOfFirstEnumElement(container); - } - else { - return this.breakpointSpanOf(container); - } - - case TypeScript.SyntaxKind.IfStatement: - case TypeScript.SyntaxKind.ForInStatement: - case TypeScript.SyntaxKind.WhileStatement: - case TypeScript.SyntaxKind.CatchClause: - if (this.posLine != this.lineMap.getLineNumberFromPosition(start(container))) { - return this.breakpointSpanOfFirstStatementInBlock(originalContainer); - } - else { - return this.breakpointSpanOf(container); - } - - case TypeScript.SyntaxKind.DoStatement: - return this.breakpointSpanOfFirstStatementInBlock(originalContainer); - - case TypeScript.SyntaxKind.ForStatement: - if (this.posLine != this.lineMap.getLineNumberFromPosition(start(container))) { - return this.breakpointSpanOfFirstStatementInBlock(originalContainer); - } - else { - return this.breakpointSpanOf(previousToken(openBraceToken)); - } - - case TypeScript.SyntaxKind.ElseClause: - case TypeScript.SyntaxKind.CaseSwitchClause: - case TypeScript.SyntaxKind.DefaultSwitchClause: - case TypeScript.SyntaxKind.WithStatement: - case TypeScript.SyntaxKind.TryStatement: - case TypeScript.SyntaxKind.FinallyClause: - return this.breakpointSpanOfFirstStatementInBlock(originalContainer); - - case TypeScript.SyntaxKind.SwitchStatement: - if (this.posLine != this.lineMap.getLineNumberFromPosition(start(container))) { - return this.breakpointSpanOfFirstStatementOfFirstCaseClause(container); - } - else { - return this.breakpointSpanOf(container); - } - } - } - - return null; - } - - private breakpointSpanOfCloseBrace(closeBraceToken: TypeScript.ISyntaxToken): TextSpan { - var container = Syntax.containingNode(closeBraceToken); - if (container) { - var originalContainer = container; - if (container.kind() == TypeScript.SyntaxKind.Block) { - // We have to check the parent and decide what to do with the breakpoint - container = Syntax.containingNode(container); - if (!container) { - container = originalContainer; - } - } - - switch (container.kind()) { - case TypeScript.SyntaxKind.Block: - if (!this.canHaveBreakpointInBlock(container)) { - return null; - } - return this.breakpointSpanOfLastStatementInBlock(container); - break; - - case TypeScript.SyntaxKind.ModuleDeclaration: - if (!this.canHaveBreakpointInDeclaration(container)) { - return null; - } - var moduleSyntax = container; - if (moduleSyntax.moduleElements && moduleSyntax.moduleElements.length > 0) { - return createBreakpointSpanInfo(closeBraceToken); - } - else { - return null; - } - - case TypeScript.SyntaxKind.ClassDeclaration: - case TypeScript.SyntaxKind.FunctionDeclaration: - case TypeScript.SyntaxKind.ConstructorDeclaration: - case TypeScript.SyntaxKind.MemberFunctionDeclaration: - case TypeScript.SyntaxKind.GetAccessor: - case TypeScript.SyntaxKind.SetAccessor: - case TypeScript.SyntaxKind.FunctionExpression: - if (!this.canHaveBreakpointInDeclaration(container)) { - return null; - } - return createBreakpointSpanInfo(closeBraceToken); - - case TypeScript.SyntaxKind.EnumDeclaration: - if (!this.canHaveBreakpointInDeclaration(container)) { - return null; - } - return createBreakpointSpanInfo(closeBraceToken); - - case TypeScript.SyntaxKind.IfStatement: - case TypeScript.SyntaxKind.ElseClause: - case TypeScript.SyntaxKind.ForInStatement: - case TypeScript.SyntaxKind.ForStatement: - case TypeScript.SyntaxKind.WhileStatement: - case TypeScript.SyntaxKind.DoStatement: - case TypeScript.SyntaxKind.CaseSwitchClause: - case TypeScript.SyntaxKind.DefaultSwitchClause: - case TypeScript.SyntaxKind.WithStatement: - case TypeScript.SyntaxKind.TryStatement: - case TypeScript.SyntaxKind.CatchClause: - case TypeScript.SyntaxKind.FinallyClause: - case TypeScript.SyntaxKind.ParenthesizedArrowFunctionExpression: - case TypeScript.SyntaxKind.SimpleArrowFunctionExpression: - return this.breakpointSpanOfLastStatementInBlock(originalContainer); - - case TypeScript.SyntaxKind.SwitchStatement: - return this.breakpointSpanOfLastStatementOfLastCaseClause(container); - } - } - - return null; - } - - - private breakpointSpanOfComma(commaToken: TypeScript.ISyntaxToken): TextSpan { - var commaParent = commaToken.parent; - if (isSeparatedList(commaParent)) { - var grandParent = commaParent.parent; - if (grandParent) { - switch (grandParent.kind()) { - case TypeScript.SyntaxKind.VariableDeclaration: - case TypeScript.SyntaxKind.EnumDeclaration: - case TypeScript.SyntaxKind.ParameterList: - var index = Syntax.childIndex(commaParent, commaToken); - // Use the previous child - if (index > 0) { - var child = childAt(commaParent, index - 1); - return this.breakpointSpanOf(child); - } - - // If we cant set breakpoint on enum element, just dont set breakpoint - if (grandParent.kind() == TypeScript.SyntaxKind.EnumDeclaration) { - return null; - } - break; - } - } - } - - return this.breakpointSpanOfContainingNode(commaToken); - } - - private breakpointSpanOfCloseParen(closeParenToken: TypeScript.ISyntaxToken): TextSpan { - var closeParenParent = closeParenToken.parent; - if (closeParenParent) { - switch (closeParenParent.kind()) { - case TypeScript.SyntaxKind.ForStatement: - case TypeScript.SyntaxKind.ParameterList: - return this.breakpointSpanOf(previousToken(closeParenToken)); - } - } - - return this.breakpointSpanOfContainingNode(closeParenToken); - } - - private canHaveBreakpointInBlock(blockNode: TypeScript.ISyntaxNode) { - if (!blockNode || TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(blockNode)) { - return false; - } - - var blockSyntax = blockNode; - return blockSyntax.statements && blockSyntax.statements.length != 0; - } - - private breakpointSpanOfFirstStatementInBlock(blockNode: TypeScript.ISyntaxNode): TextSpan { - if (!blockNode) { - return null; - } - - var blockSyntax = blockNode; - var statementsNode = blockSyntax.statements; - if (!statementsNode || statementsNode.length == 0) { - return null; - } - - var firstStatement = childAt(statementsNode, 0); - if (firstStatement && firstStatement.kind() == TypeScript.SyntaxKind.Block) { - if (this.canHaveBreakpointInBlock(firstStatement)) { - return this.breakpointSpanOfFirstStatementInBlock(firstStatement); - } - return null; - } - else { - return this.breakpointSpanOf(firstStatement); - } - } - - private breakpointSpanOfLastStatementInBlock(blockNode: TypeScript.ISyntaxNode): TextSpan { - if (!blockNode) { - return null; - } - - var blockSyntax = blockNode; - var statementsNode = blockSyntax.statements; - if (!statementsNode || statementsNode.length == 0) { - return null; - } - - var lastStatement = childAt(statementsNode, statementsNode.length - 1); - if (lastStatement && lastStatement.kind() == TypeScript.SyntaxKind.Block) { - if (this.canHaveBreakpointInBlock(lastStatement)) { - return this.breakpointSpanOfLastStatementInBlock(lastStatement); - } - return null; - } - else { - return this.breakpointSpanOf(lastStatement); - } - } - - private breakpointSpanOfFirstChildOfSyntaxList(positionedList: TypeScript.ISyntaxNodeOrToken[]): TextSpan { - if (!positionedList) { - return null; - } - - // Find the first syntax element - var listSyntax = positionedList; - if (listSyntax.length == 0) { - return null; - } - - var firstStatement = childAt(positionedList, 0); - if (firstStatement && firstStatement.kind() == TypeScript.SyntaxKind.Block) { - if (this.canHaveBreakpointInBlock(firstStatement)) { - return this.breakpointSpanOfFirstStatementInBlock(firstStatement); - } - - return null; - } - else { - return this.breakpointSpanOf(firstStatement); - } - } - - private breakpointSpanOfLastChildOfSyntaxList(positionedList: TypeScript.ISyntaxNodeOrToken[]): TextSpan { - if (!positionedList) { - return null; - } - - // Find the first syntax element - var listSyntax = positionedList; - if (listSyntax.length == 0) { - return null; - } - var lastStatement = childAt(positionedList, 0); - if (lastStatement && lastStatement.kind() == TypeScript.SyntaxKind.Block) { - if (this.canHaveBreakpointInBlock(lastStatement)) { - return this.breakpointSpanOfLastStatementInBlock(lastStatement); - } - return null; - } - else { - return this.breakpointSpanOf(lastStatement); - } - } - - private breakpointSpanOfNode(positionedNode: ISyntaxNode): TextSpan { - var node = positionedNode; - switch (node.kind()) { - // Declarations with elements - case TypeScript.SyntaxKind.ModuleDeclaration: - case TypeScript.SyntaxKind.ClassDeclaration: - case TypeScript.SyntaxKind.FunctionDeclaration: - case TypeScript.SyntaxKind.ConstructorDeclaration: - case TypeScript.SyntaxKind.MemberFunctionDeclaration: - case TypeScript.SyntaxKind.GetAccessor: - case TypeScript.SyntaxKind.SetAccessor: - case TypeScript.SyntaxKind.FunctionExpression: - return this.breakpointSpanOfDeclarationWithElements(positionedNode); - - // Var, parameter and member variable declaration syntax - case TypeScript.SyntaxKind.VariableDeclarator: - return this.breakpointSpanOfVariableDeclarator(positionedNode); - - case TypeScript.SyntaxKind.VariableDeclaration: - return this.breakpointSpanOfVariableDeclaration(positionedNode); - - case TypeScript.SyntaxKind.VariableStatement: - return this.breakpointSpanOfVariableStatement(positionedNode); - - case TypeScript.SyntaxKind.Parameter: - return this.breakpointSpanOfParameter(positionedNode); - - case TypeScript.SyntaxKind.MemberVariableDeclaration: - return this.breakpointSpanOfMemberVariableDeclaration(positionedNode); - - case TypeScript.SyntaxKind.ImportDeclaration: - return this.breakpointSpanOfImportDeclaration(positionedNode); - - case TypeScript.SyntaxKind.EnumDeclaration: - return this.breakpointSpanOfEnumDeclaration(positionedNode); - - case TypeScript.SyntaxKind.EnumElement: - return this.breakpointSpanOfEnumElement(positionedNode); - - // Statements - case TypeScript.SyntaxKind.IfStatement: - return this.breakpointSpanOfIfStatement(positionedNode); - case TypeScript.SyntaxKind.ElseClause: - return this.breakpointSpanOfElseClause(positionedNode); - case TypeScript.SyntaxKind.ForInStatement: - return this.breakpointSpanOfForInStatement(positionedNode); - case TypeScript.SyntaxKind.ForStatement: - return this.breakpointSpanOfForStatement(positionedNode); - case TypeScript.SyntaxKind.WhileStatement: - return this.breakpointSpanOfWhileStatement(positionedNode); - case TypeScript.SyntaxKind.DoStatement: - return this.breakpointSpanOfDoStatement(positionedNode); - case TypeScript.SyntaxKind.SwitchStatement: - return this.breakpointSpanOfSwitchStatement(positionedNode); - case TypeScript.SyntaxKind.CaseSwitchClause: - return this.breakpointSpanOfCaseSwitchClause(positionedNode); - case TypeScript.SyntaxKind.DefaultSwitchClause: - return this.breakpointSpanOfDefaultSwitchClause(positionedNode); - case TypeScript.SyntaxKind.WithStatement: - return this.breakpointSpanOfWithStatement(positionedNode); - case TypeScript.SyntaxKind.TryStatement: - return this.breakpointSpanOfTryStatement(positionedNode); - case TypeScript.SyntaxKind.CatchClause: - return this.breakpointSpanOfCatchClause(positionedNode); - case TypeScript.SyntaxKind.FinallyClause: - return this.breakpointSpanOfFinallyClause(positionedNode); - - // Arrow expressions - case TypeScript.SyntaxKind.ParenthesizedArrowFunctionExpression: - return this.breakpointSpanOfParenthesizedArrowFunctionExpression(positionedNode); - - case TypeScript.SyntaxKind.SimpleArrowFunctionExpression: - return this.breakpointSpanOfSimpleArrowFunctionExpression(positionedNode); - - // Expressions or statements - default: - if (SyntaxUtilities.isStatement(node)) { - return this.breakpointSpanOfStatement(positionedNode); } else { - return this.breakpointOfExpression(positionedNode); + // Span only on this declaration + return textSpan(variableDeclaration); } - } - } - - private isExpressionOfArrowExpressions(expression: ISyntaxElement): boolean { - if (!expression) { - return false; - } - - var expressionParent = expression.parent; - if (expressionParent) { - if (expressionParent.kind() == TypeScript.SyntaxKind.ParenthesizedArrowFunctionExpression) { - var parenthesizedArrowExpression = expressionParent; - var expressionOfParenthesizedArrowExpression = parenthesizedArrowExpression.expression; - return expressionOfParenthesizedArrowExpression == expression; } - else if (expressionParent.kind() == TypeScript.SyntaxKind.SimpleArrowFunctionExpression) { - var simpleArrowExpression = expressionParent; - var expressionOfSimpleArrowExpression = simpleArrowExpression.expression; - return expressionOfSimpleArrowExpression == expression; - } - else if (expressionParent.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.isExpressionOfArrowExpressions(expressionParent); - } - } - return false; - } - - private isInitializerOfForStatement(expressionNode: TypeScript.ISyntaxNode): boolean { - if (!expressionNode) { - return false; - } - - var expressionParent = expressionNode.parent; - if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.ForStatement) { - - var expression = expressionNode; - var forStatement = expressionParent; - var initializer = forStatement.initializer; - return initializer === expression; - } - else if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.isInitializerOfForStatement(expressionParent); - } - - return false; - } - - private isConditionOfForStatement(expressionNode: TypeScript.ISyntaxNode): boolean { - if (!expressionNode) { - return false; - } - - var expressionParent = expressionNode.parent; - if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.ForStatement) { - var expression = expressionNode; - var forStatement = expressionParent; - var condition = forStatement.condition; - return condition === expression; - } - else if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.isConditionOfForStatement(expressionParent); - } - - return false; - } - - private isIncrememtorOfForStatement(expressionNode: TypeScript.ISyntaxNode): boolean { - if (!expressionNode) { - return false; - } - - var expressionParent = expressionNode.parent; - if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.ForStatement) { - var expression = expressionNode; - var forStatement = expressionParent; - var incrementor = forStatement.incrementor; - return incrementor === expression; - } - else if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.isIncrememtorOfForStatement(expressionParent); - } - - return false; - } - - private breakpointOfLeftOfCommaExpression(commaExpressionNode: TypeScript.ISyntaxNode): TextSpan { - var commaExpression = commaExpressionNode; - return this.breakpointSpanOf(commaExpression.left); - } - - private breakpointOfExpression(expressionNode: TypeScript.ISyntaxNode): TextSpan { - if (this.isInitializerOfForStatement(expressionNode) || - this.isConditionOfForStatement(expressionNode) || - this.isIncrememtorOfForStatement(expressionNode)) { - if (expressionNode.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.breakpointOfLeftOfCommaExpression(expressionNode); - } - return createBreakpointSpanInfo(expressionNode); - } - - if (this.isExpressionOfArrowExpressions(expressionNode)) { - if (expressionNode.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.breakpointOfLeftOfCommaExpression(expressionNode); - } - return createBreakpointSpanInfo(expressionNode); - } - - if (expressionNode.kind() == TypeScript.SyntaxKind.ExportAssignment) { - var exportAssignmentSyntax = expressionNode; - return createBreakpointSpanInfo(expressionNode, exportAssignmentSyntax.exportKeyword, exportAssignmentSyntax.equalsToken, exportAssignmentSyntax.identifier); - } - - return this.breakpointSpanOfContainingNode(expressionNode); - } - - private breakpointSpanOfStatement(statementNode: TypeScript.ISyntaxNode): TextSpan { - var statement = statementNode; - if (statement.kind() == TypeScript.SyntaxKind.EmptyStatement) { - return null; - } - - var containingNode = Syntax.containingNode(statementNode); - if (SyntaxUtilities.isStatement(containingNode)) { - // Check if not the declarations and the compound statements - var useNodeForBreakpoint = false; - switch (containingNode.kind()) { - // Declarations - case TypeScript.SyntaxKind.ModuleDeclaration: - case TypeScript.SyntaxKind.ClassDeclaration: - case TypeScript.SyntaxKind.FunctionDeclaration: - case TypeScript.SyntaxKind.ConstructorDeclaration: - case TypeScript.SyntaxKind.MemberFunctionDeclaration: - case TypeScript.SyntaxKind.GetAccessor: - case TypeScript.SyntaxKind.SetAccessor: - case TypeScript.SyntaxKind.Block: - - // Compound Statements - case TypeScript.SyntaxKind.IfStatement: - case TypeScript.SyntaxKind.ElseClause: - case TypeScript.SyntaxKind.ForInStatement: - case TypeScript.SyntaxKind.ForStatement: - case TypeScript.SyntaxKind.WhileStatement: - case TypeScript.SyntaxKind.DoStatement: - case TypeScript.SyntaxKind.SwitchStatement: - case TypeScript.SyntaxKind.CaseSwitchClause: - case TypeScript.SyntaxKind.DefaultSwitchClause: - case TypeScript.SyntaxKind.WithStatement: - case TypeScript.SyntaxKind.TryStatement: - case TypeScript.SyntaxKind.CatchClause: - case TypeScript.SyntaxKind.FinallyClause: - case TypeScript.SyntaxKind.Block: - useNodeForBreakpoint = true; - } - - if (!useNodeForBreakpoint) { - return this.breakpointSpanOfContainingNode(statementNode); + else if (declarations && declarations[0] !== variableDeclaration) { + // If we cant set breakpoint on this declaration, set it on previous one + var indexOfCurrentDeclaration = indexOf(declarations, variableDeclaration); + return spanInVariableDeclaration(declarations[indexOfCurrentDeclaration - 1]); } } - switch (statement.kind()) { - case TypeScript.SyntaxKind.ExpressionStatement: - var expressionSyntax = statement; - return createBreakpointSpanInfo(expressionSyntax.expression); - - case TypeScript.SyntaxKind.ReturnStatement: - var returnStatementSyntax = statement; - return createBreakpointSpanInfo(statementNode, returnStatementSyntax.returnKeyword, returnStatementSyntax.expression); - - case TypeScript.SyntaxKind.ThrowStatement: - var throwStatementSyntax = statement; - return createBreakpointSpanInfo(statementNode, throwStatementSyntax.throwKeyword, throwStatementSyntax.expression); - - case TypeScript.SyntaxKind.BreakStatement: - var breakStatementSyntax = statement; - return createBreakpointSpanInfo(statementNode, breakStatementSyntax.breakKeyword, breakStatementSyntax.identifier); - - case TypeScript.SyntaxKind.ContinueStatement: - var continueStatementSyntax = statement; - return createBreakpointSpanInfo(statementNode, continueStatementSyntax.continueKeyword, continueStatementSyntax.identifier); - - case TypeScript.SyntaxKind.DebuggerStatement: - var debuggerStatementSyntax = statement; - return createBreakpointSpanInfo(debuggerStatementSyntax.debuggerKeyword); - - case TypeScript.SyntaxKind.LabeledStatement: - var labeledStatementSyntax = statement; - return this.breakpointSpanOf(labeledStatementSyntax.statement); + function canHaveSpanInParameterDeclaration(parameter: ParameterDeclaration): boolean { + // Breakpoint is possible on parameter only if it has initializer, is a rest parameter, or has public or private modifier + return !!parameter.initializer || !!(parameter.flags & NodeFlags.Rest) || + !!(parameter.flags & NodeFlags.Public) || !!(parameter.flags & NodeFlags.Private); } - return null; - } - - private getSyntaxListOfDeclarationWithElements(positionedNode: TypeScript.ISyntaxNode) { - var node = positionedNode; - var elementsList: TypeScript.ISyntaxNodeOrToken[]; - var block: TypeScript.BlockSyntax; - - switch (node.kind()) { - case TypeScript.SyntaxKind.ModuleDeclaration: - elementsList = (node).moduleElements; - break; - - case TypeScript.SyntaxKind.ClassDeclaration: - elementsList = (node).classElements; - break; - - case TypeScript.SyntaxKind.FunctionDeclaration: - block = (node).block; - break; - - case TypeScript.SyntaxKind.ConstructorDeclaration: - block = (node).block; - break; - - case TypeScript.SyntaxKind.MemberFunctionDeclaration: - block = (node).block; - break; - - case TypeScript.SyntaxKind.GetAccessor: - block = (node).block; - break; - - case TypeScript.SyntaxKind.SetAccessor: - block = (node).block; - break; - - case TypeScript.SyntaxKind.FunctionExpression: - block = (node).block; - break; - - case TypeScript.SyntaxKind.ParenthesizedArrowFunctionExpression: - block = (node).block; - break; - - case TypeScript.SyntaxKind.SimpleArrowFunctionExpression: - block = (node).block; - break; - - default: - throw TypeScript.Errors.argument('positionNode', 'unknown node kind in getSyntaxListOfDeclarationWithElements'); - } - - var parentElement: TypeScript.ISyntaxElement = positionedNode; - if (block) { - parentElement = block; - elementsList = block.statements; - } - - return elementsList; - } - - private canHaveBreakpointInDeclaration(positionedNode: TypeScript.ISyntaxNode) { - return positionedNode && !TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(positionedNode); - } - - private breakpointSpanOfDeclarationWithElements(positionedNode: TypeScript.ISyntaxNode): TextSpan { - if (!this.canHaveBreakpointInDeclaration(positionedNode)) { - return null; - } - - // If inside another module the whole declaration is debuggable - var node = positionedNode; - var moduleSyntax = positionedNode; - if ((SyntaxUtilities.isModuleElement(node) && Syntax.containingNode(positionedNode).kind() != TypeScript.SyntaxKind.SourceUnit) || - SyntaxUtilities.isClassElement(node) || - (moduleSyntax.kind() == TypeScript.SyntaxKind.ModuleDeclaration && moduleSyntax.name - && moduleSyntax.name.kind() == TypeScript.SyntaxKind.QualifiedName)) { - return createBreakpointSpanInfo(positionedNode); - } - else { - // Try to get the breakpoint in first element declaration - return this.breakpointSpanOfFirstChildOfSyntaxList(this.getSyntaxListOfDeclarationWithElements(positionedNode)); - } - } - - private canHaveBreakpointInVariableDeclarator(varDeclaratorNode: TypeScript.ISyntaxNode) { - if (!varDeclaratorNode || TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(varDeclaratorNode)) { - return false; - } - - var varDeclaratorSyntax = varDeclaratorNode; - return !!varDeclaratorSyntax.equalsValueClause; - } - - private breakpointSpanOfVariableDeclarator(varDeclaratorNode: TypeScript.ISyntaxNode): TextSpan { - if (!this.canHaveBreakpointInVariableDeclarator(varDeclaratorNode)) { - return null; - } - - var container = Syntax.containingNode(varDeclaratorNode); - if (container && container.kind() == TypeScript.SyntaxKind.VariableDeclaration) { - var parentDeclaratorsList = varDeclaratorNode.parent; - // If this is the first declarator in the list use the declaration instead - if (parentDeclaratorsList && childAt(parentDeclaratorsList, 0) == varDeclaratorNode) { - return this.breakpointSpanOfVariableDeclaration(container); - } - - // Create breakpoint on this var declarator - if (this.canHaveBreakpointInVariableDeclarator(varDeclaratorNode)) { - return createBreakpointSpanInfo(varDeclaratorNode); + function spanInParameterDeclaration(parameter: ParameterDeclaration): TypeScript.TextSpan { + if (canHaveSpanInParameterDeclaration(parameter)) { + return textSpan(parameter); } else { - return null; - } - } - else if (container) { - // Member Variable syntax - return this.breakpointSpanOfMemberVariableDeclaration(container); - } - - return null; - } - - private canHaveBreakpointInVariableDeclaration(varDeclarationNode: TypeScript.ISyntaxNode) { - if (!varDeclarationNode || TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(varDeclarationNode)) { - return false; - } - - var varDeclarationSyntax = varDeclarationNode; - var containerChildren = varDeclarationSyntax.variableDeclarators; - if (!containerChildren || childCount(containerChildren) == 0) { - return false; - } - - var child = childAt(containerChildren, 0); - if (isNode(child)) { - return this.canHaveBreakpointInVariableDeclarator(child); - } - - return false; - } - - private breakpointSpanOfVariableDeclaration(varDeclarationNode: TypeScript.ISyntaxNode): TextSpan { - if (!this.canHaveBreakpointInDeclaration(varDeclarationNode)) { - return null; - } - - var container = Syntax.containingNode(varDeclarationNode); - var varDeclarationSyntax = varDeclarationNode; - var varDeclarators = varDeclarationSyntax.variableDeclarators; - - if (container && container.kind() == TypeScript.SyntaxKind.VariableStatement) { - return this.breakpointSpanOfVariableStatement(container); - } - - if (this.canHaveBreakpointInVariableDeclaration(varDeclarationNode)) { - return createBreakpointSpanInfoWithLimChar(varDeclarationNode, end(childAt(varDeclarators, 0))); - } - else { - return null; - } - } - - private canHaveBreakpointInVariableStatement(varStatementNode: TypeScript.ISyntaxNode) { - if (!varStatementNode || TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(varStatementNode)) { - return false; - } - - var variableStatement = varStatementNode; - return this.canHaveBreakpointInVariableDeclaration(variableStatement.variableDeclaration); - } - - private breakpointSpanOfVariableStatement(varStatementNode: TypeScript.ISyntaxNode): TextSpan { - if (!this.canHaveBreakpointInVariableStatement(varStatementNode)) { - return null; - } - - var variableStatement = varStatementNode; - var variableDeclaration = variableStatement.variableDeclaration; - var varDeclarationSyntax = variableDeclaration; - var varDeclarators = varDeclarationSyntax.variableDeclarators; - return createBreakpointSpanInfoWithLimChar(varStatementNode, end(childAt(varDeclarators, 0))); - } - - private breakpointSpanOfParameter(parameterNode: TypeScript.ISyntaxNode): TextSpan { - if (parameterNode.parent.kind() === SyntaxKind.SimpleArrowFunctionExpression) { - return this.breakpointSpanOfNode(parameterNode.parent); - } - - if (TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(parameterNode)) { - return null; - } - - var parameterSyntax = parameterNode; - if (parameterSyntax.dotDotDotToken || parameterSyntax.equalsValueClause || parameterSyntax.modifiers.length > 0) { - return createBreakpointSpanInfo(parameterNode); - } - else { - return null; - } - } - - private breakpointSpanOfMemberVariableDeclaration(memberVarDeclarationNode: TypeScript.ISyntaxNode): TextSpan { - if (TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(memberVarDeclarationNode)) { - return null; - } - - var memberVariableDeclaration = memberVarDeclarationNode; - if (this.canHaveBreakpointInVariableDeclarator(memberVariableDeclaration.variableDeclarator)) { - return createBreakpointSpanInfo(memberVarDeclarationNode, memberVariableDeclaration.modifiers, memberVariableDeclaration.variableDeclarator); - } - else { - return null; - } - } - - private breakpointSpanOfImportDeclaration(importDeclarationNode: TypeScript.ISyntaxNode): TextSpan { - if (TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(importDeclarationNode)) { - return null; - } - - var importSyntax = importDeclarationNode; - return createBreakpointSpanInfo(importDeclarationNode, importSyntax.modifiers, importSyntax.importKeyword, importSyntax.identifier, importSyntax.equalsToken, importSyntax.moduleReference); - } - - private breakpointSpanOfEnumDeclaration(enumDeclarationNode: TypeScript.ISyntaxNode): TextSpan { - if (!this.canHaveBreakpointInDeclaration(enumDeclarationNode)) { - return null; - } - - return createBreakpointSpanInfo(enumDeclarationNode); - } - - private breakpointSpanOfFirstEnumElement(enumDeclarationNode: TypeScript.ISyntaxNode): TextSpan { - var enumDeclarationSyntax = enumDeclarationNode; - var enumElements = enumDeclarationSyntax.enumElements; - if (enumElements && childCount(enumElements)) { - return this.breakpointSpanOf(childAt(enumElements, 0)); - } - - return null; - } - - private breakpointSpanOfEnumElement(enumElementNode: TypeScript.ISyntaxNode): TextSpan { - if (TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(enumElementNode)) { - return null; - } - - return createBreakpointSpanInfo(enumElementNode); - } - - private breakpointSpanOfIfStatement(ifStatementNode: TypeScript.ISyntaxNode): TextSpan { - var ifStatement = ifStatementNode; - return createBreakpointSpanInfo(ifStatementNode, ifStatement.ifKeyword, ifStatement.openParenToken, ifStatement.condition, ifStatement.closeParenToken); - } - - private breakpointSpanOfElseClause(elseClauseNode: TypeScript.ISyntaxNode): TextSpan { - var elseClause = elseClauseNode; - return this.breakpointSpanOf(elseClause.statement); - } - - private breakpointSpanOfForInStatement(forInStatementNode: TypeScript.ISyntaxNode): TextSpan { - var forInStatement = forInStatementNode; - return createBreakpointSpanInfo(forInStatementNode, forInStatement.forKeyword, forInStatement.openParenToken, forInStatement.variableDeclaration, - forInStatement.left, forInStatement.inKeyword, forInStatement.expression, forInStatement.closeParenToken); - } - - private breakpointSpanOfForStatement(forStatementNode: TypeScript.ISyntaxNode): TextSpan { - var forStatement = forStatementNode; - return this.breakpointSpanOf(forStatement.variableDeclaration - ? forStatement.variableDeclaration - : forStatement.initializer); - } - - private breakpointSpanOfWhileStatement(whileStatementNode: TypeScript.ISyntaxNode): TextSpan { - var whileStatement = whileStatementNode; - return createBreakpointSpanInfo(whileStatementNode, whileStatement.whileKeyword, whileStatement.openParenToken, whileStatement.condition, whileStatement.closeParenToken); - } - - private breakpointSpanOfDoStatement(doStatementNode: TypeScript.ISyntaxNode): TextSpan { - var doStatement = doStatementNode; - return createBreakpointSpanInfo(doStatementNode, doStatement.whileKeyword, doStatement.openParenToken, doStatement.condition, doStatement.closeParenToken); - } - - private breakpointSpanOfSwitchStatement(switchStatementNode: TypeScript.ISyntaxNode): TextSpan { - var switchStatement = switchStatementNode; - return createBreakpointSpanInfo(switchStatementNode, switchStatement.switchKeyword, switchStatement.openParenToken, switchStatement.expression, switchStatement.closeParenToken); - } - - private breakpointSpanOfFirstStatementOfFirstCaseClause(switchStatementNode: TypeScript.ISyntaxNode): TextSpan { - var switchStatement = switchStatementNode; - if (switchStatement.switchClauses && switchStatement.switchClauses.length == 0) { - return null; - } - - var switchClauses = switchStatement.switchClauses; - if (switchClauses.length == 0) { - return null; - } - - var firstCaseClause = switchClauses[0]; - var statements = firstCaseClause.statements; - - return this.breakpointSpanOfFirstChildOfSyntaxList(statements); - } - - private breakpointSpanOfLastStatementOfLastCaseClause(switchStatementNode: TypeScript.ISyntaxNode): TextSpan { - var switchStatement = switchStatementNode; - if (switchStatement.switchClauses && switchStatement.switchClauses.length == 0) { - return null; - } - - var switchClauses = switchStatement.switchClauses; - if (switchClauses.length == 0) { - return null; - } - - var lastClauseNode = switchClauses[switchClauses.length - 1]; - var statements = lastClauseNode.statements; - - return this.breakpointSpanOfLastChildOfSyntaxList(statements); - } - - private breakpointSpanOfCaseSwitchClause(caseClauseNode: TypeScript.ISyntaxNode): TextSpan { - var caseSwitchClause = caseClauseNode; - return this.breakpointSpanOfFirstChildOfSyntaxList(caseSwitchClause.statements); - } - - private breakpointSpanOfDefaultSwitchClause(defaultSwithClauseNode: TypeScript.ISyntaxNode): TextSpan { - var defaultSwitchClause = defaultSwithClauseNode; - return this.breakpointSpanOfFirstChildOfSyntaxList(defaultSwitchClause.statements); - } - - private breakpointSpanOfWithStatement(withStatementNode: TypeScript.ISyntaxNode): TextSpan { - var withStatement = withStatementNode; - return this.breakpointSpanOf(withStatement.statement); - } - - private breakpointSpanOfTryStatement(tryStatementNode: TypeScript.ISyntaxNode): TextSpan { - var tryStatement = tryStatementNode; - return this.breakpointSpanOfFirstStatementInBlock(tryStatement.block); - } - - private breakpointSpanOfCatchClause(catchClauseNode: TypeScript.ISyntaxNode): TextSpan { - var catchClause = catchClauseNode; - return createBreakpointSpanInfo(catchClauseNode, catchClause.catchKeyword, catchClause.openParenToken, catchClause.identifier, catchClause.typeAnnotation, catchClause.closeParenToken); - } - - private breakpointSpanOfFinallyClause(finallyClauseNode: TypeScript.ISyntaxNode): TextSpan { - var finallyClause = finallyClauseNode; - return this.breakpointSpanOfFirstStatementInBlock(finallyClause.block); - } - - private breakpointSpanOfParenthesizedArrowFunctionExpression(arrowFunctionExpression: ParenthesizedArrowFunctionExpressionSyntax): TextSpan { - if (arrowFunctionExpression.block) { - return this.breakpointSpanOfFirstStatementInBlock(arrowFunctionExpression.block); - } - else { - return this.breakpointSpanOf(arrowFunctionExpression.expression); - } - } - - private breakpointSpanOfSimpleArrowFunctionExpression(arrowFunctionExpression: SimpleArrowFunctionExpressionSyntax): TextSpan { - if (arrowFunctionExpression.block) { - return this.breakpointSpanOfFirstStatementInBlock(arrowFunctionExpression.block); - } - else { - return this.breakpointSpanOf(arrowFunctionExpression.expression); - } - } - - private breakpointSpanOfContainingNode(positionedElement: ISyntaxElement): TextSpan { - var current = positionedElement.parent; - while (!isNode(current)) { - current = current.parent; - } - - return this.breakpointSpanOf(current); - } - - private breakpointSpanIfStartsOnSameLine(positionedElement: TypeScript.ISyntaxElement): TextSpan { - if (positionedElement && this.posLine == this.lineMap.getLineNumberFromPosition(start(positionedElement))) { - return this.breakpointSpanOf(positionedElement); - } - - return null; - } - - public breakpointSpanOf(positionedElement: TypeScript.ISyntaxElement): TextSpan { - if (!positionedElement) { - return null; - } - - for (var containingNode = Syntax.containingNode(positionedElement); containingNode != null; containingNode = Syntax.containingNode(containingNode)) { - if (containingNode.kind() == TypeScript.SyntaxKind.TypeAnnotation) { - return this.breakpointSpanIfStartsOnSameLine(containingNode); + var functionDeclaration = parameter.parent; + var indexOfParameter = indexOf(functionDeclaration.parameters, parameter); + if (indexOfParameter) { + // Not a first parameter, go to previous parameter + return spanInParameterDeclaration(functionDeclaration.parameters[indexOfParameter - 1]); + } + else { + // Set breakpoint in the function declaration body + return spanInNode(functionDeclaration.body); + } } } - var element = positionedElement; - - // Syntax node - if (isNode(element)) { - return this.breakpointSpanOfNode(positionedElement); + function canFunctionHaveSpanInWholeDeclaration(functionDeclaration: FunctionDeclaration) { + return !!(functionDeclaration.flags & NodeFlags.Export) || + (functionDeclaration.parent.kind === SyntaxKind.ClassDeclaration && functionDeclaration.kind !== SyntaxKind.Constructor); } - // Token - if (isToken(element)) { - return this.breakpointSpanOfToken(positionedElement); + function spanInFunctionDeclaration(functionDeclaration: FunctionDeclaration): TypeScript.TextSpan { + // No breakpoints in the function signature + if (!functionDeclaration.body) { + return undefined; + } + + if (canFunctionHaveSpanInWholeDeclaration(functionDeclaration)) { + // Set the span on whole function declaration + return textSpan(functionDeclaration); + } + + // Set span in function body + return spanInNode(functionDeclaration.body); } - // List - // Separated List - return this.breakpointSpanOfContainingNode(positionedElement); + function spanInFunctionBlock(block: Block): TypeScript.TextSpan { + var nodeForSpanInBlock = block.statements.length ? block.statements[0] : block.getLastToken(); + if (canFunctionHaveSpanInWholeDeclaration(block.parent)) { + return spanInNodeIfStartsOnSameLine(block.parent, nodeForSpanInBlock); + } + + return spanInNode(nodeForSpanInBlock); + } + + function spanInBlock(block: Block): TypeScript.TextSpan { + switch (block.parent.kind) { + case SyntaxKind.ModuleDeclaration: + if (!isInstantiated(block.parent)) { + return undefined; + } + + // Set on parent if on same line otherwise on first statement + case SyntaxKind.WhileStatement: + case SyntaxKind.IfStatement: + case SyntaxKind.ForInStatement: + return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); + + // Set span on previous token if it starts on same line otherwise on the first statement of the block + case SyntaxKind.ForStatement: + return spanInNodeIfStartsOnSameLine(findPrecedingToken(block.pos, sourceFile, block.parent), block.statements[0]); + } + + // Default action is to set on first statement + return spanInNode(block.statements[0]); + } + + function spanInForStatement(forStatement: ForStatement): TypeScript.TextSpan { + if (forStatement.declarations) { + return spanInNode(forStatement.declarations[0]); + } + if (forStatement.initializer) { + return spanInNode(forStatement.initializer); + } + if (forStatement.condition) { + return textSpan(forStatement.condition); + } + if (forStatement.iterator) { + return textSpan(forStatement.iterator); + } + } + + // Tokens: + function spanInOpenBraceToken(node: Node): TypeScript.TextSpan { + switch (node.parent.kind) { + case SyntaxKind.EnumDeclaration: + var enumDeclaration = node.parent; + return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile)); + + case SyntaxKind.ClassDeclaration: + var classDeclaration = node.parent; + return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile)); + + case SyntaxKind.SwitchStatement: + return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); + } + + // Default to parent node + return spanInNode(node.parent); + } + + function spanInCloseBraceToken(node: Node): TypeScript.TextSpan { + switch (node.parent.kind) { + case SyntaxKind.ModuleBlock: + // If this is not instantiated module block no bp span + if (!isInstantiated(node.parent.parent)) { + return undefined; + } + + case SyntaxKind.FunctionBlock: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ClassDeclaration: + // Span on close brace token + return textSpan(node); + + case SyntaxKind.Block: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: + return spanInNode((node.parent).statements[(node.parent).statements.length - 1]);; + + case SyntaxKind.SwitchStatement: + // breakpoint in last statement of the last clause + var switchStatement = node.parent; + var lastClause = switchStatement.clauses[switchStatement.clauses.length - 1]; + if (lastClause) { + return spanInNode(lastClause.statements[lastClause.statements.length - 1]); + } + return undefined; + + // Default to parent node + default: + return spanInNode(node.parent); + } + } + + function spanInOpenParenToken(node: Node): TypeScript.TextSpan { + if (node.parent.kind === SyntaxKind.DoStatement) { + // Go to while keyword and do action instead + return spanInPreviousNode(node); + } + + // Default to parent node + return spanInNode(node.parent); + } + + function spanInCloseParenToken(node: Node): TypeScript.TextSpan { + // Is this close paren token of parameter list, set span in previous token + switch (node.parent.kind) { + case SyntaxKind.FunctionExpression: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ArrowFunction: + case SyntaxKind.Method: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Constructor: + case SyntaxKind.WhileStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.ForStatement: + return spanInPreviousNode(node); + + // Default to parent node + default: + return spanInNode(node.parent); + } + + // Default to parent node + return spanInNode(node.parent); + } + + function spanInColonToken(node: Node): TypeScript.TextSpan { + // Is this : specifying return annotation of the function declaration + if (isAnyFunction(node.parent) || node.parent.kind === SyntaxKind.PropertyAssignment) { + return spanInPreviousNode(node); + } + + return spanInNode(node.parent); + } + + function spanInGreaterThanOrLessThanToken(node: Node): TypeScript.TextSpan { + if (node.parent.kind === SyntaxKind.TypeAssertion) { + return spanInNode((node.parent).operand); + } + + return spanInNode(node.parent); + } + + function spanInWhileKeyword(node: Node): TypeScript.TextSpan { + if (node.parent.kind === SyntaxKind.DoStatement) { + // Set span on while expression + return textSpan(node, findNextToken((node.parent).expression, node.parent)); + } + + // Default to parent node + return spanInNode(node.parent); + } } - } - - export function getBreakpointLocation(syntaxTree: TypeScript.SyntaxTree, askedPos: number): TextSpan { - // Cannot set breakpoint in dts file - if (TypeScript.isDTSFile(syntaxTree.fileName())) { - return null; - } - - var sourceUnit = syntaxTree.sourceUnit(); - var positionedToken = TypeScript.findToken(sourceUnit, askedPos); - - var lineMap = syntaxTree.lineMap(); - var posLine = lineMap.getLineNumberFromPosition(askedPos); - var tokenStartLine = lineMap.getLineNumberFromPosition(start(positionedToken)); - if (posLine < tokenStartLine) { - return null; - } - - var breakpointResolver = new BreakpointResolver(posLine, lineMap); - return breakpointResolver.breakpointSpanOf(positionedToken); - } + } } \ No newline at end of file diff --git a/src/services/compiler/declarationEmitter.ts b/src/services/compiler/declarationEmitter.ts index 85e5bf09647..460904b7e88 100644 --- a/src/services/compiler/declarationEmitter.ts +++ b/src/services/compiler/declarationEmitter.ts @@ -476,8 +476,6 @@ module TypeScript { //} } - var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - var funcSignature = funcPullDecl.getSignatureSymbol(this.semanticInfoChain); this.emitDeclarationComments(funcDecl); this.emitIndent(); @@ -603,11 +601,6 @@ module TypeScript { private emitConstructSignature(funcDecl: ConstructSignatureSyntax) { var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - var start = new Date().getTime(); - var funcSymbol = this.semanticInfoChain.getSymbolForAST(funcDecl); - - TypeScript.declarationEmitFunctionDeclarationGetSymbolTime += new Date().getTime() - start; - this.emitDeclarationComments(funcDecl); this.emitIndent(); @@ -633,11 +626,6 @@ module TypeScript { private emitMethodSignature(funcDecl: MethodSignatureSyntax) { var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - var start = new Date().getTime(); - var funcSymbol = this.semanticInfoChain.getSymbolForAST(funcDecl); - - TypeScript.declarationEmitFunctionDeclarationGetSymbolTime += new Date().getTime() - start; - this.emitDeclarationComments(funcDecl); this.emitIndent(); @@ -817,7 +805,6 @@ module TypeScript { var parameter = funcDecl.callSignature.parameterList.parameters[i]; var parameterDecl = this.semanticInfoChain.getDeclForAST(parameter); if (hasFlag(parameterDecl.flags, PullElementFlags.PropertyParameter)) { - var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); this.emitDeclarationComments(parameter); this.declFile.Write(this.getIndentString()); this.emitClassElementModifiers(parameter.modifiers); @@ -838,7 +825,6 @@ module TypeScript { var className = classDecl.identifier.text(); this.emitDeclarationComments(classDecl); - var classPullDecl = this.semanticInfoChain.getDeclForAST(classDecl); this.emitDeclFlags(classDecl, "class"); this.declFile.Write(className); @@ -934,7 +920,6 @@ module TypeScript { var interfaceName = interfaceDecl.identifier.text(); this.emitDeclarationComments(interfaceDecl); - var interfacePullDecl = this.semanticInfoChain.getDeclForAST(interfaceDecl); this.emitDeclFlags(interfaceDecl, "interface"); this.declFile.Write(interfaceName); @@ -980,7 +965,6 @@ module TypeScript { } this.emitDeclarationComments(moduleDecl); - var modulePullDecl = this.semanticInfoChain.getDeclForAST(moduleDecl); this.emitDeclFlags(moduleDecl, "enum"); this.declFile.WriteLine(moduleDecl.identifier.text() + " {"); diff --git a/src/services/compiler/precompile.ts b/src/services/compiler/precompile.ts index 3ff23d85bea..08a919a65b5 100644 --- a/src/services/compiler/precompile.ts +++ b/src/services/compiler/precompile.ts @@ -184,7 +184,7 @@ module TypeScript { export function preProcessFile(fileName: string, sourceText: IScriptSnapshot, readImportFiles = true): IPreProcessedFileInfo { var text = SimpleText.fromScriptSnapshot(sourceText); - var scanner = Scanner.createScanner(ts.ScriptTarget.ES5, text, reportDiagnostic); + var scanner = Scanner.createScanner(ts.ScriptTarget.Latest, text, reportDiagnostic); var firstToken = scanner.scan(/*allowRegularExpression:*/ false); diff --git a/src/services/compiler/typescript.ts b/src/services/compiler/typescript.ts index f98d0baf52b..5671d167d1b 100644 --- a/src/services/compiler/typescript.ts +++ b/src/services/compiler/typescript.ts @@ -512,7 +512,7 @@ module TypeScript { for (var i = 0, n = fileNames.length; i < n; i++) { var fileName = fileNames[i]; - var document = this.getDocument(fileNames[i]); + var document = this.getDocument(fileName); sharedEmitter = this._emitDocumentDeclarations(document, emitOptions, file => emitOutput.outputFiles.push(file), sharedEmitter); @@ -578,7 +578,6 @@ module TypeScript { var sourceUnit = document.sourceUnit(); Debug.assert(this._shouldEmit(document)); - var typeScriptFileName = document.fileName; if (!emitter) { var javaScriptFileName = this.mapOutputFileName(document, emitOptions, TypeScriptCompiler.mapToJSFileName); var outFile = new TextWriter(javaScriptFileName, this.writeByteOrderMarkForDocument(document), OutputFileType.JavaScript); @@ -799,8 +798,6 @@ module TypeScript { } private extractResolutionContextFromAST(resolver: PullTypeResolver, ast: ISyntaxElement, document: Document, propagateContextualTypes: boolean): { ast: ISyntaxElement; enclosingDecl: PullDecl; resolutionContext: PullTypeResolutionContext; inContextuallyTypedAssignment: boolean; inWithBlock: boolean; } { - var scriptName = document.fileName; - var enclosingDecl: PullDecl = null; var enclosingDeclAST: ISyntaxElement = null; var inContextuallyTypedAssignment = false; @@ -981,7 +978,6 @@ module TypeScript { case SyntaxKind.ReturnStatement: if (propagateContextualTypes) { - var returnStatement = current; var contextualType: PullTypeSymbol = null; if (enclosingDecl && (enclosingDecl.kind & PullElementKind.SomeFunction)) { diff --git a/src/services/core/integerUtilities.ts b/src/services/core/integerUtilities.ts index 0af38471dfd..b0a4d6667b9 100644 --- a/src/services/core/integerUtilities.ts +++ b/src/services/core/integerUtilities.ts @@ -7,12 +7,6 @@ module TypeScript { } export function integerMultiplyLow32Bits(n1: number, n2: number): number { - var n1Low16 = n1 & 0x0000ffff; - var n1High16 = n1 >>> 16; - - var n2Low16 = n2 & 0x0000ffff; - var n2High16 = n2 >>> 16; - var resultLow32 = (((n1 & 0xffff0000) * n2) >>> 0) + (((n1 & 0x0000ffff) * n2) >>> 0) >>> 0; return resultLow32; } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 9f16fa57741..69180974120 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -233,7 +233,12 @@ module ts.NavigationBar { return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.functionElement); case SyntaxKind.VariableDeclaration: - return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.variableElement); + if (node.flags & NodeFlags.Const) { + return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.constantElement); + } + else { + return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.variableElement); + } case SyntaxKind.Constructor: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); diff --git a/src/services/services.ts b/src/services/services.ts index ab62b5fecae..5d46e8d297a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -78,7 +78,7 @@ module ts { update(scriptSnapshot: TypeScript.IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TypeScript.TextChangeRange): SourceFile; } - var scanner: Scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ true); + var scanner: Scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); var emptyArray: any[] = []; @@ -576,7 +576,7 @@ module ts { return this.checker.getPropertyOfType(this, propertyName); } getApparentProperties(): Symbol[] { - return this.checker.getAugmentedPropertiesOfApparentType(this); + return this.checker.getAugmentedPropertiesOfType(this); } getCallSignatures(): Signature[] { return this.checker.getSignaturesOfType(this, SignatureKind.Call); @@ -1022,12 +1022,37 @@ module ts { containerKind: string; containerName: string; } - + + export enum SymbolDisplayPartKind { + aliasName, + className, + enumName, + fieldName, + interfaceName, + keyword, + lineBreak, + numericLiteral, + stringLiteral, + localName, + methodName, + moduleName, + operator, + parameterName, + propertyName, + punctuation, + space, + text, + typeParameterName, + enumMemberName, + functionName, + regularExpressionLiteral, + } + export interface SymbolDisplayPart { text: string; kind: string; } - + export interface QuickInfo { kind: string; kindModifiers: string; @@ -1238,7 +1263,9 @@ module ts { static label = "label"; - static alias = "alias" + static alias = "alias"; + + static constantElement = "constant"; } export class ScriptElementKindModifier { @@ -1334,7 +1361,12 @@ module ts { resetWriter(); return { displayParts: () => displayParts, - writeKind: writeKind, + writeKeyword: text => writeKind(text, SymbolDisplayPartKind.keyword), + writeOperator: text => writeKind(text, SymbolDisplayPartKind.operator), + writePunctuation: text => writeKind(text, SymbolDisplayPartKind.punctuation), + writeSpace: text => writeKind(text, SymbolDisplayPartKind.space), + writeStringLiteral: text => writeKind(text, SymbolDisplayPartKind.stringLiteral), + writeParameter: text => writeKind(text, SymbolDisplayPartKind.parameterName), writeSymbol: writeSymbol, writeLine: writeLine, increaseIndent: () => { indent++; }, @@ -1458,7 +1490,7 @@ module ts { } } - function mapToDisplayParts(writeDisplayParts: (writer: DisplayPartsSymbolWriter) => void): SymbolDisplayPart[] { + export function mapToDisplayParts(writeDisplayParts: (writer: DisplayPartsSymbolWriter) => void): SymbolDisplayPart[] { writeDisplayParts(displayPartWriter); var result = displayPartWriter.displayParts(); displayPartWriter.clear(); @@ -1467,26 +1499,26 @@ module ts { export function typeToDisplayParts(typechecker: TypeChecker, type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[] { return mapToDisplayParts(writer => { - typechecker.writeType(type, writer, enclosingDeclaration, flags); + typechecker.getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); }); } export function symbolToDisplayParts(typeChecker: TypeChecker, symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): SymbolDisplayPart[] { return mapToDisplayParts(writer => { - typeChecker.writeSymbol(symbol, writer, enclosingDeclaration, meaning, flags); + typeChecker.getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags); }); } function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]{ return mapToDisplayParts(writer => { - typechecker.writeSignature(signature, writer, enclosingDeclaration, flags); + typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags); }); } export function getDefaultCompilerOptions(): CompilerOptions { - // Set "ES5" target by default for language service + // Set "ScriptTarget.Latest" target by default for language service return { - target: ScriptTarget.ES5, + target: ScriptTarget.Latest, module: ModuleKind.None, }; } @@ -1948,18 +1980,32 @@ module ts { return isLabelOfLabeledStatement(node) || isJumpStatementTarget(node); } + function isRightSideOfQualifiedName(node: Node) { + return node.parent.kind === SyntaxKind.QualifiedName && (node.parent).right === node; + } + + function isRightSideOfPropertyAccess(node: Node) { + return node.parent.kind === SyntaxKind.PropertyAccess && (node.parent).right === node; + } + function isCallExpressionTarget(node: Node): boolean { - if (node.parent.kind === SyntaxKind.PropertyAccess && (node.parent).right === node) + if (isRightSideOfPropertyAccess(node)) { node = node.parent; + } return node.parent.kind === SyntaxKind.CallExpression && (node.parent).func === node; } function isNewExpressionTarget(node: Node): boolean { - if (node.parent.kind === SyntaxKind.PropertyAccess && (node.parent).right === node) + if (isRightSideOfPropertyAccess(node)) { node = node.parent; + } return node.parent.kind === SyntaxKind.NewExpression && (node.parent).func === node; } + function isNameOfModuleDeclaration(node: Node) { + return node.parent.kind === SyntaxKind.ModuleDeclaration && (node.parent).name === node; + } + function isNameOfFunctionDeclaration(node: Node): boolean { return node.kind === SyntaxKind.Identifier && isAnyFunction(node.parent) && (node.parent).name === node; @@ -1992,7 +2038,7 @@ module ts { function isNameOfExternalModuleImportOrDeclaration(node: Node): boolean { return node.kind === SyntaxKind.StringLiteral && - ((node.parent.kind === SyntaxKind.ModuleDeclaration && (node.parent).name === node) || + (isNameOfModuleDeclaration(node) || (node.parent.kind === SyntaxKind.ImportDeclaration && (node.parent).externalModuleName === node)); } @@ -2578,10 +2624,9 @@ module ts { } var type = typeInfoResolver.getTypeOfNode(mappedNode); - var apparentType = type && typeInfoResolver.getApparentType(type); - if (apparentType) { + if (type) { // Filter private properties - forEach(apparentType.getApparentProperties(), symbol => { + forEach(type.getApparentProperties(), symbol => { if (typeInfoResolver.isValidPropertyAccess((mappedNode.parent), symbol.name)) { symbols.push(symbol); } @@ -2701,7 +2746,7 @@ module ts { // TODO(drosen): use contextual SemanticMeaning. function getSymbolKind(symbol: Symbol, typeResolver: TypeChecker): string { - var flags = typeInfoResolver.getRootSymbols(symbol)[0].getFlags(); + var flags = symbol.getFlags(); if (flags & SymbolFlags.Class) return ScriptElementKind.classElement; if (flags & SymbolFlags.Enum) return ScriptElementKind.enumElement; @@ -2729,15 +2774,32 @@ module ts { if (isFirstDeclarationOfSymbolParameter(symbol)) { return ScriptElementKind.parameterElement; } + else if(symbol.valueDeclaration && symbol.valueDeclaration.flags & NodeFlags.Const) { + return ScriptElementKind.constantElement; + } return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement; } if (flags & SymbolFlags.Function) return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localFunctionElement : ScriptElementKind.functionElement; if (flags & SymbolFlags.GetAccessor) return ScriptElementKind.memberGetAccessorElement; if (flags & SymbolFlags.SetAccessor) return ScriptElementKind.memberSetAccessorElement; if (flags & SymbolFlags.Method) return ScriptElementKind.memberFunctionElement; - if (flags & SymbolFlags.Property) return ScriptElementKind.memberVariableElement; if (flags & SymbolFlags.Constructor) return ScriptElementKind.constructorImplementationElement; + if (flags & SymbolFlags.Property) { + if (flags & SymbolFlags.UnionProperty) { + return forEach(typeInfoResolver.getRootSymbols(symbol), rootSymbol => { + var rootSymbolFlags = rootSymbol.getFlags(); + if (rootSymbolFlags & SymbolFlags.Property) { + return ScriptElementKind.memberVariableElement; + } + if (rootSymbolFlags & SymbolFlags.GetAccessor) return ScriptElementKind.memberVariableElement; + if (rootSymbolFlags & SymbolFlags.SetAccessor) return ScriptElementKind.memberVariableElement; + Debug.assert(rootSymbolFlags & SymbolFlags.Method); + }) || ScriptElementKind.memberFunctionElement; + } + return ScriptElementKind.memberVariableElement; + } + return ScriptElementKind.unknown; } @@ -2760,7 +2822,7 @@ module ts { case SyntaxKind.ClassDeclaration: return ScriptElementKind.classElement; case SyntaxKind.InterfaceDeclaration: return ScriptElementKind.interfaceElement; case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement; - case SyntaxKind.VariableDeclaration: return ScriptElementKind.variableElement; + case SyntaxKind.VariableDeclaration: return node.flags & NodeFlags.Const ? ScriptElementKind.constantElement: ScriptElementKind.variableElement; case SyntaxKind.FunctionDeclaration: return ScriptElementKind.functionElement; case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement; case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement; @@ -2789,7 +2851,7 @@ module ts { semanticMeaning = getMeaningFromLocation(location)) { var displayParts: SymbolDisplayPart[] = []; var documentation: SymbolDisplayPart[]; - var symbolFlags = typeResolver.getRootSymbols(symbol)[0].flags; + var symbolFlags = symbol.flags; var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, typeResolver); var hasAddedSymbolInfo: boolean; // Class at constructor site need to be shown as constructor apart from property,method, vars @@ -2849,6 +2911,7 @@ module ts { switch (symbolKind) { case ScriptElementKind.memberVariableElement: case ScriptElementKind.variableElement: + case ScriptElementKind.constantElement: case ScriptElementKind.parameterElement: case ScriptElementKind.localVariableElement: // If it is call or construct signature of lambda's write type name @@ -3004,7 +3067,7 @@ module ts { // If the type is type parameter, format it specially if (type.symbol && type.symbol.flags & SymbolFlags.TypeParameter) { var typeParameterParts = mapToDisplayParts(writer => { - typeResolver.writeTypeParameter(type, writer, enclosingDeclaration); + typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); }); displayParts.push.apply(displayParts, typeParameterParts); } @@ -3016,7 +3079,8 @@ module ts { symbolFlags & SymbolFlags.Method || symbolFlags & SymbolFlags.Constructor || symbolFlags & SymbolFlags.Signature || - symbolFlags & SymbolFlags.Accessor) { + symbolFlags & SymbolFlags.Accessor || + symbolKind === ScriptElementKind.memberFunctionElement) { var allSignatures = type.getCallSignatures(); addSignatureDisplayParts(allSignatures[0], allSignatures); } @@ -3072,7 +3136,7 @@ module ts { function writeTypeParametersOfSymbol(symbol: Symbol, enclosingDeclaration: Node) { var typeParameterParts = mapToDisplayParts(writer => { - typeResolver.writeTypeParametersOfSymbol(symbol, writer, enclosingDeclaration); + typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); }); displayParts.push.apply(displayParts, typeParameterParts); } @@ -3872,8 +3936,8 @@ module ts { // before and after it have to be a non-identifier char). var endPosition = position + symbolNameLength; - if ((position === 0 || !isIdentifierPart(text.charCodeAt(position - 1), ScriptTarget.ES5)) && - (endPosition === sourceLength || !isIdentifierPart(text.charCodeAt(endPosition), ScriptTarget.ES5))) { + if ((position === 0 || !isIdentifierPart(text.charCodeAt(position - 1), ScriptTarget.Latest)) && + (endPosition === sourceLength || !isIdentifierPart(text.charCodeAt(endPosition), ScriptTarget.Latest))) { // Found a real match. Keep searching. positions.push(position); } @@ -4524,8 +4588,9 @@ module ts { } function isTypeReference(node: Node): boolean { - if (node.parent.kind === SyntaxKind.QualifiedName && (node.parent).right === node) + if (isRightSideOfQualifiedName(node)) { node = node.parent; + } return node.parent.kind === SyntaxKind.TypeReference; } @@ -4675,67 +4740,64 @@ module ts { } function getNameOrDottedNameSpan(filename: string, startPos: number, endPos: number): TypeScript.TextSpan { - function getTypeInfoEligiblePath(filename: string, position: number, isConstructorValidPosition: boolean) { - var sourceUnit = syntaxTreeCache.getCurrentFileSyntaxTree(filename).sourceUnit(); + filename = ts.normalizeSlashes(filename); + // Get node at the location + var node = getTouchingPropertyName(getCurrentSourceFile(filename), startPos); - var ast = TypeScript.ASTHelpers.getAstAtPosition(sourceUnit, position, /*useTrailingTriviaAsLimChar*/ false, /*forceInclusive*/ true); - if (ast === null) { - return null; - } - - if (ast.kind() === TypeScript.SyntaxKind.ParameterList && ast.parent.kind() === TypeScript.SyntaxKind.CallSignature && ast.parent.parent.kind() === TypeScript.SyntaxKind.ConstructorDeclaration) { - ast = ast.parent.parent; - } - - switch (ast.kind()) { - default: - return null; - case TypeScript.SyntaxKind.ConstructorDeclaration: - var constructorAST = ast; - if (!isConstructorValidPosition || !(position >= TypeScript.start(constructorAST) && position <= TypeScript.start(constructorAST) + "constructor".length)) { - return null; - } - else { - return ast; - } - case TypeScript.SyntaxKind.FunctionDeclaration: - return null; - case TypeScript.SyntaxKind.MemberAccessExpression: - case TypeScript.SyntaxKind.QualifiedName: - case TypeScript.SyntaxKind.SuperKeyword: - case TypeScript.SyntaxKind.StringLiteral: - case TypeScript.SyntaxKind.ThisKeyword: - case TypeScript.SyntaxKind.IdentifierName: - return ast; - } + if (!node) { + return; } - filename = TypeScript.switchToForwardSlashes(filename); + switch (node.kind) { + case SyntaxKind.PropertyAccess: + case SyntaxKind.QualifiedName: + case SyntaxKind.StringLiteral: + case SyntaxKind.FalseKeyword: + case SyntaxKind.TrueKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.SuperKeyword: + case SyntaxKind.ThisKeyword: + case SyntaxKind.Identifier: + break; - var node = getTypeInfoEligiblePath(filename, startPos, false); - if (!node) return null; + // Cant create the text span + default: + return; + } - while (node) { - if (TypeScript.ASTHelpers.isNameOfMemberAccessExpression(node) || - TypeScript.ASTHelpers.isRightSideOfQualifiedName(node)) { - node = node.parent; + var nodeForStartPos = node; + while (true) { + if (isRightSideOfPropertyAccess(nodeForStartPos) || isRightSideOfQualifiedName(nodeForStartPos)) { + // If on the span is in right side of the the property or qualified name, return the span from the qualified name pos to end of this node + nodeForStartPos = nodeForStartPos.parent; + } + else if (isNameOfModuleDeclaration(nodeForStartPos)) { + // If this is name of a module declarations, check if this is right side of dotted module name + // If parent of the module declaration which is parent of this node is module declaration and its body is the module declaration that this node is name of + // Then this name is name from dotted module + if (nodeForStartPos.parent.parent.kind === SyntaxKind.ModuleDeclaration && + (nodeForStartPos.parent.parent).body === nodeForStartPos.parent) { + // Use parent module declarations name for start pos + nodeForStartPos = (nodeForStartPos.parent.parent).name; + } + else { + // We have to use this name for start pos + break; + } } else { + // Is not a member expression so we have found the node for start pos break; } } - return TypeScript.TextSpan.fromBounds( - TypeScript.start(node), - TypeScript.end(node)); + return TypeScript.TextSpan.fromBounds(nodeForStartPos.getStart(), node.getEnd()); } function getBreakpointStatementAtPosition(filename: string, position: number) { // doesn't use compiler - no need to synchronize with host - filename = TypeScript.switchToForwardSlashes(filename); - - var syntaxtree = getSyntaxTree(filename); - return TypeScript.Services.Breakpoints.getBreakpointLocation(syntaxtree, position); + filename = ts.normalizeSlashes(filename); + return BreakpointResolver.spanInSourceFileAtLocation(getCurrentSourceFile(filename), position); } function getNavigationBarItems(filename: string): NavigationBarItem[] { @@ -4773,7 +4835,24 @@ module ts { } } else if (flags & SymbolFlags.Module) { - return ClassificationTypeNames.moduleName; + // Only classify a module as such if + // - It appears in a namespace context. + // - There exists a module declaration which actually impacts the value side. + if (meaningAtPosition & SemanticMeaning.Namespace || + (meaningAtPosition & SemanticMeaning.Value && hasValueSideModule(symbol))) { + return ClassificationTypeNames.moduleName; + } + } + + return undefined; + + /** + * Returns true if there exists a module that introduces entities on the value side. + */ + function hasValueSideModule(symbol: Symbol): boolean { + return forEach(symbol.declarations, declaration => { + return declaration.kind === SyntaxKind.ModuleDeclaration && isInstantiated(declaration); + }); } } @@ -4804,115 +4883,99 @@ module ts { var sourceFile = getCurrentSourceFile(fileName); var result: ClassifiedSpan[] = []; - processElement(sourceFile.getSourceUnit()); + processElement(sourceFile); return result; - function classifyTrivia(trivia: TypeScript.ISyntaxTrivia) { - if (trivia.isComment() && span.intersectsWith(trivia.fullStart(), trivia.fullWidth())) { + function classifyComment(comment: CommentRange) { + var width = comment.end - comment.pos; + if (span.intersectsWith(comment.pos, width)) { result.push({ - textSpan: new TypeScript.TextSpan(trivia.fullStart(), trivia.fullWidth()), + textSpan: new TypeScript.TextSpan(comment.pos, width), classificationType: ClassificationTypeNames.comment }); } } - function classifyTriviaList(trivia: TypeScript.ISyntaxTriviaList) { - for (var i = 0, n = trivia.count(); i < n; i++) { - classifyTrivia(trivia.syntaxTriviaAt(i)); - } - } + function classifyToken(token: Node): void { + forEach(getLeadingCommentRanges(sourceFile.text, token.getFullStart()), classifyComment); - function classifyToken(token: TypeScript.ISyntaxToken) { - if (token.hasLeadingComment()) { - classifyTriviaList(token.leadingTrivia()); - } - - if (TypeScript.width(token) > 0) { + if (token.getWidth() > 0) { var type = classifyTokenType(token); if (type) { result.push({ - textSpan: new TypeScript.TextSpan(TypeScript.start(token), TypeScript.width(token)), + textSpan: new TypeScript.TextSpan(token.getStart(), token.getWidth()), classificationType: type }); } } - if (token.hasTrailingComment()) { - classifyTriviaList(token.trailingTrivia()); - } + forEach(getTrailingCommentRanges(sourceFile.text, token.getEnd()), classifyComment); } - function classifyTokenType(token: TypeScript.ISyntaxToken): string { - var tokenKind = token.kind(); - if (TypeScript.SyntaxFacts.isAnyKeyword(token.kind())) { + function classifyTokenType(token: Node): string { + var tokenKind = token.kind; + if (isKeyword(tokenKind)) { return ClassificationTypeNames.keyword; } - // Special case < and > If they appear in a generic context they are punctation, + // Special case < and > If they appear in a generic context they are punctuation, // not operators. - if (tokenKind === TypeScript.SyntaxKind.LessThanToken || tokenKind === TypeScript.SyntaxKind.GreaterThanToken) { - var tokenParentKind = token.parent.kind(); - if (tokenParentKind === TypeScript.SyntaxKind.TypeArgumentList || - tokenParentKind === TypeScript.SyntaxKind.TypeParameterList) { - + if (tokenKind === SyntaxKind.LessThanToken || tokenKind === SyntaxKind.GreaterThanToken) { + // If the node owning the token has a type argument list or type parameter list, then + // we can effectively assume that a '<' and '>' belong to those lists. + if (getTypeArgumentOrTypeParameterList(token.parent)) { return ClassificationTypeNames.punctuation; } } - if (TypeScript.SyntaxFacts.isBinaryExpressionOperatorToken(tokenKind) || - TypeScript.SyntaxFacts.isPrefixUnaryExpressionOperatorToken(tokenKind)) { - return ClassificationTypeNames.operator; + if (isPunctuation(token.kind)) { + // the '=' in a variable declaration is special cased here. + if (token.parent.kind === SyntaxKind.BinaryExpression || + token.parent.kind === SyntaxKind.VariableDeclaration || + token.parent.kind === SyntaxKind.PrefixOperator || + token.parent.kind === SyntaxKind.PostfixOperator || + token.parent.kind === SyntaxKind.ConditionalExpression) { + return ClassificationTypeNames.operator; + } + else { + return ClassificationTypeNames.punctuation; + } } - else if (TypeScript.SyntaxFacts.isAnyPunctuation(tokenKind)) { - return ClassificationTypeNames.punctuation; - } - else if (tokenKind === TypeScript.SyntaxKind.NumericLiteral) { + else if (tokenKind === SyntaxKind.NumericLiteral) { return ClassificationTypeNames.numericLiteral; } - else if (tokenKind === TypeScript.SyntaxKind.StringLiteral) { + else if (tokenKind === SyntaxKind.StringLiteral) { return ClassificationTypeNames.stringLiteral; } - else if (tokenKind === TypeScript.SyntaxKind.RegularExpressionLiteral) { - // TODO: we shoudl get another classification type for these literals. + else if (tokenKind === SyntaxKind.RegularExpressionLiteral) { + // TODO: we should get another classification type for these literals. return ClassificationTypeNames.stringLiteral; } - else if (tokenKind === TypeScript.SyntaxKind.IdentifierName) { - var current: TypeScript.ISyntaxNodeOrToken = token; - var parent = token.parent; - while (parent.kind() === TypeScript.SyntaxKind.QualifiedName) { - current = parent; - parent = parent.parent; - } - - switch (parent.kind()) { - case TypeScript.SyntaxKind.SimplePropertyAssignment: - if ((parent).propertyName === token) { - return ClassificationTypeNames.identifier; - } - return; - case TypeScript.SyntaxKind.ClassDeclaration: - if ((parent).identifier === token) { + else if (tokenKind === SyntaxKind.Identifier) { + switch (token.parent.kind) { + case SyntaxKind.ClassDeclaration: + if ((token.parent).name === token) { return ClassificationTypeNames.className; } return; - case TypeScript.SyntaxKind.TypeParameter: - if ((parent).identifier === token) { + case SyntaxKind.TypeParameter: + if ((token.parent).name === token) { return ClassificationTypeNames.typeParameterName; } return; - case TypeScript.SyntaxKind.InterfaceDeclaration: - if ((parent).identifier === token) { + case SyntaxKind.InterfaceDeclaration: + if ((token.parent).name === token) { return ClassificationTypeNames.interfaceName; } return; - case TypeScript.SyntaxKind.EnumDeclaration: - if ((parent).identifier === token) { + case SyntaxKind.EnumDeclaration: + if ((token.parent).name === token) { return ClassificationTypeNames.enumName; } return; - case TypeScript.SyntaxKind.ModuleDeclaration: - if ((parent).name === current) { + case SyntaxKind.ModuleDeclaration: + if ((token.parent).name === token) { return ClassificationTypeNames.moduleName; } return; @@ -4922,19 +4985,18 @@ module ts { } } - function processElement(element: TypeScript.ISyntaxElement) { + function processElement(element: Node) { // Ignore nodes that don't intersect the original span to classify. - if (!TypeScript.isShared(element) && span.intersectsWith(TypeScript.fullStart(element), TypeScript.fullWidth(element))) { - for (var i = 0, n = TypeScript.childCount(element); i < n; i++) { - var child = TypeScript.childAt(element, i); - if (child) { - if (TypeScript.isToken(child)) { - classifyToken(child); - } - else { - // Recurse into our child nodes. - processElement(child); - } + if (span.intersectsWith(element.getFullStart(), element.getFullWidth())) { + var children = element.getChildren(); + for (var i = 0, n = children.length; i < n; i++) { + var child = children[i]; + if (isToken(child)) { + classifyToken(child); + } + else { + // Recurse into our child nodes. + processElement(child); } } } @@ -5337,7 +5399,7 @@ module ts { /// Classifier export function createClassifier(host: Logger): Classifier { - var scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ false); + var scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false); /// We do not have a full parser support to know when we should parse a regex or not /// If we consider every slash token to be a regex, we could be missing cases like "1/2/3", where diff --git a/src/services/shims.ts b/src/services/shims.ts index fdea0202323..a6bf421b095 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -174,6 +174,7 @@ module ts { export enum LanguageVersion { EcmaScript3 = 0, EcmaScript5 = 1, + EcmaScript6 = 2, } export enum ModuleGenTarget { @@ -213,6 +214,7 @@ module ts { switch (languageVersion) { case LanguageVersion.EcmaScript3: return ScriptTarget.ES3 case LanguageVersion.EcmaScript5: return ScriptTarget.ES5; + case LanguageVersion.EcmaScript6: return ScriptTarget.ES6; default: throw Error("unsupported LanguageVersion value: " + languageVersion); } } @@ -234,6 +236,7 @@ module ts { switch (scriptTarget) { case ScriptTarget.ES3: return LanguageVersion.EcmaScript3; case ScriptTarget.ES5: return LanguageVersion.EcmaScript5; + case ScriptTarget.ES6: return LanguageVersion.EcmaScript6; default: throw Error("unsupported ScriptTarget value: " + scriptTarget); } } diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 273cfda99b8..86e378abb45 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -258,6 +258,13 @@ module ts.SignatureHelp { return undefined; } + function getChildListThatStartsWithOpenerToken(parent: Node, openerToken: Node, sourceFile: SourceFile): Node { + var children = parent.getChildren(sourceFile); + var indexOfOpenerToken = children.indexOf(openerToken); + Debug.assert(indexOfOpenerToken >= 0 && children.length > indexOfOpenerToken + 1); + return children[indexOfOpenerToken + 1]; + } + /** * The selectedItemIndex could be negative for several reasons. * 1. There are too many arguments for all of the overloads @@ -287,74 +294,51 @@ module ts.SignatureHelp { function createSignatureHelpItems(candidates: Signature[], bestSignature: Signature, argumentInfoOrTypeArgumentInfo: ListItemInfo): SignatureHelpItems { var argumentListOrTypeArgumentList = argumentInfoOrTypeArgumentInfo.list; + var parent = argumentListOrTypeArgumentList.parent; + var isTypeParameterHelp = parent.typeArguments && parent.typeArguments.pos === argumentListOrTypeArgumentList.pos; + Debug.assert(isTypeParameterHelp || parent.arguments.pos === argumentListOrTypeArgumentList.pos); + + var callTargetNode = (argumentListOrTypeArgumentList.parent).func; + var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTargetNode); + var callTargetDisplayParts = callTargetSymbol && symbolToDisplayParts(typeInfoResolver, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined); var items: SignatureHelpItem[] = map(candidates, candidateSignature => { - var parameters = candidateSignature.parameters; - var parameterHelpItems: SignatureHelpParameter[] = parameters.length === 0 ? emptyArray : map(parameters, p => { - var displayParts: SymbolDisplayPart[] = []; + var signatureHelpParameters: SignatureHelpParameter[]; + var prefixParts: SymbolDisplayPart[] = []; + var suffixParts: SymbolDisplayPart[] = []; - if (candidateSignature.hasRestParameter && parameters[parameters.length - 1] === p) { - displayParts.push(punctuationPart(SyntaxKind.DotDotDotToken)); - } - - displayParts.push(symbolPart(p.name, p)); - - var isOptional = !!(p.valueDeclaration.flags & NodeFlags.QuestionMark); - if (isOptional) { - displayParts.push(punctuationPart(SyntaxKind.QuestionToken)); - } - - displayParts.push(punctuationPart(SyntaxKind.ColonToken)); - displayParts.push(spacePart()); - - var typeParts = typeToDisplayParts(typeInfoResolver, typeInfoResolver.getTypeOfSymbol(p), argumentListOrTypeArgumentList); - displayParts.push.apply(displayParts, typeParts); - - return { - name: p.name, - documentation: p.getDocumentationComment(), - displayParts: displayParts, - isOptional: isOptional - }; - }); - - var callTargetNode = (argumentListOrTypeArgumentList.parent).func; - var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTargetNode); - - var prefixParts = callTargetSymbol ? symbolToDisplayParts(typeInfoResolver, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined) : []; - - var separatorParts = [punctuationPart(SyntaxKind.CommaToken), spacePart()]; - - // TODO(jfreeman): Constraints? - if (candidateSignature.typeParameters && candidateSignature.typeParameters.length) { - prefixParts.push(punctuationPart(SyntaxKind.LessThanToken)); - - for (var i = 0, n = candidateSignature.typeParameters.length; i < n; i++) { - if (i) { - prefixParts.push.apply(prefixParts, separatorParts); - } - - var tp = candidateSignature.typeParameters[i].symbol; - prefixParts.push(symbolPart(tp.name, tp)); - } - - prefixParts.push(punctuationPart(SyntaxKind.GreaterThanToken)); + if (callTargetDisplayParts) { + prefixParts.push.apply(prefixParts, callTargetDisplayParts); } - prefixParts.push(punctuationPart(SyntaxKind.OpenParenToken)); + if (isTypeParameterHelp) { + prefixParts.push(punctuationPart(SyntaxKind.LessThanToken)); + var typeParameters = candidateSignature.typeParameters; + signatureHelpParameters = typeParameters && typeParameters.length > 0 ? map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; + suffixParts.push(punctuationPart(SyntaxKind.GreaterThanToken)); + var parameterParts = mapToDisplayParts(writer => + typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, argumentListOrTypeArgumentList)); + suffixParts.push.apply(suffixParts, parameterParts); + } + else { + var typeParameterParts = mapToDisplayParts(writer => + typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, argumentListOrTypeArgumentList)); + prefixParts.push.apply(prefixParts, typeParameterParts); + prefixParts.push(punctuationPart(SyntaxKind.OpenParenToken)); + var parameters = candidateSignature.parameters; + signatureHelpParameters = parameters.length > 0 ? map(parameters, createSignatureHelpParameterForParameter) : emptyArray; + suffixParts.push(punctuationPart(SyntaxKind.CloseParenToken)); + } - var suffixParts = [punctuationPart(SyntaxKind.CloseParenToken)]; - suffixParts.push(punctuationPart(SyntaxKind.ColonToken)); - suffixParts.push(spacePart()); - - var typeParts = typeToDisplayParts(typeInfoResolver, candidateSignature.getReturnType(), argumentListOrTypeArgumentList); - suffixParts.push.apply(suffixParts, typeParts); + var returnTypeParts = mapToDisplayParts(writer => + typeInfoResolver.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, argumentListOrTypeArgumentList)); + suffixParts.push.apply(suffixParts, returnTypeParts); return { isVariadic: candidateSignature.hasRestParameter, prefixDisplayParts: prefixParts, suffixDisplayParts: suffixParts, - separatorDisplayParts: separatorParts, - parameters: parameterHelpItems, + separatorDisplayParts: [punctuationPart(SyntaxKind.CommaToken), spacePart()], + parameters: signatureHelpParameters, documentation: candidateSignature.getDocumentationComment() }; }); @@ -400,12 +384,32 @@ module ts.SignatureHelp { argumentIndex: argumentIndex, argumentCount: argumentCount }; + + function createSignatureHelpParameterForParameter(parameter: Symbol): SignatureHelpParameter { + var displayParts = mapToDisplayParts(writer => + typeInfoResolver.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, argumentListOrTypeArgumentList)); + + var isOptional = !!(parameter.valueDeclaration.flags & NodeFlags.QuestionMark); + + return { + name: parameter.name, + documentation: parameter.getDocumentationComment(), + displayParts: displayParts, + isOptional: isOptional + }; + } + + function createSignatureHelpParameterForTypeParameter(typeParameter: TypeParameter): SignatureHelpParameter { + var displayParts = mapToDisplayParts(writer => + typeInfoResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, argumentListOrTypeArgumentList)); + + return { + name: typeParameter.symbol.name, + documentation: emptyArray, + displayParts: displayParts, + isOptional: false + }; + } } } - - function getChildListThatStartsWithOpenerToken(parent: Node, openerToken: Node, sourceFile: SourceFile): Node { - var children = parent.getChildren(sourceFile); - var indexOfOpenerToken = children.indexOf(openerToken); - return children[indexOfOpenerToken + 1]; - } } \ No newline at end of file diff --git a/src/services/syntax/scanner.ts b/src/services/syntax/scanner.ts index 45cc151e2d5..29ced029f1c 100644 --- a/src/services/syntax/scanner.ts +++ b/src/services/syntax/scanner.ts @@ -186,7 +186,7 @@ module TypeScript.Scanner { var lastTokenInfo = { leadingTriviaWidth: -1, width: -1 }; var lastTokenInfoTokenID: number = -1; - var triviaScanner = createScannerInternal(ts.ScriptTarget.ES5, SimpleText.fromString(""), () => { }); + var triviaScanner = createScannerInternal(ts.ScriptTarget.Latest, SimpleText.fromString(""), () => { }); interface IScannerToken extends ISyntaxToken { } diff --git a/src/services/syntax/syntaxTree.ts b/src/services/syntax/syntaxTree.ts index 1e8ac95c483..1c68350d918 100644 --- a/src/services/syntax/syntaxTree.ts +++ b/src/services/syntax/syntaxTree.ts @@ -84,7 +84,6 @@ module TypeScript { private cacheSyntaxTreeInfo(): void { // If we're not keeping around the syntax tree, store the diagnostics and line // map so they don't have to be recomputed. - var sourceUnit = this.sourceUnit(); var firstToken = firstSyntaxTreeToken(this); var leadingTrivia = firstToken.leadingTrivia(this.text); diff --git a/src/services/syntax/unicode.ts b/src/services/syntax/unicode.ts index df2f88b74c5..b1e94090de7 100644 --- a/src/services/syntax/unicode.ts +++ b/src/services/syntax/unicode.ts @@ -84,7 +84,7 @@ module TypeScript { if (languageVersion === ts.ScriptTarget.ES3) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES3IdentifierStart); } - else if (languageVersion === ts.ScriptTarget.ES5) { + else if (languageVersion >= ts.ScriptTarget.ES5) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES5IdentifierStart); } else { @@ -96,7 +96,7 @@ module TypeScript { if (languageVersion === ts.ScriptTarget.ES3) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES3IdentifierPart); } - else if (languageVersion === ts.ScriptTarget.ES5) { + else if (languageVersion >= ts.ScriptTarget.ES5) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES5IdentifierPart); } else { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 82a9a85d7ae..58f7f6f936a 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -75,14 +75,14 @@ module ts { * position >= start and (position < end or (position === end && token is keyword or identifier)) */ export function getTouchingWord(sourceFile: SourceFile, position: number): Node { - return getTouchingToken(sourceFile, position, isWord); + return getTouchingToken(sourceFile, position, n => isWord(n.kind)); } /* Gets the token whose text has range [start, end) and position >= start * and (position < end or (position === end && token is keyword or identifier or numeric\string litera)) */ export function getTouchingPropertyName(sourceFile: SourceFile, position: number): Node { - return getTouchingToken(sourceFile, position, isPropertyName); + return getTouchingToken(sourceFile, position, n => isPropertyName(n.kind)); } /** Returns the token if position is in [start, end) or if position === end and includeItemAtEndPosition(token) === true */ @@ -243,23 +243,35 @@ module ts { return n.kind !== SyntaxKind.SyntaxList || n.getChildCount() !== 0; } + export function getTypeArgumentOrTypeParameterList(node: Node): NodeArray { + if (node.kind === SyntaxKind.TypeReference || node.kind === SyntaxKind.CallExpression) { + return (node).typeArguments; + } + + if (isAnyFunction(node) || node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.InterfaceDeclaration) { + return (node).typeParameters; + } + + return undefined; + } + export function isToken(n: Node): boolean { return n.kind >= SyntaxKind.FirstToken && n.kind <= SyntaxKind.LastToken; } + function isWord(kind: SyntaxKind): boolean { + return kind === SyntaxKind.Identifier || isKeyword(kind); + } + + function isPropertyName(kind: SyntaxKind): boolean { + return kind === SyntaxKind.StringLiteral || kind === SyntaxKind.NumericLiteral || isWord(kind); + } + export function isComment(kind: SyntaxKind): boolean { return kind === SyntaxKind.SingleLineCommentTrivia || kind === SyntaxKind.MultiLineCommentTrivia; } - function isKeyword(n: Node): boolean { - return n.kind >= SyntaxKind.FirstKeyword && n.kind <= SyntaxKind.LastKeyword; - } - - function isWord(n: Node): boolean { - return n.kind === SyntaxKind.Identifier || isKeyword(n); - } - - function isPropertyName(n: Node): boolean { - return n.kind === SyntaxKind.StringLiteral || n.kind === SyntaxKind.NumericLiteral || isWord(n); + export function isPunctuation(kind: SyntaxKind): boolean { + return SyntaxKind.FirstPunctuation <= kind && kind <= SyntaxKind.LastPunctuation; } } \ No newline at end of file diff --git a/tests/baselines/reference/arrayBestCommonTypes.types b/tests/baselines/reference/arrayBestCommonTypes.types index c9d39d5c1e8..5e34380673d 100644 --- a/tests/baselines/reference/arrayBestCommonTypes.types +++ b/tests/baselines/reference/arrayBestCommonTypes.types @@ -557,7 +557,7 @@ module NonEmptyTypes { >x : string >y : base >base : base ->[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : Array<{ x: undefined; y: base; } | { x: string; y: derived; }> +>[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : ({ x: undefined; y: base; } | { x: string; y: derived; })[] >{ x: undefined, y: new base() } : { x: undefined; y: base; } >x : undefined >undefined : undefined diff --git a/tests/baselines/reference/arrayLiteralContextualType.types b/tests/baselines/reference/arrayLiteralContextualType.types index 12d08e986f7..5797999b7df 100644 --- a/tests/baselines/reference/arrayLiteralContextualType.types +++ b/tests/baselines/reference/arrayLiteralContextualType.types @@ -40,7 +40,7 @@ function bar(animals: { [n: number]: IAnimal }) { } foo([ >foo([ new Giraffe(), new Elephant()]) : void >foo : (animals: IAnimal[]) => void ->[ new Giraffe(), new Elephant()] : Array +>[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[] new Giraffe(), >new Giraffe() : Giraffe @@ -54,7 +54,7 @@ foo([ bar([ >bar([ new Giraffe(), new Elephant()]) : void >bar : (animals: { [x: number]: IAnimal; }) => void ->[ new Giraffe(), new Elephant()] : Array +>[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[] new Giraffe(), >new Giraffe() : Giraffe @@ -67,8 +67,8 @@ bar([ ]); // Legal because of the contextual type IAnimal provided by the parameter var arr = [new Giraffe(), new Elephant()]; ->arr : Array ->[new Giraffe(), new Elephant()] : Array +>arr : (Giraffe | Elephant)[] +>[new Giraffe(), new Elephant()] : (Giraffe | Elephant)[] >new Giraffe() : Giraffe >Giraffe : typeof Giraffe >new Elephant() : Elephant @@ -77,10 +77,10 @@ var arr = [new Giraffe(), new Elephant()]; foo(arr); // ok because arr is Array not {}[] >foo(arr) : void >foo : (animals: IAnimal[]) => void ->arr : Array +>arr : (Giraffe | Elephant)[] bar(arr); // ok because arr is Array not {}[] >bar(arr) : void >bar : (animals: { [x: number]: IAnimal; }) => void ->arr : Array +>arr : (Giraffe | Elephant)[] diff --git a/tests/baselines/reference/arrayLiteralTypeInference.types b/tests/baselines/reference/arrayLiteralTypeInference.types index c80e5e17030..adcc28c7440 100644 --- a/tests/baselines/reference/arrayLiteralTypeInference.types +++ b/tests/baselines/reference/arrayLiteralTypeInference.types @@ -25,7 +25,7 @@ class ActionB extends Action { var x1: Action[] = [ >x1 : Action[] >Action : Action ->[ { id: 2, trueness: false }, { id: 3, name: "three" }] : Array<{ id: number; trueness: boolean; } | { id: number; name: string; }> +>[ { id: 2, trueness: false }, { id: 3, name: "three" }] : ({ id: number; trueness: boolean; } | { id: number; name: string; })[] { id: 2, trueness: false }, >{ id: 2, trueness: false } : { id: number; trueness: boolean; } @@ -42,7 +42,7 @@ var x1: Action[] = [ var x2: Action[] = [ >x2 : Action[] >Action : Action ->[ new ActionA(), new ActionB()] : Array +>[ new ActionA(), new ActionB()] : (ActionA | ActionB)[] new ActionA(), >new ActionA() : ActionA @@ -78,7 +78,7 @@ var z1: { id: number }[] = >id : number [ ->[ { id: 2, trueness: false }, { id: 3, name: "three" } ] : Array<{ id: number; trueness: boolean; } | { id: number; name: string; }> +>[ { id: 2, trueness: false }, { id: 3, name: "three" } ] : ({ id: number; trueness: boolean; } | { id: number; name: string; })[] { id: 2, trueness: false }, >{ id: 2, trueness: false } : { id: number; trueness: boolean; } @@ -97,7 +97,7 @@ var z2: { id: number }[] = >id : number [ ->[ new ActionA(), new ActionB() ] : Array +>[ new ActionA(), new ActionB() ] : (ActionA | ActionB)[] new ActionA(), >new ActionA() : ActionA diff --git a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types index 49b65a86aa6..bc21ec39073 100644 --- a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types +++ b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types @@ -17,27 +17,27 @@ var c: { x: number; a?: number }; >a : number var as = [a, b]; // { x: number; y?: number };[] ->as : { x: number; y?: number; }[] ->[a, b] : { x: number; y?: number; }[] +>as : ({ x: number; y?: number; } | { x: number; z?: number; })[] +>[a, b] : ({ x: number; y?: number; } | { x: number; z?: number; })[] >a : { x: number; y?: number; } >b : { x: number; z?: number; } var bs = [b, a]; // { x: number; z?: number };[] ->bs : { x: number; y?: number; }[] ->[b, a] : { x: number; y?: number; }[] +>bs : ({ x: number; y?: number; } | { x: number; z?: number; })[] +>[b, a] : ({ x: number; y?: number; } | { x: number; z?: number; })[] >b : { x: number; z?: number; } >a : { x: number; y?: number; } var cs = [a, b, c]; // { x: number; y?: number };[] ->cs : { x: number; y?: number; }[] ->[a, b, c] : { x: number; y?: number; }[] +>cs : ({ x: number; y?: number; } | { x: number; z?: number; } | { x: number; a?: number; })[] +>[a, b, c] : ({ x: number; y?: number; } | { x: number; z?: number; } | { x: number; a?: number; })[] >a : { x: number; y?: number; } >b : { x: number; z?: number; } >c : { x: number; a?: number; } var ds = [(x: Object) => 1, (x: string) => 2]; // { (x:Object) => number }[] ->ds : { (x: Object): number; }[] ->[(x: Object) => 1, (x: string) => 2] : { (x: Object): number; }[] +>ds : ((x: Object) => number)[] +>[(x: Object) => 1, (x: string) => 2] : ((x: Object) => number)[] >(x: Object) => 1 : (x: Object) => number >x : Object >Object : Object @@ -45,8 +45,8 @@ var ds = [(x: Object) => 1, (x: string) => 2]; // { (x:Object) => number }[] >x : string var es = [(x: string) => 2, (x: Object) => 1]; // { (x:string) => number }[] ->es : { (x: string): number; }[] ->[(x: string) => 2, (x: Object) => 1] : { (x: string): number; }[] +>es : ((x: string) => number)[] +>[(x: string) => 2, (x: Object) => 1] : ((x: string) => number)[] >(x: string) => 2 : (x: string) => number >x : string >(x: Object) => 1 : (x: Object) => number @@ -54,8 +54,8 @@ var es = [(x: string) => 2, (x: Object) => 1]; // { (x:string) => number }[] >Object : Object var fs = [(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) => 2]; // (a: { x: number; y?: number }) => number[] ->fs : { (a: { x: number; y?: number; }): number; }[] ->[(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) => 2] : { (a: { x: number; y?: number; }): number; }[] +>fs : (((a: { x: number; y?: number; }) => number) | ((b: { x: number; z?: number; }) => number))[] +>[(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) => 2] : (((a: { x: number; y?: number; }) => number) | ((b: { x: number; z?: number; }) => number))[] >(a: { x: number; y?: number }) => 1 : (a: { x: number; y?: number; }) => number >a : { x: number; y?: number; } >x : number @@ -66,8 +66,8 @@ var fs = [(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) => >z : number var gs = [(b: { x: number; z?: number }) => 2, (a: { x: number; y?: number }) => 1]; // (b: { x: number; z?: number }) => number[] ->gs : { (b: { x: number; z?: number; }): number; }[] ->[(b: { x: number; z?: number }) => 2, (a: { x: number; y?: number }) => 1] : { (b: { x: number; z?: number; }): number; }[] +>gs : (((b: { x: number; z?: number; }) => number) | ((a: { x: number; y?: number; }) => number))[] +>[(b: { x: number; z?: number }) => 2, (a: { x: number; y?: number }) => 1] : (((b: { x: number; z?: number; }) => number) | ((a: { x: number; y?: number; }) => number))[] >(b: { x: number; z?: number }) => 2 : (b: { x: number; z?: number; }) => number >b : { x: number; z?: number; } >x : number diff --git a/tests/baselines/reference/arrayLiterals.types b/tests/baselines/reference/arrayLiterals.types index 8c2fd942c62..62475fa2b4a 100644 --- a/tests/baselines/reference/arrayLiterals.types +++ b/tests/baselines/reference/arrayLiterals.types @@ -2,15 +2,15 @@ // Empty array literal with no contextual type has type Undefined[] var arr1= [[], [1], ['']]; ->arr1 : Array ->[[], [1], ['']] : Array +>arr1 : (string[] | number[])[] +>[[], [1], ['']] : (string[] | number[])[] >[] : undefined[] >[1] : number[] >[''] : string[] var arr2 = [[null], [1], ['']]; ->arr2 : Array ->[[null], [1], ['']] : Array +>arr2 : (string[] | number[])[] +>[[null], [1], ['']] : (string[] | number[])[] >[null] : null[] >[1] : number[] >[''] : string[] @@ -65,7 +65,7 @@ var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: ' >n : number >a : string >b : number ->[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }> +>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[] >{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; } >a : string >b : number @@ -76,8 +76,8 @@ var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: ' >c : number var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; ->context2 : Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }> ->[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }> +>context2 : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[] +>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[] >{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; } >a : string >b : number @@ -105,7 +105,7 @@ class Derived2 extends Base { private n }; var context3: Base[] = [new Derived1(), new Derived2()]; >context3 : Base[] >Base : Base ->[new Derived1(), new Derived2()] : Array +>[new Derived1(), new Derived2()] : (Derived1 | Derived2)[] >new Derived1() : Derived1 >Derived1 : typeof Derived1 >new Derived2() : Derived2 diff --git a/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types b/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types index e99ca18673e..1496e99adca 100644 --- a/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types +++ b/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types @@ -61,8 +61,8 @@ var xs = [list, myList]; // {}[] >myList : MyList var ys = [list, list2]; // {}[] ->ys : Array | List> ->[list, list2] : Array | List> +>ys : (List | List)[] +>[list, list2] : (List | List)[] >list : List >list2 : List diff --git a/tests/baselines/reference/arrayOfFunctionTypes3.types b/tests/baselines/reference/arrayOfFunctionTypes3.types index b224ff881e3..3ef5334382c 100644 --- a/tests/baselines/reference/arrayOfFunctionTypes3.types +++ b/tests/baselines/reference/arrayOfFunctionTypes3.types @@ -2,8 +2,8 @@ // valid uses of arrays of function types var x = [() => 1, () => { }]; ->x : { (): void; }[] ->[() => 1, () => { }] : { (): void; }[] +>x : (() => void)[] +>[() => 1, () => { }] : (() => void)[] >() => 1 : () => number >() => { } : () => void @@ -11,7 +11,7 @@ var r2 = x[0](); >r2 : void >x[0]() : void >x[0] : () => void ->x : { (): void; }[] +>x : (() => void)[] class C { >C : C diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types index 2c3ba8bc7c7..eb94c140883 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types @@ -48,14 +48,14 @@ var r3 = true ? 1 : {}; >{} : {} var r4 = true ? a : b; // typeof a ->r4 : { x: number; y?: number; } ->true ? a : b : { x: number; y?: number; } +>r4 : { x: number; y?: number; } | { x: number; z?: number; } +>true ? a : b : { x: number; y?: number; } | { x: number; z?: number; } >a : { x: number; y?: number; } >b : { x: number; z?: number; } var r5 = true ? b : a; // typeof b ->r5 : { x: number; y?: number; } ->true ? b : a : { x: number; y?: number; } +>r5 : { x: number; y?: number; } | { x: number; z?: number; } +>true ? b : a : { x: number; y?: number; } | { x: number; z?: number; } >b : { x: number; z?: number; } >a : { x: number; y?: number; } diff --git a/tests/baselines/reference/bestCommonTypeOfTuple.types b/tests/baselines/reference/bestCommonTypeOfTuple.types index 87624c267aa..0516fc4af2b 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple.types +++ b/tests/baselines/reference/bestCommonTypeOfTuple.types @@ -75,8 +75,8 @@ t4 = [E1.one, E2.two, 20]; >two : E2 var e1 = t1[2]; // {} ->e1 : { (x: number): string; } | { (x: number): number; } ->t1[2] : { (x: number): string; } | { (x: number): number; } +>e1 : ((x: number) => string) | ((x: number) => number) +>t1[2] : ((x: number) => string) | ((x: number) => number) >t1 : [(x: number) => string, (x: number) => number] var e2 = t2[2]; // {} diff --git a/tests/baselines/reference/bpSpan_arrayLiteralExpressions.baseline b/tests/baselines/reference/bpSpan_arrayLiteralExpressions.baseline new file mode 100644 index 00000000000..d8bfbc84aa0 --- /dev/null +++ b/tests/baselines/reference/bpSpan_arrayLiteralExpressions.baseline @@ -0,0 +1,198 @@ + +1 >var a = [10, 20, 30]; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 21) SpanInfo: {"start":0,"length":20} + >var a = [10, 20, 30] + >:=> (line 1, col 0) to (line 1, col 20) +-------------------------------- +2 >function foo(a: number) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (22 to 47) SpanInfo: {"start":52,"length":8} + >return a + >:=> (line 3, col 4) to (line 3, col 12) +-------------------------------- +3 > return a; + + ~~~~~~~~~~~~~~ => Pos: (48 to 61) SpanInfo: {"start":52,"length":8} + >return a + >:=> (line 3, col 4) to (line 3, col 12) +-------------------------------- +4 >} + + ~~ => Pos: (62 to 63) SpanInfo: {"start":62,"length":1} + >} + >:=> (line 4, col 0) to (line 4, col 1) +-------------------------------- +5 >a = [foo(30), (function () { + + ~~~~~ => Pos: (64 to 68) SpanInfo: {"start":64,"length":49} + >a = [foo(30), (function () { + > return 30; + >})()] + >:=> (line 5, col 0) to (line 7, col 5) +5 >a = [foo(30), (function () { + + ~~~~~~~~ => Pos: (69 to 76) SpanInfo: {"start":69,"length":7} + >foo(30) + >:=> (line 5, col 5) to (line 5, col 12) +5 >a = [foo(30), (function () { + + ~~ => Pos: (77 to 78) SpanInfo: {"start":78,"length":34} + >(function () { + > return 30; + >})() + >:=> (line 5, col 14) to (line 7, col 4) +5 >a = [foo(30), (function () { + + ~~~~~~~~~~~~~~ => Pos: (79 to 92) SpanInfo: {"start":97,"length":9} + >return 30 + >:=> (line 6, col 4) to (line 6, col 13) +-------------------------------- +6 > return 30; + + ~~~~~~~~~~~~~~~ => Pos: (93 to 107) SpanInfo: {"start":97,"length":9} + >return 30 + >:=> (line 6, col 4) to (line 6, col 13) +-------------------------------- +7 >})()]; + + ~ => Pos: (108 to 108) SpanInfo: {"start":108,"length":1} + >} + >:=> (line 7, col 0) to (line 7, col 1) +7 >})()]; + + ~~~ => Pos: (109 to 111) SpanInfo: {"start":78,"length":34} + >(function () { + > return 30; + >})() + >:=> (line 5, col 14) to (line 7, col 4) +7 >})()]; + + ~~~ => Pos: (112 to 114) SpanInfo: {"start":64,"length":49} + >a = [foo(30), (function () { + > return 30; + >})()] + >:=> (line 5, col 0) to (line 7, col 5) +-------------------------------- +8 >function bar() { + + ~~~~~~~~~~~~~~~~~ => Pos: (115 to 131) SpanInfo: {"start":136,"length":8} + >return a + >:=> (line 9, col 4) to (line 9, col 12) +-------------------------------- +9 > return a; + + ~~~~~~~~~~~~~~ => Pos: (132 to 145) SpanInfo: {"start":136,"length":8} + >return a + >:=> (line 9, col 4) to (line 9, col 12) +-------------------------------- +10 >} + + ~~ => Pos: (146 to 147) SpanInfo: {"start":146,"length":1} + >} + >:=> (line 10, col 0) to (line 10, col 1) +-------------------------------- +11 >var x = bar()[0]; + + ~~~~~~~ => Pos: (148 to 154) SpanInfo: {"start":148,"length":16} + >var x = bar()[0] + >:=> (line 11, col 0) to (line 11, col 16) +11 >var x = bar()[0]; + + ~~~~~~ => Pos: (155 to 160) SpanInfo: {"start":156,"length":5} + >bar() + >:=> (line 11, col 8) to (line 11, col 13) +11 >var x = bar()[0]; + + ~~~~~ => Pos: (161 to 165) SpanInfo: {"start":148,"length":16} + >var x = bar()[0] + >:=> (line 11, col 0) to (line 11, col 16) +-------------------------------- +12 >x = (function () { + + ~~~ => Pos: (166 to 168) SpanInfo: {"start":166,"length":40} + >x = (function () { + > return a; + >})()[x] + >:=> (line 12, col 0) to (line 14, col 7) +12 >x = (function () { + + ~~ => Pos: (169 to 170) SpanInfo: {"start":170,"length":33} + >(function () { + > return a; + >})() + >:=> (line 12, col 4) to (line 14, col 4) +12 >x = (function () { + + ~~~~~~~~~~~~~~ => Pos: (171 to 184) SpanInfo: {"start":189,"length":8} + >return a + >:=> (line 13, col 4) to (line 13, col 12) +-------------------------------- +13 > return a; + + ~~~~~~~~~~~~~~ => Pos: (185 to 198) SpanInfo: {"start":189,"length":8} + >return a + >:=> (line 13, col 4) to (line 13, col 12) +-------------------------------- +14 >})()[x]; + + ~ => Pos: (199 to 199) SpanInfo: {"start":199,"length":1} + >} + >:=> (line 14, col 0) to (line 14, col 1) +14 >})()[x]; + + ~~~ => Pos: (200 to 202) SpanInfo: {"start":170,"length":33} + >(function () { + > return a; + >})() + >:=> (line 12, col 4) to (line 14, col 4) +14 >})()[x]; + + ~~~~~ => Pos: (203 to 207) SpanInfo: {"start":166,"length":40} + >x = (function () { + > return a; + >})()[x] + >:=> (line 12, col 0) to (line 14, col 7) +-------------------------------- +15 >a[(function () { + + ~~ => Pos: (208 to 209) SpanInfo: {"start":208,"length":36} + >a[(function () { + > return x; + >})()] + >:=> (line 15, col 0) to (line 17, col 5) +15 >a[(function () { + + ~ => Pos: (210 to 210) SpanInfo: {"start":210,"length":33} + >(function () { + > return x; + >})() + >:=> (line 15, col 2) to (line 17, col 4) +15 >a[(function () { + + ~~~~~~~~~~~~~~ => Pos: (211 to 224) SpanInfo: {"start":229,"length":8} + >return x + >:=> (line 16, col 4) to (line 16, col 12) +-------------------------------- +16 > return x; + + ~~~~~~~~~~~~~~ => Pos: (225 to 238) SpanInfo: {"start":229,"length":8} + >return x + >:=> (line 16, col 4) to (line 16, col 12) +-------------------------------- +17 >})()]; + ~ => Pos: (239 to 239) SpanInfo: {"start":239,"length":1} + >} + >:=> (line 17, col 0) to (line 17, col 1) +17 >})()]; + ~~~ => Pos: (240 to 242) SpanInfo: {"start":210,"length":33} + >(function () { + > return x; + >})() + >:=> (line 15, col 2) to (line 17, col 4) +17 >})()]; + ~~ => Pos: (243 to 244) SpanInfo: {"start":208,"length":36} + >a[(function () { + > return x; + >})()] + >:=> (line 15, col 0) to (line 17, col 5) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_binaryExpressions.baseline b/tests/baselines/reference/bpSpan_binaryExpressions.baseline new file mode 100644 index 00000000000..370fec39a25 --- /dev/null +++ b/tests/baselines/reference/bpSpan_binaryExpressions.baseline @@ -0,0 +1,119 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >var y = 20; + + ~~~~~~~~~~~~ => Pos: (12 to 23) SpanInfo: {"start":12,"length":10} + >var y = 20 + >:=> (line 2, col 0) to (line 2, col 10) +-------------------------------- +3 >x += 30; + + ~~~~~~~~~ => Pos: (24 to 32) SpanInfo: {"start":24,"length":7} + >x += 30 + >:=> (line 3, col 0) to (line 3, col 7) +-------------------------------- +4 >x *= 0; + + ~~~~~~~~ => Pos: (33 to 40) SpanInfo: {"start":33,"length":6} + >x *= 0 + >:=> (line 4, col 0) to (line 4, col 6) +-------------------------------- +5 >x = x + 1; + + ~~~~~~~~~~~ => Pos: (41 to 51) SpanInfo: {"start":41,"length":9} + >x = x + 1 + >:=> (line 5, col 0) to (line 5, col 9) +-------------------------------- +6 >x = (function foo() { + + ~~~ => Pos: (52 to 54) SpanInfo: {"start":52,"length":44} + >x = (function foo() { + > return y; + >})() + y + >:=> (line 6, col 0) to (line 8, col 8) +6 >x = (function foo() { + + ~~ => Pos: (55 to 56) SpanInfo: {"start":56,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 6, col 4) to (line 8, col 4) +6 >x = (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (57 to 73) SpanInfo: {"start":78,"length":8} + >return y + >:=> (line 7, col 4) to (line 7, col 12) +-------------------------------- +7 > return y; + + ~~~~~~~~~~~~~~ => Pos: (74 to 87) SpanInfo: {"start":78,"length":8} + >return y + >:=> (line 7, col 4) to (line 7, col 12) +-------------------------------- +8 >})() + y; + + ~ => Pos: (88 to 88) SpanInfo: {"start":88,"length":1} + >} + >:=> (line 8, col 0) to (line 8, col 1) +8 >})() + y; + + ~~~ => Pos: (89 to 91) SpanInfo: {"start":56,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 6, col 4) to (line 8, col 4) +8 >})() + y; + + ~~~~~~ => Pos: (92 to 97) SpanInfo: {"start":52,"length":44} + >x = (function foo() { + > return y; + >})() + y + >:=> (line 6, col 0) to (line 8, col 8) +-------------------------------- +9 >x = y + 30 + (function foo() { + + ~~~~~~~~~~~~ => Pos: (98 to 109) SpanInfo: {"start":98,"length":54} + >x = y + 30 + (function foo() { + > return y; + >})() * 40 + >:=> (line 9, col 0) to (line 11, col 9) +9 >x = y + 30 + (function foo() { + + ~~ => Pos: (110 to 111) SpanInfo: {"start":111,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 9, col 13) to (line 11, col 4) +9 >x = y + 30 + (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (112 to 128) SpanInfo: {"start":133,"length":8} + >return y + >:=> (line 10, col 4) to (line 10, col 12) +-------------------------------- +10 > return y; + + ~~~~~~~~~~~~~~ => Pos: (129 to 142) SpanInfo: {"start":133,"length":8} + >return y + >:=> (line 10, col 4) to (line 10, col 12) +-------------------------------- +11 >})() * 40; + ~ => Pos: (143 to 143) SpanInfo: {"start":143,"length":1} + >} + >:=> (line 11, col 0) to (line 11, col 1) +11 >})() * 40; + ~~~ => Pos: (144 to 146) SpanInfo: {"start":111,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 9, col 13) to (line 11, col 4) +11 >})() * 40; + ~~~~~~ => Pos: (147 to 152) SpanInfo: {"start":98,"length":54} + >x = y + 30 + (function foo() { + > return y; + >})() * 40 + >:=> (line 9, col 0) to (line 11, col 9) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_breakOrContinue.baseline b/tests/baselines/reference/bpSpan_breakOrContinue.baseline new file mode 100644 index 00000000000..617589b9047 --- /dev/null +++ b/tests/baselines/reference/bpSpan_breakOrContinue.baseline @@ -0,0 +1,71 @@ + +1 >while (true) { + + ~~~~~~~~~~~~~~~ => Pos: (0 to 14) SpanInfo: {"start":0,"length":12} + >while (true) + >:=> (line 1, col 0) to (line 1, col 12) +-------------------------------- +2 > break; + + ~~~~~~~~~~~ => Pos: (15 to 25) SpanInfo: {"start":19,"length":5} + >break + >:=> (line 2, col 4) to (line 2, col 9) +-------------------------------- +3 >} + + ~~ => Pos: (26 to 27) SpanInfo: {"start":19,"length":5} + >break + >:=> (line 2, col 4) to (line 2, col 9) +-------------------------------- +4 >y: while (true) { + + ~~~~~~~~~~~~~~~~~~ => Pos: (28 to 45) SpanInfo: {"start":31,"length":12} + >while (true) + >:=> (line 4, col 3) to (line 4, col 15) +-------------------------------- +5 > break y; + + ~~~~~~~~~~~~~ => Pos: (46 to 58) SpanInfo: {"start":50,"length":7} + >break y + >:=> (line 5, col 4) to (line 5, col 11) +-------------------------------- +6 >} + + ~~ => Pos: (59 to 60) SpanInfo: {"start":50,"length":7} + >break y + >:=> (line 5, col 4) to (line 5, col 11) +-------------------------------- +7 >while (true) { + + ~~~~~~~~~~~~~~~ => Pos: (61 to 75) SpanInfo: {"start":61,"length":12} + >while (true) + >:=> (line 7, col 0) to (line 7, col 12) +-------------------------------- +8 > continue; + + ~~~~~~~~~~~~~~ => Pos: (76 to 89) SpanInfo: {"start":80,"length":8} + >continue + >:=> (line 8, col 4) to (line 8, col 12) +-------------------------------- +9 >} + + ~~ => Pos: (90 to 91) SpanInfo: {"start":80,"length":8} + >continue + >:=> (line 8, col 4) to (line 8, col 12) +-------------------------------- +10 >z: while (true) { + + ~~~~~~~~~~~~~~~~~~ => Pos: (92 to 109) SpanInfo: {"start":95,"length":12} + >while (true) + >:=> (line 10, col 3) to (line 10, col 15) +-------------------------------- +11 > continue z; + + ~~~~~~~~~~~~~~~~ => Pos: (110 to 125) SpanInfo: {"start":114,"length":10} + >continue z + >:=> (line 11, col 4) to (line 11, col 14) +-------------------------------- +12 >} + ~ => Pos: (126 to 126) SpanInfo: {"start":114,"length":10} + >continue z + >:=> (line 11, col 4) to (line 11, col 14) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_class.baseline b/tests/baselines/reference/bpSpan_class.baseline new file mode 100644 index 00000000000..3370762f72b --- /dev/null +++ b/tests/baselines/reference/bpSpan_class.baseline @@ -0,0 +1,365 @@ + +1 >class Greeter { + + ~~~~~~~~~~~~~~~~ => Pos: (0 to 15) SpanInfo: {"start":0,"length":396} + >class Greeter { + > constructor(public greeting: string, ...b: string[]) { + > } + > greet() { + > return "

" + this.greeting + "

"; + > } + > private x: string; + > private x1: number = 10; + > private fn() { + > return this.greeting; + > } + > get greetings() { + > return this.greeting; + > } + > set greetings(greetings: string) { + > this.greeting = greetings; + > } + >} + >:=> (line 1, col 0) to (line 18, col 1) +-------------------------------- +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~~~~~~~~~~~~~~ => Pos: (16 to 31) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (32 to 55) SpanInfo: {"start":32,"length":23} + >public greeting: string + >:=> (line 2, col 16) to (line 2, col 39) +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~~~~~~~~~~~~~~=> Pos: (56 to 71) SpanInfo: {"start":57,"length":14} + >...b: string[] + >:=> (line 2, col 41) to (line 2, col 55) +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~=> Pos: (72 to 74) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +3 > } + + ~~~~~~ => Pos: (75 to 80) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +4 > greet() { + + ~~~~~~~~~~~~~~ => Pos: (81 to 94) SpanInfo: {"start":85,"length":64} + >greet() { + > return "

" + this.greeting + "

"; + > } + >:=> (line 4, col 4) to (line 6, col 5) +-------------------------------- +5 > return "

" + this.greeting + "

"; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (95 to 143) SpanInfo: {"start":103,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 5, col 8) to (line 5, col 47) +-------------------------------- +6 > } + + ~~~~~~ => Pos: (144 to 149) SpanInfo: {"start":148,"length":1} + >} + >:=> (line 6, col 4) to (line 6, col 5) +-------------------------------- +7 > private x: string; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (150 to 172) SpanInfo: undefined +-------------------------------- +8 > private x1: number = 10; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (173 to 201) SpanInfo: {"start":177,"length":24} + >private x1: number = 10; + >:=> (line 8, col 4) to (line 8, col 28) +-------------------------------- +9 > private fn() { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (202 to 220) SpanInfo: {"start":206,"length":50} + >private fn() { + > return this.greeting; + > } + >:=> (line 9, col 4) to (line 11, col 5) +-------------------------------- +10 > return this.greeting; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (221 to 250) SpanInfo: {"start":229,"length":20} + >return this.greeting + >:=> (line 10, col 8) to (line 10, col 28) +-------------------------------- +11 > } + + ~~~~~~ => Pos: (251 to 256) SpanInfo: {"start":255,"length":1} + >} + >:=> (line 11, col 4) to (line 11, col 5) +-------------------------------- +12 > get greetings() { + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (257 to 278) SpanInfo: {"start":261,"length":53} + >get greetings() { + > return this.greeting; + > } + >:=> (line 12, col 4) to (line 14, col 5) +-------------------------------- +13 > return this.greeting; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (279 to 308) SpanInfo: {"start":287,"length":20} + >return this.greeting + >:=> (line 13, col 8) to (line 13, col 28) +-------------------------------- +14 > } + + ~~~~~~ => Pos: (309 to 314) SpanInfo: {"start":313,"length":1} + >} + >:=> (line 14, col 4) to (line 14, col 5) +-------------------------------- +15 > set greetings(greetings: string) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (315 to 353) SpanInfo: {"start":319,"length":75} + >set greetings(greetings: string) { + > this.greeting = greetings; + > } + >:=> (line 15, col 4) to (line 17, col 5) +-------------------------------- +16 > this.greeting = greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (354 to 388) SpanInfo: {"start":362,"length":25} + >this.greeting = greetings + >:=> (line 16, col 8) to (line 16, col 33) +-------------------------------- +17 > } + + ~~~~~~ => Pos: (389 to 394) SpanInfo: {"start":393,"length":1} + >} + >:=> (line 17, col 4) to (line 17, col 5) +-------------------------------- +18 >} + + ~~ => Pos: (395 to 396) SpanInfo: {"start":395,"length":1} + >} + >:=> (line 18, col 0) to (line 18, col 1) +-------------------------------- +19 >class Greeter2 { + + ~~~~~~~~~~~~~~~~~ => Pos: (397 to 413) SpanInfo: {"start":397,"length":18} + >class Greeter2 { + >} + >:=> (line 19, col 0) to (line 20, col 1) +-------------------------------- +20 >} + + ~~ => Pos: (414 to 415) SpanInfo: {"start":414,"length":1} + >} + >:=> (line 20, col 0) to (line 20, col 1) +-------------------------------- +21 >class Greeter1 + + ~~~~~~~~~~~~~~~~ => Pos: (416 to 431) SpanInfo: {"start":416,"length":419} + >class Greeter1 + >{ + > constructor(public greeting: string, ...b: string[]) + > { + > } + > greet() + > { + > return "

" + this.greeting + "

"; + > } + > private x: string; + > private x1: number = 10; + > private fn() + > { + > return this.greeting; + > } + > get greetings() + > { + > return this.greeting; + > } + > set greetings(greetings: string) + > { + > this.greeting = greetings; + > } + >} + >:=> (line 21, col 0) to (line 44, col 1) +-------------------------------- +22 >{ + + ~~ => Pos: (432 to 433) SpanInfo: {"start":501,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +-------------------------------- +23 > constructor(public greeting: string, ...b: string[]) + + ~~~~~~~~~~~~~~~~ => Pos: (434 to 449) SpanInfo: {"start":501,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +23 > constructor(public greeting: string, ...b: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (450 to 473) SpanInfo: {"start":450,"length":23} + >public greeting: string + >:=> (line 23, col 16) to (line 23, col 39) +23 > constructor(public greeting: string, ...b: string[]) + + ~~~~~~~~~~~~~~~~~=> Pos: (474 to 490) SpanInfo: {"start":475,"length":14} + >...b: string[] + >:=> (line 23, col 41) to (line 23, col 55) +-------------------------------- +24 > { + + ~~~~~~ => Pos: (491 to 496) SpanInfo: {"start":501,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +-------------------------------- +25 > } + + ~~~~~~ => Pos: (497 to 502) SpanInfo: {"start":501,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +-------------------------------- +26 > greet() + + ~~~~~~~~~~~~ => Pos: (503 to 514) SpanInfo: {"start":507,"length":68} + >greet() + > { + > return "

" + this.greeting + "

"; + > } + >:=> (line 26, col 4) to (line 29, col 5) +-------------------------------- +27 > { + + ~~~~~~ => Pos: (515 to 520) SpanInfo: {"start":529,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 28, col 8) to (line 28, col 47) +-------------------------------- +28 > return "

" + this.greeting + "

"; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (521 to 569) SpanInfo: {"start":529,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 28, col 8) to (line 28, col 47) +-------------------------------- +29 > } + + ~~~~~~ => Pos: (570 to 575) SpanInfo: {"start":574,"length":1} + >} + >:=> (line 29, col 4) to (line 29, col 5) +-------------------------------- +30 > private x: string; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (576 to 598) SpanInfo: undefined +-------------------------------- +31 > private x1: number = 10; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (599 to 627) SpanInfo: {"start":603,"length":24} + >private x1: number = 10; + >:=> (line 31, col 4) to (line 31, col 28) +-------------------------------- +32 > private fn() + + ~~~~~~~~~~~~~~~~~ => Pos: (628 to 644) SpanInfo: {"start":632,"length":54} + >private fn() + > { + > return this.greeting; + > } + >:=> (line 32, col 4) to (line 35, col 5) +-------------------------------- +33 > { + + ~~~~~~ => Pos: (645 to 650) SpanInfo: {"start":659,"length":20} + >return this.greeting + >:=> (line 34, col 8) to (line 34, col 28) +-------------------------------- +34 > return this.greeting; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (651 to 680) SpanInfo: {"start":659,"length":20} + >return this.greeting + >:=> (line 34, col 8) to (line 34, col 28) +-------------------------------- +35 > } + + ~~~~~~ => Pos: (681 to 686) SpanInfo: {"start":685,"length":1} + >} + >:=> (line 35, col 4) to (line 35, col 5) +-------------------------------- +36 > get greetings() + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (687 to 707) SpanInfo: {"start":691,"length":58} + >get greetings() + > { + > return this.greeting; + > } + >:=> (line 36, col 4) to (line 39, col 5) +-------------------------------- +37 > { + + ~~~~~~ => Pos: (708 to 713) SpanInfo: {"start":722,"length":20} + >return this.greeting + >:=> (line 38, col 8) to (line 38, col 28) +-------------------------------- +38 > return this.greeting; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (714 to 743) SpanInfo: {"start":722,"length":20} + >return this.greeting + >:=> (line 38, col 8) to (line 38, col 28) +-------------------------------- +39 > } + + ~~~~~~ => Pos: (744 to 749) SpanInfo: {"start":748,"length":1} + >} + >:=> (line 39, col 4) to (line 39, col 5) +-------------------------------- +40 > set greetings(greetings: string) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (750 to 786) SpanInfo: {"start":754,"length":79} + >set greetings(greetings: string) + > { + > this.greeting = greetings; + > } + >:=> (line 40, col 4) to (line 43, col 5) +-------------------------------- +41 > { + + ~~~~~~ => Pos: (787 to 792) SpanInfo: {"start":801,"length":25} + >this.greeting = greetings + >:=> (line 42, col 8) to (line 42, col 33) +-------------------------------- +42 > this.greeting = greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (793 to 827) SpanInfo: {"start":801,"length":25} + >this.greeting = greetings + >:=> (line 42, col 8) to (line 42, col 33) +-------------------------------- +43 > } + + ~~~~~~ => Pos: (828 to 833) SpanInfo: {"start":832,"length":1} + >} + >:=> (line 43, col 4) to (line 43, col 5) +-------------------------------- +44 >} + + ~~ => Pos: (834 to 835) SpanInfo: {"start":834,"length":1} + >} + >:=> (line 44, col 0) to (line 44, col 1) +-------------------------------- +45 >class Greeter12 + + ~~~~~~~~~~~~~~~~ => Pos: (836 to 851) SpanInfo: {"start":836,"length":19} + >class Greeter12 + >{ + >} + >:=> (line 45, col 0) to (line 47, col 1) +-------------------------------- +46 >{ + + ~~ => Pos: (852 to 853) SpanInfo: {"start":854,"length":1} + >} + >:=> (line 47, col 0) to (line 47, col 1) +-------------------------------- +47 >} + ~ => Pos: (854 to 854) SpanInfo: {"start":854,"length":1} + >} + >:=> (line 47, col 0) to (line 47, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_classAmbient.baseline b/tests/baselines/reference/bpSpan_classAmbient.baseline new file mode 100644 index 00000000000..b168c5416c5 --- /dev/null +++ b/tests/baselines/reference/bpSpan_classAmbient.baseline @@ -0,0 +1,31 @@ + +1 >declare class Greeter { + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 23) SpanInfo: undefined +-------------------------------- +2 > public greeting: string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (24 to 52) SpanInfo: undefined +-------------------------------- +3 > constructor(greeting: string, ...b: string[]); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (53 to 103) SpanInfo: undefined +-------------------------------- +4 > greet(): string; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (104 to 124) SpanInfo: undefined +-------------------------------- +5 > private val; + + ~~~~~~~~~~~~~~~~~ => Pos: (125 to 141) SpanInfo: undefined +-------------------------------- +6 > static x: number; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (142 to 163) SpanInfo: undefined +-------------------------------- +7 > static fn(a: number, ...b:string[]); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (164 to 204) SpanInfo: undefined +-------------------------------- +8 >} + ~ => Pos: (205 to 205) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_classes.baseline b/tests/baselines/reference/bpSpan_classes.baseline new file mode 100644 index 00000000000..811109af835 --- /dev/null +++ b/tests/baselines/reference/bpSpan_classes.baseline @@ -0,0 +1,356 @@ + +1 >module Foo.Bar { + + ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":0,"length":881} + >module Foo.Bar { + > "use strict"; + > + > class Greeter { + > constructor(public greeting: string) { + > } + > + > greet() { + > return "

" + this.greeting + "

"; + > } + > } + > + > + > function foo(greeting: string): Greeter { + > return new Greeter(greeting); + > } + > + > var greeter = new Greeter("Hello, world!"); + > var str = greeter.greet(); + > + > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + > var greeters: Greeter[] = []; /* inline block comment */ + > greeters[0] = new Greeter(greeting); + > for (var i = 0; i < restGreetings.length; i++) { + > greeters.push(new Greeter(restGreetings[i])); + > } + > + > return greeters; + > } + > + > var b = foo2("Hello", "World", "!"); + > // This is simple signle line comment + > for (var j = 0; j < b.length; j++) { + > b[j].greet(); + > } + >} + >:=> (line 1, col 0) to (line 36, col 1) +1 >module Foo.Bar { + + ~~~~~~ => Pos: (11 to 16) SpanInfo: {"start":11,"length":870} + >Bar { + > "use strict"; + > + > class Greeter { + > constructor(public greeting: string) { + > } + > + > greet() { + > return "

" + this.greeting + "

"; + > } + > } + > + > + > function foo(greeting: string): Greeter { + > return new Greeter(greeting); + > } + > + > var greeter = new Greeter("Hello, world!"); + > var str = greeter.greet(); + > + > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + > var greeters: Greeter[] = []; /* inline block comment */ + > greeters[0] = new Greeter(greeting); + > for (var i = 0; i < restGreetings.length; i++) { + > greeters.push(new Greeter(restGreetings[i])); + > } + > + > return greeters; + > } + > + > var b = foo2("Hello", "World", "!"); + > // This is simple signle line comment + > for (var j = 0; j < b.length; j++) { + > b[j].greet(); + > } + >} + >:=> (line 1, col 11) to (line 36, col 1) +-------------------------------- +2 > "use strict"; + + ~~~~~~~~~~~~~~~~~~ => Pos: (17 to 34) SpanInfo: {"start":21,"length":12} + >"use strict" + >:=> (line 2, col 4) to (line 2, col 16) +-------------------------------- +3 > + + ~ => Pos: (35 to 35) SpanInfo: undefined +-------------------------------- +4 > class Greeter { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (36 to 55) SpanInfo: {"start":40,"length":160} + >class Greeter { + > constructor(public greeting: string) { + > } + > + > greet() { + > return "

" + this.greeting + "

"; + > } + > } + >:=> (line 4, col 4) to (line 11, col 5) +-------------------------------- +5 > constructor(public greeting: string) { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (56 to 75) SpanInfo: {"start":111,"length":1} + >} + >:=> (line 6, col 8) to (line 6, col 9) +5 > constructor(public greeting: string) { + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (76 to 99) SpanInfo: {"start":76,"length":23} + >public greeting: string + >:=> (line 5, col 20) to (line 5, col 43) +5 > constructor(public greeting: string) { + + ~~~=> Pos: (100 to 102) SpanInfo: {"start":111,"length":1} + >} + >:=> (line 6, col 8) to (line 6, col 9) +-------------------------------- +6 > } + + ~~~~~~~~~~ => Pos: (103 to 112) SpanInfo: {"start":111,"length":1} + >} + >:=> (line 6, col 8) to (line 6, col 9) +-------------------------------- +7 > + + ~ => Pos: (113 to 113) SpanInfo: undefined +-------------------------------- +8 > greet() { + + ~~~~~~~~~~~~~~~~~~ => Pos: (114 to 131) SpanInfo: {"start":122,"length":72} + >greet() { + > return "

" + this.greeting + "

"; + > } + >:=> (line 8, col 8) to (line 10, col 9) +-------------------------------- +9 > return "

" + this.greeting + "

"; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (132 to 184) SpanInfo: {"start":144,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 9, col 12) to (line 9, col 51) +-------------------------------- +10 > } + + ~~~~~~~~~~ => Pos: (185 to 194) SpanInfo: {"start":193,"length":1} + >} + >:=> (line 10, col 8) to (line 10, col 9) +-------------------------------- +11 > } + + ~~~~~~ => Pos: (195 to 200) SpanInfo: {"start":199,"length":1} + >} + >:=> (line 11, col 4) to (line 11, col 5) +-------------------------------- +12 > + + ~ => Pos: (201 to 201) SpanInfo: undefined +-------------------------------- +13 > + + ~ => Pos: (202 to 202) SpanInfo: undefined +-------------------------------- +14 > function foo(greeting: string): Greeter { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (203 to 248) SpanInfo: {"start":257,"length":28} + >return new Greeter(greeting) + >:=> (line 15, col 8) to (line 15, col 36) +-------------------------------- +15 > return new Greeter(greeting); + + ~~~~~~~~~~~~~~ => Pos: (249 to 262) SpanInfo: {"start":257,"length":28} + >return new Greeter(greeting) + >:=> (line 15, col 8) to (line 15, col 36) +15 > return new Greeter(greeting); + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (263 to 286) SpanInfo: {"start":264,"length":21} + >new Greeter(greeting) + >:=> (line 15, col 15) to (line 15, col 36) +-------------------------------- +16 > } + + ~~~~~~ => Pos: (287 to 292) SpanInfo: {"start":291,"length":1} + >} + >:=> (line 16, col 4) to (line 16, col 5) +-------------------------------- +17 > + + ~ => Pos: (293 to 293) SpanInfo: undefined +-------------------------------- +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~~~~~~~~~~ => Pos: (294 to 310) SpanInfo: {"start":298,"length":42} + >var greeter = new Greeter("Hello, world!") + >:=> (line 18, col 4) to (line 18, col 46) +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (311 to 341) SpanInfo: {"start":312,"length":28} + >new Greeter("Hello, world!") + >:=> (line 18, col 18) to (line 18, col 46) +-------------------------------- +19 > var str = greeter.greet(); + + ~~~~~~~~~~~~~ => Pos: (342 to 354) SpanInfo: {"start":346,"length":25} + >var str = greeter.greet() + >:=> (line 19, col 4) to (line 19, col 29) +19 > var str = greeter.greet(); + + ~~~~~~~~~~~~~~~~~~ => Pos: (355 to 372) SpanInfo: {"start":356,"length":15} + >greeter.greet() + >:=> (line 19, col 14) to (line 19, col 29) +-------------------------------- +20 > + + ~ => Pos: (373 to 373) SpanInfo: undefined +-------------------------------- +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (374 to 408) SpanInfo: {"start":468,"length":28} + >var greeters: Greeter[] = [] + >:=> (line 22, col 8) to (line 22, col 36) +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (409 to 456) SpanInfo: {"start":410,"length":46} + >...restGreetings /* more greeting */: string[] + >:=> (line 21, col 36) to (line 21, col 82) +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~=> Pos: (457 to 459) SpanInfo: {"start":468,"length":28} + >var greeters: Greeter[] = [] + >:=> (line 22, col 8) to (line 22, col 36) +-------------------------------- +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (460 to 524) SpanInfo: {"start":468,"length":28} + >var greeters: Greeter[] = [] + >:=> (line 22, col 8) to (line 22, col 36) +-------------------------------- +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (525 to 545) SpanInfo: {"start":533,"length":35} + >greeters[0] = new Greeter(greeting) + >:=> (line 23, col 8) to (line 23, col 43) +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (546 to 569) SpanInfo: {"start":547,"length":21} + >new Greeter(greeting) + >:=> (line 23, col 22) to (line 23, col 43) +-------------------------------- +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (570 to 592) SpanInfo: {"start":583,"length":9} + >var i = 0 + >:=> (line 24, col 13) to (line 24, col 22) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (593 to 618) SpanInfo: {"start":594,"length":24} + >i < restGreetings.length + >:=> (line 24, col 24) to (line 24, col 48) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~~=> Pos: (619 to 626) SpanInfo: {"start":620,"length":3} + >i++ + >:=> (line 24, col 50) to (line 24, col 53) +-------------------------------- +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (627 to 652) SpanInfo: {"start":639,"length":44} + >greeters.push(new Greeter(restGreetings[i])) + >:=> (line 25, col 12) to (line 25, col 56) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (653 to 681) SpanInfo: {"start":653,"length":29} + >new Greeter(restGreetings[i]) + >:=> (line 25, col 26) to (line 25, col 55) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~=> Pos: (682 to 684) SpanInfo: {"start":639,"length":44} + >greeters.push(new Greeter(restGreetings[i])) + >:=> (line 25, col 12) to (line 25, col 56) +-------------------------------- +26 > } + + ~~~~~~~~~~ => Pos: (685 to 694) SpanInfo: {"start":639,"length":44} + >greeters.push(new Greeter(restGreetings[i])) + >:=> (line 25, col 12) to (line 25, col 56) +-------------------------------- +27 > + + ~ => Pos: (695 to 695) SpanInfo: undefined +-------------------------------- +28 > return greeters; + + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (696 to 720) SpanInfo: {"start":704,"length":15} + >return greeters + >:=> (line 28, col 8) to (line 28, col 23) +-------------------------------- +29 > } + + ~~~~~~ => Pos: (721 to 726) SpanInfo: {"start":725,"length":1} + >} + >:=> (line 29, col 4) to (line 29, col 5) +-------------------------------- +30 > + + ~ => Pos: (727 to 727) SpanInfo: undefined +-------------------------------- +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~~~~~~~ => Pos: (728 to 738) SpanInfo: {"start":732,"length":35} + >var b = foo2("Hello", "World", "!") + >:=> (line 31, col 4) to (line 31, col 39) +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (739 to 768) SpanInfo: {"start":740,"length":27} + >foo2("Hello", "World", "!") + >:=> (line 31, col 12) to (line 31, col 39) +-------------------------------- +32 > // This is simple signle line comment + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (769 to 810) SpanInfo: undefined +-------------------------------- +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (811 to 829) SpanInfo: {"start":820,"length":9} + >var j = 0 + >:=> (line 33, col 9) to (line 33, col 18) +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~~~~~~~~~~ => Pos: (830 to 843) SpanInfo: {"start":831,"length":12} + >j < b.length + >:=> (line 33, col 20) to (line 33, col 32) +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~~~~ => Pos: (844 to 851) SpanInfo: {"start":845,"length":3} + >j++ + >:=> (line 33, col 34) to (line 33, col 37) +-------------------------------- +34 > b[j].greet(); + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (852 to 873) SpanInfo: {"start":860,"length":12} + >b[j].greet() + >:=> (line 34, col 8) to (line 34, col 20) +-------------------------------- +35 > } + + ~~~~~~ => Pos: (874 to 879) SpanInfo: {"start":860,"length":12} + >b[j].greet() + >:=> (line 34, col 8) to (line 34, col 20) +-------------------------------- +36 >} + ~ => Pos: (880 to 880) SpanInfo: {"start":880,"length":1} + >} + >:=> (line 36, col 0) to (line 36, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_conditionalExpressions.baseline b/tests/baselines/reference/bpSpan_conditionalExpressions.baseline new file mode 100644 index 00000000000..5abd49d50cf --- /dev/null +++ b/tests/baselines/reference/bpSpan_conditionalExpressions.baseline @@ -0,0 +1,129 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >var y = x ? x + 10 : 30; + + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (12 to 36) SpanInfo: {"start":12,"length":23} + >var y = x ? x + 10 : 30 + >:=> (line 2, col 0) to (line 2, col 23) +-------------------------------- +3 >var z = (function foo() { + + ~~~~~~~ => Pos: (37 to 43) SpanInfo: {"start":37,"length":90} + >var z = (function foo() { + > return x; + >})() ? y : function bar() { + > return x; + >} () + >:=> (line 3, col 0) to (line 7, col 4) +3 >var z = (function foo() { + + ~~ => Pos: (44 to 45) SpanInfo: {"start":45,"length":36} + >(function foo() { + > return x; + >})() + >:=> (line 3, col 8) to (line 5, col 4) +3 >var z = (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (46 to 62) SpanInfo: {"start":67,"length":8} + >return x + >:=> (line 4, col 4) to (line 4, col 12) +-------------------------------- +4 > return x; + + ~~~~~~~~~~~~~~ => Pos: (63 to 76) SpanInfo: {"start":67,"length":8} + >return x + >:=> (line 4, col 4) to (line 4, col 12) +-------------------------------- +5 >})() ? y : function bar() { + + ~ => Pos: (77 to 77) SpanInfo: {"start":77,"length":1} + >} + >:=> (line 5, col 0) to (line 5, col 1) +5 >})() ? y : function bar() { + + ~~~ => Pos: (78 to 80) SpanInfo: {"start":45,"length":36} + >(function foo() { + > return x; + >})() + >:=> (line 3, col 8) to (line 5, col 4) +5 >})() ? y : function bar() { + + ~~~~~~ => Pos: (81 to 86) SpanInfo: {"start":37,"length":90} + >var z = (function foo() { + > return x; + >})() ? y : function bar() { + > return x; + >} () + >:=> (line 3, col 0) to (line 7, col 4) +5 >})() ? y : function bar() { + + ~~~~~~~~~~~~~~~~~~ => Pos: (87 to 104) SpanInfo: {"start":113,"length":8} + >return x + >:=> (line 6, col 8) to (line 6, col 16) +-------------------------------- +6 > return x; + + ~~~~~~~~~~~~~~~~~~ => Pos: (105 to 122) SpanInfo: {"start":113,"length":8} + >return x + >:=> (line 6, col 8) to (line 6, col 16) +-------------------------------- +7 >} (); + + ~ => Pos: (123 to 123) SpanInfo: {"start":123,"length":1} + >} + >:=> (line 7, col 0) to (line 7, col 1) +7 >} (); + + ~~~~~ => Pos: (124 to 128) SpanInfo: {"start":88,"length":39} + >function bar() { + > return x; + >} () + >:=> (line 5, col 11) to (line 7, col 4) +-------------------------------- +8 >x = y ? (function () { + + ~~~~~~~ => Pos: (129 to 135) SpanInfo: {"start":129,"length":47} + >x = y ? (function () { + > return z; + >})() : 10 + >:=> (line 8, col 0) to (line 10, col 10) +8 >x = y ? (function () { + + ~~ => Pos: (136 to 137) SpanInfo: {"start":137,"length":33} + >(function () { + > return z; + >})() + >:=> (line 8, col 8) to (line 10, col 4) +8 >x = y ? (function () { + + ~~~~~~~~~~~~~~ => Pos: (138 to 151) SpanInfo: {"start":156,"length":8} + >return z + >:=> (line 9, col 4) to (line 9, col 12) +-------------------------------- +9 > return z; + + ~~~~~~~~~~~~~~ => Pos: (152 to 165) SpanInfo: {"start":156,"length":8} + >return z + >:=> (line 9, col 4) to (line 9, col 12) +-------------------------------- +10 >})() : 10; + ~ => Pos: (166 to 166) SpanInfo: {"start":166,"length":1} + >} + >:=> (line 10, col 0) to (line 10, col 1) +10 >})() : 10; + ~~~ => Pos: (167 to 169) SpanInfo: {"start":137,"length":33} + >(function () { + > return z; + >})() + >:=> (line 8, col 8) to (line 10, col 4) +10 >})() : 10; + ~~~~~~~ => Pos: (170 to 176) SpanInfo: {"start":129,"length":47} + >x = y ? (function () { + > return z; + >})() : 10 + >:=> (line 8, col 0) to (line 10, col 10) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_debugger.baseline b/tests/baselines/reference/bpSpan_debugger.baseline new file mode 100644 index 00000000000..700ef7a56a9 --- /dev/null +++ b/tests/baselines/reference/bpSpan_debugger.baseline @@ -0,0 +1,5 @@ + +1 >debugger; + ~~~~~~~~~ => Pos: (0 to 8) SpanInfo: {"start":0,"length":8} + >debugger + >:=> (line 1, col 0) to (line 1, col 8) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_do.baseline b/tests/baselines/reference/bpSpan_do.baseline new file mode 100644 index 00000000000..3ff287c2046 --- /dev/null +++ b/tests/baselines/reference/bpSpan_do.baseline @@ -0,0 +1,142 @@ + +1 >var i = 0; + + ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":0,"length":9} + >var i = 0 + >:=> (line 1, col 0) to (line 1, col 9) +-------------------------------- +2 >do + + ~~~ => Pos: (11 to 13) SpanInfo: {"start":20,"length":3} + >i++ + >:=> (line 4, col 4) to (line 4, col 7) +-------------------------------- +3 >{ + + ~~ => Pos: (14 to 15) SpanInfo: {"start":20,"length":3} + >i++ + >:=> (line 4, col 4) to (line 4, col 7) +-------------------------------- +4 > i++; + + ~~~~~~~~~ => Pos: (16 to 24) SpanInfo: {"start":20,"length":3} + >i++ + >:=> (line 4, col 4) to (line 4, col 7) +-------------------------------- +5 >} while (i < 10); + + ~ => Pos: (25 to 25) SpanInfo: {"start":20,"length":3} + >i++ + >:=> (line 4, col 4) to (line 4, col 7) +5 >} while (i < 10); + + ~~~~~~~~~~~~~~~~~ => Pos: (26 to 42) SpanInfo: {"start":27,"length":14} + >while (i < 10) + >:=> (line 5, col 2) to (line 5, col 16) +-------------------------------- +6 >do { + + ~~~~~ => Pos: (43 to 47) SpanInfo: {"start":52,"length":3} + >i++ + >:=> (line 7, col 4) to (line 7, col 7) +-------------------------------- +7 > i++; + + ~~~~~~~~~ => Pos: (48 to 56) SpanInfo: {"start":52,"length":3} + >i++ + >:=> (line 7, col 4) to (line 7, col 7) +-------------------------------- +8 >} while (i < 20); + + ~ => Pos: (57 to 57) SpanInfo: {"start":52,"length":3} + >i++ + >:=> (line 7, col 4) to (line 7, col 7) +8 >} while (i < 20); + + ~~~~~~~~~~~~~~~~~ => Pos: (58 to 74) SpanInfo: {"start":59,"length":14} + >while (i < 20) + >:=> (line 8, col 2) to (line 8, col 16) +-------------------------------- +9 >do { + + ~~~~~ => Pos: (75 to 79) SpanInfo: {"start":84,"length":3} + >i++ + >:=> (line 10, col 4) to (line 10, col 7) +-------------------------------- +10 > i++; + + ~~~~~~~~~ => Pos: (80 to 88) SpanInfo: {"start":84,"length":3} + >i++ + >:=> (line 10, col 4) to (line 10, col 7) +-------------------------------- +11 >} + + ~~~ => Pos: (89 to 91) SpanInfo: {"start":84,"length":3} + >i++ + >:=> (line 10, col 4) to (line 10, col 7) +-------------------------------- +12 >while (i < 30); + + ~~~~~~~~~~~~~~~~ => Pos: (92 to 107) SpanInfo: {"start":92,"length":14} + >while (i < 30) + >:=> (line 12, col 0) to (line 12, col 14) +-------------------------------- +13 >do { + + ~~~~~ => Pos: (108 to 112) SpanInfo: {"start":117,"length":3} + >i-- + >:=> (line 14, col 4) to (line 14, col 7) +-------------------------------- +14 > i--; + + ~~~~~~~~~ => Pos: (113 to 121) SpanInfo: {"start":117,"length":3} + >i-- + >:=> (line 14, col 4) to (line 14, col 7) +-------------------------------- +15 >} while ((function () { + + ~ => Pos: (122 to 122) SpanInfo: {"start":117,"length":3} + >i-- + >:=> (line 14, col 4) to (line 14, col 7) +15 >} while ((function () { + + ~~~~~~~~ => Pos: (123 to 130) SpanInfo: {"start":124,"length":60} + >while ((function () { + > return 30 * i; + > })() !== i) + >:=> (line 15, col 2) to (line 17, col 15) +15 >} while ((function () { + + ~ => Pos: (131 to 131) SpanInfo: {"start":131,"length":46} + >(function () { + > return 30 * i; + > })() + >:=> (line 15, col 9) to (line 17, col 8) +15 >} while ((function () { + + ~~~~~~~~~~~~~~ => Pos: (132 to 145) SpanInfo: {"start":154,"length":13} + >return 30 * i + >:=> (line 16, col 8) to (line 16, col 21) +-------------------------------- +16 > return 30 * i; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (146 to 168) SpanInfo: {"start":154,"length":13} + >return 30 * i + >:=> (line 16, col 8) to (line 16, col 21) +-------------------------------- +17 > })() !== i); + ~~~~~ => Pos: (169 to 173) SpanInfo: {"start":173,"length":1} + >} + >:=> (line 17, col 4) to (line 17, col 5) +17 > })() !== i); + ~~~ => Pos: (174 to 176) SpanInfo: {"start":131,"length":46} + >(function () { + > return 30 * i; + > })() + >:=> (line 15, col 9) to (line 17, col 8) +17 > })() !== i); + ~~~~~~~~~ => Pos: (177 to 185) SpanInfo: {"start":124,"length":60} + >while ((function () { + > return 30 * i; + > })() !== i) + >:=> (line 15, col 2) to (line 17, col 15) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_enums.baseline b/tests/baselines/reference/bpSpan_enums.baseline new file mode 100644 index 00000000000..1dd77f8d417 --- /dev/null +++ b/tests/baselines/reference/bpSpan_enums.baseline @@ -0,0 +1,248 @@ + +1 >enum e { + + ~~~~~~~~~ => Pos: (0 to 8) SpanInfo: {"start":0,"length":30} + >enum e { + > x, + > y, + > x + >} + >:=> (line 1, col 0) to (line 5, col 1) +-------------------------------- +2 > x, + + ~~~~~~~ => Pos: (9 to 15) SpanInfo: {"start":13,"length":1} + >x + >:=> (line 2, col 4) to (line 2, col 5) +-------------------------------- +3 > y, + + ~~~~~~~ => Pos: (16 to 22) SpanInfo: {"start":20,"length":1} + >y + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +4 > x + + ~~~~~~ => Pos: (23 to 28) SpanInfo: {"start":27,"length":1} + >x + >:=> (line 4, col 4) to (line 4, col 5) +-------------------------------- +5 >} + + ~~ => Pos: (29 to 30) SpanInfo: {"start":29,"length":1} + >} + >:=> (line 5, col 0) to (line 5, col 1) +-------------------------------- +6 >enum e2 { + + ~~~~~~~~~~ => Pos: (31 to 40) SpanInfo: {"start":31,"length":49} + >enum e2 { + > x = 10, + > y = 10, + > z, + > x2 + >} + >:=> (line 6, col 0) to (line 11, col 1) +-------------------------------- +7 > x = 10, + + ~~~~~~~~~~~~ => Pos: (41 to 52) SpanInfo: {"start":45,"length":6} + >x = 10 + >:=> (line 7, col 4) to (line 7, col 10) +-------------------------------- +8 > y = 10, + + ~~~~~~~~~~~~ => Pos: (53 to 64) SpanInfo: {"start":57,"length":6} + >y = 10 + >:=> (line 8, col 4) to (line 8, col 10) +-------------------------------- +9 > z, + + ~~~~~~~ => Pos: (65 to 71) SpanInfo: {"start":69,"length":1} + >z + >:=> (line 9, col 4) to (line 9, col 5) +-------------------------------- +10 > x2 + + ~~~~~~~ => Pos: (72 to 78) SpanInfo: {"start":76,"length":2} + >x2 + >:=> (line 10, col 4) to (line 10, col 6) +-------------------------------- +11 >} + + ~~ => Pos: (79 to 80) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 11, col 0) to (line 11, col 1) +-------------------------------- +12 >enum e3 { + + ~~~~~~~~~~ => Pos: (81 to 90) SpanInfo: {"start":81,"length":11} + >enum e3 { + >} + >:=> (line 12, col 0) to (line 13, col 1) +-------------------------------- +13 >} + + ~~ => Pos: (91 to 92) SpanInfo: {"start":91,"length":1} + >} + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +14 >declare enum e4 { + + ~~~~~~~~~~~~~~~~~~ => Pos: (93 to 110) SpanInfo: undefined +-------------------------------- +15 > x, + + ~~~~~~~ => Pos: (111 to 117) SpanInfo: undefined +-------------------------------- +16 > y, + + ~~~~~~~ => Pos: (118 to 124) SpanInfo: undefined +-------------------------------- +17 > z, + + ~~~~~~~ => Pos: (125 to 131) SpanInfo: undefined +-------------------------------- +18 > x2 + + ~~~~~~~ => Pos: (132 to 138) SpanInfo: undefined +-------------------------------- +19 >} + + ~~ => Pos: (139 to 140) SpanInfo: undefined +-------------------------------- +20 >enum e11 + + ~~~~~~~~~~ => Pos: (141 to 150) SpanInfo: {"start":141,"length":33} + >enum e11 + >{ + > x, + > y, + > x + >} + >:=> (line 20, col 0) to (line 25, col 1) +-------------------------------- +21 >{ + + ~~ => Pos: (151 to 152) SpanInfo: {"start":157,"length":1} + >x + >:=> (line 22, col 4) to (line 22, col 5) +-------------------------------- +22 > x, + + ~~~~~~~ => Pos: (153 to 159) SpanInfo: {"start":157,"length":1} + >x + >:=> (line 22, col 4) to (line 22, col 5) +-------------------------------- +23 > y, + + ~~~~~~~ => Pos: (160 to 166) SpanInfo: {"start":164,"length":1} + >y + >:=> (line 23, col 4) to (line 23, col 5) +-------------------------------- +24 > x + + ~~~~~~ => Pos: (167 to 172) SpanInfo: {"start":171,"length":1} + >x + >:=> (line 24, col 4) to (line 24, col 5) +-------------------------------- +25 >} + + ~~ => Pos: (173 to 174) SpanInfo: {"start":173,"length":1} + >} + >:=> (line 25, col 0) to (line 25, col 1) +-------------------------------- +26 >enum e12 + + ~~~~~~~~~ => Pos: (175 to 183) SpanInfo: {"start":175,"length":50} + >enum e12 + >{ + > x = 10, + > y = 10, + > z, + > x2 + >} + >:=> (line 26, col 0) to (line 32, col 1) +-------------------------------- +27 >{ + + ~~ => Pos: (184 to 185) SpanInfo: {"start":190,"length":6} + >x = 10 + >:=> (line 28, col 4) to (line 28, col 10) +-------------------------------- +28 > x = 10, + + ~~~~~~~~~~~~ => Pos: (186 to 197) SpanInfo: {"start":190,"length":6} + >x = 10 + >:=> (line 28, col 4) to (line 28, col 10) +-------------------------------- +29 > y = 10, + + ~~~~~~~~~~~~ => Pos: (198 to 209) SpanInfo: {"start":202,"length":6} + >y = 10 + >:=> (line 29, col 4) to (line 29, col 10) +-------------------------------- +30 > z, + + ~~~~~~~ => Pos: (210 to 216) SpanInfo: {"start":214,"length":1} + >z + >:=> (line 30, col 4) to (line 30, col 5) +-------------------------------- +31 > x2 + + ~~~~~~~ => Pos: (217 to 223) SpanInfo: {"start":221,"length":2} + >x2 + >:=> (line 31, col 4) to (line 31, col 6) +-------------------------------- +32 >} + + ~~ => Pos: (224 to 225) SpanInfo: {"start":224,"length":1} + >} + >:=> (line 32, col 0) to (line 32, col 1) +-------------------------------- +33 >enum e13 + + ~~~~~~~~~ => Pos: (226 to 234) SpanInfo: {"start":226,"length":12} + >enum e13 + >{ + >} + >:=> (line 33, col 0) to (line 35, col 1) +-------------------------------- +34 >{ + + ~~ => Pos: (235 to 236) SpanInfo: {"start":237,"length":1} + >} + >:=> (line 35, col 0) to (line 35, col 1) +-------------------------------- +35 >} + + ~~ => Pos: (237 to 238) SpanInfo: {"start":237,"length":1} + >} + >:=> (line 35, col 0) to (line 35, col 1) +-------------------------------- +36 >declare enum e14 + + ~~~~~~~~~~~~~~~~~ => Pos: (239 to 255) SpanInfo: undefined +-------------------------------- +37 >{ + + ~~ => Pos: (256 to 257) SpanInfo: undefined +-------------------------------- +38 > x, + + ~~~~~~~ => Pos: (258 to 264) SpanInfo: undefined +-------------------------------- +39 > y, + + ~~~~~~~ => Pos: (265 to 271) SpanInfo: undefined +-------------------------------- +40 > z, + + ~~~~~~~ => Pos: (272 to 278) SpanInfo: undefined +-------------------------------- +41 > x2 + + ~~~~~~~ => Pos: (279 to 285) SpanInfo: undefined +-------------------------------- +42 >} + ~ => Pos: (286 to 286) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_exportAssignment.baseline b/tests/baselines/reference/bpSpan_exportAssignment.baseline new file mode 100644 index 00000000000..a9d635a929c --- /dev/null +++ b/tests/baselines/reference/bpSpan_exportAssignment.baseline @@ -0,0 +1,23 @@ + +1 >class a { + + ~~~~~~~~~~ => Pos: (0 to 9) SpanInfo: {"start":0,"length":25} + >class a { + > public c; + >} + >:=> (line 1, col 0) to (line 3, col 1) +-------------------------------- +2 > public c; + + ~~~~~~~~~~~~~~ => Pos: (10 to 23) SpanInfo: undefined +-------------------------------- +3 >} + + ~~ => Pos: (24 to 25) SpanInfo: {"start":24,"length":1} + >} + >:=> (line 3, col 0) to (line 3, col 1) +-------------------------------- +4 >export = a; + ~~~~~~~~~~~ => Pos: (26 to 36) SpanInfo: {"start":26,"length":10} + >export = a + >:=> (line 4, col 0) to (line 4, col 10) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_for.baseline b/tests/baselines/reference/bpSpan_for.baseline new file mode 100644 index 00000000000..7fd6ba4c858 --- /dev/null +++ b/tests/baselines/reference/bpSpan_for.baseline @@ -0,0 +1,253 @@ + +1 >for (var i = 0; i < 10; i++) { + + ~~~~~~~~~~~~~~~ => Pos: (0 to 14) SpanInfo: {"start":5,"length":9} + >var i = 0 + >:=> (line 1, col 5) to (line 1, col 14) +1 >for (var i = 0; i < 10; i++) { + + ~~~~~~~~ => Pos: (15 to 22) SpanInfo: {"start":16,"length":6} + >i < 10 + >:=> (line 1, col 16) to (line 1, col 22) +1 >for (var i = 0; i < 10; i++) { + + ~~~~~~~~ => Pos: (23 to 30) SpanInfo: {"start":24,"length":3} + >i++ + >:=> (line 1, col 24) to (line 1, col 27) +-------------------------------- +2 > WScript.Echo("i: " + i); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (31 to 59) SpanInfo: {"start":35,"length":23} + >WScript.Echo("i: " + i) + >:=> (line 2, col 4) to (line 2, col 27) +-------------------------------- +3 >} + + ~~ => Pos: (60 to 61) SpanInfo: {"start":35,"length":23} + >WScript.Echo("i: " + i) + >:=> (line 2, col 4) to (line 2, col 27) +-------------------------------- +4 >for (i = 0; i < 10; i++) + + ~~~~~~~~~~~ => Pos: (62 to 72) SpanInfo: {"start":67,"length":5} + >i = 0 + >:=> (line 4, col 5) to (line 4, col 10) +4 >for (i = 0; i < 10; i++) + + ~~~~~~~~ => Pos: (73 to 80) SpanInfo: {"start":74,"length":6} + >i < 10 + >:=> (line 4, col 12) to (line 4, col 18) +4 >for (i = 0; i < 10; i++) + + ~~~~~~ => Pos: (81 to 86) SpanInfo: {"start":82,"length":3} + >i++ + >:=> (line 4, col 20) to (line 4, col 23) +-------------------------------- +5 >{ + + ~~ => Pos: (87 to 88) SpanInfo: {"start":93,"length":23} + >WScript.Echo("i: " + i) + >:=> (line 6, col 4) to (line 6, col 27) +-------------------------------- +6 > WScript.Echo("i: " + i); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (89 to 117) SpanInfo: {"start":93,"length":23} + >WScript.Echo("i: " + i) + >:=> (line 6, col 4) to (line 6, col 27) +-------------------------------- +7 >} + + ~~ => Pos: (118 to 119) SpanInfo: {"start":93,"length":23} + >WScript.Echo("i: " + i) + >:=> (line 6, col 4) to (line 6, col 27) +-------------------------------- +8 >for (var j = 0; j < 10; ) { + + ~~~~~~~~~~~~~~~ => Pos: (120 to 134) SpanInfo: {"start":125,"length":9} + >var j = 0 + >:=> (line 8, col 5) to (line 8, col 14) +8 >for (var j = 0; j < 10; ) { + + ~~~~~~~~~~~~~ => Pos: (135 to 147) SpanInfo: {"start":136,"length":6} + >j < 10 + >:=> (line 8, col 16) to (line 8, col 22) +-------------------------------- +9 > j++; + + ~~~~~~~~~ => Pos: (148 to 156) SpanInfo: {"start":152,"length":3} + >j++ + >:=> (line 9, col 4) to (line 9, col 7) +-------------------------------- +10 > if (j == 1) { + + ~~~~~~~~~~~~~~~~~~ => Pos: (157 to 174) SpanInfo: {"start":161,"length":11} + >if (j == 1) + >:=> (line 10, col 4) to (line 10, col 15) +-------------------------------- +11 > continue; + + ~~~~~~~~~~~~~~~~~~ => Pos: (175 to 192) SpanInfo: {"start":183,"length":8} + >continue + >:=> (line 11, col 8) to (line 11, col 16) +-------------------------------- +12 > } + + ~~~~~~ => Pos: (193 to 198) SpanInfo: {"start":183,"length":8} + >continue + >:=> (line 11, col 8) to (line 11, col 16) +-------------------------------- +13 >} + + ~~ => Pos: (199 to 200) SpanInfo: {"start":161,"length":11} + >if (j == 1) + >:=> (line 10, col 4) to (line 10, col 15) +-------------------------------- +14 >for (j = 0; j < 10;) + + ~~~~~~~~~~~ => Pos: (201 to 211) SpanInfo: {"start":206,"length":5} + >j = 0 + >:=> (line 14, col 5) to (line 14, col 10) +14 >for (j = 0; j < 10;) + + ~~~~~~~~~~ => Pos: (212 to 221) SpanInfo: {"start":213,"length":6} + >j < 10 + >:=> (line 14, col 12) to (line 14, col 18) +-------------------------------- +15 >{ + + ~~ => Pos: (222 to 223) SpanInfo: {"start":228,"length":3} + >j++ + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +16 > j++; + + ~~~~~~~~~ => Pos: (224 to 232) SpanInfo: {"start":228,"length":3} + >j++ + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +17 >} + + ~~ => Pos: (233 to 234) SpanInfo: {"start":228,"length":3} + >j++ + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +18 >for (var k = 0;; k++) { + + ~~~~~~~~~~~~~~~~ => Pos: (235 to 250) SpanInfo: {"start":240,"length":9} + >var k = 0 + >:=> (line 18, col 5) to (line 18, col 14) +18 >for (var k = 0;; k++) { + + ~~~~~~~~ => Pos: (251 to 258) SpanInfo: {"start":252,"length":3} + >k++ + >:=> (line 18, col 17) to (line 18, col 20) +-------------------------------- +19 >} + + ~~ => Pos: (259 to 260) SpanInfo: undefined +-------------------------------- +20 >for (k = 0;; k++) + + ~~~~~~~~~~~~ => Pos: (261 to 272) SpanInfo: {"start":266,"length":5} + >k = 0 + >:=> (line 20, col 5) to (line 20, col 10) +20 >for (k = 0;; k++) + + ~~~~~~ => Pos: (273 to 278) SpanInfo: {"start":274,"length":3} + >k++ + >:=> (line 20, col 13) to (line 20, col 16) +-------------------------------- +21 >{ + + ~~ => Pos: (279 to 280) SpanInfo: undefined +-------------------------------- +22 >} + + ~~ => Pos: (281 to 282) SpanInfo: undefined +-------------------------------- +23 >for (; k < 10; k++) { + + ~~~~~~~~~~~~~~ => Pos: (283 to 296) SpanInfo: {"start":290,"length":6} + >k < 10 + >:=> (line 23, col 7) to (line 23, col 13) +23 >for (; k < 10; k++) { + + ~~~~~~~~ => Pos: (297 to 304) SpanInfo: {"start":298,"length":3} + >k++ + >:=> (line 23, col 15) to (line 23, col 18) +-------------------------------- +24 >} + + ~~ => Pos: (305 to 306) SpanInfo: undefined +-------------------------------- +25 >for (;;) { + + ~~~~~~~~~~~ => Pos: (307 to 317) SpanInfo: undefined +-------------------------------- +26 > i++; + + ~~~~~~~~~ => Pos: (318 to 326) SpanInfo: {"start":322,"length":3} + >i++ + >:=> (line 26, col 4) to (line 26, col 7) +-------------------------------- +27 >} + + ~~ => Pos: (327 to 328) SpanInfo: {"start":322,"length":3} + >i++ + >:=> (line 26, col 4) to (line 26, col 7) +-------------------------------- +28 >for (;;) + + ~~~~~~~~~ => Pos: (329 to 337) SpanInfo: undefined +-------------------------------- +29 >{ + + ~~ => Pos: (338 to 339) SpanInfo: {"start":344,"length":3} + >i++ + >:=> (line 30, col 4) to (line 30, col 7) +-------------------------------- +30 > i++; + + ~~~~~~~~~ => Pos: (340 to 348) SpanInfo: {"start":344,"length":3} + >i++ + >:=> (line 30, col 4) to (line 30, col 7) +-------------------------------- +31 >} + + ~~ => Pos: (349 to 350) SpanInfo: {"start":344,"length":3} + >i++ + >:=> (line 30, col 4) to (line 30, col 7) +-------------------------------- +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~ => Pos: (351 to 355) SpanInfo: {"start":356,"length":13} + >i = 0, j = 20 + >:=> (line 32, col 5) to (line 32, col 18) +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~~ => Pos: (356 to 361) SpanInfo: {"start":356,"length":5} + >i = 0 + >:=> (line 32, col 5) to (line 32, col 10) +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~~~~ => Pos: (362 to 369) SpanInfo: {"start":363,"length":6} + >j = 20 + >:=> (line 32, col 12) to (line 32, col 18) +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~~~~ => Pos: (370 to 377) SpanInfo: {"start":371,"length":6} + >j < 20 + >:=> (line 32, col 20) to (line 32, col 26) +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~~~~ => Pos: (378 to 385) SpanInfo: {"start":379,"length":6} + >i < 20 + >:=> (line 32, col 28) to (line 32, col 34) +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~~~~ => Pos: (386 to 393) SpanInfo: {"start":387,"length":3} + >j++ + >:=> (line 32, col 36) to (line 32, col 39) +-------------------------------- +33 >} + ~ => Pos: (394 to 394) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_forIn.baseline b/tests/baselines/reference/bpSpan_forIn.baseline new file mode 100644 index 00000000000..c2b72df5b12 --- /dev/null +++ b/tests/baselines/reference/bpSpan_forIn.baseline @@ -0,0 +1,143 @@ + +1 >for (var x in String) { + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 23) SpanInfo: {"start":0,"length":21} + >for (var x in String) + >:=> (line 1, col 0) to (line 1, col 21) +-------------------------------- +2 > WScript.Echo(x); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (24 to 44) SpanInfo: {"start":28,"length":15} + >WScript.Echo(x) + >:=> (line 2, col 4) to (line 2, col 19) +-------------------------------- +3 >} + + ~~ => Pos: (45 to 46) SpanInfo: {"start":28,"length":15} + >WScript.Echo(x) + >:=> (line 2, col 4) to (line 2, col 19) +-------------------------------- +4 >for (x in String) { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (47 to 66) SpanInfo: {"start":47,"length":17} + >for (x in String) + >:=> (line 4, col 0) to (line 4, col 17) +-------------------------------- +5 > WScript.Echo(x); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (67 to 87) SpanInfo: {"start":71,"length":15} + >WScript.Echo(x) + >:=> (line 5, col 4) to (line 5, col 19) +-------------------------------- +6 >} + + ~~ => Pos: (88 to 89) SpanInfo: {"start":71,"length":15} + >WScript.Echo(x) + >:=> (line 5, col 4) to (line 5, col 19) +-------------------------------- +7 >for (var x2 in String) + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (90 to 112) SpanInfo: {"start":90,"length":22} + >for (var x2 in String) + >:=> (line 7, col 0) to (line 7, col 22) +-------------------------------- +8 >{ + + ~~ => Pos: (113 to 114) SpanInfo: {"start":119,"length":16} + >WScript.Echo(x2) + >:=> (line 9, col 4) to (line 9, col 20) +-------------------------------- +9 > WScript.Echo(x2); + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (115 to 136) SpanInfo: {"start":119,"length":16} + >WScript.Echo(x2) + >:=> (line 9, col 4) to (line 9, col 20) +-------------------------------- +10 >} + + ~~ => Pos: (137 to 138) SpanInfo: {"start":119,"length":16} + >WScript.Echo(x2) + >:=> (line 9, col 4) to (line 9, col 20) +-------------------------------- +11 >for (x in String) + + ~~~~~~~~~~~~~~~~~~ => Pos: (139 to 156) SpanInfo: {"start":139,"length":17} + >for (x in String) + >:=> (line 11, col 0) to (line 11, col 17) +-------------------------------- +12 >{ + + ~~ => Pos: (157 to 158) SpanInfo: {"start":163,"length":15} + >WScript.Echo(x) + >:=> (line 13, col 4) to (line 13, col 19) +-------------------------------- +13 > WScript.Echo(x); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (159 to 179) SpanInfo: {"start":163,"length":15} + >WScript.Echo(x) + >:=> (line 13, col 4) to (line 13, col 19) +-------------------------------- +14 >} + + ~~ => Pos: (180 to 181) SpanInfo: {"start":163,"length":15} + >WScript.Echo(x) + >:=> (line 13, col 4) to (line 13, col 19) +-------------------------------- +15 >var z = 10; + + ~~~~~~~~~~~~ => Pos: (182 to 193) SpanInfo: {"start":182,"length":10} + >var z = 10 + >:=> (line 15, col 0) to (line 15, col 10) +-------------------------------- +16 >for (x in function foo() { + + ~~~~~~~~~ => Pos: (194 to 202) SpanInfo: {"start":194,"length":54} + >for (x in function foo() { + > return new String(); + >}) + >:=> (line 16, col 0) to (line 18, col 2) +16 >for (x in function foo() { + + ~~~~~~~~~~~~~~~~~~ => Pos: (203 to 220) SpanInfo: {"start":225,"length":19} + >return new String() + >:=> (line 17, col 4) to (line 17, col 23) +-------------------------------- +17 > return new String(); + + ~~~~~~~~~~ => Pos: (221 to 230) SpanInfo: {"start":225,"length":19} + >return new String() + >:=> (line 17, col 4) to (line 17, col 23) +17 > return new String(); + + ~~~~~~~~~~~~~~~ => Pos: (231 to 245) SpanInfo: {"start":232,"length":12} + >new String() + >:=> (line 17, col 11) to (line 17, col 23) +-------------------------------- +18 >}) { + + ~ => Pos: (246 to 246) SpanInfo: {"start":246,"length":1} + >} + >:=> (line 18, col 0) to (line 18, col 1) +18 >}) { + + ~ => Pos: (247 to 247) SpanInfo: {"start":194,"length":54} + >for (x in function foo() { + > return new String(); + >}) + >:=> (line 16, col 0) to (line 18, col 2) +18 >}) { + + ~~~ => Pos: (248 to 250) SpanInfo: {"start":255,"length":3} + >z++ + >:=> (line 19, col 4) to (line 19, col 7) +-------------------------------- +19 > z++; + + ~~~~~~~~~ => Pos: (251 to 259) SpanInfo: {"start":255,"length":3} + >z++ + >:=> (line 19, col 4) to (line 19, col 7) +-------------------------------- +20 >} + ~ => Pos: (260 to 260) SpanInfo: {"start":255,"length":3} + >z++ + >:=> (line 19, col 4) to (line 19, col 7) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_functionExpressions.baseline b/tests/baselines/reference/bpSpan_functionExpressions.baseline new file mode 100644 index 00000000000..135edff9418 --- /dev/null +++ b/tests/baselines/reference/bpSpan_functionExpressions.baseline @@ -0,0 +1,189 @@ + +1 >var greetings = 0; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 18) SpanInfo: {"start":0,"length":17} + >var greetings = 0 + >:=> (line 1, col 0) to (line 1, col 17) +-------------------------------- +2 >var greet = (greeting: string): number => { + + ~~~~~~~~~~~ => Pos: (19 to 29) SpanInfo: {"start":19,"length":84} + >var greet = (greeting: string): number => { + > greetings++; + > return greetings; + >} + >:=> (line 2, col 0) to (line 5, col 1) +2 >var greet = (greeting: string): number => { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (30 to 62) SpanInfo: {"start":67,"length":11} + >greetings++ + >:=> (line 3, col 4) to (line 3, col 15) +-------------------------------- +3 > greetings++; + + ~~~~~~~~~~~~~~~~~ => Pos: (63 to 79) SpanInfo: {"start":67,"length":11} + >greetings++ + >:=> (line 3, col 4) to (line 3, col 15) +-------------------------------- +4 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (80 to 101) SpanInfo: {"start":84,"length":16} + >return greetings + >:=> (line 4, col 4) to (line 4, col 20) +-------------------------------- +5 >} + + ~~ => Pos: (102 to 103) SpanInfo: {"start":102,"length":1} + >} + >:=> (line 5, col 0) to (line 5, col 1) +-------------------------------- +6 >greet("Hello"); + + ~~~~~~~~~~~~~~~~ => Pos: (104 to 119) SpanInfo: {"start":104,"length":14} + >greet("Hello") + >:=> (line 6, col 0) to (line 6, col 14) +-------------------------------- +7 >var incrGreetings = () => greetings++; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (120 to 138) SpanInfo: {"start":120,"length":37} + >var incrGreetings = () => greetings++ + >:=> (line 7, col 0) to (line 7, col 37) +7 >var incrGreetings = () => greetings++; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (139 to 158) SpanInfo: {"start":146,"length":11} + >greetings++ + >:=> (line 7, col 26) to (line 7, col 37) +-------------------------------- +8 >var greetNewMsg = msg => greet(msg); + + ~~~~~~~~~~~~~~~~~ => Pos: (159 to 175) SpanInfo: {"start":159,"length":35} + >var greetNewMsg = msg => greet(msg) + >:=> (line 8, col 0) to (line 8, col 35) +8 >var greetNewMsg = msg => greet(msg); + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (176 to 195) SpanInfo: {"start":184,"length":10} + >greet(msg) + >:=> (line 8, col 25) to (line 8, col 35) +-------------------------------- +9 >greetNewMsg = function (msg: string) { + + ~~~~~~~~~~~~~ => Pos: (196 to 208) SpanInfo: {"start":196,"length":63} + >greetNewMsg = function (msg: string) { + > return greet(msg); + >} + >:=> (line 9, col 0) to (line 11, col 1) +9 >greetNewMsg = function (msg: string) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (209 to 234) SpanInfo: {"start":239,"length":17} + >return greet(msg) + >:=> (line 10, col 4) to (line 10, col 21) +-------------------------------- +10 > return greet(msg); + + ~~~~~~~~~~ => Pos: (235 to 244) SpanInfo: {"start":239,"length":17} + >return greet(msg) + >:=> (line 10, col 4) to (line 10, col 21) +10 > return greet(msg); + + ~~~~~~~~~~~~~ => Pos: (245 to 257) SpanInfo: {"start":246,"length":10} + >greet(msg) + >:=> (line 10, col 11) to (line 10, col 21) +-------------------------------- +11 >}; + + ~~~ => Pos: (258 to 260) SpanInfo: {"start":258,"length":1} + >} + >:=> (line 11, col 0) to (line 11, col 1) +-------------------------------- +12 >function bar(a = function foo() { + + ~~~~~~~~~~~~~ => Pos: (261 to 273) SpanInfo: {"start":326,"length":9} + >if (!a()) + >:=> (line 15, col 4) to (line 15, col 13) +12 >function bar(a = function foo() { + + ~~~ => Pos: (274 to 276) SpanInfo: {"start":274,"length":44} + >a = function foo() { + > return greetings; + >} + >:=> (line 12, col 13) to (line 14, col 1) +12 >function bar(a = function foo() { + + ~~~~~~~~~~~~~~~~~~ => Pos: (277 to 294) SpanInfo: {"start":299,"length":16} + >return greetings + >:=> (line 13, col 4) to (line 13, col 20) +-------------------------------- +13 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (295 to 316) SpanInfo: {"start":299,"length":16} + >return greetings + >:=> (line 13, col 4) to (line 13, col 20) +-------------------------------- +14 >}) { + + ~~ => Pos: (317 to 318) SpanInfo: {"start":317,"length":1} + >} + >:=> (line 14, col 0) to (line 14, col 1) +14 >}) { + + ~~~ => Pos: (319 to 321) SpanInfo: {"start":326,"length":9} + >if (!a()) + >:=> (line 15, col 4) to (line 15, col 13) +-------------------------------- +15 > if (!a()) { + + ~~~~~~~~~ => Pos: (322 to 330) SpanInfo: {"start":326,"length":9} + >if (!a()) + >:=> (line 15, col 4) to (line 15, col 13) +15 > if (!a()) { + + ~~~ => Pos: (331 to 333) SpanInfo: {"start":331,"length":3} + >a() + >:=> (line 15, col 9) to (line 15, col 12) +15 > if (!a()) { + + ~~~~ => Pos: (334 to 337) SpanInfo: {"start":326,"length":9} + >if (!a()) + >:=> (line 15, col 4) to (line 15, col 13) +-------------------------------- +16 > return a; + + ~~~~~~~~~~~~~~~~~~ => Pos: (338 to 355) SpanInfo: {"start":346,"length":8} + >return a + >:=> (line 16, col 8) to (line 16, col 16) +-------------------------------- +17 > } + + ~~~~~~ => Pos: (356 to 361) SpanInfo: {"start":346,"length":8} + >return a + >:=> (line 16, col 8) to (line 16, col 16) +-------------------------------- +18 > return function bar() { + + ~~~~~~~~~~ => Pos: (362 to 371) SpanInfo: {"start":366,"length":56} + >return function bar() { + > return -greetings; + > } + >:=> (line 18, col 4) to (line 20, col 5) +18 > return function bar() { + + ~~~~~~~~~~~~~~~~~~ => Pos: (372 to 389) SpanInfo: {"start":398,"length":17} + >return -greetings + >:=> (line 19, col 8) to (line 19, col 25) +-------------------------------- +19 > return -greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (390 to 416) SpanInfo: {"start":398,"length":17} + >return -greetings + >:=> (line 19, col 8) to (line 19, col 25) +-------------------------------- +20 > }; + + ~~~~~~~ => Pos: (417 to 423) SpanInfo: {"start":421,"length":1} + >} + >:=> (line 20, col 4) to (line 20, col 5) +-------------------------------- +21 >} + ~ => Pos: (424 to 424) SpanInfo: {"start":424,"length":1} + >} + >:=> (line 21, col 0) to (line 21, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_functions.baseline b/tests/baselines/reference/bpSpan_functions.baseline new file mode 100644 index 00000000000..535f177c0f6 --- /dev/null +++ b/tests/baselines/reference/bpSpan_functions.baseline @@ -0,0 +1,372 @@ + +1 >var greetings = 0; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 18) SpanInfo: {"start":0,"length":17} + >var greetings = 0 + >:=> (line 1, col 0) to (line 1, col 17) +-------------------------------- +2 >function greet(greeting: string): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (19 to 61) SpanInfo: {"start":66,"length":11} + >greetings++ + >:=> (line 3, col 4) to (line 3, col 15) +-------------------------------- +3 > greetings++; + + ~~~~~~~~~~~~~~~~~ => Pos: (62 to 78) SpanInfo: {"start":66,"length":11} + >greetings++ + >:=> (line 3, col 4) to (line 3, col 15) +-------------------------------- +4 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (79 to 100) SpanInfo: {"start":83,"length":16} + >return greetings + >:=> (line 4, col 4) to (line 4, col 20) +-------------------------------- +5 >} + + ~~ => Pos: (101 to 102) SpanInfo: {"start":101,"length":1} + >} + >:=> (line 5, col 0) to (line 5, col 1) +-------------------------------- +6 >function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (103 to 135) SpanInfo: {"start":196,"length":11} + >greetings++ + >:=> (line 7, col 4) to (line 7, col 15) +6 >function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (136 to 155) SpanInfo: {"start":137,"length":6} + >n = 10 + >:=> (line 6, col 34) to (line 6, col 40) +6 >function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (156 to 188) SpanInfo: {"start":157,"length":23} + >...restParams: string[] + >:=> (line 6, col 54) to (line 6, col 77) +6 >function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~=> Pos: (189 to 191) SpanInfo: {"start":196,"length":11} + >greetings++ + >:=> (line 7, col 4) to (line 7, col 15) +-------------------------------- +7 > greetings++; + + ~~~~~~~~~~~~~~~~~ => Pos: (192 to 208) SpanInfo: {"start":196,"length":11} + >greetings++ + >:=> (line 7, col 4) to (line 7, col 15) +-------------------------------- +8 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (209 to 230) SpanInfo: {"start":213,"length":16} + >return greetings + >:=> (line 8, col 4) to (line 8, col 20) +-------------------------------- +9 >} + + ~~ => Pos: (231 to 232) SpanInfo: {"start":231,"length":1} + >} + >:=> (line 9, col 0) to (line 9, col 1) +-------------------------------- +10 >function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (233 to 262) SpanInfo: {"start":315,"length":6} + >return + >:=> (line 12, col 4) to (line 12, col 10) +10 >function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (263 to 282) SpanInfo: {"start":264,"length":6} + >n = 10 + >:=> (line 10, col 31) to (line 10, col 37) +10 >function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (283 to 308) SpanInfo: {"start":284,"length":23} + >...restParams: string[] + >:=> (line 10, col 51) to (line 10, col 74) +-------------------------------- +11 >{ + + ~~ => Pos: (309 to 310) SpanInfo: {"start":315,"length":6} + >return + >:=> (line 12, col 4) to (line 12, col 10) +-------------------------------- +12 > return; + + ~~~~~~~~~~~~ => Pos: (311 to 322) SpanInfo: {"start":315,"length":6} + >return + >:=> (line 12, col 4) to (line 12, col 10) +-------------------------------- +13 >} + + ~~ => Pos: (323 to 324) SpanInfo: {"start":323,"length":1} + >} + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +14 >module m { + + ~~~~~~~~~~~ => Pos: (325 to 335) SpanInfo: {"start":325,"length":389} + >module m { + > var greetings = 0; + > function greet(greeting: string): number { + > greetings++; + > return greetings; + > } + > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + > { + > return; + > } + >} + >:=> (line 14, col 0) to (line 28, col 1) +-------------------------------- +15 > var greetings = 0; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (336 to 358) SpanInfo: {"start":340,"length":17} + >var greetings = 0 + >:=> (line 15, col 4) to (line 15, col 21) +-------------------------------- +16 > function greet(greeting: string): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (359 to 405) SpanInfo: {"start":414,"length":11} + >greetings++ + >:=> (line 17, col 8) to (line 17, col 19) +-------------------------------- +17 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (406 to 426) SpanInfo: {"start":414,"length":11} + >greetings++ + >:=> (line 17, col 8) to (line 17, col 19) +-------------------------------- +18 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (427 to 452) SpanInfo: {"start":435,"length":16} + >return greetings + >:=> (line 18, col 8) to (line 18, col 24) +-------------------------------- +19 > } + + ~~~~~~ => Pos: (453 to 458) SpanInfo: {"start":457,"length":1} + >} + >:=> (line 19, col 4) to (line 19, col 5) +-------------------------------- +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (459 to 495) SpanInfo: {"start":560,"length":11} + >greetings++ + >:=> (line 21, col 8) to (line 21, col 19) +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (496 to 515) SpanInfo: {"start":497,"length":6} + >n = 10 + >:=> (line 20, col 38) to (line 20, col 44) +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (516 to 548) SpanInfo: {"start":517,"length":23} + >...restParams: string[] + >:=> (line 20, col 58) to (line 20, col 81) +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~=> Pos: (549 to 551) SpanInfo: {"start":560,"length":11} + >greetings++ + >:=> (line 21, col 8) to (line 21, col 19) +-------------------------------- +21 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (552 to 572) SpanInfo: {"start":560,"length":11} + >greetings++ + >:=> (line 21, col 8) to (line 21, col 19) +-------------------------------- +22 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (573 to 598) SpanInfo: {"start":581,"length":16} + >return greetings + >:=> (line 22, col 8) to (line 22, col 24) +-------------------------------- +23 > } + + ~~~~~~ => Pos: (599 to 604) SpanInfo: {"start":603,"length":1} + >} + >:=> (line 23, col 4) to (line 23, col 5) +-------------------------------- +24 > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (605 to 638) SpanInfo: {"start":699,"length":6} + >return + >:=> (line 26, col 8) to (line 26, col 14) +24 > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (639 to 658) SpanInfo: {"start":640,"length":6} + >n = 10 + >:=> (line 24, col 35) to (line 24, col 41) +24 > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (659 to 684) SpanInfo: {"start":660,"length":23} + >...restParams: string[] + >:=> (line 24, col 55) to (line 24, col 78) +-------------------------------- +25 > { + + ~~~~~~ => Pos: (685 to 690) SpanInfo: {"start":699,"length":6} + >return + >:=> (line 26, col 8) to (line 26, col 14) +-------------------------------- +26 > return; + + ~~~~~~~~~~~~~~~~ => Pos: (691 to 706) SpanInfo: {"start":699,"length":6} + >return + >:=> (line 26, col 8) to (line 26, col 14) +-------------------------------- +27 > } + + ~~~~~~ => Pos: (707 to 712) SpanInfo: {"start":711,"length":1} + >} + >:=> (line 27, col 4) to (line 27, col 5) +-------------------------------- +28 >} + + ~~ => Pos: (713 to 714) SpanInfo: {"start":713,"length":1} + >} + >:=> (line 28, col 0) to (line 28, col 1) +-------------------------------- +29 >module m1 { + + ~~~~~~~~~~~~ => Pos: (715 to 726) SpanInfo: {"start":715,"length":411} + >module m1 { + > var greetings = 0; + > export function greet(greeting: string): number { + > greetings++; + > return greetings; + > } + > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + > { + > return; + > } + >} + >:=> (line 29, col 0) to (line 43, col 1) +-------------------------------- +30 > var greetings = 0; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (727 to 749) SpanInfo: {"start":731,"length":17} + >var greetings = 0 + >:=> (line 30, col 4) to (line 30, col 21) +-------------------------------- +31 > export function greet(greeting: string): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (750 to 803) SpanInfo: {"start":754,"length":102} + >export function greet(greeting: string): number { + > greetings++; + > return greetings; + > } + >:=> (line 31, col 4) to (line 34, col 5) +-------------------------------- +32 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (804 to 824) SpanInfo: {"start":812,"length":11} + >greetings++ + >:=> (line 32, col 8) to (line 32, col 19) +-------------------------------- +33 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (825 to 850) SpanInfo: {"start":833,"length":16} + >return greetings + >:=> (line 33, col 8) to (line 33, col 24) +-------------------------------- +34 > } + + ~~~~~~ => Pos: (851 to 856) SpanInfo: {"start":855,"length":1} + >} + >:=> (line 34, col 4) to (line 34, col 5) +-------------------------------- +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (857 to 900) SpanInfo: {"start":861,"length":148} + >export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + >:=> (line 35, col 4) to (line 38, col 5) +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (901 to 920) SpanInfo: {"start":902,"length":6} + >n = 10 + >:=> (line 35, col 45) to (line 35, col 51) +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (921 to 953) SpanInfo: {"start":922,"length":23} + >...restParams: string[] + >:=> (line 35, col 65) to (line 35, col 88) +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~=> Pos: (954 to 956) SpanInfo: {"start":861,"length":148} + >export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + >:=> (line 35, col 4) to (line 38, col 5) +-------------------------------- +36 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (957 to 977) SpanInfo: {"start":965,"length":11} + >greetings++ + >:=> (line 36, col 8) to (line 36, col 19) +-------------------------------- +37 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (978 to 1003) SpanInfo: {"start":986,"length":16} + >return greetings + >:=> (line 37, col 8) to (line 37, col 24) +-------------------------------- +38 > } + + ~~~~~~ => Pos: (1004 to 1009) SpanInfo: {"start":1008,"length":1} + >} + >:=> (line 38, col 4) to (line 38, col 5) +-------------------------------- +39 > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (1010 to 1050) SpanInfo: {"start":1014,"length":110} + >export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + > { + > return; + > } + >:=> (line 39, col 4) to (line 42, col 5) +39 > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (1051 to 1070) SpanInfo: {"start":1052,"length":6} + >n = 10 + >:=> (line 39, col 42) to (line 39, col 48) +39 > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (1071 to 1096) SpanInfo: {"start":1072,"length":23} + >...restParams: string[] + >:=> (line 39, col 62) to (line 39, col 85) +-------------------------------- +40 > { + + ~~~~~~ => Pos: (1097 to 1102) SpanInfo: {"start":1111,"length":6} + >return + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +41 > return; + + ~~~~~~~~~~~~~~~~ => Pos: (1103 to 1118) SpanInfo: {"start":1111,"length":6} + >return + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +42 > } + + ~~~~~~ => Pos: (1119 to 1124) SpanInfo: {"start":1123,"length":1} + >} + >:=> (line 42, col 4) to (line 42, col 5) +-------------------------------- +43 >} + ~ => Pos: (1125 to 1125) SpanInfo: {"start":1125,"length":1} + >} + >:=> (line 43, col 0) to (line 43, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_ifElse.baseline b/tests/baselines/reference/bpSpan_ifElse.baseline new file mode 100644 index 00000000000..b66316d3392 --- /dev/null +++ b/tests/baselines/reference/bpSpan_ifElse.baseline @@ -0,0 +1,166 @@ + +1 >var i = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var i = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >if (i == 10) { + + ~~~~~~~~~~~~~~~ => Pos: (12 to 26) SpanInfo: {"start":12,"length":12} + >if (i == 10) + >:=> (line 2, col 0) to (line 2, col 12) +-------------------------------- +3 > i++; + + ~~~~~~~~~ => Pos: (27 to 35) SpanInfo: {"start":31,"length":3} + >i++ + >:=> (line 3, col 4) to (line 3, col 7) +-------------------------------- +4 >} else + + ~ => Pos: (36 to 36) SpanInfo: {"start":31,"length":3} + >i++ + >:=> (line 3, col 4) to (line 3, col 7) +4 >} else + + ~~~~~~ => Pos: (37 to 42) SpanInfo: undefined +-------------------------------- +5 >{ + + ~~ => Pos: (43 to 44) SpanInfo: undefined +-------------------------------- +6 >} + + ~~ => Pos: (45 to 46) SpanInfo: undefined +-------------------------------- +7 >if (i == 10) + + ~~~~~~~~~~~~~ => Pos: (47 to 59) SpanInfo: {"start":47,"length":12} + >if (i == 10) + >:=> (line 7, col 0) to (line 7, col 12) +-------------------------------- +8 >{ + + ~~ => Pos: (60 to 61) SpanInfo: {"start":66,"length":3} + >i++ + >:=> (line 9, col 4) to (line 9, col 7) +-------------------------------- +9 > i++; + + ~~~~~~~~~ => Pos: (62 to 70) SpanInfo: {"start":66,"length":3} + >i++ + >:=> (line 9, col 4) to (line 9, col 7) +-------------------------------- +10 >} + + ~~ => Pos: (71 to 72) SpanInfo: {"start":66,"length":3} + >i++ + >:=> (line 9, col 4) to (line 9, col 7) +-------------------------------- +11 >else if (i == 20) { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (73 to 92) SpanInfo: {"start":78,"length":12} + >if (i == 20) + >:=> (line 11, col 5) to (line 11, col 17) +-------------------------------- +12 > i--; + + ~~~~~~~~~ => Pos: (93 to 101) SpanInfo: {"start":97,"length":3} + >i-- + >:=> (line 12, col 4) to (line 12, col 7) +-------------------------------- +13 >} else if (i == 30) { + + ~ => Pos: (102 to 102) SpanInfo: {"start":97,"length":3} + >i-- + >:=> (line 12, col 4) to (line 12, col 7) +13 >} else if (i == 30) { + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (103 to 123) SpanInfo: {"start":109,"length":12} + >if (i == 30) + >:=> (line 13, col 7) to (line 13, col 19) +-------------------------------- +14 > i += 70; + + ~~~~~~~~~~~~~ => Pos: (124 to 136) SpanInfo: {"start":128,"length":7} + >i += 70 + >:=> (line 14, col 4) to (line 14, col 11) +-------------------------------- +15 >} else { + + ~ => Pos: (137 to 137) SpanInfo: {"start":128,"length":7} + >i += 70 + >:=> (line 14, col 4) to (line 14, col 11) +15 >} else { + + ~~~~~~~~ => Pos: (138 to 145) SpanInfo: {"start":150,"length":3} + >i-- + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +16 > i--; + + ~~~~~~~~~ => Pos: (146 to 154) SpanInfo: {"start":150,"length":3} + >i-- + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +17 >} + + ~~ => Pos: (155 to 156) SpanInfo: {"start":150,"length":3} + >i-- + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +18 >if (function foo() { + + ~~~~ => Pos: (157 to 160) SpanInfo: {"start":157,"length":41} + >if (function foo() { + > return 30; + >} ()) + >:=> (line 18, col 0) to (line 20, col 5) +18 >if (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (161 to 177) SpanInfo: {"start":182,"length":9} + >return 30 + >:=> (line 19, col 4) to (line 19, col 13) +-------------------------------- +19 > return 30; + + ~~~~~~~~~~~~~~~ => Pos: (178 to 192) SpanInfo: {"start":182,"length":9} + >return 30 + >:=> (line 19, col 4) to (line 19, col 13) +-------------------------------- +20 >} ()) { + + ~ => Pos: (193 to 193) SpanInfo: {"start":193,"length":1} + >} + >:=> (line 20, col 0) to (line 20, col 1) +20 >} ()) { + + ~~~ => Pos: (194 to 196) SpanInfo: {"start":161,"length":36} + >function foo() { + > return 30; + >} () + >:=> (line 18, col 4) to (line 20, col 4) +20 >} ()) { + + ~ => Pos: (197 to 197) SpanInfo: {"start":157,"length":41} + >if (function foo() { + > return 30; + >} ()) + >:=> (line 18, col 0) to (line 20, col 5) +20 >} ()) { + + ~~~ => Pos: (198 to 200) SpanInfo: {"start":205,"length":3} + >i++ + >:=> (line 21, col 4) to (line 21, col 7) +-------------------------------- +21 > i++; + + ~~~~~~~~~ => Pos: (201 to 209) SpanInfo: {"start":205,"length":3} + >i++ + >:=> (line 21, col 4) to (line 21, col 7) +-------------------------------- +22 >} + ~ => Pos: (210 to 210) SpanInfo: {"start":205,"length":3} + >i++ + >:=> (line 21, col 4) to (line 21, col 7) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_import.baseline b/tests/baselines/reference/bpSpan_import.baseline new file mode 100644 index 00000000000..26279b48f26 --- /dev/null +++ b/tests/baselines/reference/bpSpan_import.baseline @@ -0,0 +1,60 @@ + +1 >module m { + + ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":0,"length":32} + >module m { + > class c { + > } + >} + >:=> (line 1, col 0) to (line 4, col 1) +-------------------------------- +2 > class c { + + ~~~~~~~~~~~~~~ => Pos: (11 to 24) SpanInfo: {"start":15,"length":15} + >class c { + > } + >:=> (line 2, col 4) to (line 3, col 5) +-------------------------------- +3 > } + + ~~~~~~ => Pos: (25 to 30) SpanInfo: {"start":29,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +4 >} + + ~~ => Pos: (31 to 32) SpanInfo: {"start":31,"length":1} + >} + >:=> (line 4, col 0) to (line 4, col 1) +-------------------------------- +5 >import a = m.c; + + ~~~~~~~~~~~~~~~~ => Pos: (33 to 48) SpanInfo: {"start":33,"length":14} + >import a = m.c + >:=> (line 5, col 0) to (line 5, col 14) +-------------------------------- +6 >export import b = m.c; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (49 to 71) SpanInfo: {"start":49,"length":21} + >export import b = m.c + >:=> (line 6, col 0) to (line 6, col 21) +-------------------------------- +7 >var x = new a(); + + ~~~~~~~ => Pos: (72 to 78) SpanInfo: {"start":72,"length":15} + >var x = new a() + >:=> (line 7, col 0) to (line 7, col 15) +7 >var x = new a(); + + ~~~~~~~~~~ => Pos: (79 to 88) SpanInfo: {"start":80,"length":7} + >new a() + >:=> (line 7, col 8) to (line 7, col 15) +-------------------------------- +8 >var y = new b(); + ~~~~~~~ => Pos: (89 to 95) SpanInfo: {"start":89,"length":15} + >var y = new b() + >:=> (line 8, col 0) to (line 8, col 15) +8 >var y = new b(); + ~~~~~~~~~ => Pos: (96 to 104) SpanInfo: {"start":97,"length":7} + >new b() + >:=> (line 8, col 8) to (line 8, col 15) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_inBlankLine.baseline b/tests/baselines/reference/bpSpan_inBlankLine.baseline new file mode 100644 index 00000000000..40fe26a16a6 --- /dev/null +++ b/tests/baselines/reference/bpSpan_inBlankLine.baseline @@ -0,0 +1,15 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 > + + ~ => Pos: (12 to 12) SpanInfo: undefined +-------------------------------- +3 >var y = 10; + ~~~~~~~~~~~ => Pos: (13 to 23) SpanInfo: {"start":13,"length":10} + >var y = 10 + >:=> (line 3, col 0) to (line 3, col 10) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_inComments.baseline b/tests/baselines/reference/bpSpan_inComments.baseline new file mode 100644 index 00000000000..5c167293513 --- /dev/null +++ b/tests/baselines/reference/bpSpan_inComments.baseline @@ -0,0 +1,19 @@ + +1 >/*comment here*/ var x = 10; /*comment here*/ + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (0 to 45) SpanInfo: {"start":17,"length":10} + >var x = 10 + >:=> (line 1, col 17) to (line 1, col 27) +-------------------------------- +2 >// comment only line + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (46 to 66) SpanInfo: undefined +-------------------------------- +3 >/*multiline comment + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (67 to 86) SpanInfo: undefined +-------------------------------- +4 >another line of multiline comment */ var y = 10; // comment here + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (87 to 150) SpanInfo: {"start":124,"length":10} + >var y = 10 + >:=> (line 4, col 37) to (line 4, col 47) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_interface.baseline b/tests/baselines/reference/bpSpan_interface.baseline new file mode 100644 index 00000000000..14e7921757d --- /dev/null +++ b/tests/baselines/reference/bpSpan_interface.baseline @@ -0,0 +1,91 @@ + +1 >interface I { + + ~~~~~~~~~~~~~~ => Pos: (0 to 13) SpanInfo: undefined +-------------------------------- +2 > property: string; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (14 to 35) SpanInfo: undefined +-------------------------------- +3 > method(): number; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (36 to 57) SpanInfo: undefined +-------------------------------- +4 > (a: string): string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (58 to 82) SpanInfo: undefined +-------------------------------- +5 > new (a: string): I; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (83 to 106) SpanInfo: undefined +-------------------------------- +6 > [a: number]: number; + + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (107 to 131) SpanInfo: undefined +-------------------------------- +7 >} + + ~~ => Pos: (132 to 133) SpanInfo: undefined +-------------------------------- +8 >module m { + + ~~~~~~~~~~~ => Pos: (134 to 144) SpanInfo: undefined +-------------------------------- +9 > interface I1 { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (145 to 163) SpanInfo: undefined +-------------------------------- +10 > property: string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (164 to 189) SpanInfo: undefined +-------------------------------- +11 > method(): number; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (190 to 215) SpanInfo: undefined +-------------------------------- +12 > (a: string): string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (216 to 244) SpanInfo: undefined +-------------------------------- +13 > new (a: string): I; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (245 to 272) SpanInfo: undefined +-------------------------------- +14 > [a: number]: number; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (273 to 301) SpanInfo: undefined +-------------------------------- +15 > } + + ~~~~~~ => Pos: (302 to 307) SpanInfo: undefined +-------------------------------- +16 > export interface I2 { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (308 to 333) SpanInfo: undefined +-------------------------------- +17 > property: string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (334 to 359) SpanInfo: undefined +-------------------------------- +18 > method(): number; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (360 to 385) SpanInfo: undefined +-------------------------------- +19 > (a: string): string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (386 to 414) SpanInfo: undefined +-------------------------------- +20 > new (a: string): I; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (415 to 442) SpanInfo: undefined +-------------------------------- +21 > [a: number]: number; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (443 to 471) SpanInfo: undefined +-------------------------------- +22 > } + + ~~~~~~ => Pos: (472 to 477) SpanInfo: undefined +-------------------------------- +23 >} + ~ => Pos: (478 to 478) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_labeled.baseline b/tests/baselines/reference/bpSpan_labeled.baseline new file mode 100644 index 00000000000..8c2d23adedb --- /dev/null +++ b/tests/baselines/reference/bpSpan_labeled.baseline @@ -0,0 +1,11 @@ + +1 >x: + + ~~~ => Pos: (0 to 2) SpanInfo: {"start":3,"length":10} + >var b = 10 + >:=> (line 2, col 0) to (line 2, col 10) +-------------------------------- +2 >var b = 10; + ~~~~~~~~~~~ => Pos: (3 to 13) SpanInfo: {"start":3,"length":10} + >var b = 10 + >:=> (line 2, col 0) to (line 2, col 10) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_module.baseline b/tests/baselines/reference/bpSpan_module.baseline new file mode 100644 index 00000000000..14145512658 --- /dev/null +++ b/tests/baselines/reference/bpSpan_module.baseline @@ -0,0 +1,234 @@ + +1 >module m2 { + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":38} + >module m2 { + > var a = 10; + > a++; + >} + >:=> (line 1, col 0) to (line 4, col 1) +-------------------------------- +2 > var a = 10; + + ~~~~~~~~~~~~~~~~ => Pos: (12 to 27) SpanInfo: {"start":16,"length":10} + >var a = 10 + >:=> (line 2, col 4) to (line 2, col 14) +-------------------------------- +3 > a++; + + ~~~~~~~~~ => Pos: (28 to 36) SpanInfo: {"start":32,"length":3} + >a++ + >:=> (line 3, col 4) to (line 3, col 7) +-------------------------------- +4 >} + + ~~ => Pos: (37 to 38) SpanInfo: {"start":37,"length":1} + >} + >:=> (line 4, col 0) to (line 4, col 1) +-------------------------------- +5 >module m3 { + + ~~~~~~~~~~~~ => Pos: (39 to 50) SpanInfo: {"start":39,"length":118} + >module m3 { + > module m4 { + > export var x = 30; + > } + > + > export function foo() { + > return m4.x; + > } + >} + >:=> (line 5, col 0) to (line 13, col 1) +-------------------------------- +6 > module m4 { + + ~~~~~~~~~~~~~~~~ => Pos: (51 to 66) SpanInfo: {"start":55,"length":44} + >module m4 { + > export var x = 30; + > } + >:=> (line 6, col 4) to (line 8, col 5) +-------------------------------- +7 > export var x = 30; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (67 to 93) SpanInfo: {"start":75,"length":17} + >export var x = 30 + >:=> (line 7, col 8) to (line 7, col 25) +-------------------------------- +8 > } + + ~~~~~~ => Pos: (94 to 99) SpanInfo: {"start":98,"length":1} + >} + >:=> (line 8, col 4) to (line 8, col 5) +-------------------------------- +9 > + + ~ => Pos: (100 to 100) SpanInfo: undefined +-------------------------------- +10 > export function foo() { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (101 to 128) SpanInfo: {"start":105,"length":50} + >export function foo() { + > return m4.x; + > } + >:=> (line 10, col 4) to (line 12, col 5) +-------------------------------- +11 > return m4.x; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (129 to 149) SpanInfo: {"start":137,"length":11} + >return m4.x + >:=> (line 11, col 8) to (line 11, col 19) +-------------------------------- +12 > } + + ~~~~~~ => Pos: (150 to 155) SpanInfo: {"start":154,"length":1} + >} + >:=> (line 12, col 4) to (line 12, col 5) +-------------------------------- +13 >} + + ~~ => Pos: (156 to 157) SpanInfo: {"start":156,"length":1} + >} + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +14 >module m4 { + + ~~~~~~~~~~~~ => Pos: (158 to 169) SpanInfo: undefined +-------------------------------- +15 > interface I { } + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (170 to 189) SpanInfo: undefined +-------------------------------- +16 >} + + ~~ => Pos: (190 to 191) SpanInfo: undefined +-------------------------------- +17 >module m12 + + ~~~~~~~~~~~ => Pos: (192 to 202) SpanInfo: {"start":192,"length":39} + >module m12 + >{ + > var a = 10; + > a++; + >} + >:=> (line 17, col 0) to (line 21, col 1) +-------------------------------- +18 >{ + + ~~ => Pos: (203 to 204) SpanInfo: {"start":209,"length":10} + >var a = 10 + >:=> (line 19, col 4) to (line 19, col 14) +-------------------------------- +19 > var a = 10; + + ~~~~~~~~~~~~~~~~ => Pos: (205 to 220) SpanInfo: {"start":209,"length":10} + >var a = 10 + >:=> (line 19, col 4) to (line 19, col 14) +-------------------------------- +20 > a++; + + ~~~~~~~~~ => Pos: (221 to 229) SpanInfo: {"start":225,"length":3} + >a++ + >:=> (line 20, col 4) to (line 20, col 7) +-------------------------------- +21 >} + + ~~ => Pos: (230 to 231) SpanInfo: {"start":230,"length":1} + >} + >:=> (line 21, col 0) to (line 21, col 1) +-------------------------------- +22 >module m13 + + ~~~~~~~~~~~ => Pos: (232 to 242) SpanInfo: {"start":232,"length":125} + >module m13 + >{ + > module m14 + > { + > export var x = 30; + > } + > + > export function foo() { + > return m4.x; + > } + >} + >:=> (line 22, col 0) to (line 32, col 1) +-------------------------------- +23 >{ + + ~~ => Pos: (243 to 244) SpanInfo: {"start":249,"length":50} + >module m14 + > { + > export var x = 30; + > } + >:=> (line 24, col 4) to (line 27, col 5) +-------------------------------- +24 > module m14 + + ~~~~~~~~~~~~~~~~ => Pos: (245 to 260) SpanInfo: {"start":249,"length":50} + >module m14 + > { + > export var x = 30; + > } + >:=> (line 24, col 4) to (line 27, col 5) +-------------------------------- +25 > { + + ~~~~~~ => Pos: (261 to 266) SpanInfo: {"start":275,"length":17} + >export var x = 30 + >:=> (line 26, col 8) to (line 26, col 25) +-------------------------------- +26 > export var x = 30; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (267 to 293) SpanInfo: {"start":275,"length":17} + >export var x = 30 + >:=> (line 26, col 8) to (line 26, col 25) +-------------------------------- +27 > } + + ~~~~~~ => Pos: (294 to 299) SpanInfo: {"start":298,"length":1} + >} + >:=> (line 27, col 4) to (line 27, col 5) +-------------------------------- +28 > + + ~ => Pos: (300 to 300) SpanInfo: undefined +-------------------------------- +29 > export function foo() { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (301 to 328) SpanInfo: {"start":305,"length":50} + >export function foo() { + > return m4.x; + > } + >:=> (line 29, col 4) to (line 31, col 5) +-------------------------------- +30 > return m4.x; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (329 to 349) SpanInfo: {"start":337,"length":11} + >return m4.x + >:=> (line 30, col 8) to (line 30, col 19) +-------------------------------- +31 > } + + ~~~~~~ => Pos: (350 to 355) SpanInfo: {"start":354,"length":1} + >} + >:=> (line 31, col 4) to (line 31, col 5) +-------------------------------- +32 >} + + ~~ => Pos: (356 to 357) SpanInfo: {"start":356,"length":1} + >} + >:=> (line 32, col 0) to (line 32, col 1) +-------------------------------- +33 >module m14 + + ~~~~~~~~~~~~ => Pos: (358 to 369) SpanInfo: undefined +-------------------------------- +34 >{ + + ~~ => Pos: (370 to 371) SpanInfo: undefined +-------------------------------- +35 > interface I { } + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (372 to 391) SpanInfo: undefined +-------------------------------- +36 >} + ~ => Pos: (392 to 392) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_moduleAmbient.baseline b/tests/baselines/reference/bpSpan_moduleAmbient.baseline new file mode 100644 index 00000000000..8ea705dc09f --- /dev/null +++ b/tests/baselines/reference/bpSpan_moduleAmbient.baseline @@ -0,0 +1,19 @@ + +1 >declare module Bar { + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 20) SpanInfo: undefined +-------------------------------- +2 >} + + ~~ => Pos: (21 to 22) SpanInfo: undefined +-------------------------------- +3 >declare module Foo { + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (23 to 43) SpanInfo: undefined +-------------------------------- +4 > var x; + + ~~~~~~~~~~~ => Pos: (44 to 54) SpanInfo: undefined +-------------------------------- +5 >} + ~ => Pos: (55 to 55) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_moduleEmpty.baseline b/tests/baselines/reference/bpSpan_moduleEmpty.baseline new file mode 100644 index 00000000000..3139d4603d2 --- /dev/null +++ b/tests/baselines/reference/bpSpan_moduleEmpty.baseline @@ -0,0 +1,7 @@ + +1 >module Bar { + + ~~~~~~~~~~~~~ => Pos: (0 to 12) SpanInfo: undefined +-------------------------------- +2 >} + ~ => Pos: (13 to 13) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_objectLiteralExpressions.baseline b/tests/baselines/reference/bpSpan_objectLiteralExpressions.baseline new file mode 100644 index 00000000000..0d864a9b1bd --- /dev/null +++ b/tests/baselines/reference/bpSpan_objectLiteralExpressions.baseline @@ -0,0 +1,233 @@ + +1 >var x = { + + ~~~~~~~~~~ => Pos: (0 to 9) SpanInfo: {"start":0,"length":179} + >var x = { + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >} + >:=> (line 1, col 0) to (line 13, col 1) +-------------------------------- +2 > a: 10, + + ~~~~~~~~~~~ => Pos: (10 to 20) SpanInfo: {"start":0,"length":179} + >var x = { + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >} + >:=> (line 1, col 0) to (line 13, col 1) +-------------------------------- +3 > b: () => 10, + + ~~~~~~~~~~~~~~~~~ => Pos: (21 to 37) SpanInfo: {"start":34,"length":2} + >10 + >:=> (line 3, col 13) to (line 3, col 15) +-------------------------------- +4 > someMethod() { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (38 to 56) SpanInfo: {"start":65,"length":14} + >return "Hello" + >:=> (line 5, col 8) to (line 5, col 22) +-------------------------------- +5 > return "Hello"; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (57 to 80) SpanInfo: {"start":65,"length":14} + >return "Hello" + >:=> (line 5, col 8) to (line 5, col 22) +-------------------------------- +6 > }, + + ~~~~~~~ => Pos: (81 to 87) SpanInfo: {"start":85,"length":1} + >} + >:=> (line 6, col 4) to (line 6, col 5) +-------------------------------- +7 > get y() { + + ~~~~~~~~~~~~~~ => Pos: (88 to 101) SpanInfo: {"start":110,"length":9} + >return 30 + >:=> (line 8, col 8) to (line 8, col 17) +-------------------------------- +8 > return 30; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (102 to 120) SpanInfo: {"start":110,"length":9} + >return 30 + >:=> (line 8, col 8) to (line 8, col 17) +-------------------------------- +9 > }, + + ~~~~~~~ => Pos: (121 to 127) SpanInfo: {"start":125,"length":1} + >} + >:=> (line 9, col 4) to (line 9, col 5) +-------------------------------- +10 > set z(x: number) { + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (128 to 150) SpanInfo: {"start":159,"length":11} + >var bar = x + >:=> (line 11, col 8) to (line 11, col 19) +-------------------------------- +11 > var bar = x; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (151 to 171) SpanInfo: {"start":159,"length":11} + >var bar = x + >:=> (line 11, col 8) to (line 11, col 19) +-------------------------------- +12 > } + + ~~~~~~ => Pos: (172 to 177) SpanInfo: {"start":176,"length":1} + >} + >:=> (line 12, col 4) to (line 12, col 5) +-------------------------------- +13 >}; + + ~~~ => Pos: (178 to 180) SpanInfo: {"start":0,"length":179} + >var x = { + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >} + >:=> (line 1, col 0) to (line 13, col 1) +-------------------------------- +14 >var a = ({ + + ~~~~~~~~~~~ => Pos: (181 to 191) SpanInfo: {"start":181,"length":192} + >var a = ({ + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >}).someMethod + >:=> (line 14, col 0) to (line 26, col 13) +-------------------------------- +15 > a: 10, + + ~~~~~~~~~~~ => Pos: (192 to 202) SpanInfo: {"start":181,"length":192} + >var a = ({ + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >}).someMethod + >:=> (line 14, col 0) to (line 26, col 13) +-------------------------------- +16 > b: () => 10, + + ~~~~~~~~~~~~~~~~~ => Pos: (203 to 219) SpanInfo: {"start":216,"length":2} + >10 + >:=> (line 16, col 13) to (line 16, col 15) +-------------------------------- +17 > someMethod() { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (220 to 238) SpanInfo: {"start":247,"length":14} + >return "Hello" + >:=> (line 18, col 8) to (line 18, col 22) +-------------------------------- +18 > return "Hello"; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (239 to 262) SpanInfo: {"start":247,"length":14} + >return "Hello" + >:=> (line 18, col 8) to (line 18, col 22) +-------------------------------- +19 > }, + + ~~~~~~~ => Pos: (263 to 269) SpanInfo: {"start":267,"length":1} + >} + >:=> (line 19, col 4) to (line 19, col 5) +-------------------------------- +20 > get y() { + + ~~~~~~~~~~~~~~ => Pos: (270 to 283) SpanInfo: {"start":292,"length":9} + >return 30 + >:=> (line 21, col 8) to (line 21, col 17) +-------------------------------- +21 > return 30; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (284 to 302) SpanInfo: {"start":292,"length":9} + >return 30 + >:=> (line 21, col 8) to (line 21, col 17) +-------------------------------- +22 > }, + + ~~~~~~~ => Pos: (303 to 309) SpanInfo: {"start":307,"length":1} + >} + >:=> (line 22, col 4) to (line 22, col 5) +-------------------------------- +23 > set z(x: number) { + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (310 to 332) SpanInfo: {"start":341,"length":11} + >var bar = x + >:=> (line 24, col 8) to (line 24, col 19) +-------------------------------- +24 > var bar = x; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (333 to 353) SpanInfo: {"start":341,"length":11} + >var bar = x + >:=> (line 24, col 8) to (line 24, col 19) +-------------------------------- +25 > } + + ~~~~~~ => Pos: (354 to 359) SpanInfo: {"start":358,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +-------------------------------- +26 >}).someMethod; + + ~~~~~~~~~~~~~~~ => Pos: (360 to 374) SpanInfo: {"start":181,"length":192} + >var a = ({ + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >}).someMethod + >:=> (line 14, col 0) to (line 26, col 13) +-------------------------------- +27 >a(); + ~~~~ => Pos: (375 to 378) SpanInfo: {"start":375,"length":3} + >a() + >:=> (line 27, col 0) to (line 27, col 3) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_parenCallOrNewExpressions.baseline b/tests/baselines/reference/bpSpan_parenCallOrNewExpressions.baseline new file mode 100644 index 00000000000..47c932640f9 --- /dev/null +++ b/tests/baselines/reference/bpSpan_parenCallOrNewExpressions.baseline @@ -0,0 +1,364 @@ + +1 >function foo(a: number) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 25) SpanInfo: {"start":30,"length":8} + >return a + >:=> (line 2, col 4) to (line 2, col 12) +-------------------------------- +2 > return a; + + ~~~~~~~~~~~~~~ => Pos: (26 to 39) SpanInfo: {"start":30,"length":8} + >return a + >:=> (line 2, col 4) to (line 2, col 12) +-------------------------------- +3 >} + + ~~ => Pos: (40 to 41) SpanInfo: {"start":40,"length":1} + >} + >:=> (line 3, col 0) to (line 3, col 1) +-------------------------------- +4 >foo((function bar() { + + ~~~~ => Pos: (42 to 45) SpanInfo: {"start":42,"length":47} + >foo((function bar() { + > return foo(40); + >})()) + >:=> (line 4, col 0) to (line 6, col 5) +4 >foo((function bar() { + + ~ => Pos: (46 to 46) SpanInfo: {"start":46,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 4, col 4) to (line 6, col 4) +4 >foo((function bar() { + + ~~~~~~~~~~~~~~~~~ => Pos: (47 to 63) SpanInfo: {"start":68,"length":14} + >return foo(40) + >:=> (line 5, col 4) to (line 5, col 18) +-------------------------------- +5 > return foo(40); + + ~~~~~~~~~~ => Pos: (64 to 73) SpanInfo: {"start":68,"length":14} + >return foo(40) + >:=> (line 5, col 4) to (line 5, col 18) +5 > return foo(40); + + ~~~~~~~~~~ => Pos: (74 to 83) SpanInfo: {"start":75,"length":7} + >foo(40) + >:=> (line 5, col 11) to (line 5, col 18) +-------------------------------- +6 >})()); + + ~ => Pos: (84 to 84) SpanInfo: {"start":84,"length":1} + >} + >:=> (line 6, col 0) to (line 6, col 1) +6 >})()); + + ~~~ => Pos: (85 to 87) SpanInfo: {"start":46,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 4, col 4) to (line 6, col 4) +6 >})()); + + ~~~ => Pos: (88 to 90) SpanInfo: {"start":42,"length":47} + >foo((function bar() { + > return foo(40); + >})()) + >:=> (line 4, col 0) to (line 6, col 5) +-------------------------------- +7 >var y = foo((function () { + + ~~~~~~~ => Pos: (91 to 97) SpanInfo: {"start":91,"length":52} + >var y = foo((function () { + > return foo(40); + >})()) + >:=> (line 7, col 0) to (line 9, col 5) +7 >var y = foo((function () { + + ~~~~~ => Pos: (98 to 102) SpanInfo: {"start":99,"length":44} + >foo((function () { + > return foo(40); + >})()) + >:=> (line 7, col 8) to (line 9, col 5) +7 >var y = foo((function () { + + ~ => Pos: (103 to 103) SpanInfo: {"start":103,"length":39} + >(function () { + > return foo(40); + >})() + >:=> (line 7, col 12) to (line 9, col 4) +7 >var y = foo((function () { + + ~~~~~~~~~~~~~~ => Pos: (104 to 117) SpanInfo: {"start":122,"length":14} + >return foo(40) + >:=> (line 8, col 4) to (line 8, col 18) +-------------------------------- +8 > return foo(40); + + ~~~~~~~~~~ => Pos: (118 to 127) SpanInfo: {"start":122,"length":14} + >return foo(40) + >:=> (line 8, col 4) to (line 8, col 18) +8 > return foo(40); + + ~~~~~~~~~~ => Pos: (128 to 137) SpanInfo: {"start":129,"length":7} + >foo(40) + >:=> (line 8, col 11) to (line 8, col 18) +-------------------------------- +9 >})());; + + ~ => Pos: (138 to 138) SpanInfo: {"start":138,"length":1} + >} + >:=> (line 9, col 0) to (line 9, col 1) +9 >})());; + + ~~~ => Pos: (139 to 141) SpanInfo: {"start":103,"length":39} + >(function () { + > return foo(40); + >})() + >:=> (line 7, col 12) to (line 9, col 4) +9 >})());; + + ~~~~ => Pos: (142 to 145) SpanInfo: {"start":99,"length":44} + >foo((function () { + > return foo(40); + >})()) + >:=> (line 7, col 8) to (line 9, col 5) +-------------------------------- +10 >class greeter { + + ~~~~~~~~~~~~~~~~ => Pos: (146 to 161) SpanInfo: {"start":146,"length":52} + >class greeter { + > constructor(a: number) { + > } + >} + >:=> (line 10, col 0) to (line 13, col 1) +-------------------------------- +11 > constructor(a: number) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (162 to 190) SpanInfo: {"start":195,"length":1} + >} + >:=> (line 12, col 4) to (line 12, col 5) +-------------------------------- +12 > } + + ~~~~~~ => Pos: (191 to 196) SpanInfo: {"start":195,"length":1} + >} + >:=> (line 12, col 4) to (line 12, col 5) +-------------------------------- +13 >} + + ~~ => Pos: (197 to 198) SpanInfo: {"start":197,"length":1} + >} + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +14 >foo(30); + + ~~~~~~~~~ => Pos: (199 to 207) SpanInfo: {"start":199,"length":7} + >foo(30) + >:=> (line 14, col 0) to (line 14, col 7) +-------------------------------- +15 >foo(40 + y); + + ~~~~~~~~~~~~~ => Pos: (208 to 220) SpanInfo: {"start":208,"length":11} + >foo(40 + y) + >:=> (line 15, col 0) to (line 15, col 11) +-------------------------------- +16 >y = foo(30); + + ~~~ => Pos: (221 to 223) SpanInfo: {"start":221,"length":11} + >y = foo(30) + >:=> (line 16, col 0) to (line 16, col 11) +16 >y = foo(30); + + ~~~~~~~~~~ => Pos: (224 to 233) SpanInfo: {"start":225,"length":7} + >foo(30) + >:=> (line 16, col 4) to (line 16, col 11) +-------------------------------- +17 >y = foo(500 + y); + + ~~~ => Pos: (234 to 236) SpanInfo: {"start":234,"length":16} + >y = foo(500 + y) + >:=> (line 17, col 0) to (line 17, col 16) +17 >y = foo(500 + y); + + ~~~~~~~~~~~~~~~ => Pos: (237 to 251) SpanInfo: {"start":238,"length":12} + >foo(500 + y) + >:=> (line 17, col 4) to (line 17, col 16) +-------------------------------- +18 >new greeter((function bar() { + + ~~~~~~~~~~~~ => Pos: (252 to 263) SpanInfo: {"start":252,"length":55} + >new greeter((function bar() { + > return foo(40); + >})()) + >:=> (line 18, col 0) to (line 20, col 5) +18 >new greeter((function bar() { + + ~ => Pos: (264 to 264) SpanInfo: {"start":264,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 18, col 12) to (line 20, col 4) +18 >new greeter((function bar() { + + ~~~~~~~~~~~~~~~~~ => Pos: (265 to 281) SpanInfo: {"start":286,"length":14} + >return foo(40) + >:=> (line 19, col 4) to (line 19, col 18) +-------------------------------- +19 > return foo(40); + + ~~~~~~~~~~ => Pos: (282 to 291) SpanInfo: {"start":286,"length":14} + >return foo(40) + >:=> (line 19, col 4) to (line 19, col 18) +19 > return foo(40); + + ~~~~~~~~~~ => Pos: (292 to 301) SpanInfo: {"start":293,"length":7} + >foo(40) + >:=> (line 19, col 11) to (line 19, col 18) +-------------------------------- +20 >})()); + + ~ => Pos: (302 to 302) SpanInfo: {"start":302,"length":1} + >} + >:=> (line 20, col 0) to (line 20, col 1) +20 >})()); + + ~~~ => Pos: (303 to 305) SpanInfo: {"start":264,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 18, col 12) to (line 20, col 4) +20 >})()); + + ~~~ => Pos: (306 to 308) SpanInfo: {"start":252,"length":55} + >new greeter((function bar() { + > return foo(40); + >})()) + >:=> (line 18, col 0) to (line 20, col 5) +-------------------------------- +21 >var anotherGreeter = new greeter((function bar() { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (309 to 328) SpanInfo: {"start":309,"length":76} + >var anotherGreeter = new greeter((function bar() { + > return foo(40); + >})()) + >:=> (line 21, col 0) to (line 23, col 5) +21 >var anotherGreeter = new greeter((function bar() { + + ~~~~~~~~~~~~~ => Pos: (329 to 341) SpanInfo: {"start":330,"length":55} + >new greeter((function bar() { + > return foo(40); + >})()) + >:=> (line 21, col 21) to (line 23, col 5) +21 >var anotherGreeter = new greeter((function bar() { + + ~ => Pos: (342 to 342) SpanInfo: {"start":342,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 21, col 33) to (line 23, col 4) +21 >var anotherGreeter = new greeter((function bar() { + + ~~~~~~~~~~~~~~~~~=> Pos: (343 to 359) SpanInfo: {"start":364,"length":14} + >return foo(40) + >:=> (line 22, col 4) to (line 22, col 18) +-------------------------------- +22 > return foo(40); + + ~~~~~~~~~~ => Pos: (360 to 369) SpanInfo: {"start":364,"length":14} + >return foo(40) + >:=> (line 22, col 4) to (line 22, col 18) +22 > return foo(40); + + ~~~~~~~~~~ => Pos: (370 to 379) SpanInfo: {"start":371,"length":7} + >foo(40) + >:=> (line 22, col 11) to (line 22, col 18) +-------------------------------- +23 >})()); + + ~ => Pos: (380 to 380) SpanInfo: {"start":380,"length":1} + >} + >:=> (line 23, col 0) to (line 23, col 1) +23 >})()); + + ~~~ => Pos: (381 to 383) SpanInfo: {"start":342,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 21, col 33) to (line 23, col 4) +23 >})()); + + ~~~ => Pos: (384 to 386) SpanInfo: {"start":330,"length":55} + >new greeter((function bar() { + > return foo(40); + >})()) + >:=> (line 21, col 21) to (line 23, col 5) +-------------------------------- +24 >anotherGreeter = new greeter(30); + + ~~~~~~~~~~~~~~~~ => Pos: (387 to 402) SpanInfo: {"start":387,"length":32} + >anotherGreeter = new greeter(30) + >:=> (line 24, col 0) to (line 24, col 32) +24 >anotherGreeter = new greeter(30); + + ~~~~~~~~~~~~~~~~~~ => Pos: (403 to 420) SpanInfo: {"start":404,"length":15} + >new greeter(30) + >:=> (line 24, col 17) to (line 24, col 32) +-------------------------------- +25 >anotherGreeter = new greeter(40 + y); + + ~~~~~~~~~~~~~~~~ => Pos: (421 to 436) SpanInfo: {"start":421,"length":36} + >anotherGreeter = new greeter(40 + y) + >:=> (line 25, col 0) to (line 25, col 36) +25 >anotherGreeter = new greeter(40 + y); + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (437 to 458) SpanInfo: {"start":438,"length":19} + >new greeter(40 + y) + >:=> (line 25, col 17) to (line 25, col 36) +-------------------------------- +26 >new greeter(30); + + ~~~~~~~~~~~~~~~~~ => Pos: (459 to 475) SpanInfo: {"start":459,"length":15} + >new greeter(30) + >:=> (line 26, col 0) to (line 26, col 15) +-------------------------------- +27 >new greeter(40 + y); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (476 to 496) SpanInfo: {"start":476,"length":19} + >new greeter(40 + y) + >:=> (line 27, col 0) to (line 27, col 19) +-------------------------------- +28 >function foo2(x: number, y: string) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (497 to 534) SpanInfo: {"start":535,"length":1} + >} + >:=> (line 29, col 0) to (line 29, col 1) +-------------------------------- +29 >} + + ~~ => Pos: (535 to 536) SpanInfo: {"start":535,"length":1} + >} + >:=> (line 29, col 0) to (line 29, col 1) +-------------------------------- +30 >foo2(foo(30), foo(40).toString()); + ~~~~~ => Pos: (537 to 541) SpanInfo: {"start":537,"length":33} + >foo2(foo(30), foo(40).toString()) + >:=> (line 30, col 0) to (line 30, col 33) +30 >foo2(foo(30), foo(40).toString()); + ~~~~~~~~ => Pos: (542 to 549) SpanInfo: {"start":542,"length":7} + >foo(30) + >:=> (line 30, col 5) to (line 30, col 12) +30 >foo2(foo(30), foo(40).toString()); + ~~~~~~~~ => Pos: (550 to 557) SpanInfo: {"start":551,"length":7} + >foo(40) + >:=> (line 30, col 14) to (line 30, col 21) +30 >foo2(foo(30), foo(40).toString()); + ~~~~~~~~~~~ => Pos: (558 to 568) SpanInfo: {"start":551,"length":18} + >foo(40).toString() + >:=> (line 30, col 14) to (line 30, col 32) +30 >foo2(foo(30), foo(40).toString()); + ~~ => Pos: (569 to 570) SpanInfo: {"start":537,"length":33} + >foo2(foo(30), foo(40).toString()) + >:=> (line 30, col 0) to (line 30, col 33) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_stmts.baseline b/tests/baselines/reference/bpSpan_stmts.baseline new file mode 100644 index 00000000000..a81559ee9a5 --- /dev/null +++ b/tests/baselines/reference/bpSpan_stmts.baseline @@ -0,0 +1,572 @@ + +1 >function f() { + + ~~~~~~~~~~~~~~~ => Pos: (0 to 14) SpanInfo: undefined +-------------------------------- +2 > var y; + + ~~~~~~~~~~~ => Pos: (15 to 25) SpanInfo: undefined +-------------------------------- +3 > var x = 0; + + ~~~~~~~~~~~~~~~ => Pos: (26 to 40) SpanInfo: {"start":30,"length":9} + >var x = 0 + >:=> (line 3, col 4) to (line 3, col 13) +-------------------------------- +4 > for (var i = 0; i < 10; i++) { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (41 to 59) SpanInfo: {"start":50,"length":9} + >var i = 0 + >:=> (line 4, col 9) to (line 4, col 18) +4 > for (var i = 0; i < 10; i++) { + + ~~~~~~~~ => Pos: (60 to 67) SpanInfo: {"start":61,"length":6} + >i < 10 + >:=> (line 4, col 20) to (line 4, col 26) +4 > for (var i = 0; i < 10; i++) { + + ~~~~~~~~ => Pos: (68 to 75) SpanInfo: {"start":69,"length":3} + >i++ + >:=> (line 4, col 28) to (line 4, col 31) +-------------------------------- +5 > x += i; + + ~~~~~~~~~~~~~~~~ => Pos: (76 to 91) SpanInfo: {"start":84,"length":6} + >x += i + >:=> (line 5, col 8) to (line 5, col 14) +-------------------------------- +6 > x *= 0; + + ~~~~~~~~~~~~~~~~ => Pos: (92 to 107) SpanInfo: {"start":100,"length":6} + >x *= 0 + >:=> (line 6, col 8) to (line 6, col 14) +-------------------------------- +7 > } + + ~~~~~~ => Pos: (108 to 113) SpanInfo: {"start":100,"length":6} + >x *= 0 + >:=> (line 6, col 8) to (line 6, col 14) +-------------------------------- +8 > if (x > 17) { + + ~~~~~~~~~~~~~~~~~~ => Pos: (114 to 131) SpanInfo: {"start":118,"length":11} + >if (x > 17) + >:=> (line 8, col 4) to (line 8, col 15) +-------------------------------- +9 > x /= 9; + + ~~~~~~~~~~~~~~~~ => Pos: (132 to 147) SpanInfo: {"start":140,"length":6} + >x /= 9 + >:=> (line 9, col 8) to (line 9, col 14) +-------------------------------- +10 > } else { + + ~~~~~ => Pos: (148 to 152) SpanInfo: {"start":140,"length":6} + >x /= 9 + >:=> (line 9, col 8) to (line 9, col 14) +10 > } else { + + ~~~~~~~~ => Pos: (153 to 160) SpanInfo: {"start":169,"length":7} + >x += 10 + >:=> (line 11, col 8) to (line 11, col 15) +-------------------------------- +11 > x += 10; + + ~~~~~~~~~~~~~~~~~ => Pos: (161 to 177) SpanInfo: {"start":169,"length":7} + >x += 10 + >:=> (line 11, col 8) to (line 11, col 15) +-------------------------------- +12 > x++; + + ~~~~~~~~~~~~~ => Pos: (178 to 190) SpanInfo: {"start":186,"length":3} + >x++ + >:=> (line 12, col 8) to (line 12, col 11) +-------------------------------- +13 > } + + ~~~~~~ => Pos: (191 to 196) SpanInfo: {"start":186,"length":3} + >x++ + >:=> (line 12, col 8) to (line 12, col 11) +-------------------------------- +14 > var a = [ + + ~~~~~~~~~~~~~~ => Pos: (197 to 210) SpanInfo: {"start":201,"length":47} + >var a = [ + > 1, + > 2, + > 3 + > ] + >:=> (line 14, col 4) to (line 18, col 5) +-------------------------------- +15 > 1, + + ~~~~~~~~~~~ => Pos: (211 to 221) SpanInfo: {"start":201,"length":47} + >var a = [ + > 1, + > 2, + > 3 + > ] + >:=> (line 14, col 4) to (line 18, col 5) +-------------------------------- +16 > 2, + + ~~~~~~~~~~~ => Pos: (222 to 232) SpanInfo: {"start":201,"length":47} + >var a = [ + > 1, + > 2, + > 3 + > ] + >:=> (line 14, col 4) to (line 18, col 5) +-------------------------------- +17 > 3 + + ~~~~~~~~~~ => Pos: (233 to 242) SpanInfo: {"start":201,"length":47} + >var a = [ + > 1, + > 2, + > 3 + > ] + >:=> (line 14, col 4) to (line 18, col 5) +-------------------------------- +18 > ]; + + ~~~~~~~ => Pos: (243 to 249) SpanInfo: {"start":201,"length":47} + >var a = [ + > 1, + > 2, + > 3 + > ] + >:=> (line 14, col 4) to (line 18, col 5) +-------------------------------- +19 > var obj = { + + ~~~~~~~~~~~~~~~~ => Pos: (250 to 265) SpanInfo: {"start":254,"length":50} + >var obj = { + > z: 1, + > q: "hello" + > } + >:=> (line 19, col 4) to (line 22, col 5) +-------------------------------- +20 > z: 1, + + ~~~~~~~~~~~~~~ => Pos: (266 to 279) SpanInfo: {"start":254,"length":50} + >var obj = { + > z: 1, + > q: "hello" + > } + >:=> (line 19, col 4) to (line 22, col 5) +-------------------------------- +21 > q: "hello" + + ~~~~~~~~~~~~~~~~~~~ => Pos: (280 to 298) SpanInfo: {"start":254,"length":50} + >var obj = { + > z: 1, + > q: "hello" + > } + >:=> (line 19, col 4) to (line 22, col 5) +-------------------------------- +22 > }; + + ~~~~~~~ => Pos: (299 to 305) SpanInfo: {"start":254,"length":50} + >var obj = { + > z: 1, + > q: "hello" + > } + >:=> (line 19, col 4) to (line 22, col 5) +-------------------------------- +23 > for (var j in a) { + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (306 to 328) SpanInfo: {"start":310,"length":16} + >for (var j in a) + >:=> (line 23, col 4) to (line 23, col 20) +-------------------------------- +24 > obj.z = a[j]; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (329 to 350) SpanInfo: {"start":337,"length":12} + >obj.z = a[j] + >:=> (line 24, col 8) to (line 24, col 20) +-------------------------------- +25 > var v = 10; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (351 to 370) SpanInfo: {"start":359,"length":10} + >var v = 10 + >:=> (line 25, col 8) to (line 25, col 18) +-------------------------------- +26 > } + + ~~~~~~ => Pos: (371 to 376) SpanInfo: {"start":359,"length":10} + >var v = 10 + >:=> (line 25, col 8) to (line 25, col 18) +-------------------------------- +27 > try { + + ~~~~~~~~~~ => Pos: (377 to 386) SpanInfo: {"start":395,"length":14} + >obj.q = "ohhh" + >:=> (line 28, col 8) to (line 28, col 22) +-------------------------------- +28 > obj.q = "ohhh"; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (387 to 410) SpanInfo: {"start":395,"length":14} + >obj.q = "ohhh" + >:=> (line 28, col 8) to (line 28, col 22) +-------------------------------- +29 > } catch (e) { + + ~~~~~ => Pos: (411 to 415) SpanInfo: {"start":395,"length":14} + >obj.q = "ohhh" + >:=> (line 28, col 8) to (line 28, col 22) +29 > } catch (e) { + + ~~~~~~~~~~~~~ => Pos: (416 to 428) SpanInfo: {"start":437,"length":15} + >if (obj.z < 10) + >:=> (line 30, col 8) to (line 30, col 23) +-------------------------------- +30 > if (obj.z < 10) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (429 to 454) SpanInfo: {"start":437,"length":15} + >if (obj.z < 10) + >:=> (line 30, col 8) to (line 30, col 23) +-------------------------------- +31 > obj.z = 12; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (455 to 478) SpanInfo: {"start":467,"length":10} + >obj.z = 12 + >:=> (line 31, col 12) to (line 31, col 22) +-------------------------------- +32 > } else { + + ~~~~~~~~~ => Pos: (479 to 487) SpanInfo: {"start":467,"length":10} + >obj.z = 12 + >:=> (line 31, col 12) to (line 31, col 22) +32 > } else { + + ~~~~~~~~ => Pos: (488 to 495) SpanInfo: {"start":508,"length":13} + >obj.q = "hmm" + >:=> (line 33, col 12) to (line 33, col 25) +-------------------------------- +33 > obj.q = "hmm"; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (496 to 522) SpanInfo: {"start":508,"length":13} + >obj.q = "hmm" + >:=> (line 33, col 12) to (line 33, col 25) +-------------------------------- +34 > } + + ~~~~~~~~~~ => Pos: (523 to 532) SpanInfo: {"start":508,"length":13} + >obj.q = "hmm" + >:=> (line 33, col 12) to (line 33, col 25) +-------------------------------- +35 > } + + ~~~~~~ => Pos: (533 to 538) SpanInfo: {"start":437,"length":15} + >if (obj.z < 10) + >:=> (line 30, col 8) to (line 30, col 23) +-------------------------------- +36 > try { + + ~~~~~~~~~~ => Pos: (539 to 548) SpanInfo: {"start":557,"length":17} + >throw new Error() + >:=> (line 37, col 8) to (line 37, col 25) +-------------------------------- +37 > throw new Error(); + + ~~~~~~~~~~~~~ => Pos: (549 to 561) SpanInfo: {"start":557,"length":17} + >throw new Error() + >:=> (line 37, col 8) to (line 37, col 25) +37 > throw new Error(); + + ~~~~~~~~~~~~~~ => Pos: (562 to 575) SpanInfo: {"start":563,"length":11} + >new Error() + >:=> (line 37, col 14) to (line 37, col 25) +-------------------------------- +38 > } catch (e1) { + + ~~~~~ => Pos: (576 to 580) SpanInfo: {"start":557,"length":17} + >throw new Error() + >:=> (line 37, col 8) to (line 37, col 25) +38 > } catch (e1) { + + ~~~~~~~~~~~~~~ => Pos: (581 to 594) SpanInfo: {"start":603,"length":10} + >var b = e1 + >:=> (line 39, col 8) to (line 39, col 18) +-------------------------------- +39 > var b = e1; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (595 to 614) SpanInfo: {"start":603,"length":10} + >var b = e1 + >:=> (line 39, col 8) to (line 39, col 18) +-------------------------------- +40 > } finally { + + ~~~~~ => Pos: (615 to 619) SpanInfo: {"start":603,"length":10} + >var b = e1 + >:=> (line 39, col 8) to (line 39, col 18) +40 > } finally { + + ~~~~~~~~~~~ => Pos: (620 to 630) SpanInfo: {"start":639,"length":6} + >y = 70 + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +41 > y = 70; + + ~~~~~~~~~~~~~~~~ => Pos: (631 to 646) SpanInfo: {"start":639,"length":6} + >y = 70 + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +42 > } + + ~~~~~~ => Pos: (647 to 652) SpanInfo: {"start":639,"length":6} + >y = 70 + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +43 > with (obj) { + + ~~~~~~~~~~~~~~~~~ => Pos: (653 to 669) SpanInfo: {"start":678,"length":5} + >i = 2 + >:=> (line 44, col 8) to (line 44, col 13) +-------------------------------- +44 > i = 2; + + ~~~~~~~~~~~~~~~ => Pos: (670 to 684) SpanInfo: {"start":678,"length":5} + >i = 2 + >:=> (line 44, col 8) to (line 44, col 13) +-------------------------------- +45 > z = 10; + + ~~~~~~~~~~~~~~~~ => Pos: (685 to 700) SpanInfo: {"start":693,"length":6} + >z = 10 + >:=> (line 45, col 8) to (line 45, col 14) +-------------------------------- +46 > } + + ~~~~~~ => Pos: (701 to 706) SpanInfo: {"start":693,"length":6} + >z = 10 + >:=> (line 45, col 8) to (line 45, col 14) +-------------------------------- +47 > switch (obj.z) { + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (707 to 727) SpanInfo: {"start":711,"length":14} + >switch (obj.z) + >:=> (line 47, col 4) to (line 47, col 18) +-------------------------------- +48 > case 0: { + + ~~~~~~~~~~~~~~~~~~ => Pos: (728 to 745) SpanInfo: {"start":758,"length":3} + >x++ + >:=> (line 49, col 12) to (line 49, col 15) +-------------------------------- +49 > x++; + + ~~~~~~~~~~~~~~~~~ => Pos: (746 to 762) SpanInfo: {"start":758,"length":3} + >x++ + >:=> (line 49, col 12) to (line 49, col 15) +-------------------------------- +50 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (763 to 781) SpanInfo: {"start":775,"length":5} + >break + >:=> (line 50, col 12) to (line 50, col 17) +-------------------------------- +51 > + + ~ => Pos: (782 to 782) SpanInfo: undefined +-------------------------------- +52 > } + + ~~~~~~~~~~ => Pos: (783 to 792) SpanInfo: {"start":775,"length":5} + >break + >:=> (line 50, col 12) to (line 50, col 17) +-------------------------------- +53 > case 1: { + + ~~~~~~~~~~~~~~~~~~ => Pos: (793 to 810) SpanInfo: {"start":823,"length":3} + >x-- + >:=> (line 54, col 12) to (line 54, col 15) +-------------------------------- +54 > x--; + + ~~~~~~~~~~~~~~~~~ => Pos: (811 to 827) SpanInfo: {"start":823,"length":3} + >x-- + >:=> (line 54, col 12) to (line 54, col 15) +-------------------------------- +55 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (828 to 846) SpanInfo: {"start":840,"length":5} + >break + >:=> (line 55, col 12) to (line 55, col 17) +-------------------------------- +56 > + + ~ => Pos: (847 to 847) SpanInfo: undefined +-------------------------------- +57 > } + + ~~~~~~~~~~ => Pos: (848 to 857) SpanInfo: {"start":840,"length":5} + >break + >:=> (line 55, col 12) to (line 55, col 17) +-------------------------------- +58 > default: { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (858 to 876) SpanInfo: {"start":889,"length":6} + >x *= 2 + >:=> (line 59, col 12) to (line 59, col 18) +-------------------------------- +59 > x *= 2; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (877 to 896) SpanInfo: {"start":889,"length":6} + >x *= 2 + >:=> (line 59, col 12) to (line 59, col 18) +-------------------------------- +60 > x = 50; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (897 to 916) SpanInfo: {"start":909,"length":6} + >x = 50 + >:=> (line 60, col 12) to (line 60, col 18) +-------------------------------- +61 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (917 to 935) SpanInfo: {"start":929,"length":5} + >break + >:=> (line 61, col 12) to (line 61, col 17) +-------------------------------- +62 > + + ~ => Pos: (936 to 936) SpanInfo: undefined +-------------------------------- +63 > } + + ~~~~~~~~~~ => Pos: (937 to 946) SpanInfo: {"start":929,"length":5} + >break + >:=> (line 61, col 12) to (line 61, col 17) +-------------------------------- +64 > } + + ~~~~~~ => Pos: (947 to 952) SpanInfo: {"start":889,"length":6} + >x *= 2 + >:=> (line 59, col 12) to (line 59, col 18) +-------------------------------- +65 > while (x < 10) { + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (953 to 973) SpanInfo: {"start":957,"length":14} + >while (x < 10) + >:=> (line 65, col 4) to (line 65, col 18) +-------------------------------- +66 > x++; + + ~~~~~~~~~~~~~ => Pos: (974 to 986) SpanInfo: {"start":982,"length":3} + >x++ + >:=> (line 66, col 8) to (line 66, col 11) +-------------------------------- +67 > } + + ~~~~~~ => Pos: (987 to 992) SpanInfo: {"start":982,"length":3} + >x++ + >:=> (line 66, col 8) to (line 66, col 11) +-------------------------------- +68 > do { + + ~~~~~~~~~ => Pos: (993 to 1001) SpanInfo: {"start":1010,"length":3} + >x-- + >:=> (line 69, col 8) to (line 69, col 11) +-------------------------------- +69 > x--; + + ~~~~~~~~~~~~~ => Pos: (1002 to 1014) SpanInfo: {"start":1010,"length":3} + >x-- + >:=> (line 69, col 8) to (line 69, col 11) +-------------------------------- +70 > } while (x > 4) + + ~~~~~ => Pos: (1015 to 1019) SpanInfo: {"start":1010,"length":3} + >x-- + >:=> (line 69, col 8) to (line 69, col 11) +70 > } while (x > 4) + + ~~~~~~~~~~~~~~~ => Pos: (1020 to 1034) SpanInfo: {"start":1021,"length":13} + >while (x > 4) + >:=> (line 70, col 6) to (line 70, col 19) +-------------------------------- +71 > x = y; + + ~~~~~~~~~~~ => Pos: (1035 to 1045) SpanInfo: {"start":1039,"length":5} + >x = y + >:=> (line 71, col 4) to (line 71, col 9) +-------------------------------- +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (1046 to 1083) SpanInfo: {"start":1050,"length":32} + >var z = (x == 1) ? x + 1 : x - 1 + >:=> (line 72, col 4) to (line 72, col 36) +-------------------------------- +73 > (x == 1) ? x + 1 : x - 1; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (1084 to 1113) SpanInfo: {"start":1088,"length":24} + >(x == 1) ? x + 1 : x - 1 + >:=> (line 73, col 4) to (line 73, col 28) +-------------------------------- +74 > x === 1; + + ~~~~~~~~~~~~~ => Pos: (1114 to 1126) SpanInfo: {"start":1118,"length":7} + >x === 1 + >:=> (line 74, col 4) to (line 74, col 11) +-------------------------------- +75 > x = z = 40; + + ~~~~~~~~~~~~~~~~ => Pos: (1127 to 1142) SpanInfo: {"start":1131,"length":10} + >x = z = 40 + >:=> (line 75, col 4) to (line 75, col 14) +-------------------------------- +76 > eval("y"); + + ~~~~~~~~~~~~~~~ => Pos: (1143 to 1157) SpanInfo: {"start":1147,"length":9} + >eval("y") + >:=> (line 76, col 4) to (line 76, col 13) +-------------------------------- +77 > return; + + ~~~~~~~~~~~~ => Pos: (1158 to 1169) SpanInfo: {"start":1162,"length":6} + >return + >:=> (line 77, col 4) to (line 77, col 10) +-------------------------------- +78 >} + + ~~ => Pos: (1170 to 1171) SpanInfo: {"start":1170,"length":1} + >} + >:=> (line 78, col 0) to (line 78, col 1) +-------------------------------- +79 >var b = function () { + + ~~~~~~~ => Pos: (1172 to 1178) SpanInfo: {"start":1172,"length":54} + >var b = function () { + > var x = 10; + > x = x + 1; + >} + >:=> (line 79, col 0) to (line 82, col 1) +79 >var b = function () { + + ~~~~~~~~~~~~~~~ => Pos: (1179 to 1193) SpanInfo: {"start":1198,"length":10} + >var x = 10 + >:=> (line 80, col 4) to (line 80, col 14) +-------------------------------- +80 > var x = 10; + + ~~~~~~~~~~~~~~~~ => Pos: (1194 to 1209) SpanInfo: {"start":1198,"length":10} + >var x = 10 + >:=> (line 80, col 4) to (line 80, col 14) +-------------------------------- +81 > x = x + 1; + + ~~~~~~~~~~~~~~~ => Pos: (1210 to 1224) SpanInfo: {"start":1214,"length":9} + >x = x + 1 + >:=> (line 81, col 4) to (line 81, col 13) +-------------------------------- +82 >}; + + ~~~ => Pos: (1225 to 1227) SpanInfo: {"start":1225,"length":1} + >} + >:=> (line 82, col 0) to (line 82, col 1) +-------------------------------- +83 >f(); + ~~~~ => Pos: (1228 to 1231) SpanInfo: {"start":1228,"length":3} + >f() + >:=> (line 83, col 0) to (line 83, col 3) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_switch.baseline b/tests/baselines/reference/bpSpan_switch.baseline new file mode 100644 index 00000000000..c0e2259784d --- /dev/null +++ b/tests/baselines/reference/bpSpan_switch.baseline @@ -0,0 +1,272 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >switch (x) { + + ~~~~~~~~~~~~~ => Pos: (12 to 24) SpanInfo: {"start":12,"length":10} + >switch (x) + >:=> (line 2, col 0) to (line 2, col 10) +-------------------------------- +3 > case 5: + + ~~~~~~~~~~~~ => Pos: (25 to 36) SpanInfo: {"start":45,"length":3} + >x++ + >:=> (line 4, col 8) to (line 4, col 11) +-------------------------------- +4 > x++; + + ~~~~~~~~~~~~~ => Pos: (37 to 49) SpanInfo: {"start":45,"length":3} + >x++ + >:=> (line 4, col 8) to (line 4, col 11) +-------------------------------- +5 > break; + + ~~~~~~~~~~~~~~~ => Pos: (50 to 64) SpanInfo: {"start":58,"length":5} + >break + >:=> (line 5, col 8) to (line 5, col 13) +-------------------------------- +6 > case 10: + + ~~~~~~~~~~~~~ => Pos: (65 to 77) SpanInfo: {"start":100,"length":3} + >x-- + >:=> (line 8, col 12) to (line 8, col 15) +-------------------------------- +7 > { + + ~~~~~~~~~~ => Pos: (78 to 87) SpanInfo: {"start":100,"length":3} + >x-- + >:=> (line 8, col 12) to (line 8, col 15) +-------------------------------- +8 > x--; + + ~~~~~~~~~~~~~~~~~ => Pos: (88 to 104) SpanInfo: {"start":100,"length":3} + >x-- + >:=> (line 8, col 12) to (line 8, col 15) +-------------------------------- +9 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (105 to 123) SpanInfo: {"start":117,"length":5} + >break + >:=> (line 9, col 12) to (line 9, col 17) +-------------------------------- +10 > } + + ~~~~~~~~~~ => Pos: (124 to 133) SpanInfo: {"start":117,"length":5} + >break + >:=> (line 9, col 12) to (line 9, col 17) +-------------------------------- +11 > default: + + ~~~~~~~~~~~~~ => Pos: (134 to 146) SpanInfo: {"start":155,"length":9} + >x = x *10 + >:=> (line 12, col 8) to (line 12, col 17) +-------------------------------- +12 > x = x *10; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (147 to 165) SpanInfo: {"start":155,"length":9} + >x = x *10 + >:=> (line 12, col 8) to (line 12, col 17) +-------------------------------- +13 >} + + ~~ => Pos: (166 to 167) SpanInfo: {"start":155,"length":9} + >x = x *10 + >:=> (line 12, col 8) to (line 12, col 17) +-------------------------------- +14 >switch (x) + + ~~~~~~~~~~~ => Pos: (168 to 178) SpanInfo: {"start":168,"length":10} + >switch (x) + >:=> (line 14, col 0) to (line 14, col 10) +-------------------------------- +15 >{ + + ~~ => Pos: (179 to 180) SpanInfo: {"start":201,"length":3} + >x++ + >:=> (line 17, col 8) to (line 17, col 11) +-------------------------------- +16 > case 5: + + ~~~~~~~~~~~~ => Pos: (181 to 192) SpanInfo: {"start":201,"length":3} + >x++ + >:=> (line 17, col 8) to (line 17, col 11) +-------------------------------- +17 > x++; + + ~~~~~~~~~~~~~ => Pos: (193 to 205) SpanInfo: {"start":201,"length":3} + >x++ + >:=> (line 17, col 8) to (line 17, col 11) +-------------------------------- +18 > break; + + ~~~~~~~~~~~~~~~ => Pos: (206 to 220) SpanInfo: {"start":214,"length":5} + >break + >:=> (line 18, col 8) to (line 18, col 13) +-------------------------------- +19 > case 10: + + ~~~~~~~~~~~~~ => Pos: (221 to 233) SpanInfo: {"start":256,"length":3} + >x-- + >:=> (line 21, col 12) to (line 21, col 15) +-------------------------------- +20 > { + + ~~~~~~~~~~ => Pos: (234 to 243) SpanInfo: {"start":256,"length":3} + >x-- + >:=> (line 21, col 12) to (line 21, col 15) +-------------------------------- +21 > x--; + + ~~~~~~~~~~~~~~~~~ => Pos: (244 to 260) SpanInfo: {"start":256,"length":3} + >x-- + >:=> (line 21, col 12) to (line 21, col 15) +-------------------------------- +22 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (261 to 279) SpanInfo: {"start":273,"length":5} + >break + >:=> (line 22, col 12) to (line 22, col 17) +-------------------------------- +23 > } + + ~~~~~~~~~~ => Pos: (280 to 289) SpanInfo: {"start":273,"length":5} + >break + >:=> (line 22, col 12) to (line 22, col 17) +-------------------------------- +24 > default: + + ~~~~~~~~~~~~~ => Pos: (290 to 302) SpanInfo: {"start":325,"length":10} + >x = x * 10 + >:=> (line 26, col 12) to (line 26, col 22) +-------------------------------- +25 > { + + ~~~~~~~~~~ => Pos: (303 to 312) SpanInfo: {"start":325,"length":10} + >x = x * 10 + >:=> (line 26, col 12) to (line 26, col 22) +-------------------------------- +26 > x = x * 10; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (313 to 336) SpanInfo: {"start":325,"length":10} + >x = x * 10 + >:=> (line 26, col 12) to (line 26, col 22) +-------------------------------- +27 > } + + ~~~~~~~~~~ => Pos: (337 to 346) SpanInfo: {"start":325,"length":10} + >x = x * 10 + >:=> (line 26, col 12) to (line 26, col 22) +-------------------------------- +28 >} + + ~~ => Pos: (347 to 348) SpanInfo: {"start":325,"length":10} + >x = x * 10 + >:=> (line 26, col 12) to (line 26, col 22) +-------------------------------- +29 >switch ((function foo() { + + ~~~~~~~~ => Pos: (349 to 356) SpanInfo: {"start":349,"length":50} + >switch ((function foo() { + > return x * 30; + >})()) + >:=> (line 29, col 0) to (line 31, col 5) +29 >switch ((function foo() { + + ~ => Pos: (357 to 357) SpanInfo: {"start":357,"length":41} + >(function foo() { + > return x * 30; + >})() + >:=> (line 29, col 8) to (line 31, col 4) +29 >switch ((function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (358 to 374) SpanInfo: {"start":379,"length":13} + >return x * 30 + >:=> (line 30, col 4) to (line 30, col 17) +-------------------------------- +30 > return x * 30; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (375 to 393) SpanInfo: {"start":379,"length":13} + >return x * 30 + >:=> (line 30, col 4) to (line 30, col 17) +-------------------------------- +31 >})()) { + + ~ => Pos: (394 to 394) SpanInfo: {"start":394,"length":1} + >} + >:=> (line 31, col 0) to (line 31, col 1) +31 >})()) { + + ~~~ => Pos: (395 to 397) SpanInfo: {"start":357,"length":41} + >(function foo() { + > return x * 30; + >})() + >:=> (line 29, col 8) to (line 31, col 4) +31 >})()) { + + ~ => Pos: (398 to 398) SpanInfo: {"start":349,"length":50} + >switch ((function foo() { + > return x * 30; + >})()) + >:=> (line 29, col 0) to (line 31, col 5) +31 >})()) { + + ~~~ => Pos: (399 to 401) SpanInfo: {"start":466,"length":3} + >x++ + >:=> (line 35, col 8) to (line 35, col 11) +-------------------------------- +32 > case (function bar() { + + ~~~~~~~~ => Pos: (402 to 409) SpanInfo: {"start":466,"length":3} + >x++ + >:=> (line 35, col 8) to (line 35, col 11) +32 > case (function bar() { + + ~~ => Pos: (410 to 411) SpanInfo: {"start":411,"length":45} + >(function bar() { + > return 30; + > })() + >:=> (line 32, col 9) to (line 34, col 8) +32 > case (function bar() { + + ~~~~~~~~~~~~~~~~~ => Pos: (412 to 428) SpanInfo: {"start":437,"length":9} + >return 30 + >:=> (line 33, col 8) to (line 33, col 17) +-------------------------------- +33 > return 30; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (429 to 447) SpanInfo: {"start":437,"length":9} + >return 30 + >:=> (line 33, col 8) to (line 33, col 17) +-------------------------------- +34 > })(): + + ~~~~~ => Pos: (448 to 452) SpanInfo: {"start":452,"length":1} + >} + >:=> (line 34, col 4) to (line 34, col 5) +34 > })(): + + ~~~ => Pos: (453 to 455) SpanInfo: {"start":411,"length":45} + >(function bar() { + > return 30; + > })() + >:=> (line 32, col 9) to (line 34, col 8) +34 > })(): + + ~~ => Pos: (456 to 457) SpanInfo: {"start":466,"length":3} + >x++ + >:=> (line 35, col 8) to (line 35, col 11) +-------------------------------- +35 > x++; + + ~~~~~~~~~~~~~ => Pos: (458 to 470) SpanInfo: {"start":466,"length":3} + >x++ + >:=> (line 35, col 8) to (line 35, col 11) +-------------------------------- +36 >} + ~ => Pos: (471 to 471) SpanInfo: {"start":466,"length":3} + >x++ + >:=> (line 35, col 8) to (line 35, col 11) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_tryCatchFinally.baseline b/tests/baselines/reference/bpSpan_tryCatchFinally.baseline new file mode 100644 index 00000000000..5a9e569f403 --- /dev/null +++ b/tests/baselines/reference/bpSpan_tryCatchFinally.baseline @@ -0,0 +1,223 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >try { + + ~~~~~~ => Pos: (12 to 17) SpanInfo: {"start":22,"length":9} + >x = x + 1 + >:=> (line 3, col 4) to (line 3, col 13) +-------------------------------- +3 > x = x + 1; + + ~~~~~~~~~~~~~~~ => Pos: (18 to 32) SpanInfo: {"start":22,"length":9} + >x = x + 1 + >:=> (line 3, col 4) to (line 3, col 13) +-------------------------------- +4 >} catch (e) { + + ~ => Pos: (33 to 33) SpanInfo: {"start":22,"length":9} + >x = x + 1 + >:=> (line 3, col 4) to (line 3, col 13) +4 >} catch (e) { + + ~~~~~~~~~~~~~ => Pos: (34 to 46) SpanInfo: {"start":51,"length":9} + >x = x - 1 + >:=> (line 5, col 4) to (line 5, col 13) +-------------------------------- +5 > x = x - 1; + + ~~~~~~~~~~~~~~~ => Pos: (47 to 61) SpanInfo: {"start":51,"length":9} + >x = x - 1 + >:=> (line 5, col 4) to (line 5, col 13) +-------------------------------- +6 >} finally { + + ~ => Pos: (62 to 62) SpanInfo: {"start":51,"length":9} + >x = x - 1 + >:=> (line 5, col 4) to (line 5, col 13) +6 >} finally { + + ~~~~~~~~~~~ => Pos: (63 to 73) SpanInfo: {"start":78,"length":10} + >x = x * 10 + >:=> (line 7, col 4) to (line 7, col 14) +-------------------------------- +7 > x = x * 10; + + ~~~~~~~~~~~~~~~~ => Pos: (74 to 89) SpanInfo: {"start":78,"length":10} + >x = x * 10 + >:=> (line 7, col 4) to (line 7, col 14) +-------------------------------- +8 >} + + ~~ => Pos: (90 to 91) SpanInfo: {"start":78,"length":10} + >x = x * 10 + >:=> (line 7, col 4) to (line 7, col 14) +-------------------------------- +9 >try + + ~~~~ => Pos: (92 to 95) SpanInfo: {"start":102,"length":9} + >x = x + 1 + >:=> (line 11, col 4) to (line 11, col 13) +-------------------------------- +10 >{ + + ~~ => Pos: (96 to 97) SpanInfo: {"start":102,"length":9} + >x = x + 1 + >:=> (line 11, col 4) to (line 11, col 13) +-------------------------------- +11 > x = x + 1; + + ~~~~~~~~~~~~~~~ => Pos: (98 to 112) SpanInfo: {"start":102,"length":9} + >x = x + 1 + >:=> (line 11, col 4) to (line 11, col 13) +-------------------------------- +12 > throw new Error(); + + ~~~~~~~~~ => Pos: (113 to 121) SpanInfo: {"start":117,"length":17} + >throw new Error() + >:=> (line 12, col 4) to (line 12, col 21) +12 > throw new Error(); + + ~~~~~~~~~~~~~~ => Pos: (122 to 135) SpanInfo: {"start":123,"length":11} + >new Error() + >:=> (line 12, col 10) to (line 12, col 21) +-------------------------------- +13 >} + + ~~ => Pos: (136 to 137) SpanInfo: {"start":117,"length":17} + >throw new Error() + >:=> (line 12, col 4) to (line 12, col 21) +-------------------------------- +14 >catch (e) + + ~~~~~~~~~~ => Pos: (138 to 147) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +15 >{ + + ~~ => Pos: (148 to 149) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +16 > x = x - 1; + + ~~~~~~~~~~~~~~~ => Pos: (150 to 164) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +17 >} + + ~~ => Pos: (165 to 166) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +18 >finally + + ~~~~~~~~ => Pos: (167 to 174) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) +-------------------------------- +19 >{ + + ~~ => Pos: (175 to 176) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) +-------------------------------- +20 > x = x * 10; + + ~~~~~~~~~~~~~~~~ => Pos: (177 to 192) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) +-------------------------------- +21 >} + + ~~ => Pos: (193 to 194) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) +-------------------------------- +22 >try { + + ~~~~~~ => Pos: (195 to 200) SpanInfo: {"start":205,"length":65} + >throw (function foo() { + > new Error(x.toString()); + > })() + >:=> (line 23, col 4) to (line 25, col 8) +-------------------------------- +23 > throw (function foo() { + + ~~~~~~~~~ => Pos: (201 to 209) SpanInfo: {"start":205,"length":65} + >throw (function foo() { + > new Error(x.toString()); + > })() + >:=> (line 23, col 4) to (line 25, col 8) +23 > throw (function foo() { + + ~~ => Pos: (210 to 211) SpanInfo: {"start":211,"length":59} + >(function foo() { + > new Error(x.toString()); + > })() + >:=> (line 23, col 10) to (line 25, col 8) +23 > throw (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (212 to 228) SpanInfo: {"start":237,"length":23} + >new Error(x.toString()) + >:=> (line 24, col 8) to (line 24, col 31) +-------------------------------- +24 > new Error(x.toString()); + + ~~~~~~~~~~~~~~~~~~ => Pos: (229 to 246) SpanInfo: {"start":237,"length":23} + >new Error(x.toString()) + >:=> (line 24, col 8) to (line 24, col 31) +24 > new Error(x.toString()); + + ~~~~~~~~~~~~ => Pos: (247 to 258) SpanInfo: {"start":247,"length":12} + >x.toString() + >:=> (line 24, col 18) to (line 24, col 30) +24 > new Error(x.toString()); + + ~~~ => Pos: (259 to 261) SpanInfo: {"start":237,"length":23} + >new Error(x.toString()) + >:=> (line 24, col 8) to (line 24, col 31) +-------------------------------- +25 > })(); + + ~~~~~ => Pos: (262 to 266) SpanInfo: {"start":266,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +25 > })(); + + ~~~~~ => Pos: (267 to 271) SpanInfo: {"start":211,"length":59} + >(function foo() { + > new Error(x.toString()); + > })() + >:=> (line 23, col 10) to (line 25, col 8) +-------------------------------- +26 >} + + ~~ => Pos: (272 to 273) SpanInfo: {"start":205,"length":65} + >throw (function foo() { + > new Error(x.toString()); + > })() + >:=> (line 23, col 4) to (line 25, col 8) +-------------------------------- +27 >finally { + + ~~~~~~~~~~ => Pos: (274 to 283) SpanInfo: {"start":288,"length":3} + >x++ + >:=> (line 28, col 4) to (line 28, col 7) +-------------------------------- +28 > x++; + + ~~~~~~~~~ => Pos: (284 to 292) SpanInfo: {"start":288,"length":3} + >x++ + >:=> (line 28, col 4) to (line 28, col 7) +-------------------------------- +29 >} + ~ => Pos: (293 to 293) SpanInfo: {"start":288,"length":3} + >x++ + >:=> (line 28, col 4) to (line 28, col 7) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_typeAssertionExpressions.baseline b/tests/baselines/reference/bpSpan_typeAssertionExpressions.baseline new file mode 100644 index 00000000000..c04ddb8503b --- /dev/null +++ b/tests/baselines/reference/bpSpan_typeAssertionExpressions.baseline @@ -0,0 +1,82 @@ + +1 >class Greeter { + + ~~~~~~~~~~~~~~~~ => Pos: (0 to 15) SpanInfo: {"start":0,"length":17} + >class Greeter { + >} + >:=> (line 1, col 0) to (line 2, col 1) +-------------------------------- +2 >} + + ~~ => Pos: (16 to 17) SpanInfo: {"start":16,"length":1} + >} + >:=> (line 2, col 0) to (line 2, col 1) +-------------------------------- +3 >var a = new Greeter(); + + ~~~~~~~ => Pos: (18 to 24) SpanInfo: {"start":18,"length":30} + >var a = new Greeter() + >:=> (line 3, col 0) to (line 3, col 30) +3 >var a = new Greeter(); + + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (25 to 49) SpanInfo: {"start":35,"length":13} + >new Greeter() + >:=> (line 3, col 17) to (line 3, col 30) +-------------------------------- +4 >a = ( new Greeter()); + + ~~~~~ => Pos: (50 to 54) SpanInfo: {"start":50,"length":29} + >a = ( new Greeter()) + >:=> (line 4, col 0) to (line 4, col 29) +4 >a = ( new Greeter()); + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (55 to 77) SpanInfo: {"start":65,"length":13} + >new Greeter() + >:=> (line 4, col 15) to (line 4, col 28) +4 >a = ( new Greeter()); + + ~~~ => Pos: (78 to 80) SpanInfo: {"start":50,"length":29} + >a = ( new Greeter()) + >:=> (line 4, col 0) to (line 4, col 29) +-------------------------------- +5 >a = (function foo() { + + ~~~ => Pos: (81 to 83) SpanInfo: {"start":81,"length":61} + >a = (function foo() { + > return new Greeter(); + >})() + >:=> (line 5, col 0) to (line 7, col 4) +5 >a = (function foo() { + + ~~~~~~~~~~~ => Pos: (84 to 94) SpanInfo: {"start":94,"length":48} + >(function foo() { + > return new Greeter(); + >})() + >:=> (line 5, col 13) to (line 7, col 4) +5 >a = (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (95 to 111) SpanInfo: {"start":116,"length":20} + >return new Greeter() + >:=> (line 6, col 4) to (line 6, col 24) +-------------------------------- +6 > return new Greeter(); + + ~~~~~~~~~~ => Pos: (112 to 121) SpanInfo: {"start":116,"length":20} + >return new Greeter() + >:=> (line 6, col 4) to (line 6, col 24) +6 > return new Greeter(); + + ~~~~~~~~~~~~~~~~ => Pos: (122 to 137) SpanInfo: {"start":123,"length":13} + >new Greeter() + >:=> (line 6, col 11) to (line 6, col 24) +-------------------------------- +7 >})(); + ~ => Pos: (138 to 138) SpanInfo: {"start":138,"length":1} + >} + >:=> (line 7, col 0) to (line 7, col 1) +7 >})(); + ~~~~ => Pos: (139 to 142) SpanInfo: {"start":94,"length":48} + >(function foo() { + > return new Greeter(); + >})() + >:=> (line 5, col 13) to (line 7, col 4) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_unaryExpressions.baseline b/tests/baselines/reference/bpSpan_unaryExpressions.baseline new file mode 100644 index 00000000000..2ad1191cf95 --- /dev/null +++ b/tests/baselines/reference/bpSpan_unaryExpressions.baseline @@ -0,0 +1,74 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >var y = 20; + + ~~~~~~~~~~~~ => Pos: (12 to 23) SpanInfo: {"start":12,"length":10} + >var y = 20 + >:=> (line 2, col 0) to (line 2, col 10) +-------------------------------- +3 >x++; + + ~~~~~ => Pos: (24 to 28) SpanInfo: {"start":24,"length":3} + >x++ + >:=> (line 3, col 0) to (line 3, col 3) +-------------------------------- +4 >y--; + + ~~~~~ => Pos: (29 to 33) SpanInfo: {"start":29,"length":3} + >y-- + >:=> (line 4, col 0) to (line 4, col 3) +-------------------------------- +5 >typeof (function foo() { + + ~~~~~~ => Pos: (34 to 39) SpanInfo: {"start":34,"length":43} + >typeof (function foo() { + > return y; + >})() + >:=> (line 5, col 0) to (line 7, col 4) +5 >typeof (function foo() { + + ~~ => Pos: (40 to 41) SpanInfo: {"start":41,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 5, col 7) to (line 7, col 4) +5 >typeof (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (42 to 58) SpanInfo: {"start":63,"length":8} + >return y + >:=> (line 6, col 4) to (line 6, col 12) +-------------------------------- +6 > return y; + + ~~~~~~~~~~~~~~ => Pos: (59 to 72) SpanInfo: {"start":63,"length":8} + >return y + >:=> (line 6, col 4) to (line 6, col 12) +-------------------------------- +7 >})(); + + ~ => Pos: (73 to 73) SpanInfo: {"start":73,"length":1} + >} + >:=> (line 7, col 0) to (line 7, col 1) +7 >})(); + + ~~~~~ => Pos: (74 to 78) SpanInfo: {"start":41,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 5, col 7) to (line 7, col 4) +-------------------------------- +8 >++x; + + ~~~~~ => Pos: (79 to 83) SpanInfo: {"start":79,"length":3} + >++x + >:=> (line 8, col 0) to (line 8, col 3) +-------------------------------- +9 >++y; + ~~~~ => Pos: (84 to 87) SpanInfo: {"start":84,"length":3} + >++y + >:=> (line 9, col 0) to (line 9, col 3) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_variables.baseline b/tests/baselines/reference/bpSpan_variables.baseline new file mode 100644 index 00000000000..1904c34b835 --- /dev/null +++ b/tests/baselines/reference/bpSpan_variables.baseline @@ -0,0 +1,90 @@ + +1 >var a = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var a = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >var b; + + ~~~~~~~ => Pos: (12 to 18) SpanInfo: undefined +-------------------------------- +3 >var c = 10, d, e; + + ~~~~~~~~~~~~~~~~~~ => Pos: (19 to 36) SpanInfo: {"start":19,"length":10} + >var c = 10 + >:=> (line 3, col 0) to (line 3, col 10) +-------------------------------- +4 >var c2, d2 = 10; + + ~~~~~~~ => Pos: (37 to 43) SpanInfo: undefined +4 >var c2, d2 = 10; + + ~~~~~~~~~~ => Pos: (44 to 53) SpanInfo: {"start":45,"length":7} + >d2 = 10 + >:=> (line 4, col 8) to (line 4, col 15) +-------------------------------- +5 >module m { + + ~~~~~~~~~~~ => Pos: (54 to 64) SpanInfo: {"start":54,"length":146} + >module m { + > var x1; + > var x2 = 10, x3 = 10; + > var x4, x5; + > export var xx1; + > export var xx2 = 10, xx3 = 10; + > export var xx4, xx5; + >} + >:=> (line 5, col 0) to (line 12, col 1) +-------------------------------- +6 > var x1; + + ~~~~~~~~~~~~ => Pos: (65 to 76) SpanInfo: undefined +-------------------------------- +7 > var x2 = 10, x3 = 10; + + ~~~~~~~~~~~~~~~~ => Pos: (77 to 92) SpanInfo: {"start":81,"length":11} + >var x2 = 10 + >:=> (line 7, col 4) to (line 7, col 15) +7 > var x2 = 10, x3 = 10; + + ~~~~~~~~~~ => Pos: (93 to 102) SpanInfo: {"start":94,"length":7} + >x3 = 10 + >:=> (line 7, col 17) to (line 7, col 24) +-------------------------------- +8 > var x4, x5; + + ~~~~~~~~~~~~~~~~ => Pos: (103 to 118) SpanInfo: undefined +-------------------------------- +9 > export var xx1; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (119 to 138) SpanInfo: {"start":123,"length":14} + >export var xx1 + >:=> (line 9, col 4) to (line 9, col 18) +-------------------------------- +10 > export var xx2 = 10, xx3 = 10; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (139 to 162) SpanInfo: {"start":143,"length":19} + >export var xx2 = 10 + >:=> (line 10, col 4) to (line 10, col 23) +10 > export var xx2 = 10, xx3 = 10; + + ~~~~~~~~~~~ => Pos: (163 to 173) SpanInfo: {"start":164,"length":8} + >xx3 = 10 + >:=> (line 10, col 25) to (line 10, col 33) +-------------------------------- +11 > export var xx4, xx5; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (174 to 192) SpanInfo: {"start":178,"length":14} + >export var xx4 + >:=> (line 11, col 4) to (line 11, col 18) +11 > export var xx4, xx5; + + ~~~~~~ => Pos: (193 to 198) SpanInfo: {"start":194,"length":3} + >xx5 + >:=> (line 11, col 20) to (line 11, col 23) +-------------------------------- +12 >} + ~ => Pos: (199 to 199) SpanInfo: {"start":199,"length":1} + >} + >:=> (line 12, col 0) to (line 12, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_while.baseline b/tests/baselines/reference/bpSpan_while.baseline new file mode 100644 index 00000000000..91632b78009 --- /dev/null +++ b/tests/baselines/reference/bpSpan_while.baseline @@ -0,0 +1,133 @@ + +1 >var a = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var a = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >while (a == 10) { + + ~~~~~~~~~~~~~~~~~~ => Pos: (12 to 29) SpanInfo: {"start":12,"length":15} + >while (a == 10) + >:=> (line 2, col 0) to (line 2, col 15) +-------------------------------- +3 > a++; + + ~~~~~~~~~ => Pos: (30 to 38) SpanInfo: {"start":34,"length":3} + >a++ + >:=> (line 3, col 4) to (line 3, col 7) +-------------------------------- +4 >} + + ~~ => Pos: (39 to 40) SpanInfo: {"start":34,"length":3} + >a++ + >:=> (line 3, col 4) to (line 3, col 7) +-------------------------------- +5 >while (a == 10) + + ~~~~~~~~~~~~~~~~~ => Pos: (41 to 57) SpanInfo: {"start":41,"length":15} + >while (a == 10) + >:=> (line 5, col 0) to (line 5, col 15) +-------------------------------- +6 >{ + + ~~ => Pos: (58 to 59) SpanInfo: {"start":64,"length":3} + >a++ + >:=> (line 7, col 4) to (line 7, col 7) +-------------------------------- +7 > a++; + + ~~~~~~~~~ => Pos: (60 to 68) SpanInfo: {"start":64,"length":3} + >a++ + >:=> (line 7, col 4) to (line 7, col 7) +-------------------------------- +8 >} + + ~~ => Pos: (69 to 70) SpanInfo: {"start":64,"length":3} + >a++ + >:=> (line 7, col 4) to (line 7, col 7) +-------------------------------- +9 >while (a == 10) a++; + + ~~~~~~~~~~~~~~~ => Pos: (71 to 85) SpanInfo: {"start":71,"length":15} + >while (a == 10) + >:=> (line 9, col 0) to (line 9, col 15) +9 >while (a == 10) a++; + + ~~~~~~~ => Pos: (86 to 92) SpanInfo: {"start":88,"length":3} + >a++ + >:=> (line 9, col 17) to (line 9, col 20) +-------------------------------- +10 >while (a == 10) + + ~~~~~~~~~~~~~~~~~ => Pos: (93 to 109) SpanInfo: {"start":93,"length":15} + >while (a == 10) + >:=> (line 10, col 0) to (line 10, col 15) +-------------------------------- +11 > a++; + + ~~~~~~~~~ => Pos: (110 to 118) SpanInfo: {"start":114,"length":3} + >a++ + >:=> (line 11, col 4) to (line 11, col 7) +-------------------------------- +12 >while ((function () { + + ~~~~~~~ => Pos: (119 to 125) SpanInfo: {"start":119,"length":52} + >while ((function () { + > return 30 * a; + >})() !== a) + >:=> (line 12, col 0) to (line 14, col 11) +12 >while ((function () { + + ~ => Pos: (126 to 126) SpanInfo: {"start":126,"length":38} + >(function () { + > return 30 * a; + >})() + >:=> (line 12, col 7) to (line 14, col 4) +12 >while ((function () { + + ~~~~~~~~~~~~~~ => Pos: (127 to 140) SpanInfo: {"start":145,"length":13} + >return 30 * a + >:=> (line 13, col 4) to (line 13, col 17) +-------------------------------- +13 > return 30 * a; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (141 to 159) SpanInfo: {"start":145,"length":13} + >return 30 * a + >:=> (line 13, col 4) to (line 13, col 17) +-------------------------------- +14 >})() !== a) { + + ~ => Pos: (160 to 160) SpanInfo: {"start":160,"length":1} + >} + >:=> (line 14, col 0) to (line 14, col 1) +14 >})() !== a) { + + ~~~ => Pos: (161 to 163) SpanInfo: {"start":126,"length":38} + >(function () { + > return 30 * a; + >})() + >:=> (line 12, col 7) to (line 14, col 4) +14 >})() !== a) { + + ~~~~~~~ => Pos: (164 to 170) SpanInfo: {"start":119,"length":52} + >while ((function () { + > return 30 * a; + >})() !== a) + >:=> (line 12, col 0) to (line 14, col 11) +14 >})() !== a) { + + ~~~ => Pos: (171 to 173) SpanInfo: {"start":178,"length":3} + >a-- + >:=> (line 15, col 4) to (line 15, col 7) +-------------------------------- +15 > a--; + + ~~~~~~~~~ => Pos: (174 to 182) SpanInfo: {"start":178,"length":3} + >a-- + >:=> (line 15, col 4) to (line 15, col 7) +-------------------------------- +16 >} + ~ => Pos: (183 to 183) SpanInfo: {"start":178,"length":3} + >a-- + >:=> (line 15, col 4) to (line 15, col 7) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_with.baseline b/tests/baselines/reference/bpSpan_with.baseline new file mode 100644 index 00000000000..d4a00e7a3aa --- /dev/null +++ b/tests/baselines/reference/bpSpan_with.baseline @@ -0,0 +1,21 @@ + +1 >var obj: string; + + ~~~~~~~~~~~~~~~~~ => Pos: (0 to 16) SpanInfo: undefined +-------------------------------- +2 >with (obj) { + + ~~~~~~~~~~~~~ => Pos: (17 to 29) SpanInfo: {"start":34,"length":6} + >x = 10 + >:=> (line 3, col 4) to (line 3, col 10) +-------------------------------- +3 > x = 10; + + ~~~~~~~~~~~~ => Pos: (30 to 41) SpanInfo: {"start":34,"length":6} + >x = 10 + >:=> (line 3, col 4) to (line 3, col 10) +-------------------------------- +4 >} + ~ => Pos: (42 to 42) SpanInfo: {"start":34,"length":6} + >x = 10 + >:=> (line 3, col 4) to (line 3, col 10) \ No newline at end of file diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.errors.txt b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.errors.txt deleted file mode 100644 index 2e63bf0a795..00000000000 --- a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.errors.txt +++ /dev/null @@ -1,215 +0,0 @@ -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(32,12): error TS2365: Operator '<' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(40,12): error TS2365: Operator '<' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(49,12): error TS2365: Operator '>' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(57,12): error TS2365: Operator '>' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(66,12): error TS2365: Operator '<=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(74,12): error TS2365: Operator '<=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(83,12): error TS2365: Operator '>=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(91,12): error TS2365: Operator '>=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(100,12): error TS2365: Operator '==' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(108,12): error TS2365: Operator '==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(117,12): error TS2365: Operator '!=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(125,12): error TS2365: Operator '!=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(134,12): error TS2365: Operator '===' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(142,12): error TS2365: Operator '===' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(151,12): error TS2365: Operator '!==' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(159,12): error TS2365: Operator '!==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - - -==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts (16 errors) ==== - class Base { - public a: string; - } - - class Derived extends Base { - public b: string; - } - - var a1: { fn(x: T): T }; - var b1: { fn(x: string): string }; - - var a2: { fn(x: T): T }; - var b2: { fn(x: string, y: number): string }; - - var a3: { fn(x: T, y: U): T }; - var b3: { fn(x: string, y: number): string }; - - var a4: { fn(x?: T): T }; - var b4: { fn(x?: string): string }; - - var a5: { fn(...x: T[]): T }; - var b5: { fn(...x: string[]): string }; - - var a6: { fn(x: T, y: T): T }; - var b6: { fn(x: string, y: number): {} }; - - //var a7: { fn(x: T, y: U): T }; - var b7: { fn(x: Base, y: Derived): Base }; - - // operator < - var r1a1 = a1 < b1; - var r1a2 = a2 < b2; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r1a3 = a3 < b3; - var r1a4 = a4 < b4; - var r1a5 = a5 < b5; - var r1a6 = a6 < b6; - //var r1a7 = a7 < b7; - - var r1b1 = b1 < a1; - var r1b2 = b2 < a2; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r1b3 = b3 < a3; - var r1b4 = b4 < a4; - var r1b5 = b5 < a5; - var r1b6 = b6 < a6; - //var r1b7 = b7 < a7; - - // operator > - var r2a1 = a1 > b1; - var r2a2 = a2 > b2; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r2a3 = a3 > b3; - var r2a4 = a4 > b4; - var r2a5 = a5 > b5; - var r2a6 = a6 > b6; - //var r2a7 = a7 > b7; - - var r2b1 = b1 > a1; - var r2b2 = b2 > a2; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r2b3 = b3 > a3; - var r2b4 = b4 > a4; - var r2b5 = b5 > a5; - var r2b6 = b6 > a6; - //var r2b7 = b7 > a7; - - // operator <= - var r3a1 = a1 <= b1; - var r3a2 = a2 <= b2; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r3a3 = a3 <= b3; - var r3a4 = a4 <= b4; - var r3a5 = a5 <= b5; - var r3a6 = a6 <= b6; - //var r3a7 = a7 <= b7; - - var r3b1 = b1 <= a1; - var r3b2 = b2 <= a2; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r3b3 = b3 <= a3; - var r3b4 = b4 <= a4; - var r3b5 = b5 <= a5; - var r3b6 = b6 <= a6; - //var r3b7 = b7 <= a7; - - // operator >= - var r4a1 = a1 >= b1; - var r4a2 = a2 >= b2; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r4a3 = a3 >= b3; - var r4a4 = a4 >= b4; - var r4a5 = a5 >= b5; - var r4a6 = a6 >= b6; - //var r4a7 = a7 >= b7; - - var r4b1 = b1 >= a1; - var r4b2 = b2 >= a2; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r4b3 = b3 >= a3; - var r4b4 = b4 >= a4; - var r4b5 = b5 >= a5; - var r4b6 = b6 >= a6; - //var r4b7 = b7 >= a7; - - // operator == - var r5a1 = a1 == b1; - var r5a2 = a2 == b2; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r5a3 = a3 == b3; - var r5a4 = a4 == b4; - var r5a5 = a5 == b5; - var r5a6 = a6 == b6; - //var r5a7 = a7 == b7; - - var r5b1 = b1 == a1; - var r5b2 = b2 == a2; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r5b3 = b3 == a3; - var r5b4 = b4 == a4; - var r5b5 = b5 == a5; - var r5b6 = b6 == a6; - //var r5b7 = b7 == a7; - - // operator != - var r6a1 = a1 != b1; - var r6a2 = a2 != b2; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r6a3 = a3 != b3; - var r6a4 = a4 != b4; - var r6a5 = a5 != b5; - var r6a6 = a6 != b6; - //var r6a7 = a7 != b7; - - var r6b1 = b1 != a1; - var r6b2 = b2 != a2; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r6b3 = b3 != a3; - var r6b4 = b4 != a4; - var r6b5 = b5 != a5; - var r6b6 = b6 != a6; - //var r6b7 = b7 != a7; - - // operator === - var r7a1 = a1 === b1; - var r7a2 = a2 === b2; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r7a3 = a3 === b3; - var r7a4 = a4 === b4; - var r7a5 = a5 === b5; - var r7a6 = a6 === b6; - //var r7a7 = a7 === b7; - - var r7b1 = b1 === a1; - var r7b2 = b2 === a2; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r7b3 = b3 === a3; - var r7b4 = b4 === a4; - var r7b5 = b5 === a5; - var r7b6 = b6 === a6; - //var r7b7 = b7 === a7; - - // operator !== - var r8a1 = a1 !== b1; - var r8a2 = a2 !== b2; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r8a3 = a3 !== b3; - var r8a4 = a4 !== b4; - var r8a5 = a5 !== b5; - var r8a6 = a6 !== b6; - //var r8a7 = a7 !== b7; - - var r8b1 = b1 !== a1; - var r8b2 = b2 !== a2; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r8b3 = b3 !== a3; - var r8b4 = b4 !== a4; - var r8b5 = b5 !== a5; - var r8b6 = b6 !== a6; - //var r8b7 = b7 !== a7; \ No newline at end of file diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.types b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.types new file mode 100644 index 00000000000..c3f0d96e839 --- /dev/null +++ b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.types @@ -0,0 +1,727 @@ +=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts === +class Base { +>Base : Base + + public a: string; +>a : string +} + +class Derived extends Base { +>Derived : Derived +>Base : Base + + public b: string; +>b : string +} + +var a1: { fn(x: T): T }; +>a1 : { fn(x: T): T; } +>fn : (x: T) => T +>T : T +>x : T +>T : T +>T : T + +var b1: { fn(x: string): string }; +>b1 : { fn(x: string): string; } +>fn : (x: string) => string +>x : string + +var a2: { fn(x: T): T }; +>a2 : { fn(x: T): T; } +>fn : (x: T) => T +>T : T +>x : T +>T : T +>T : T + +var b2: { fn(x: string, y: number): string }; +>b2 : { fn(x: string, y: number): string; } +>fn : (x: string, y: number) => string +>x : string +>y : number + +var a3: { fn(x: T, y: U): T }; +>a3 : { fn(x: T, y: U): T; } +>fn : (x: T, y: U) => T +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>T : T + +var b3: { fn(x: string, y: number): string }; +>b3 : { fn(x: string, y: number): string; } +>fn : (x: string, y: number) => string +>x : string +>y : number + +var a4: { fn(x?: T): T }; +>a4 : { fn(x?: T): T; } +>fn : (x?: T) => T +>T : T +>x : T +>T : T +>T : T + +var b4: { fn(x?: string): string }; +>b4 : { fn(x?: string): string; } +>fn : (x?: string) => string +>x : string + +var a5: { fn(...x: T[]): T }; +>a5 : { fn(...x: T[]): T; } +>fn : (...x: T[]) => T +>T : T +>x : T[] +>T : T +>T : T + +var b5: { fn(...x: string[]): string }; +>b5 : { fn(...x: string[]): string; } +>fn : (...x: string[]) => string +>x : string[] + +var a6: { fn(x: T, y: T): T }; +>a6 : { fn(x: T, y: T): T; } +>fn : (x: T, y: T) => T +>T : T +>x : T +>T : T +>y : T +>T : T +>T : T + +var b6: { fn(x: string, y: number): {} }; +>b6 : { fn(x: string, y: number): {}; } +>fn : (x: string, y: number) => {} +>x : string +>y : number + +//var a7: { fn(x: T, y: U): T }; +var b7: { fn(x: Base, y: Derived): Base }; +>b7 : { fn(x: Base, y: Derived): Base; } +>fn : (x: Base, y: Derived) => Base +>x : Base +>Base : Base +>y : Derived +>Derived : Derived +>Base : Base + +// operator < +var r1a1 = a1 < b1; +>r1a1 : boolean +>a1 < b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r1a2 = a2 < b2; +>r1a2 : boolean +>a2 < b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r1a3 = a3 < b3; +>r1a3 : boolean +>a3 < b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r1a4 = a4 < b4; +>r1a4 : boolean +>a4 < b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r1a5 = a5 < b5; +>r1a5 : boolean +>a5 < b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r1a6 = a6 < b6; +>r1a6 : boolean +>a6 < b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r1a7 = a7 < b7; + +var r1b1 = b1 < a1; +>r1b1 : boolean +>b1 < a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r1b2 = b2 < a2; +>r1b2 : boolean +>b2 < a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r1b3 = b3 < a3; +>r1b3 : boolean +>b3 < a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r1b4 = b4 < a4; +>r1b4 : boolean +>b4 < a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r1b5 = b5 < a5; +>r1b5 : boolean +>b5 < a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r1b6 = b6 < a6; +>r1b6 : boolean +>b6 < a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r1b7 = b7 < a7; + +// operator > +var r2a1 = a1 > b1; +>r2a1 : boolean +>a1 > b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r2a2 = a2 > b2; +>r2a2 : boolean +>a2 > b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r2a3 = a3 > b3; +>r2a3 : boolean +>a3 > b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r2a4 = a4 > b4; +>r2a4 : boolean +>a4 > b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r2a5 = a5 > b5; +>r2a5 : boolean +>a5 > b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r2a6 = a6 > b6; +>r2a6 : boolean +>a6 > b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r2a7 = a7 > b7; + +var r2b1 = b1 > a1; +>r2b1 : boolean +>b1 > a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r2b2 = b2 > a2; +>r2b2 : boolean +>b2 > a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r2b3 = b3 > a3; +>r2b3 : boolean +>b3 > a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r2b4 = b4 > a4; +>r2b4 : boolean +>b4 > a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r2b5 = b5 > a5; +>r2b5 : boolean +>b5 > a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r2b6 = b6 > a6; +>r2b6 : boolean +>b6 > a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r2b7 = b7 > a7; + +// operator <= +var r3a1 = a1 <= b1; +>r3a1 : boolean +>a1 <= b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r3a2 = a2 <= b2; +>r3a2 : boolean +>a2 <= b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r3a3 = a3 <= b3; +>r3a3 : boolean +>a3 <= b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r3a4 = a4 <= b4; +>r3a4 : boolean +>a4 <= b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r3a5 = a5 <= b5; +>r3a5 : boolean +>a5 <= b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r3a6 = a6 <= b6; +>r3a6 : boolean +>a6 <= b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r3a7 = a7 <= b7; + +var r3b1 = b1 <= a1; +>r3b1 : boolean +>b1 <= a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r3b2 = b2 <= a2; +>r3b2 : boolean +>b2 <= a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r3b3 = b3 <= a3; +>r3b3 : boolean +>b3 <= a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r3b4 = b4 <= a4; +>r3b4 : boolean +>b4 <= a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r3b5 = b5 <= a5; +>r3b5 : boolean +>b5 <= a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r3b6 = b6 <= a6; +>r3b6 : boolean +>b6 <= a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r3b7 = b7 <= a7; + +// operator >= +var r4a1 = a1 >= b1; +>r4a1 : boolean +>a1 >= b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r4a2 = a2 >= b2; +>r4a2 : boolean +>a2 >= b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r4a3 = a3 >= b3; +>r4a3 : boolean +>a3 >= b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r4a4 = a4 >= b4; +>r4a4 : boolean +>a4 >= b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r4a5 = a5 >= b5; +>r4a5 : boolean +>a5 >= b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r4a6 = a6 >= b6; +>r4a6 : boolean +>a6 >= b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r4a7 = a7 >= b7; + +var r4b1 = b1 >= a1; +>r4b1 : boolean +>b1 >= a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r4b2 = b2 >= a2; +>r4b2 : boolean +>b2 >= a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r4b3 = b3 >= a3; +>r4b3 : boolean +>b3 >= a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r4b4 = b4 >= a4; +>r4b4 : boolean +>b4 >= a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r4b5 = b5 >= a5; +>r4b5 : boolean +>b5 >= a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r4b6 = b6 >= a6; +>r4b6 : boolean +>b6 >= a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r4b7 = b7 >= a7; + +// operator == +var r5a1 = a1 == b1; +>r5a1 : boolean +>a1 == b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r5a2 = a2 == b2; +>r5a2 : boolean +>a2 == b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r5a3 = a3 == b3; +>r5a3 : boolean +>a3 == b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r5a4 = a4 == b4; +>r5a4 : boolean +>a4 == b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r5a5 = a5 == b5; +>r5a5 : boolean +>a5 == b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r5a6 = a6 == b6; +>r5a6 : boolean +>a6 == b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r5a7 = a7 == b7; + +var r5b1 = b1 == a1; +>r5b1 : boolean +>b1 == a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r5b2 = b2 == a2; +>r5b2 : boolean +>b2 == a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r5b3 = b3 == a3; +>r5b3 : boolean +>b3 == a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r5b4 = b4 == a4; +>r5b4 : boolean +>b4 == a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r5b5 = b5 == a5; +>r5b5 : boolean +>b5 == a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r5b6 = b6 == a6; +>r5b6 : boolean +>b6 == a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r5b7 = b7 == a7; + +// operator != +var r6a1 = a1 != b1; +>r6a1 : boolean +>a1 != b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r6a2 = a2 != b2; +>r6a2 : boolean +>a2 != b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r6a3 = a3 != b3; +>r6a3 : boolean +>a3 != b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r6a4 = a4 != b4; +>r6a4 : boolean +>a4 != b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r6a5 = a5 != b5; +>r6a5 : boolean +>a5 != b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r6a6 = a6 != b6; +>r6a6 : boolean +>a6 != b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r6a7 = a7 != b7; + +var r6b1 = b1 != a1; +>r6b1 : boolean +>b1 != a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r6b2 = b2 != a2; +>r6b2 : boolean +>b2 != a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r6b3 = b3 != a3; +>r6b3 : boolean +>b3 != a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r6b4 = b4 != a4; +>r6b4 : boolean +>b4 != a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r6b5 = b5 != a5; +>r6b5 : boolean +>b5 != a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r6b6 = b6 != a6; +>r6b6 : boolean +>b6 != a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r6b7 = b7 != a7; + +// operator === +var r7a1 = a1 === b1; +>r7a1 : boolean +>a1 === b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r7a2 = a2 === b2; +>r7a2 : boolean +>a2 === b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r7a3 = a3 === b3; +>r7a3 : boolean +>a3 === b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r7a4 = a4 === b4; +>r7a4 : boolean +>a4 === b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r7a5 = a5 === b5; +>r7a5 : boolean +>a5 === b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r7a6 = a6 === b6; +>r7a6 : boolean +>a6 === b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r7a7 = a7 === b7; + +var r7b1 = b1 === a1; +>r7b1 : boolean +>b1 === a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r7b2 = b2 === a2; +>r7b2 : boolean +>b2 === a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r7b3 = b3 === a3; +>r7b3 : boolean +>b3 === a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r7b4 = b4 === a4; +>r7b4 : boolean +>b4 === a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r7b5 = b5 === a5; +>r7b5 : boolean +>b5 === a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r7b6 = b6 === a6; +>r7b6 : boolean +>b6 === a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r7b7 = b7 === a7; + +// operator !== +var r8a1 = a1 !== b1; +>r8a1 : boolean +>a1 !== b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r8a2 = a2 !== b2; +>r8a2 : boolean +>a2 !== b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r8a3 = a3 !== b3; +>r8a3 : boolean +>a3 !== b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r8a4 = a4 !== b4; +>r8a4 : boolean +>a4 !== b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r8a5 = a5 !== b5; +>r8a5 : boolean +>a5 !== b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r8a6 = a6 !== b6; +>r8a6 : boolean +>a6 !== b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r8a7 = a7 !== b7; + +var r8b1 = b1 !== a1; +>r8b1 : boolean +>b1 !== a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r8b2 = b2 !== a2; +>r8b2 : boolean +>b2 !== a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r8b3 = b3 !== a3; +>r8b3 : boolean +>b3 !== a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r8b4 = b4 !== a4; +>r8b4 : boolean +>b4 !== a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r8b5 = b5 !== a5; +>r8b5 : boolean +>b5 !== a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r8b6 = b6 !== a6; +>r8b6 : boolean +>b6 !== a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r8b7 = b7 !== a7; diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.errors.txt b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.errors.txt deleted file mode 100644 index 0e352ebcc9d..00000000000 --- a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.errors.txt +++ /dev/null @@ -1,215 +0,0 @@ -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(32,12): error TS2365: Operator '<' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(40,12): error TS2365: Operator '<' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(49,12): error TS2365: Operator '>' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(57,12): error TS2365: Operator '>' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(66,12): error TS2365: Operator '<=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(74,12): error TS2365: Operator '<=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(83,12): error TS2365: Operator '>=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(91,12): error TS2365: Operator '>=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(100,12): error TS2365: Operator '==' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(108,12): error TS2365: Operator '==' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(117,12): error TS2365: Operator '!=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(125,12): error TS2365: Operator '!=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(134,12): error TS2365: Operator '===' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(142,12): error TS2365: Operator '===' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(151,12): error TS2365: Operator '!==' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(159,12): error TS2365: Operator '!==' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - - -==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts (16 errors) ==== - class Base { - public a: string; - } - - class Derived extends Base { - public b: string; - } - - var a1: { new (x: T): T }; - var b1: { new (x: string): string }; - - var a2: { new (x: T): T }; - var b2: { new (x: string, y: number): string }; - - var a3: { new (x: T, y: U): T }; - var b3: { new (x: string, y: number): string }; - - var a4: { new (x?: T): T }; - var b4: { new (x?: string): string }; - - var a5: { new (...x: T[]): T }; - var b5: { new (...x: string[]): string }; - - var a6: { new (x: T, y: T): T }; - var b6: { new (x: string, y: number): {} }; - - //var a7: { new (x: T, y: U): T }; - var b7: { new (x: Base, y: Derived): Base }; - - // operator < - var r1a1 = a1 < b1; - var r1a2 = a2 < b2; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r1a3 = a3 < b3; - var r1a4 = a4 < b4; - var r1a5 = a5 < b5; - var r1a6 = a6 < b6; - //var r1a7 = a7 < b7; - - var r1b1 = b1 < a1; - var r1b2 = b2 < a2; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r1b3 = b3 < a3; - var r1b4 = b4 < a4; - var r1b5 = b5 < a5; - var r1b6 = b6 < a6; - //var r1b7 = b7 < a7; - - // operator > - var r2a1 = a1 > b1; - var r2a2 = a2 > b2; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r2a3 = a3 > b3; - var r2a4 = a4 > b4; - var r2a5 = a5 > b5; - var r2a6 = a6 > b6; - //var r2a7 = a7 > b7; - - var r2b1 = b1 > a1; - var r2b2 = b2 > a2; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r2b3 = b3 > a3; - var r2b4 = b4 > a4; - var r2b5 = b5 > a5; - var r2b6 = b6 > a6; - //var r2b7 = b7 > a7; - - // operator <= - var r3a1 = a1 <= b1; - var r3a2 = a2 <= b2; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r3a3 = a3 <= b3; - var r3a4 = a4 <= b4; - var r3a5 = a5 <= b5; - var r3a6 = a6 <= b6; - //var r3a7 = a7 <= b7; - - var r3b1 = b1 <= a1; - var r3b2 = b2 <= a2; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r3b3 = b3 <= a3; - var r3b4 = b4 <= a4; - var r3b5 = b5 <= a5; - var r3b6 = b6 <= a6; - //var r3b7 = b7 <= a7; - - // operator >= - var r4a1 = a1 >= b1; - var r4a2 = a2 >= b2; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r4a3 = a3 >= b3; - var r4a4 = a4 >= b4; - var r4a5 = a5 >= b5; - var r4a6 = a6 >= b6; - //var r4a7 = a7 >= b7; - - var r4b1 = b1 >= a1; - var r4b2 = b2 >= a2; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r4b3 = b3 >= a3; - var r4b4 = b4 >= a4; - var r4b5 = b5 >= a5; - var r4b6 = b6 >= a6; - //var r4b7 = b7 >= a7; - - // operator == - var r5a1 = a1 == b1; - var r5a2 = a2 == b2; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r5a3 = a3 == b3; - var r5a4 = a4 == b4; - var r5a5 = a5 == b5; - var r5a6 = a6 == b6; - //var r5a7 = a7 == b7; - - var r5b1 = b1 == a1; - var r5b2 = b2 == a2; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r5b3 = b3 == a3; - var r5b4 = b4 == a4; - var r5b5 = b5 == a5; - var r5b6 = b6 == a6; - //var r5b7 = b7 == a7; - - // operator != - var r6a1 = a1 != b1; - var r6a2 = a2 != b2; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r6a3 = a3 != b3; - var r6a4 = a4 != b4; - var r6a5 = a5 != b5; - var r6a6 = a6 != b6; - //var r6a7 = a7 != b7; - - var r6b1 = b1 != a1; - var r6b2 = b2 != a2; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r6b3 = b3 != a3; - var r6b4 = b4 != a4; - var r6b5 = b5 != a5; - var r6b6 = b6 != a6; - //var r6b7 = b7 != a7; - - // operator === - var r7a1 = a1 === b1; - var r7a2 = a2 === b2; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r7a3 = a3 === b3; - var r7a4 = a4 === b4; - var r7a5 = a5 === b5; - var r7a6 = a6 === b6; - //var r7a7 = a7 === b7; - - var r7b1 = b1 === a1; - var r7b2 = b2 === a2; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r7b3 = b3 === a3; - var r7b4 = b4 === a4; - var r7b5 = b5 === a5; - var r7b6 = b6 === a6; - //var r7b7 = b7 === a7; - - // operator !== - var r8a1 = a1 !== b1; - var r8a2 = a2 !== b2; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r8a3 = a3 !== b3; - var r8a4 = a4 !== b4; - var r8a5 = a5 !== b5; - var r8a6 = a6 !== b6; - //var r8a7 = a7 !== b7; - - var r8b1 = b1 !== a1; - var r8b2 = b2 !== a2; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r8b3 = b3 !== a3; - var r8b4 = b4 !== a4; - var r8b5 = b5 !== a5; - var r8b6 = b6 !== a6; - //var r8b7 = b7 !== a7; \ No newline at end of file diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.types b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.types new file mode 100644 index 00000000000..29d92c25726 --- /dev/null +++ b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.types @@ -0,0 +1,714 @@ +=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts === +class Base { +>Base : Base + + public a: string; +>a : string +} + +class Derived extends Base { +>Derived : Derived +>Base : Base + + public b: string; +>b : string +} + +var a1: { new (x: T): T }; +>a1 : new (x: T) => T +>T : T +>x : T +>T : T +>T : T + +var b1: { new (x: string): string }; +>b1 : new (x: string) => string +>x : string + +var a2: { new (x: T): T }; +>a2 : new (x: T) => T +>T : T +>x : T +>T : T +>T : T + +var b2: { new (x: string, y: number): string }; +>b2 : new (x: string, y: number) => string +>x : string +>y : number + +var a3: { new (x: T, y: U): T }; +>a3 : new (x: T, y: U) => T +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>T : T + +var b3: { new (x: string, y: number): string }; +>b3 : new (x: string, y: number) => string +>x : string +>y : number + +var a4: { new (x?: T): T }; +>a4 : new (x?: T) => T +>T : T +>x : T +>T : T +>T : T + +var b4: { new (x?: string): string }; +>b4 : new (x?: string) => string +>x : string + +var a5: { new (...x: T[]): T }; +>a5 : new (...x: T[]) => T +>T : T +>x : T[] +>T : T +>T : T + +var b5: { new (...x: string[]): string }; +>b5 : new (...x: string[]) => string +>x : string[] + +var a6: { new (x: T, y: T): T }; +>a6 : new (x: T, y: T) => T +>T : T +>x : T +>T : T +>y : T +>T : T +>T : T + +var b6: { new (x: string, y: number): {} }; +>b6 : new (x: string, y: number) => {} +>x : string +>y : number + +//var a7: { new (x: T, y: U): T }; +var b7: { new (x: Base, y: Derived): Base }; +>b7 : new (x: Base, y: Derived) => Base +>x : Base +>Base : Base +>y : Derived +>Derived : Derived +>Base : Base + +// operator < +var r1a1 = a1 < b1; +>r1a1 : boolean +>a1 < b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r1a2 = a2 < b2; +>r1a2 : boolean +>a2 < b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r1a3 = a3 < b3; +>r1a3 : boolean +>a3 < b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r1a4 = a4 < b4; +>r1a4 : boolean +>a4 < b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r1a5 = a5 < b5; +>r1a5 : boolean +>a5 < b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r1a6 = a6 < b6; +>r1a6 : boolean +>a6 < b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r1a7 = a7 < b7; + +var r1b1 = b1 < a1; +>r1b1 : boolean +>b1 < a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r1b2 = b2 < a2; +>r1b2 : boolean +>b2 < a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r1b3 = b3 < a3; +>r1b3 : boolean +>b3 < a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r1b4 = b4 < a4; +>r1b4 : boolean +>b4 < a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r1b5 = b5 < a5; +>r1b5 : boolean +>b5 < a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r1b6 = b6 < a6; +>r1b6 : boolean +>b6 < a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r1b7 = b7 < a7; + +// operator > +var r2a1 = a1 > b1; +>r2a1 : boolean +>a1 > b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r2a2 = a2 > b2; +>r2a2 : boolean +>a2 > b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r2a3 = a3 > b3; +>r2a3 : boolean +>a3 > b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r2a4 = a4 > b4; +>r2a4 : boolean +>a4 > b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r2a5 = a5 > b5; +>r2a5 : boolean +>a5 > b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r2a6 = a6 > b6; +>r2a6 : boolean +>a6 > b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r2a7 = a7 > b7; + +var r2b1 = b1 > a1; +>r2b1 : boolean +>b1 > a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r2b2 = b2 > a2; +>r2b2 : boolean +>b2 > a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r2b3 = b3 > a3; +>r2b3 : boolean +>b3 > a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r2b4 = b4 > a4; +>r2b4 : boolean +>b4 > a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r2b5 = b5 > a5; +>r2b5 : boolean +>b5 > a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r2b6 = b6 > a6; +>r2b6 : boolean +>b6 > a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r2b7 = b7 > a7; + +// operator <= +var r3a1 = a1 <= b1; +>r3a1 : boolean +>a1 <= b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r3a2 = a2 <= b2; +>r3a2 : boolean +>a2 <= b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r3a3 = a3 <= b3; +>r3a3 : boolean +>a3 <= b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r3a4 = a4 <= b4; +>r3a4 : boolean +>a4 <= b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r3a5 = a5 <= b5; +>r3a5 : boolean +>a5 <= b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r3a6 = a6 <= b6; +>r3a6 : boolean +>a6 <= b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r3a7 = a7 <= b7; + +var r3b1 = b1 <= a1; +>r3b1 : boolean +>b1 <= a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r3b2 = b2 <= a2; +>r3b2 : boolean +>b2 <= a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r3b3 = b3 <= a3; +>r3b3 : boolean +>b3 <= a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r3b4 = b4 <= a4; +>r3b4 : boolean +>b4 <= a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r3b5 = b5 <= a5; +>r3b5 : boolean +>b5 <= a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r3b6 = b6 <= a6; +>r3b6 : boolean +>b6 <= a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r3b7 = b7 <= a7; + +// operator >= +var r4a1 = a1 >= b1; +>r4a1 : boolean +>a1 >= b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r4a2 = a2 >= b2; +>r4a2 : boolean +>a2 >= b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r4a3 = a3 >= b3; +>r4a3 : boolean +>a3 >= b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r4a4 = a4 >= b4; +>r4a4 : boolean +>a4 >= b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r4a5 = a5 >= b5; +>r4a5 : boolean +>a5 >= b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r4a6 = a6 >= b6; +>r4a6 : boolean +>a6 >= b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r4a7 = a7 >= b7; + +var r4b1 = b1 >= a1; +>r4b1 : boolean +>b1 >= a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r4b2 = b2 >= a2; +>r4b2 : boolean +>b2 >= a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r4b3 = b3 >= a3; +>r4b3 : boolean +>b3 >= a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r4b4 = b4 >= a4; +>r4b4 : boolean +>b4 >= a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r4b5 = b5 >= a5; +>r4b5 : boolean +>b5 >= a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r4b6 = b6 >= a6; +>r4b6 : boolean +>b6 >= a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r4b7 = b7 >= a7; + +// operator == +var r5a1 = a1 == b1; +>r5a1 : boolean +>a1 == b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r5a2 = a2 == b2; +>r5a2 : boolean +>a2 == b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r5a3 = a3 == b3; +>r5a3 : boolean +>a3 == b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r5a4 = a4 == b4; +>r5a4 : boolean +>a4 == b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r5a5 = a5 == b5; +>r5a5 : boolean +>a5 == b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r5a6 = a6 == b6; +>r5a6 : boolean +>a6 == b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r5a7 = a7 == b7; + +var r5b1 = b1 == a1; +>r5b1 : boolean +>b1 == a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r5b2 = b2 == a2; +>r5b2 : boolean +>b2 == a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r5b3 = b3 == a3; +>r5b3 : boolean +>b3 == a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r5b4 = b4 == a4; +>r5b4 : boolean +>b4 == a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r5b5 = b5 == a5; +>r5b5 : boolean +>b5 == a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r5b6 = b6 == a6; +>r5b6 : boolean +>b6 == a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r5b7 = b7 == a7; + +// operator != +var r6a1 = a1 != b1; +>r6a1 : boolean +>a1 != b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r6a2 = a2 != b2; +>r6a2 : boolean +>a2 != b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r6a3 = a3 != b3; +>r6a3 : boolean +>a3 != b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r6a4 = a4 != b4; +>r6a4 : boolean +>a4 != b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r6a5 = a5 != b5; +>r6a5 : boolean +>a5 != b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r6a6 = a6 != b6; +>r6a6 : boolean +>a6 != b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r6a7 = a7 != b7; + +var r6b1 = b1 != a1; +>r6b1 : boolean +>b1 != a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r6b2 = b2 != a2; +>r6b2 : boolean +>b2 != a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r6b3 = b3 != a3; +>r6b3 : boolean +>b3 != a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r6b4 = b4 != a4; +>r6b4 : boolean +>b4 != a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r6b5 = b5 != a5; +>r6b5 : boolean +>b5 != a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r6b6 = b6 != a6; +>r6b6 : boolean +>b6 != a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r6b7 = b7 != a7; + +// operator === +var r7a1 = a1 === b1; +>r7a1 : boolean +>a1 === b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r7a2 = a2 === b2; +>r7a2 : boolean +>a2 === b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r7a3 = a3 === b3; +>r7a3 : boolean +>a3 === b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r7a4 = a4 === b4; +>r7a4 : boolean +>a4 === b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r7a5 = a5 === b5; +>r7a5 : boolean +>a5 === b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r7a6 = a6 === b6; +>r7a6 : boolean +>a6 === b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r7a7 = a7 === b7; + +var r7b1 = b1 === a1; +>r7b1 : boolean +>b1 === a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r7b2 = b2 === a2; +>r7b2 : boolean +>b2 === a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r7b3 = b3 === a3; +>r7b3 : boolean +>b3 === a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r7b4 = b4 === a4; +>r7b4 : boolean +>b4 === a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r7b5 = b5 === a5; +>r7b5 : boolean +>b5 === a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r7b6 = b6 === a6; +>r7b6 : boolean +>b6 === a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r7b7 = b7 === a7; + +// operator !== +var r8a1 = a1 !== b1; +>r8a1 : boolean +>a1 !== b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r8a2 = a2 !== b2; +>r8a2 : boolean +>a2 !== b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r8a3 = a3 !== b3; +>r8a3 : boolean +>a3 !== b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r8a4 = a4 !== b4; +>r8a4 : boolean +>a4 !== b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r8a5 = a5 !== b5; +>r8a5 : boolean +>a5 !== b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r8a6 = a6 !== b6; +>r8a6 : boolean +>a6 !== b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r8a7 = a7 !== b7; + +var r8b1 = b1 !== a1; +>r8b1 : boolean +>b1 !== a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r8b2 = b2 !== a2; +>r8b2 : boolean +>b2 !== a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r8b3 = b3 !== a3; +>r8b3 : boolean +>b3 !== a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r8b4 = b4 !== a4; +>r8b4 : boolean +>b4 !== a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r8b5 = b5 !== a5; +>r8b5 : boolean +>b5 !== a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r8b6 = b6 !== a6; +>r8b6 : boolean +>b6 !== a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r8b7 = b7 !== a7; diff --git a/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types b/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types index edef88acfc3..f925f7f1db6 100644 --- a/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types +++ b/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types @@ -169,7 +169,7 @@ var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2; >result10 : (t: X) => any >t : X >X : X ->true ? (m) => m.propertyX1 : (n) => n.propertyX2 : { (m: X): number; } | { (n: X): string; } +>true ? (m) => m.propertyX1 : (n) => n.propertyX2 : ((m: X) => number) | ((n: X) => string) >(m) => m.propertyX1 : (m: X) => number >m : X >m.propertyX1 : number diff --git a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt index fb2c02d1c28..b1dd23fc3e3 100644 --- a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt +++ b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt @@ -4,13 +4,13 @@ tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithou tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type 'A | B' is not assignable to type 'B': Type 'A' is not assignable to type 'B': Property 'propertyB' is missing in type 'A'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(18,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => number': +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(18,5): error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => number': Type '(n: X) => string' is not assignable to type '(t: X) => number': Type 'string' is not assignable to type 'number'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => string': +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => string': Type '(m: X) => number' is not assignable to type '(t: X) => string': Type 'number' is not assignable to type 'string'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => boolean': +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => boolean': Type '(m: X) => number' is not assignable to type '(t: X) => boolean': Type 'number' is not assignable to type 'boolean'. @@ -43,16 +43,16 @@ tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithou var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => number': +!!! error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => number': !!! error TS2322: Type '(n: X) => string' is not assignable to type '(t: X) => number': !!! error TS2322: Type 'string' is not assignable to type 'number'. var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => string': +!!! error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => string': !!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => string': !!! error TS2322: Type 'number' is not assignable to type 'string'. var result6: (t: X) => boolean = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => boolean': +!!! error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => boolean': !!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => boolean': !!! error TS2322: Type 'number' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt new file mode 100644 index 00000000000..629cf7f75af --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt @@ -0,0 +1,35 @@ +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(7,9): error TS2451: Cannot redeclare block-scoped variable 'x'. +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(15,13): error TS2451: Cannot redeclare block-scoped variable 'y'. +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS2451: Cannot redeclare block-scoped variable 'z'. + + +==== tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts (3 errors) ==== + + // Error as declaration of var would cause a write to the const value + var x = 0; + { + const x = 0; + + var x = 0; + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'x'. + } + + + var y = 0; + { + const y = 0; + { + var y = 0; + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'y'. + } + } + + + { + const z = 0; + var z = 0 + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'z'. + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.js b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.js new file mode 100644 index 00000000000..67d3e688075 --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.js @@ -0,0 +1,18 @@ +//// [constDeclarationShadowedByVarDeclaration2.ts] + +// No errors, const declaration is not shadowed +function outer() { + const x = 0; + function inner() { + var x = "inner"; + } +} + +//// [constDeclarationShadowedByVarDeclaration2.js] +// No errors, const declaration is not shadowed +function outer() { + const x = 0; + function inner() { + var x = "inner"; + } +} diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.types b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.types new file mode 100644 index 00000000000..4217db45509 --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts === + +// No errors, const declaration is not shadowed +function outer() { +>outer : () => void + + const x = 0; +>x : number + + function inner() { +>inner : () => void + + var x = "inner"; +>x : string + } +} diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.js b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.js new file mode 100644 index 00000000000..6f5b898c5ff --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.js @@ -0,0 +1,21 @@ +//// [constDeclarationShadowedByVarDeclaration3.ts] +// Ensure only checking for const declarations shadowed by vars +class Rule { + public regex: RegExp = new RegExp(''); + public name: string = ''; + + constructor(name: string) { + this.name = name; + } +} + +//// [constDeclarationShadowedByVarDeclaration3.js] +// Ensure only checking for const declarations shadowed by vars +var Rule = (function () { + function Rule(name) { + this.regex = new RegExp(''); + this.name = ''; + this.name = name; + } + return Rule; +})(); diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.types b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.types new file mode 100644 index 00000000000..89490567f14 --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts === +// Ensure only checking for const declarations shadowed by vars +class Rule { +>Rule : Rule + + public regex: RegExp = new RegExp(''); +>regex : RegExp +>RegExp : RegExp +>new RegExp('') : RegExp +>RegExp : { (pattern: string, flags?: string): RegExp; new (pattern: string, flags?: string): RegExp; $1: string; $2: string; $3: string; $4: string; $5: string; $6: string; $7: string; $8: string; $9: string; lastMatch: string; } + + public name: string = ''; +>name : string + + constructor(name: string) { +>name : string + + this.name = name; +>this.name = name : string +>this.name : string +>this : Rule +>name : string +>name : string + } +} diff --git a/tests/baselines/reference/constDeclarations-access.errors.txt b/tests/baselines/reference/constDeclarations-access.errors.txt new file mode 100644 index 00000000000..04b942aec09 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file2.ts(1,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. + + +==== tests/cases/compiler/file1.ts (0 errors) ==== + + const x = 0 + +==== tests/cases/compiler/file2.ts (1 errors) ==== + x++; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access2.errors.txt b/tests/baselines/reference/constDeclarations-access2.errors.txt new file mode 100644 index 00000000000..6a360e11014 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access2.errors.txt @@ -0,0 +1,94 @@ +tests/cases/compiler/constDeclarations-access2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. + + +==== tests/cases/compiler/constDeclarations-access2.ts (17 errors) ==== + + const x = 0 + + // Errors + x = 1; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x += 2; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x -= 3; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x *= 4; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x /= 5; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x %= 6; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x <<= 7; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x >>= 8; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x >>>= 9; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x &= 10; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x |= 11; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x ^= 12; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + x++; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + x--; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++x; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --x; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + ++((x)); + ~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + // OK + var a = x + 1; + + function f(v: number) { } + f(x); + + if (x) { } + + x; + (x); + + -x; + +x; + + x.toString(); + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access3.errors.txt b/tests/baselines/reference/constDeclarations-access3.errors.txt new file mode 100644 index 00000000000..577b087dff0 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access3.errors.txt @@ -0,0 +1,102 @@ +tests/cases/compiler/constDeclarations-access3.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant. + + +==== tests/cases/compiler/constDeclarations-access3.ts (18 errors) ==== + + + module M { + export const x = 0; + } + + // Errors + M.x = 1; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x += 2; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x -= 3; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x *= 4; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x /= 5; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x %= 6; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x <<= 7; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>= 8; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>>= 9; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x &= 10; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x |= 11; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x ^= 12; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + M.x++; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + M.x--; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + ++((M.x)); + ~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + M["x"] = 0; + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + // OK + var a = M.x + 1; + + function f(v: number) { } + f(M.x); + + if (M.x) { } + + M.x; + (M.x); + + -M.x; + +M.x; + + M.x.toString(); + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access4.errors.txt b/tests/baselines/reference/constDeclarations-access4.errors.txt new file mode 100644 index 00000000000..9745c0d2624 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access4.errors.txt @@ -0,0 +1,102 @@ +tests/cases/compiler/constDeclarations-access4.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant. + + +==== tests/cases/compiler/constDeclarations-access4.ts (18 errors) ==== + + + declare module M { + const x: number; + } + + // Errors + M.x = 1; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x += 2; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x -= 3; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x *= 4; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x /= 5; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x %= 6; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x <<= 7; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>= 8; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>>= 9; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x &= 10; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x |= 11; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x ^= 12; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + M.x++; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + M.x--; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + ++((M.x)); + ~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + M["x"] = 0; + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + // OK + var a = M.x + 1; + + function f(v: number) { } + f(M.x); + + if (M.x) { } + + M.x; + (M.x); + + -M.x; + +M.x; + + M.x.toString(); + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt new file mode 100644 index 00000000000..23200e50ee4 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -0,0 +1,103 @@ +tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(17,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(19,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant. + + +==== tests/cases/compiler/constDeclarations_access_2.ts (18 errors) ==== + /// + import m = require('constDeclarations_access_1'); + // Errors + m.x = 1; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x += 2; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x -= 3; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x *= 4; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x /= 5; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x %= 6; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x <<= 7; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x >>= 8; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x >>>= 9; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x &= 10; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x |= 11; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x ^= 12; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m + m.x++; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + m.x--; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++m.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --m.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + ++((m.x)); + ~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + m["x"] = 0; + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + // OK + var a = m.x + 1; + + function f(v: number) { } + f(m.x); + + if (m.x) { } + + m.x; + (m.x); + + -m.x; + +m.x; + + m.x.toString(); + +==== tests/cases/compiler/constDeclarations_access_1.ts (0 errors) ==== + + + export const x = 0; + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt b/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt new file mode 100644 index 00000000000..6e2d00dc4c4 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt @@ -0,0 +1,34 @@ +tests/cases/compiler/constDeclarations-ambient-errors.ts(3,27): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(4,26): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(5,18): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(5,37): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(5,51): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(8,14): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(9,22): error TS1039: Initializers are not allowed in ambient contexts. + + +==== tests/cases/compiler/constDeclarations-ambient-errors.ts (7 errors) ==== + + // error: no intialization expected in ambient declarations + declare const c1: boolean = true; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + declare const c2: number = 0; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + declare const c3 = null, c4 :string = "", c5: any = 0; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + + declare module M { + const c6 = 0; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + const c7: number = 7; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-ambient.js b/tests/baselines/reference/constDeclarations-ambient.js new file mode 100644 index 00000000000..dd78f73051a --- /dev/null +++ b/tests/baselines/reference/constDeclarations-ambient.js @@ -0,0 +1,13 @@ +//// [constDeclarations-ambient.ts] + +// No error +declare const c1: boolean; +declare const c2: number; +declare const c3, c4 :string, c5: any; + +declare module M { + const c6; + const c7: number; +} + +//// [constDeclarations-ambient.js] diff --git a/tests/baselines/reference/constDeclarations-ambient.types b/tests/baselines/reference/constDeclarations-ambient.types new file mode 100644 index 00000000000..0ab2d4b700a --- /dev/null +++ b/tests/baselines/reference/constDeclarations-ambient.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/constDeclarations-ambient.ts === + +// No error +declare const c1: boolean; +>c1 : boolean + +declare const c2: number; +>c2 : number + +declare const c3, c4 :string, c5: any; +>c3 : any +>c4 : string +>c5 : any + +declare module M { +>M : typeof M + + const c6; +>c6 : any + + const c7: number; +>c7 : number +} diff --git a/tests/baselines/reference/constDeclarations-errors.errors.txt b/tests/baselines/reference/constDeclarations-errors.errors.txt new file mode 100644 index 00000000000..d87007474a1 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -0,0 +1,50 @@ +tests/cases/compiler/constDeclarations-errors.ts(3,7): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(4,7): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,7): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,15): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,27): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(8,11): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(14,11): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(17,20): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(11,27): error TS2449: The operand of an increment or decrement operator cannot be a constant. + + +==== tests/cases/compiler/constDeclarations-errors.ts (10 errors) ==== + + // error, missing intialicer + const c1; + ~~ +!!! error TS1155: 'const' declarations must be initialized + const c2: number; + ~~ +!!! error TS1155: 'const' declarations must be initialized + const c3, c4, c5 :string, c6; // error, missing initialicer + ~~ +!!! error TS1155: 'const' declarations must be initialized + ~~ +!!! error TS1155: 'const' declarations must be initialized + ~~ +!!! error TS1155: 'const' declarations must be initialized + ~~ +!!! error TS1155: 'const' declarations must be initialized + + // error, can not be unintalized + for(const c in {}) { } + ~ +!!! error TS1155: 'const' declarations must be initialized + + // error, assigning to a const + for(const c8 = 0; c8 < 1; c8++) { } + ~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + // error, can not be unintalized + for(const c9; c9 < 1;) { } + ~~ +!!! error TS1155: 'const' declarations must be initialized + + // error, can not be unintalized + for(const c10 = 0, c11; c10 < 1;) { } + ~~~ +!!! error TS1155: 'const' declarations must be initialized \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-es5.errors.txt b/tests/baselines/reference/constDeclarations-es5.errors.txt new file mode 100644 index 00000000000..0b830eab05a --- /dev/null +++ b/tests/baselines/reference/constDeclarations-es5.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/constDeclarations-es5.ts(2,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(3,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(4,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. + + +==== tests/cases/compiler/constDeclarations-es5.ts (3 errors) ==== + + const z7 = false; + ~~~~~~~~~~~~~~~~~ +!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. + const z8: number = 23; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. + const z9 = 0, z10 :string = "", z11 = null; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt b/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt new file mode 100644 index 00000000000..745ef305ac6 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt @@ -0,0 +1,66 @@ +tests/cases/compiler/constDeclarations-invalidContexts.ts(4,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(6,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(9,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(12,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(17,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(20,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(23,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(26,12): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(29,29): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/constDeclarations-invalidContexts.ts (10 errors) ==== + + // Errors, const must be defined inside a block + if (true) + const c1 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + else + const c2 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + while (true) + const c3 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + do + const c4 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + while (true); + + var obj; + with (obj) + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + const c5 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + for (var i = 0; i < 10; i++) + const c6 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + for (var i2 in {}) + const c7 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + if (true) + label: const c8 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + while (false) + label2: label3: label4: const c9 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + + + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-scopes.errors.txt b/tests/baselines/reference/constDeclarations-scopes.errors.txt new file mode 100644 index 00000000000..138acd9b16d --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes.errors.txt @@ -0,0 +1,153 @@ +tests/cases/compiler/constDeclarations-scopes.ts(28,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/constDeclarations-scopes.ts (1 errors) ==== + + // global + const c = "string"; + + var n: number; + + // Control flow statements with blocks + if (true) { + const c = 0; + n = c; + } + else { + const c = 0; + n = c; + } + + while (true) { + const c = 0; + n = c; + } + + do { + const c = 0; + n = c; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + const c = 0; + n = c; + } + + for (var i = 0; i < 10; i++) { + const c = 0; + n = c; + } + + for (var i2 in {}) { + const c = 0; + n = c; + } + + if (true) { + label: const c = 0; + n = c; + } + + while (false) { + label2: label3: label4: const c = 0; + n = c; + } + + // Try/catch/finally + try { + const c = 0; + n = c; + } + catch (e) { + const c = 0; + n = c; + } + finally { + const c = 0; + n = c; + } + + // Switch + switch (0) { + case 0: + const c = 0; + n = c; + break; + } + + // blocks + { + const c = 0; + n = c; + { + const c = false; + var b: boolean = c; + } + } + + // functions + + function F() { + const c = 0; + n = c; + } + + var F2 = () => { + const c = 0; + n = c; + }; + + var F3 = function () { + const c = 0; + n = c; + }; + + // modules + module m { + const c = 0; + n = c; + + { + const c = false; + var b2: boolean = c; + } + } + + // methods + class C { + constructor() { + const c = 0; + n = c; + } + + method() { + const c = 0; + n = c; + } + + get v() { + const c = 0; + n = c; + return n; + } + + set v(value) { + const c = 0; + n = c; + } + } + + // object literals + var o = { + f() { + const c = 0; + n = c; + }, + f2: () => { + const c = 0; + n = c; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-scopes.js b/tests/baselines/reference/constDeclarations-scopes.js new file mode 100644 index 00000000000..800dd856422 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes.js @@ -0,0 +1,276 @@ +//// [constDeclarations-scopes.ts] + +// global +const c = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + const c = 0; + n = c; +} +else { + const c = 0; + n = c; +} + +while (true) { + const c = 0; + n = c; +} + +do { + const c = 0; + n = c; +} while (true); + +var obj; +with (obj) { + const c = 0; + n = c; +} + +for (var i = 0; i < 10; i++) { + const c = 0; + n = c; +} + +for (var i2 in {}) { + const c = 0; + n = c; +} + +if (true) { + label: const c = 0; + n = c; +} + +while (false) { + label2: label3: label4: const c = 0; + n = c; +} + +// Try/catch/finally +try { + const c = 0; + n = c; +} +catch (e) { + const c = 0; + n = c; +} +finally { + const c = 0; + n = c; +} + +// Switch +switch (0) { + case 0: + const c = 0; + n = c; + break; +} + +// blocks +{ + const c = 0; + n = c; + { + const c = false; + var b: boolean = c; + } +} + +// functions + +function F() { + const c = 0; + n = c; +} + +var F2 = () => { + const c = 0; + n = c; +}; + +var F3 = function () { + const c = 0; + n = c; +}; + +// modules +module m { + const c = 0; + n = c; + + { + const c = false; + var b2: boolean = c; + } +} + +// methods +class C { + constructor() { + const c = 0; + n = c; + } + + method() { + const c = 0; + n = c; + } + + get v() { + const c = 0; + n = c; + return n; + } + + set v(value) { + const c = 0; + n = c; + } +} + +// object literals +var o = { + f() { + const c = 0; + n = c; + }, + f2: () => { + const c = 0; + n = c; + } +} + +//// [constDeclarations-scopes.js] +// global +const c = "string"; +var n; +// Control flow statements with blocks +if (true) { + const c = 0; + n = c; +} +else { + const c = 0; + n = c; +} +while (true) { + const c = 0; + n = c; +} +do { + const c = 0; + n = c; +} while (true); +var obj; +with (obj) { + const c = 0; + n = c; +} +for (var i = 0; i < 10; i++) { + const c = 0; + n = c; +} +for (var i2 in {}) { + const c = 0; + n = c; +} +if (true) { + label: const c = 0; + n = c; +} +while (false) { + label2: label3: label4: const c = 0; + n = c; +} +try { + const c = 0; + n = c; +} +catch (e) { + const c = 0; + n = c; +} +finally { + const c = 0; + n = c; +} +switch (0) { + case 0: + const c = 0; + n = c; + break; +} +{ + const c = 0; + n = c; + { + const c = false; + var b = c; + } +} +// functions +function F() { + const c = 0; + n = c; +} +var F2 = function () { + const c = 0; + n = c; +}; +var F3 = function () { + const c = 0; + n = c; +}; +// modules +var m; +(function (m) { + const c = 0; + n = c; + { + const c = false; + var b2 = c; + } +})(m || (m = {})); +// methods +var C = (function () { + function C() { + const c = 0; + n = c; + } + C.prototype.method = function () { + const c = 0; + n = c; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + const c = 0; + n = c; + return n; + }, + set: function (value) { + const c = 0; + n = c; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + const c = 0; + n = c; + }, + f2: function () { + const c = 0; + n = c; + } +}; diff --git a/tests/baselines/reference/constDeclarations-scopes2.js b/tests/baselines/reference/constDeclarations-scopes2.js new file mode 100644 index 00000000000..1d0f252ab4f --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes2.js @@ -0,0 +1,27 @@ +//// [constDeclarations-scopes2.ts] + +// global +const c = "string"; + +var n: number; +var b: boolean; + +// for scope +for (const c = 0; c < 10; n = c ) { + // for block + const c = false; + b = c; +} + + + +//// [constDeclarations-scopes2.js] +// global +const c = "string"; +var n; +var b; +for (const c = 0; c < 10; n = c) { + // for block + const c = false; + b = c; +} diff --git a/tests/baselines/reference/constDeclarations-scopes2.types b/tests/baselines/reference/constDeclarations-scopes2.types new file mode 100644 index 00000000000..9609ef8f44b --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes2.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/constDeclarations-scopes2.ts === + +// global +const c = "string"; +>c : string + +var n: number; +>n : number + +var b: boolean; +>b : boolean + +// for scope +for (const c = 0; c < 10; n = c ) { +>c : number +>c < 10 : boolean +>c : number +>n = c : number +>n : number +>c : number + + // for block + const c = false; +>c : boolean + + b = c; +>b = c : boolean +>b : boolean +>c : boolean +} + + diff --git a/tests/baselines/reference/constDeclarations-useBeforeDefinition.errors.txt b/tests/baselines/reference/constDeclarations-useBeforeDefinition.errors.txt new file mode 100644 index 00000000000..97cf58c6e9d --- /dev/null +++ b/tests/baselines/reference/constDeclarations-useBeforeDefinition.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/constDeclarations-useBeforeDefinition.ts(3,5): error TS2448: Block-scoped variable 'c1' used before its declaration. +tests/cases/compiler/constDeclarations-useBeforeDefinition.ts(9,5): error TS2448: Block-scoped variable 'v1' used before its declaration. + + +==== tests/cases/compiler/constDeclarations-useBeforeDefinition.ts (2 errors) ==== + + { + c1; + ~~ +!!! error TS2448: Block-scoped variable 'c1' used before its declaration. + const c1 = 0; + } + + var v1; + { + v1; + ~~ +!!! error TS2448: Block-scoped variable 'v1' used before its declaration. + const v1 = 0; + } + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-useBeforeDefinition2.errors.txt b/tests/baselines/reference/constDeclarations-useBeforeDefinition2.errors.txt new file mode 100644 index 00000000000..a4d28f51878 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-useBeforeDefinition2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file1.ts(2,1): error TS2448: Block-scoped variable 'c' used before its declaration. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + c; + ~ +!!! error TS2448: Block-scoped variable 'c' used before its declaration. + +==== tests/cases/compiler/file2.ts (0 errors) ==== + const c = 0; \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-validContexts.errors.txt b/tests/baselines/reference/constDeclarations-validContexts.errors.txt new file mode 100644 index 00000000000..7af16a53cbe --- /dev/null +++ b/tests/baselines/reference/constDeclarations-validContexts.errors.txt @@ -0,0 +1,129 @@ +tests/cases/compiler/constDeclarations-validContexts.ts(20,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/constDeclarations-validContexts.ts (1 errors) ==== + + + // Control flow statements with blocks + if (true) { + const c1 = 0; + } + else { + const c2 = 0; + } + + while (true) { + const c3 = 0; + } + + do { + const c4 = 0; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + const c5 = 0; + } + + for (var i = 0; i < 10; i++) { + const c6 = 0; + } + + for (var i2 in {}) { + const c7 = 0; + } + + if (true) { + label: const c8 = 0; + } + + while (false) { + label2: label3: label4: const c9 = 0; + } + + // Try/catch/finally + try { + const c10 = 0; + } + catch (e) { + const c11 = 0; + } + finally { + const c12 = 0; + } + + // Switch + switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; + } + + // blocks + { + const c15 = 0; + { + const c16 = 0 + label17: const c17 = 0; + } + } + + // global + const c18 = 0; + + // functions + function F() { + const c19 = 0; + } + + var F2 = () => { + const c20 = 0; + }; + + var F3 = function () { + const c21 = 0; + }; + + // modules + module m { + const c22 = 0; + + { + const c23 = 0; + } + } + + // methods + class C { + constructor() { + const c24 = 0; + } + + method() { + const c25 = 0; + } + + get v() { + const c26 = 0; + return c26; + } + + set v(value) { + const c27 = value; + } + } + + // object literals + var o = { + f() { + const c28 = 0; + }, + f2: () => { + const c29 = 0; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-validContexts.js b/tests/baselines/reference/constDeclarations-validContexts.js new file mode 100644 index 00000000000..355f39af2f2 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-validContexts.js @@ -0,0 +1,229 @@ +//// [constDeclarations-validContexts.ts] + + +// Control flow statements with blocks +if (true) { + const c1 = 0; +} +else { + const c2 = 0; +} + +while (true) { + const c3 = 0; +} + +do { + const c4 = 0; +} while (true); + +var obj; +with (obj) { + const c5 = 0; +} + +for (var i = 0; i < 10; i++) { + const c6 = 0; +} + +for (var i2 in {}) { + const c7 = 0; +} + +if (true) { + label: const c8 = 0; +} + +while (false) { + label2: label3: label4: const c9 = 0; +} + +// Try/catch/finally +try { + const c10 = 0; +} +catch (e) { + const c11 = 0; +} +finally { + const c12 = 0; +} + +// Switch +switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; +} + +// blocks +{ + const c15 = 0; + { + const c16 = 0 + label17: const c17 = 0; + } +} + +// global +const c18 = 0; + +// functions +function F() { + const c19 = 0; +} + +var F2 = () => { + const c20 = 0; +}; + +var F3 = function () { + const c21 = 0; +}; + +// modules +module m { + const c22 = 0; + + { + const c23 = 0; + } +} + +// methods +class C { + constructor() { + const c24 = 0; + } + + method() { + const c25 = 0; + } + + get v() { + const c26 = 0; + return c26; + } + + set v(value) { + const c27 = value; + } +} + +// object literals +var o = { + f() { + const c28 = 0; + }, + f2: () => { + const c29 = 0; + } +} + +//// [constDeclarations-validContexts.js] +// Control flow statements with blocks +if (true) { + const c1 = 0; +} +else { + const c2 = 0; +} +while (true) { + const c3 = 0; +} +do { + const c4 = 0; +} while (true); +var obj; +with (obj) { + const c5 = 0; +} +for (var i = 0; i < 10; i++) { + const c6 = 0; +} +for (var i2 in {}) { + const c7 = 0; +} +if (true) { + label: const c8 = 0; +} +while (false) { + label2: label3: label4: const c9 = 0; +} +try { + const c10 = 0; +} +catch (e) { + const c11 = 0; +} +finally { + const c12 = 0; +} +switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; +} +{ + const c15 = 0; + { + const c16 = 0; + label17: const c17 = 0; + } +} +// global +const c18 = 0; +// functions +function F() { + const c19 = 0; +} +var F2 = function () { + const c20 = 0; +}; +var F3 = function () { + const c21 = 0; +}; +// modules +var m; +(function (m) { + const c22 = 0; + { + const c23 = 0; + } +})(m || (m = {})); +// methods +var C = (function () { + function C() { + const c24 = 0; + } + C.prototype.method = function () { + const c25 = 0; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + const c26 = 0; + return c26; + }, + set: function (value) { + const c27 = value; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + const c28 = 0; + }, + f2: function () { + const c29 = 0; + } +}; diff --git a/tests/baselines/reference/constDeclarations.js b/tests/baselines/reference/constDeclarations.js new file mode 100644 index 00000000000..060c0aba61c --- /dev/null +++ b/tests/baselines/reference/constDeclarations.js @@ -0,0 +1,30 @@ +//// [constDeclarations.ts] + +// No error +const c1 = false; +const c2: number = 23; +const c3 = 0, c4 :string = "", c5 = null; + + +for(const c4 = 0; c4 < 9; ) { break; } + + +for(const c5 = 0, c6 = 0; c5 < c6; ) { break; } + +//// [constDeclarations.js] +// No error +const c1 = false; +const c2 = 23; +const c3 = 0, c4 = "", c5 = null; +for (const c4 = 0; c4 < 9;) { + break; +} +for (const c5 = 0, c6 = 0; c5 < c6;) { + break; +} + + +//// [constDeclarations.d.ts] +declare const c1: boolean; +declare const c2: number; +declare const c3: number, c4: string, c5: any; diff --git a/tests/baselines/reference/constDeclarations.types b/tests/baselines/reference/constDeclarations.types new file mode 100644 index 00000000000..e82a2f0035f --- /dev/null +++ b/tests/baselines/reference/constDeclarations.types @@ -0,0 +1,28 @@ +=== tests/cases/compiler/constDeclarations.ts === + +// No error +const c1 = false; +>c1 : boolean + +const c2: number = 23; +>c2 : number + +const c3 = 0, c4 :string = "", c5 = null; +>c3 : number +>c4 : string +>c5 : any + + +for(const c4 = 0; c4 < 9; ) { break; } +>c4 : number +>c4 < 9 : boolean +>c4 : number + + +for(const c5 = 0, c6 = 0; c5 < c6; ) { break; } +>c5 : number +>c6 : number +>c5 < c6 : boolean +>c5 : number +>c6 : number + diff --git a/tests/baselines/reference/constDeclarations2.js b/tests/baselines/reference/constDeclarations2.js new file mode 100644 index 00000000000..e4ee67ebdcd --- /dev/null +++ b/tests/baselines/reference/constDeclarations2.js @@ -0,0 +1,26 @@ +//// [constDeclarations2.ts] + +// No error +module M { + export const c1 = false; + export const c2: number = 23; + export const c3 = 0, c4 :string = "", c5 = null; +} + + +//// [constDeclarations2.js] +// No error +var M; +(function (M) { + M.c1 = false; + M.c2 = 23; + M.c3 = 0, M.c4 = "", M.c5 = null; +})(M || (M = {})); + + +//// [constDeclarations2.d.ts] +declare module M { + const c1: boolean; + const c2: number; + const c3: number, c4: string, c5: any; +} diff --git a/tests/baselines/reference/constDeclarations2.types b/tests/baselines/reference/constDeclarations2.types new file mode 100644 index 00000000000..c81eca96b0d --- /dev/null +++ b/tests/baselines/reference/constDeclarations2.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/constDeclarations2.ts === + +// No error +module M { +>M : typeof M + + export const c1 = false; +>c1 : boolean + + export const c2: number = 23; +>c2 : number + + export const c3 = 0, c4 :string = "", c5 = null; +>c3 : number +>c4 : string +>c5 : any +} + diff --git a/tests/baselines/reference/contextualSignatureInstantiation.js b/tests/baselines/reference/contextualSignatureInstantiation.js new file mode 100644 index 00000000000..11e19b3262e --- /dev/null +++ b/tests/baselines/reference/contextualSignatureInstantiation.js @@ -0,0 +1,50 @@ +//// [contextualSignatureInstantiation.ts] +// TypeScript Spec, section 4.12.2: +// If e is an expression of a function type that contains exactly one generic call signature and no other members, +// and T is a function type with exactly one non - generic call signature and no other members, then any inferences +// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed +// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5). + +declare function foo(cb: (x: number, y: string) => T): T; +declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V; +declare function baz(x: T, y: T, cb: (x: T, y: T) => U): U; + +declare function g(x: T, y: T): T; +declare function h(x: T, y: U): T[] | U[]; + +var a: number; +var a = bar(1, 1, g); // Should be number +var a = baz(1, 1, g); // Should be number + +var b: number | string; +var b = foo(g); // Should be number | string +var b = bar(1, "one", g); // Should be number | string +var b = bar("one", 1, g); // Should be number | string +var b = baz(b, b, g); // Should be number | string + +var d: number[] | string[]; +var d = foo(h); // Should be number[] | string[] +var d = bar(1, "one", h); // Should be number[] | string[] +var d = bar("one", 1, h); // Should be number[] | string[] +var d = baz(d, d, g); // Should be number[] | string[] + + +//// [contextualSignatureInstantiation.js] +// TypeScript Spec, section 4.12.2: +// If e is an expression of a function type that contains exactly one generic call signature and no other members, +// and T is a function type with exactly one non - generic call signature and no other members, then any inferences +// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed +// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5). +var a; +var a = bar(1, 1, g); // Should be number +var a = baz(1, 1, g); // Should be number +var b; +var b = foo(g); // Should be number | string +var b = bar(1, "one", g); // Should be number | string +var b = bar("one", 1, g); // Should be number | string +var b = baz(b, b, g); // Should be number | string +var d; +var d = foo(h); // Should be number[] | string[] +var d = bar(1, "one", h); // Should be number[] | string[] +var d = bar("one", 1, h); // Should be number[] | string[] +var d = baz(d, d, g); // Should be number[] | string[] diff --git a/tests/baselines/reference/contextualSignatureInstantiation.types b/tests/baselines/reference/contextualSignatureInstantiation.types new file mode 100644 index 00000000000..4363272622a --- /dev/null +++ b/tests/baselines/reference/contextualSignatureInstantiation.types @@ -0,0 +1,142 @@ +=== tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts === +// TypeScript Spec, section 4.12.2: +// If e is an expression of a function type that contains exactly one generic call signature and no other members, +// and T is a function type with exactly one non - generic call signature and no other members, then any inferences +// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed +// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5). + +declare function foo(cb: (x: number, y: string) => T): T; +>foo : (cb: (x: number, y: string) => T) => T +>T : T +>cb : (x: number, y: string) => T +>x : number +>y : string +>T : T +>T : T + +declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V; +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>T : T +>U : U +>V : V +>x : T +>T : T +>y : U +>U : U +>cb : (x: T, y: U) => V +>x : T +>T : T +>y : U +>U : U +>V : V +>V : V + +declare function baz(x: T, y: T, cb: (x: T, y: T) => U): U; +>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U +>T : T +>U : U +>x : T +>T : T +>y : T +>T : T +>cb : (x: T, y: T) => U +>x : T +>T : T +>y : T +>T : T +>U : U +>U : U + +declare function g(x: T, y: T): T; +>g : (x: T, y: T) => T +>T : T +>x : T +>T : T +>y : T +>T : T +>T : T + +declare function h(x: T, y: U): T[] | U[]; +>h : (x: T, y: U) => T[] | U[] +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>T : T +>U : U + +var a: number; +>a : number + +var a = bar(1, 1, g); // Should be number +>a : number +>bar(1, 1, g) : number +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>g : (x: T, y: T) => T + +var a = baz(1, 1, g); // Should be number +>a : number +>baz(1, 1, g) : number +>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U +>g : (x: T, y: T) => T + +var b: number | string; +>b : string | number + +var b = foo(g); // Should be number | string +>b : string | number +>foo(g) : string | number +>foo : (cb: (x: number, y: string) => T) => T +>g : (x: T, y: T) => T + +var b = bar(1, "one", g); // Should be number | string +>b : string | number +>bar(1, "one", g) : string | number +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>g : (x: T, y: T) => T + +var b = bar("one", 1, g); // Should be number | string +>b : string | number +>bar("one", 1, g) : string | number +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>g : (x: T, y: T) => T + +var b = baz(b, b, g); // Should be number | string +>b : string | number +>baz(b, b, g) : string | number +>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U +>b : string | number +>b : string | number +>g : (x: T, y: T) => T + +var d: number[] | string[]; +>d : string[] | number[] + +var d = foo(h); // Should be number[] | string[] +>d : string[] | number[] +>foo(h) : string[] | number[] +>foo : (cb: (x: number, y: string) => T) => T +>h : (x: T, y: U) => T[] | U[] + +var d = bar(1, "one", h); // Should be number[] | string[] +>d : string[] | number[] +>bar(1, "one", h) : string[] | number[] +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>h : (x: T, y: U) => T[] | U[] + +var d = bar("one", 1, h); // Should be number[] | string[] +>d : string[] | number[] +>bar("one", 1, h) : string[] | number[] +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>h : (x: T, y: U) => T[] | U[] + +var d = baz(d, d, g); // Should be number[] | string[] +>d : string[] | number[] +>baz(d, d, g) : string[] | number[] +>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U +>d : string[] | number[] +>d : string[] | number[] +>g : (x: T, y: T) => T + diff --git a/tests/baselines/reference/contextualTyping21.errors.txt b/tests/baselines/reference/contextualTyping21.errors.txt index 620b0635d12..c6ca82d87ac 100644 --- a/tests/baselines/reference/contextualTyping21.errors.txt +++ b/tests/baselines/reference/contextualTyping21.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type 'Array' is not assignable to type '{ id: number; }[]': +tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '(number | { id: number; })[]' is not assignable to type '{ id: number; }[]': Type 'number | { id: number; }' is not assignable to type '{ id: number; }': Type 'number' is not assignable to type '{ id: number; }': Property 'id' is missing in type 'Number'. @@ -7,7 +7,7 @@ tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type 'Array' is not assignable to type '{ id: number; }[]': +!!! error TS2322: Type '(number | { id: number; })[]' is not assignable to type '{ id: number; }[]': !!! error TS2322: Type 'number | { id: number; }' is not assignable to type '{ id: number; }': !!! error TS2322: Type 'number' is not assignable to type '{ id: number; }': !!! error TS2322: Property 'id' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping30.errors.txt b/tests/baselines/reference/contextualTyping30.errors.txt index 4c8d87d41b6..f7a9eeead35 100644 --- a/tests/baselines/reference/contextualTyping30.errors.txt +++ b/tests/baselines/reference/contextualTyping30.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. Type 'string | number' is not assignable to type 'number': Type 'string' is not assignable to type 'number'. @@ -6,6 +6,6 @@ tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type ==== tests/cases/compiler/contextualTyping30.ts (1 errors) ==== function foo(param:number[]){}; foo([1, "a"]); ~~~~~~~~ -!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. !!! error TS2345: Type 'string | number' is not assignable to type 'number': !!! error TS2345: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping32.types b/tests/baselines/reference/contextualTyping32.types index 383615aec3c..c273be967e3 100644 --- a/tests/baselines/reference/contextualTyping32.types +++ b/tests/baselines/reference/contextualTyping32.types @@ -5,7 +5,7 @@ function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){ret >i : number >foo([function(){return 1;}, function(){return 4}]) : void >foo : (param: { (): number; (i: number): number; }[]) => void ->[function(){return 1;}, function(){return 4}] : { (): number; }[] +>[function(){return 1;}, function(){return 4}] : (() => number)[] >function(){return 1;} : () => number >function(){return 4} : () => number diff --git a/tests/baselines/reference/contextualTyping33.errors.txt b/tests/baselines/reference/contextualTyping33.errors.txt index 82799037ec6..4aafb6d9645 100644 --- a/tests/baselines/reference/contextualTyping33.errors.txt +++ b/tests/baselines/reference/contextualTyping33.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type 'Array<{ (): number; } | { (): string; }>' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. - Type '{ (): number; } | { (): string; }' is not assignable to type '{ (): number; (i: number): number; }': +tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type '((() => number) | (() => string))[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. + Type '(() => number) | (() => string)' is not assignable to type '{ (): number; (i: number): number; }': Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'. ==== tests/cases/compiler/contextualTyping33.ts (1 errors) ==== function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){return 1;}, function(){return "foo"}]); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type 'Array<{ (): number; } | { (): string; }>' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. -!!! error TS2345: Type '{ (): number; } | { (): string; }' is not assignable to type '{ (): number; (i: number): number; }': +!!! error TS2345: Argument of type '((() => number) | (() => string))[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. +!!! error TS2345: Type '(() => number) | (() => string)' is not assignable to type '{ (): number; (i: number): number; }': !!! error TS2345: Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingArrayOfLambdas.types b/tests/baselines/reference/contextualTypingArrayOfLambdas.types index f3bb8bab70f..d3e5b9942e3 100644 --- a/tests/baselines/reference/contextualTypingArrayOfLambdas.types +++ b/tests/baselines/reference/contextualTypingArrayOfLambdas.types @@ -23,8 +23,8 @@ class C extends A { } var xs = [(x: A) => { }, (x: B) => { }, (x: C) => { }]; ->xs : { (x: A): void; }[] ->[(x: A) => { }, (x: B) => { }, (x: C) => { }] : { (x: A): void; }[] +>xs : ((x: A) => void)[] +>[(x: A) => { }, (x: B) => { }, (x: C) => { }] : ((x: A) => void)[] >(x: A) => { } : (x: A) => void >x : A >A : A diff --git a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt index cb3b439681e..92b74829e55 100644 --- a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt +++ b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type 'Array' is not assignable to type 'I': +tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '(number | Date)[]' is not assignable to type 'I': Index signatures are incompatible: Type 'number | Date' is not assignable to type 'Date': Type 'number' is not assignable to type 'Date': @@ -12,7 +12,7 @@ tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Typ var x3: I = [new Date(), 1]; ~~ -!!! error TS2322: Type 'Array' is not assignable to type 'I': +!!! error TS2322: Type '(number | Date)[]' is not assignable to type 'I': !!! error TS2322: Index signatures are incompatible: !!! error TS2322: Type 'number | Date' is not assignable to type 'Date': !!! error TS2322: Type 'number' is not assignable to type 'Date': diff --git a/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt b/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt index 574e25c6f45..3bcfb557048 100644 --- a/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt +++ b/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2322: Type '{ (a: C): number; } | { (b: number): void; }' is not assignable to type '(a: A) => void': +tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2322: Type '((a: C) => number) | ((b: number) => void)' is not assignable to type '(a: A) => void': Type '(b: number) => void' is not assignable to type '(a: A) => void': Types of parameters 'b' and 'a' are incompatible: Type 'number' is not assignable to type 'A': @@ -18,7 +18,7 @@ tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS var x2: (a: A) => void = true ? (a: C) => a.foo : (b: number) => { }; ~~ -!!! error TS2322: Type '{ (a: C): number; } | { (b: number): void; }' is not assignable to type '(a: A) => void': +!!! error TS2322: Type '((a: C) => number) | ((b: number) => void)' is not assignable to type '(a: A) => void': !!! error TS2322: Type '(b: number) => void' is not assignable to type '(a: A) => void': !!! error TS2322: Types of parameters 'b' and 'a' are incompatible: !!! error TS2322: Type 'number' is not assignable to type 'A': diff --git a/tests/baselines/reference/contextuallyTypingOrOperator.types b/tests/baselines/reference/contextuallyTypingOrOperator.types index 4b47ea763bc..47b78f5691d 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator.types @@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >s : string var v2 = (s: string) => s.length || function (s) { s.length }; ->v2 : (s: string) => number | { (s: any): void; } ->(s: string) => s.length || function (s) { s.length } : (s: string) => number | { (s: any): void; } +>v2 : (s: string) => number | ((s: any) => void) +>(s: string) => s.length || function (s) { s.length } : (s: string) => number | ((s: any) => void) >s : string ->s.length || function (s) { s.length } : number | { (s: any): void; } +>s.length || function (s) { s.length } : number | ((s: any) => void) >s.length : number >s : string >length : number @@ -31,10 +31,10 @@ var v2 = (s: string) => s.length || function (s) { s.length }; >length : any var v3 = (s: string) => s.length || function (s: number) { return 1 }; ->v3 : (s: string) => number | { (s: number): number; } ->(s: string) => s.length || function (s: number) { return 1 } : (s: string) => number | { (s: number): number; } +>v3 : (s: string) => number | ((s: number) => number) +>(s: string) => s.length || function (s: number) { return 1 } : (s: string) => number | ((s: number) => number) >s : string ->s.length || function (s: number) { return 1 } : number | { (s: number): number; } +>s.length || function (s: number) { return 1 } : number | ((s: number) => number) >s.length : number >s : string >length : number @@ -42,10 +42,10 @@ var v3 = (s: string) => s.length || function (s: number) { return 1 }; >s : number var v4 = (s: number) => 1 || function (s: string) { return s.length }; ->v4 : (s: number) => number | { (s: string): number; } ->(s: number) => 1 || function (s: string) { return s.length } : (s: number) => number | { (s: string): number; } +>v4 : (s: number) => number | ((s: string) => number) +>(s: number) => 1 || function (s: string) { return s.length } : (s: number) => number | ((s: string) => number) >s : number ->1 || function (s: string) { return s.length } : number | { (s: string): number; } +>1 || function (s: string) { return s.length } : number | ((s: string) => number) >function (s: string) { return s.length } : (s: string) => number >s : string >s.length : number diff --git a/tests/baselines/reference/contextuallyTypingOrOperator2.types b/tests/baselines/reference/contextuallyTypingOrOperator2.types index c233066d6dc..65ed442d5e9 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator2.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator2.types @@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >s : string var v2 = (s: string) => s.length || function (s) { s.aaa }; ->v2 : (s: string) => number | { (s: any): void; } ->(s: string) => s.length || function (s) { s.aaa } : (s: string) => number | { (s: any): void; } +>v2 : (s: string) => number | ((s: any) => void) +>(s: string) => s.length || function (s) { s.aaa } : (s: string) => number | ((s: any) => void) >s : string ->s.length || function (s) { s.aaa } : number | { (s: any): void; } +>s.length || function (s) { s.aaa } : number | ((s: any) => void) >s.length : number >s : string >length : number diff --git a/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types b/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types index 47b7ed95dc6..36b85d7950c 100644 --- a/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types +++ b/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types @@ -49,7 +49,7 @@ b = d2; var r: Base[] = [d1, d2]; >r : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived | Derived2)[] >d1 : Derived >d2 : Derived2 diff --git a/tests/baselines/reference/enumBasics.types b/tests/baselines/reference/enumBasics.types index 696e68eded2..c0d7fb9bed1 100644 --- a/tests/baselines/reference/enumBasics.types +++ b/tests/baselines/reference/enumBasics.types @@ -157,8 +157,8 @@ enum E9 { // (refer to .js to validate) // Enum constant members are propagated var doNotPropagate = [ ->doNotPropagate : Array ->[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : Array +>doNotPropagate : (E3 | E4 | E7 | E8)[] +>[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : (E3 | E4 | E7 | E8)[] E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z >E8.B : E8 @@ -183,8 +183,8 @@ var doNotPropagate = [ ]; // Enum computed members are not propagated var doPropagate = [ ->doPropagate : Array ->[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : Array +>doPropagate : (E5 | E6 | E9)[] +>[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : (E5 | E6 | E9)[] E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C >E9.A : E9 diff --git a/tests/baselines/reference/enumIdentifierLiterals.errors.txt b/tests/baselines/reference/enumIdentifierLiterals.errors.txt index 6327e40289a..dbf8734ea73 100644 --- a/tests/baselines/reference/enumIdentifierLiterals.errors.txt +++ b/tests/baselines/reference/enumIdentifierLiterals.errors.txt @@ -1,25 +1,22 @@ -tests/cases/compiler/enumIdentifierLiterals.ts(2,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(3,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(4,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(5,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(6,5): error TS1151: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(2,5): error TS2452: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(3,5): error TS2452: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(4,5): error TS2452: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(6,5): error TS2452: An enum member cannot have a numeric name. -==== tests/cases/compiler/enumIdentifierLiterals.ts (5 errors) ==== +==== tests/cases/compiler/enumIdentifierLiterals.ts (4 errors) ==== enum Nums { 1.0, ~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. 11e-1, ~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. 0.12e1, ~~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. "13e-1", - ~~~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. 0xF00D ~~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. } \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.js b/tests/baselines/reference/es6-amd.js new file mode 100644 index 00000000000..0cce3af0446 --- /dev/null +++ b/tests/baselines/reference/es6-amd.js @@ -0,0 +1,31 @@ +//// [es6-amd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-amd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es6-amd.js.map + +//// [es6-amd.d.ts] +declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es6-amd.js.map b/tests/baselines/reference/es6-amd.js.map new file mode 100644 index 00000000000..7371ba578bd --- /dev/null +++ b/tests/baselines/reference/es6-amd.js.map @@ -0,0 +1,2 @@ +//// [es6-amd.js.map] +{"version":3,"file":"es6-amd.js","sourceRoot":"","sources":["es6-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA,IAAM,CAAC;IAEHA,SAFEA,CAACA;IAKHC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.sourcemap.txt b/tests/baselines/reference/es6-amd.sourcemap.txt new file mode 100644 index 00000000000..070a35703e1 --- /dev/null +++ b/tests/baselines/reference/es6-amd.sourcemap.txt @@ -0,0 +1,128 @@ +=================================================================== +JsFile: es6-amd.js +mapUrl: es6-amd.js.map +sourceRoot: +sources: es6-amd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-amd.js +sourceFile:es6-amd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^-> +1 > + > +2 >class +3 > A +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 8) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^^^^^^^^ +3 > ^ +1-> + >{ + > +2 > +3 > A +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +2 >Emitted(2, 14) Source(2, 7) + SourceIndex(0) name (A) +3 >Emitted(2, 15) Source(2, 8) + SourceIndex(0) name (A) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >{ + > constructor () + > { + > + > +2 > } +1 >Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>})(); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) +4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=es6-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.types b/tests/baselines/reference/es6-amd.types new file mode 100644 index 00000000000..62815911f7f --- /dev/null +++ b/tests/baselines/reference/es6-amd.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; + } +} diff --git a/tests/baselines/reference/es6-declaration-amd.js b/tests/baselines/reference/es6-declaration-amd.js new file mode 100644 index 00000000000..471f96b223d --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.js @@ -0,0 +1,31 @@ +//// [es6-declaration-amd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-declaration-amd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es6-declaration-amd.js.map + +//// [es6-declaration-amd.d.ts] +declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es6-declaration-amd.js.map b/tests/baselines/reference/es6-declaration-amd.js.map new file mode 100644 index 00000000000..0987f9478e9 --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.js.map @@ -0,0 +1,2 @@ +//// [es6-declaration-amd.js.map] +{"version":3,"file":"es6-declaration-amd.js","sourceRoot":"","sources":["es6-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA,IAAM,CAAC;IAEHA,SAFEA,CAACA;IAKHC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt new file mode 100644 index 00000000000..1fc0b5f05fe --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt @@ -0,0 +1,128 @@ +=================================================================== +JsFile: es6-declaration-amd.js +mapUrl: es6-declaration-amd.js.map +sourceRoot: +sources: es6-declaration-amd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-declaration-amd.js +sourceFile:es6-declaration-amd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^-> +1 > + > +2 >class +3 > A +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 8) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^^^^^^^^ +3 > ^ +1-> + >{ + > +2 > +3 > A +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +2 >Emitted(2, 14) Source(2, 7) + SourceIndex(0) name (A) +3 >Emitted(2, 15) Source(2, 8) + SourceIndex(0) name (A) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >{ + > constructor () + > { + > + > +2 > } +1 >Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>})(); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) +4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=es6-declaration-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.types b/tests/baselines/reference/es6-declaration-amd.types new file mode 100644 index 00000000000..e275fc52439 --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-declaration-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; + } +} diff --git a/tests/baselines/reference/es6-sourcemap-amd.js b/tests/baselines/reference/es6-sourcemap-amd.js new file mode 100644 index 00000000000..805e56cf830 --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.js @@ -0,0 +1,25 @@ +//// [es6-sourcemap-amd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-sourcemap-amd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.js.map b/tests/baselines/reference/es6-sourcemap-amd.js.map new file mode 100644 index 00000000000..689f0447fa8 --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.js.map @@ -0,0 +1,2 @@ +//// [es6-sourcemap-amd.js.map] +{"version":3,"file":"es6-sourcemap-amd.js","sourceRoot":"","sources":["es6-sourcemap-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA,IAAM,CAAC;IAEHA,SAFEA,CAACA;IAKHC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt new file mode 100644 index 00000000000..09abb195987 --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt @@ -0,0 +1,128 @@ +=================================================================== +JsFile: es6-sourcemap-amd.js +mapUrl: es6-sourcemap-amd.js.map +sourceRoot: +sources: es6-sourcemap-amd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-sourcemap-amd.js +sourceFile:es6-sourcemap-amd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^-> +1 > + > +2 >class +3 > A +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 8) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^^^^^^^^ +3 > ^ +1-> + >{ + > +2 > +3 > A +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +2 >Emitted(2, 14) Source(2, 7) + SourceIndex(0) name (A) +3 >Emitted(2, 15) Source(2, 8) + SourceIndex(0) name (A) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >{ + > constructor () + > { + > + > +2 > } +1 >Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>})(); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) +4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.types b/tests/baselines/reference/es6-sourcemap-amd.types new file mode 100644 index 00000000000..661ab2e7cdd --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-sourcemap-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; + } +} diff --git a/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt b/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt index 66e8a2a66df..53ecb88363d 100644 --- a/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt +++ b/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDec tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(40,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C2'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(43,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '(x: string) => number', but here has type '(x: number) => string'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(46,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. -tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(47,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. +tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(47,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | D)[]'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(50,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'D[]', but here has type 'D[]'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(53,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. @@ -79,7 +79,7 @@ tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDec !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. for( var arr = [new C(), new C2(), new D()];;){} ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | D)[]'. for(var arr2 = [new D()];;){} for( var arr2 = new Array>();;){} diff --git a/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.js b/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.js index 37bcf84669c..f58b1047b8f 100644 --- a/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.js +++ b/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.js @@ -11,6 +11,4 @@ function foo(args) { //// [functionDeclarationWithArgumentOfTypeFunctionTypeArray.d.ts] -declare function foo(args: { - (x: any): number; -}[]): number; +declare function foo(args: ((x: any) => number)[]): number; diff --git a/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.types b/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.types index af751fbb0e9..a1d32a2a405 100644 --- a/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.types +++ b/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.types @@ -1,12 +1,12 @@ === tests/cases/compiler/functionDeclarationWithArgumentOfTypeFunctionTypeArray.ts === function foo(args: { (x): number }[]) { ->foo : (args: { (x: any): number; }[]) => number ->args : { (x: any): number; }[] +>foo : (args: ((x: any) => number)[]) => number +>args : ((x: any) => number)[] >x : any return args.length; >args.length : number ->args : { (x: any): number; }[] +>args : ((x: any) => number)[] >length : number } diff --git a/tests/baselines/reference/functionSubtypingOfVarArgs2.types b/tests/baselines/reference/functionSubtypingOfVarArgs2.types index 2f81898c7de..5e2b14ffc7a 100644 --- a/tests/baselines/reference/functionSubtypingOfVarArgs2.types +++ b/tests/baselines/reference/functionSubtypingOfVarArgs2.types @@ -3,7 +3,7 @@ class EventBase { >EventBase : EventBase private _listeners: { (...args: any[]): void; }[] = []; ->_listeners : { (...args: any[]): void; }[] +>_listeners : ((...args: any[]) => void)[] >args : any[] >[] : undefined[] @@ -14,11 +14,11 @@ class EventBase { this._listeners.push(listener); >this._listeners.push(listener) : number ->this._listeners.push : (...items: { (...args: any[]): void; }[]) => number ->this._listeners : { (...args: any[]): void; }[] +>this._listeners.push : (...items: ((...args: any[]) => void)[]) => number +>this._listeners : ((...args: any[]) => void)[] >this : EventBase ->_listeners : { (...args: any[]): void; }[] ->push : (...items: { (...args: any[]): void; }[]) => number +>_listeners : ((...args: any[]) => void)[] +>push : (...items: ((...args: any[]) => void)[]) => number >listener : (...args: any[]) => void } } diff --git a/tests/baselines/reference/functionTypeArgumentArrayAssignment.errors.txt b/tests/baselines/reference/functionTypeArgumentArrayAssignment.errors.txt deleted file mode 100644 index 9897286a624..00000000000 --- a/tests/baselines/reference/functionTypeArgumentArrayAssignment.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/functionTypeArgumentArrayAssignment.ts(3,2): error TS2300: Duplicate identifier 'length'. - - -==== tests/cases/compiler/functionTypeArgumentArrayAssignment.ts (1 errors) ==== - interface Array { - foo: T; - length: number; - ~~~~~~ -!!! error TS2300: Duplicate identifier 'length'. - } - - function map() { - var ys: U[] = []; - } - \ No newline at end of file diff --git a/tests/baselines/reference/functionTypeArgumentArrayAssignment.js b/tests/baselines/reference/functionTypeArgumentArrayAssignment.js index 9569c4566d8..38188c3505a 100644 --- a/tests/baselines/reference/functionTypeArgumentArrayAssignment.js +++ b/tests/baselines/reference/functionTypeArgumentArrayAssignment.js @@ -1,15 +1,20 @@ //// [functionTypeArgumentArrayAssignment.ts] -interface Array { - foo: T; - length: number; -} +module test { + interface Array { + foo: T; + length: number; + } -function map() { -var ys: U[] = []; + function map() { + var ys: U[] = []; + } } //// [functionTypeArgumentArrayAssignment.js] -function map() { - var ys = []; -} +var test; +(function (test) { + function map() { + var ys = []; + } +})(test || (test = {})); diff --git a/tests/baselines/reference/functionTypeArgumentArrayAssignment.types b/tests/baselines/reference/functionTypeArgumentArrayAssignment.types new file mode 100644 index 00000000000..588dfd506ef --- /dev/null +++ b/tests/baselines/reference/functionTypeArgumentArrayAssignment.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/functionTypeArgumentArrayAssignment.ts === +module test { +>test : typeof test + + interface Array { +>Array : Array +>T : T + + foo: T; +>foo : T +>T : T + + length: number; +>length : number + } + + function map() { +>map : () => void +>U : U + + var ys: U[] = []; +>ys : U[] +>U : U +>[] : undefined[] + } +} + diff --git a/tests/baselines/reference/functionTypesLackingReturnTypes.errors.txt b/tests/baselines/reference/functionTypesLackingReturnTypes.errors.txt index a0be6f32df0..84ec6ff1ba5 100644 --- a/tests/baselines/reference/functionTypesLackingReturnTypes.errors.txt +++ b/tests/baselines/reference/functionTypesLackingReturnTypes.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/functionTypesLackingReturnTypes.ts(3,17): error TS1005: '=>' expected. -tests/cases/compiler/functionTypesLackingReturnTypes.ts(7,15): error TS1005: '=>' expected. +tests/cases/compiler/functionTypesLackingReturnTypes.ts(7,9): error TS2304: Cannot find name 'param'. ==== tests/cases/compiler/functionTypesLackingReturnTypes.ts (2 errors) ==== @@ -12,8 +12,8 @@ tests/cases/compiler/functionTypesLackingReturnTypes.ts(7,15): error TS1005: '=> // Error (no '=>') var g: (param); - ~ -!!! error TS1005: '=>' expected. + ~~~~~ +!!! error TS2304: Cannot find name 'param'. // Okay var h: { () } diff --git a/tests/baselines/reference/functionWithMultipleReturnStatements2.errors.txt b/tests/baselines/reference/functionWithMultipleReturnStatements2.errors.txt new file mode 100644 index 00000000000..2b14bd97bad --- /dev/null +++ b/tests/baselines/reference/functionWithMultipleReturnStatements2.errors.txt @@ -0,0 +1,112 @@ +tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts(58,1): error TS2354: No best common type exists among return expressions. +tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts(67,1): error TS2354: No best common type exists among return expressions. + + +==== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts (2 errors) ==== + // return type of a function with multiple returns is the BCT of each return statement + // no errors expected here + + function f1() { + if (true) { + return 1; + } else { + return null; + } + } + + function f2() { + if (true) { + return 1; + } else if (false) { + return null; + } else { + return 2; + } + } + + function f4() { + try { + return 1; + } + catch (e) { + return undefined; + } + finally { + return 1; + } + } + + function f5() { + return 1; + return new Object(); + } + + function f6(x: T) { + if (true) { + return x; + } else { + return null; + } + } + + //function f7(x: T, y: U) { + // if (true) { + // return x; + // } else { + // return y; + // } + //} + + var a: { x: number; y?: number }; + var b: { x: number; z?: number }; + // returns typeof a + function f9() { + ~~~~~~~~~~~~~~~ + if (true) { + ~~~~~~~~~~~~~~~ + return a; + ~~~~~~~~~~~~~~~~~ + } else { + ~~~~~~~~~~~~ + return b; + ~~~~~~~~~~~~~~~~~ + } + ~~~~~ + } + ~ +!!! error TS2354: No best common type exists among return expressions. + + // returns typeof b + function f10() { + ~~~~~~~~~~~~~~~~ + if (true) { + ~~~~~~~~~~~~~~~ + return b; + ~~~~~~~~~~~~~~~~~ + } else { + ~~~~~~~~~~~~ + return a; + ~~~~~~~~~~~~~~~~~ + } + ~~~~~ + } + ~ +!!! error TS2354: No best common type exists among return expressions. + + // returns number => void + function f11() { + if (true) { + return (x: number) => { } + } else { + return (x: Object) => { } + } + } + + // returns Object => void + function f12() { + if (true) { + return (x: Object) => { } + } else { + return (x: number) => { } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/functionWithMultipleReturnStatements2.types b/tests/baselines/reference/functionWithMultipleReturnStatements2.types deleted file mode 100644 index 706aca40c94..00000000000 --- a/tests/baselines/reference/functionWithMultipleReturnStatements2.types +++ /dev/null @@ -1,146 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts === -// return type of a function with multiple returns is the BCT of each return statement -// no errors expected here - -function f1() { ->f1 : () => number - - if (true) { - return 1; - } else { - return null; - } -} - -function f2() { ->f2 : () => number - - if (true) { - return 1; - } else if (false) { - return null; - } else { - return 2; - } -} - -function f4() { ->f4 : () => number - - try { - return 1; - } - catch (e) { ->e : any - - return undefined; ->undefined : undefined - } - finally { - return 1; - } -} - -function f5() { ->f5 : () => Object - - return 1; - return new Object(); ->new Object() : Object ->Object : { (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; } -} - -function f6(x: T) { ->f6 : (x: T) => T ->T : T ->x : T ->T : T - - if (true) { - return x; ->x : T - - } else { - return null; - } -} - -//function f7(x: T, y: U) { -// if (true) { -// return x; -// } else { -// return y; -// } -//} - -var a: { x: number; y?: number }; ->a : { x: number; y?: number; } ->x : number ->y : number - -var b: { x: number; z?: number }; ->b : { x: number; z?: number; } ->x : number ->z : number - -// returns typeof a -function f9() { ->f9 : () => { x: number; y?: number; } - - if (true) { - return a; ->a : { x: number; y?: number; } - - } else { - return b; ->b : { x: number; z?: number; } - } -} - -// returns typeof b -function f10() { ->f10 : () => { x: number; z?: number; } - - if (true) { - return b; ->b : { x: number; z?: number; } - - } else { - return a; ->a : { x: number; y?: number; } - } -} - -// returns number => void -function f11() { ->f11 : () => (x: number) => void - - if (true) { - return (x: number) => { } ->(x: number) => { } : (x: number) => void ->x : number - - } else { - return (x: Object) => { } ->(x: Object) => { } : (x: Object) => void ->x : Object ->Object : Object - } -} - -// returns Object => void -function f12() { ->f12 : () => (x: Object) => void - - if (true) { - return (x: Object) => { } ->(x: Object) => { } : (x: Object) => void ->x : Object ->Object : Object - - } else { - return (x: number) => { } ->(x: number) => { } : (x: number) => void ->x : number - } -} diff --git a/tests/baselines/reference/generatedContextualTyping.types b/tests/baselines/reference/generatedContextualTyping.types index 78fc6f6cfef..79787f6d994 100644 --- a/tests/baselines/reference/generatedContextualTyping.types +++ b/tests/baselines/reference/generatedContextualTyping.types @@ -34,57 +34,57 @@ var b = new Base(), d1 = new Derived1(), d2 = new Derived2(); var x1: () => Base[] = () => [d1, d2]; >x1 : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x2: () => Base[] = function() { return [d1, d2] }; >x2 : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x3: () => Base[] = function named() { return [d1, d2] }; >x3 : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x4: { (): Base[]; } = () => [d1, d2]; >x4 : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x5: { (): Base[]; } = function() { return [d1, d2] }; >x5 : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x6: { (): Base[]; } = function named() { return [d1, d2] }; >x6 : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x7: Base[] = [d1, d2]; >x7 : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -92,7 +92,7 @@ var x8: Array = [d1, d2]; >x8 : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -100,7 +100,7 @@ var x9: { [n: number]: Base; } = [d1, d2]; >x9 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -108,9 +108,9 @@ var x10: {n: Base[]; } = { n: [d1, d2] }; >x10 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -127,11 +127,11 @@ var x12: Genric = { func: n => { return [d1, d2]; } }; >x12 : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -139,8 +139,8 @@ class x13 { member: () => Base[] = () => [d1, d2] } >x13 : x13 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -148,8 +148,8 @@ class x14 { member: () => Base[] = function() { return [d1, d2] } } >x14 : x14 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -157,9 +157,9 @@ class x15 { member: () => Base[] = function named() { return [d1, d2] } } >x15 : x15 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -167,8 +167,8 @@ class x16 { member: { (): Base[]; } = () => [d1, d2] } >x16 : x16 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -176,8 +176,8 @@ class x17 { member: { (): Base[]; } = function() { return [d1, d2] } } >x17 : x17 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -185,9 +185,9 @@ class x18 { member: { (): Base[]; } = function named() { return [d1, d2] } } >x18 : x18 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -195,7 +195,7 @@ class x19 { member: Base[] = [d1, d2] } >x19 : x19 >member : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -204,7 +204,7 @@ class x20 { member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -213,7 +213,7 @@ class x21 { member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -222,9 +222,9 @@ class x22 { member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -243,11 +243,11 @@ class x24 { member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -255,8 +255,8 @@ class x25 { private member: () => Base[] = () => [d1, d2] } >x25 : x25 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -264,8 +264,8 @@ class x26 { private member: () => Base[] = function() { return [d1, d2] } } >x26 : x26 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -273,9 +273,9 @@ class x27 { private member: () => Base[] = function named() { return [d1, d2] } >x27 : x27 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -283,8 +283,8 @@ class x28 { private member: { (): Base[]; } = () => [d1, d2] } >x28 : x28 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -292,8 +292,8 @@ class x29 { private member: { (): Base[]; } = function() { return [d1, d2] } } >x29 : x29 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -301,9 +301,9 @@ class x30 { private member: { (): Base[]; } = function named() { return [d1, d2] >x30 : x30 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -311,7 +311,7 @@ class x31 { private member: Base[] = [d1, d2] } >x31 : x31 >member : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -320,7 +320,7 @@ class x32 { private member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -329,7 +329,7 @@ class x33 { private member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -338,9 +338,9 @@ class x34 { private member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -359,11 +359,11 @@ class x36 { private member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -371,8 +371,8 @@ class x37 { public member: () => Base[] = () => [d1, d2] } >x37 : x37 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -380,8 +380,8 @@ class x38 { public member: () => Base[] = function() { return [d1, d2] } } >x38 : x38 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -389,9 +389,9 @@ class x39 { public member: () => Base[] = function named() { return [d1, d2] } } >x39 : x39 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -399,8 +399,8 @@ class x40 { public member: { (): Base[]; } = () => [d1, d2] } >x40 : x40 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -408,8 +408,8 @@ class x41 { public member: { (): Base[]; } = function() { return [d1, d2] } } >x41 : x41 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -417,9 +417,9 @@ class x42 { public member: { (): Base[]; } = function named() { return [d1, d2] >x42 : x42 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -427,7 +427,7 @@ class x43 { public member: Base[] = [d1, d2] } >x43 : x43 >member : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -436,7 +436,7 @@ class x44 { public member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -445,7 +445,7 @@ class x45 { public member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -454,9 +454,9 @@ class x46 { public member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -475,11 +475,11 @@ class x48 { public member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -487,8 +487,8 @@ class x49 { static member: () => Base[] = () => [d1, d2] } >x49 : x49 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -496,8 +496,8 @@ class x50 { static member: () => Base[] = function() { return [d1, d2] } } >x50 : x50 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -505,9 +505,9 @@ class x51 { static member: () => Base[] = function named() { return [d1, d2] } } >x51 : x51 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -515,8 +515,8 @@ class x52 { static member: { (): Base[]; } = () => [d1, d2] } >x52 : x52 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -524,8 +524,8 @@ class x53 { static member: { (): Base[]; } = function() { return [d1, d2] } } >x53 : x53 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -533,9 +533,9 @@ class x54 { static member: { (): Base[]; } = function named() { return [d1, d2] >x54 : x54 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -543,7 +543,7 @@ class x55 { static member: Base[] = [d1, d2] } >x55 : x55 >member : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -552,7 +552,7 @@ class x56 { static member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -561,7 +561,7 @@ class x57 { static member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -570,9 +570,9 @@ class x58 { static member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -591,11 +591,11 @@ class x60 { static member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -603,8 +603,8 @@ class x61 { private static member: () => Base[] = () => [d1, d2] } >x61 : x61 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -612,8 +612,8 @@ class x62 { private static member: () => Base[] = function() { return [d1, d2] } >x62 : x62 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -621,9 +621,9 @@ class x63 { private static member: () => Base[] = function named() { return [d1, >x63 : x63 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -631,8 +631,8 @@ class x64 { private static member: { (): Base[]; } = () => [d1, d2] } >x64 : x64 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -640,8 +640,8 @@ class x65 { private static member: { (): Base[]; } = function() { return [d1, d2 >x65 : x65 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -649,9 +649,9 @@ class x66 { private static member: { (): Base[]; } = function named() { return [ >x66 : x66 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -659,7 +659,7 @@ class x67 { private static member: Base[] = [d1, d2] } >x67 : x67 >member : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -668,7 +668,7 @@ class x68 { private static member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -677,7 +677,7 @@ class x69 { private static member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -686,9 +686,9 @@ class x70 { private static member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -707,11 +707,11 @@ class x72 { private static member: Genric = { func: n => { return [d1, d2] >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -719,8 +719,8 @@ class x73 { public static member: () => Base[] = () => [d1, d2] } >x73 : x73 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -728,8 +728,8 @@ class x74 { public static member: () => Base[] = function() { return [d1, d2] } >x74 : x74 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -737,9 +737,9 @@ class x75 { public static member: () => Base[] = function named() { return [d1, >x75 : x75 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -747,8 +747,8 @@ class x76 { public static member: { (): Base[]; } = () => [d1, d2] } >x76 : x76 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -756,8 +756,8 @@ class x77 { public static member: { (): Base[]; } = function() { return [d1, d2] >x77 : x77 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -765,9 +765,9 @@ class x78 { public static member: { (): Base[]; } = function named() { return [d >x78 : x78 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -775,7 +775,7 @@ class x79 { public static member: Base[] = [d1, d2] } >x79 : x79 >member : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -784,7 +784,7 @@ class x80 { public static member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -793,7 +793,7 @@ class x81 { public static member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -802,9 +802,9 @@ class x82 { public static member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -823,11 +823,11 @@ class x84 { public static member: Genric = { func: n => { return [d1, d2]; >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -835,8 +835,8 @@ class x85 { constructor(parm: () => Base[] = () => [d1, d2]) { } } >x85 : x85 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -844,8 +844,8 @@ class x86 { constructor(parm: () => Base[] = function() { return [d1, d2] }) { } >x86 : x86 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -853,9 +853,9 @@ class x87 { constructor(parm: () => Base[] = function named() { return [d1, d2] >x87 : x87 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -863,8 +863,8 @@ class x88 { constructor(parm: { (): Base[]; } = () => [d1, d2]) { } } >x88 : x88 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -872,8 +872,8 @@ class x89 { constructor(parm: { (): Base[]; } = function() { return [d1, d2] }) >x89 : x89 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -881,9 +881,9 @@ class x90 { constructor(parm: { (): Base[]; } = function named() { return [d1, d >x90 : x90 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -891,7 +891,7 @@ class x91 { constructor(parm: Base[] = [d1, d2]) { } } >x91 : x91 >parm : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -900,7 +900,7 @@ class x92 { constructor(parm: Array = [d1, d2]) { } } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -909,7 +909,7 @@ class x93 { constructor(parm: { [n: number]: Base; } = [d1, d2]) { } } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -918,9 +918,9 @@ class x94 { constructor(parm: {n: Base[]; } = { n: [d1, d2] }) { } } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -939,11 +939,11 @@ class x96 { constructor(parm: Genric = { func: n => { return [d1, d2]; } } >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -951,8 +951,8 @@ class x97 { constructor(public parm: () => Base[] = () => [d1, d2]) { } } >x97 : x97 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -960,8 +960,8 @@ class x98 { constructor(public parm: () => Base[] = function() { return [d1, d2] >x98 : x98 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -969,9 +969,9 @@ class x99 { constructor(public parm: () => Base[] = function named() { return [d >x99 : x99 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -979,8 +979,8 @@ class x100 { constructor(public parm: { (): Base[]; } = () => [d1, d2]) { } } >x100 : x100 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -988,8 +988,8 @@ class x101 { constructor(public parm: { (): Base[]; } = function() { return [d1, >x101 : x101 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -997,9 +997,9 @@ class x102 { constructor(public parm: { (): Base[]; } = function named() { retur >x102 : x102 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1007,7 +1007,7 @@ class x103 { constructor(public parm: Base[] = [d1, d2]) { } } >x103 : x103 >parm : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1016,7 +1016,7 @@ class x104 { constructor(public parm: Array = [d1, d2]) { } } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1025,7 +1025,7 @@ class x105 { constructor(public parm: { [n: number]: Base; } = [d1, d2]) { } } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1034,9 +1034,9 @@ class x106 { constructor(public parm: {n: Base[]; } = { n: [d1, d2] }) { } } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1055,11 +1055,11 @@ class x108 { constructor(public parm: Genric = { func: n => { return [d1, >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1067,8 +1067,8 @@ class x109 { constructor(private parm: () => Base[] = () => [d1, d2]) { } } >x109 : x109 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1076,8 +1076,8 @@ class x110 { constructor(private parm: () => Base[] = function() { return [d1, d >x110 : x110 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1085,9 +1085,9 @@ class x111 { constructor(private parm: () => Base[] = function named() { return >x111 : x111 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1095,8 +1095,8 @@ class x112 { constructor(private parm: { (): Base[]; } = () => [d1, d2]) { } } >x112 : x112 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1104,8 +1104,8 @@ class x113 { constructor(private parm: { (): Base[]; } = function() { return [d1 >x113 : x113 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1113,9 +1113,9 @@ class x114 { constructor(private parm: { (): Base[]; } = function named() { retu >x114 : x114 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1123,7 +1123,7 @@ class x115 { constructor(private parm: Base[] = [d1, d2]) { } } >x115 : x115 >parm : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1132,7 +1132,7 @@ class x116 { constructor(private parm: Array = [d1, d2]) { } } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1141,7 +1141,7 @@ class x117 { constructor(private parm: { [n: number]: Base; } = [d1, d2]) { } } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1150,9 +1150,9 @@ class x118 { constructor(private parm: {n: Base[]; } = { n: [d1, d2] }) { } } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1171,11 +1171,11 @@ class x120 { constructor(private parm: Genric = { func: n => { return [d1, >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1183,8 +1183,8 @@ function x121(parm: () => Base[] = () => [d1, d2]) { } >x121 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1192,8 +1192,8 @@ function x122(parm: () => Base[] = function() { return [d1, d2] }) { } >x122 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1201,9 +1201,9 @@ function x123(parm: () => Base[] = function named() { return [d1, d2] }) { } >x123 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1211,8 +1211,8 @@ function x124(parm: { (): Base[]; } = () => [d1, d2]) { } >x124 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1220,8 +1220,8 @@ function x125(parm: { (): Base[]; } = function() { return [d1, d2] }) { } >x125 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1229,9 +1229,9 @@ function x126(parm: { (): Base[]; } = function named() { return [d1, d2] }) { } >x126 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1239,7 +1239,7 @@ function x127(parm: Base[] = [d1, d2]) { } >x127 : (parm?: Base[]) => void >parm : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1248,7 +1248,7 @@ function x128(parm: Array = [d1, d2]) { } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1257,7 +1257,7 @@ function x129(parm: { [n: number]: Base; } = [d1, d2]) { } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1266,9 +1266,9 @@ function x130(parm: {n: Base[]; } = { n: [d1, d2] }) { } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1287,68 +1287,68 @@ function x132(parm: Genric = { func: n => { return [d1, d2]; } }) { } >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x133(): () => Base[] { return () => [d1, d2]; } >x133 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x134(): () => Base[] { return function() { return [d1, d2] }; } >x134 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x135(): () => Base[] { return function named() { return [d1, d2] }; } >x135 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x136(): { (): Base[]; } { return () => [d1, d2]; } >x136 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x137(): { (): Base[]; } { return function() { return [d1, d2] }; } >x137 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x138(): { (): Base[]; } { return function named() { return [d1, d2] }; } >x138 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x139(): Base[] { return [d1, d2]; } >x139 : () => Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1356,7 +1356,7 @@ function x140(): Array { return [d1, d2]; } >x140 : () => Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1364,7 +1364,7 @@ function x141(): { [n: number]: Base; } { return [d1, d2]; } >x141 : () => { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1372,9 +1372,9 @@ function x142(): {n: Base[]; } { return { n: [d1, d2] }; } >x142 : () => { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1391,97 +1391,97 @@ function x144(): Genric { return { func: n => { return [d1, d2]; } }; } >x144 : () => Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x145(): () => Base[] { return () => [d1, d2]; return () => [d1, d2]; } >x145 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x146(): () => Base[] { return function() { return [d1, d2] }; return function() { return [d1, d2] }; } >x146 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x147(): () => Base[] { return function named() { return [d1, d2] }; return function named() { return [d1, d2] }; } >x147 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x148(): { (): Base[]; } { return () => [d1, d2]; return () => [d1, d2]; } >x148 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x149(): { (): Base[]; } { return function() { return [d1, d2] }; return function() { return [d1, d2] }; } >x149 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x150(): { (): Base[]; } { return function named() { return [d1, d2] }; return function named() { return [d1, d2] }; } >x150 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x151(): Base[] { return [d1, d2]; return [d1, d2]; } >x151 : () => Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1489,10 +1489,10 @@ function x152(): Array { return [d1, d2]; return [d1, d2]; } >x152 : () => Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1500,10 +1500,10 @@ function x153(): { [n: number]: Base; } { return [d1, d2]; return [d1, d2]; } >x153 : () => { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1511,14 +1511,14 @@ function x154(): {n: Base[]; } { return { n: [d1, d2] }; return { n: [d1, d2] } >x154 : () => { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1539,82 +1539,82 @@ function x156(): Genric { return { func: n => { return [d1, d2]; } }; retu >x156 : () => Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x157: () => () => Base[] = () => { return () => [d1, d2]; }; >x157 : () => () => Base[] >Base : Base ->() => { return () => [d1, d2]; } : () => () => Array ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => { return () => [d1, d2]; } : () => () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x158: () => () => Base[] = () => { return function() { return [d1, d2] }; }; >x158 : () => () => Base[] >Base : Base ->() => { return function() { return [d1, d2] }; } : () => () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>() => { return function() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x159: () => () => Base[] = () => { return function named() { return [d1, d2] }; }; >x159 : () => () => Base[] >Base : Base ->() => { return function named() { return [d1, d2] }; } : () => () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>() => { return function named() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x160: () => { (): Base[]; } = () => { return () => [d1, d2]; }; >x160 : () => () => Base[] >Base : Base ->() => { return () => [d1, d2]; } : () => () => Array ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => { return () => [d1, d2]; } : () => () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x161: () => { (): Base[]; } = () => { return function() { return [d1, d2] }; }; >x161 : () => () => Base[] >Base : Base ->() => { return function() { return [d1, d2] }; } : () => () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>() => { return function() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x162: () => { (): Base[]; } = () => { return function named() { return [d1, d2] }; }; >x162 : () => () => Base[] >Base : Base ->() => { return function named() { return [d1, d2] }; } : () => () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>() => { return function named() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x163: () => Base[] = () => { return [d1, d2]; }; >x163 : () => Base[] >Base : Base ->() => { return [d1, d2]; } : () => Array ->[d1, d2] : Array +>() => { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1622,8 +1622,8 @@ var x164: () => Array = () => { return [d1, d2]; }; >x164 : () => Base[] >Array : T[] >Base : Base ->() => { return [d1, d2]; } : () => Array ->[d1, d2] : Array +>() => { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1631,8 +1631,8 @@ var x165: () => { [n: number]: Base; } = () => { return [d1, d2]; }; >x165 : () => { [x: number]: Base; } >n : number >Base : Base ->() => { return [d1, d2]; } : () => Array ->[d1, d2] : Array +>() => { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1640,10 +1640,10 @@ var x166: () => {n: Base[]; } = () => { return { n: [d1, d2] }; }; >x166 : () => { n: Base[]; } >n : Base[] >Base : Base ->() => { return { n: [d1, d2] }; } : () => { n: Array; } ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>() => { return { n: [d1, d2] }; } : () => { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1661,76 +1661,76 @@ var x168: () => Genric = () => { return { func: n => { return [d1, d2]; } >x168 : () => Genric >Genric : Genric >Base : Base ->() => { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => Array; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>() => { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x169: () => () => Base[] = function() { return () => [d1, d2]; }; >x169 : () => () => Base[] >Base : Base ->function() { return () => [d1, d2]; } : () => () => Array ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>function() { return () => [d1, d2]; } : () => () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x170: () => () => Base[] = function() { return function() { return [d1, d2] }; }; >x170 : () => () => Base[] >Base : Base ->function() { return function() { return [d1, d2] }; } : () => () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return function() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x171: () => () => Base[] = function() { return function named() { return [d1, d2] }; }; >x171 : () => () => Base[] >Base : Base ->function() { return function named() { return [d1, d2] }; } : () => () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function() { return function named() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x172: () => { (): Base[]; } = function() { return () => [d1, d2]; }; >x172 : () => () => Base[] >Base : Base ->function() { return () => [d1, d2]; } : () => () => Array ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>function() { return () => [d1, d2]; } : () => () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x173: () => { (): Base[]; } = function() { return function() { return [d1, d2] }; }; >x173 : () => () => Base[] >Base : Base ->function() { return function() { return [d1, d2] }; } : () => () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return function() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x174: () => { (): Base[]; } = function() { return function named() { return [d1, d2] }; }; >x174 : () => () => Base[] >Base : Base ->function() { return function named() { return [d1, d2] }; } : () => () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function() { return function named() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x175: () => Base[] = function() { return [d1, d2]; }; >x175 : () => Base[] >Base : Base ->function() { return [d1, d2]; } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1738,8 +1738,8 @@ var x176: () => Array = function() { return [d1, d2]; }; >x176 : () => Base[] >Array : T[] >Base : Base ->function() { return [d1, d2]; } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1747,8 +1747,8 @@ var x177: () => { [n: number]: Base; } = function() { return [d1, d2]; }; >x177 : () => { [x: number]: Base; } >n : number >Base : Base ->function() { return [d1, d2]; } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1756,10 +1756,10 @@ var x178: () => {n: Base[]; } = function() { return { n: [d1, d2] }; }; >x178 : () => { n: Base[]; } >n : Base[] >Base : Base ->function() { return { n: [d1, d2] }; } : () => { n: Array; } ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>function() { return { n: [d1, d2] }; } : () => { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1777,12 +1777,12 @@ var x180: () => Genric = function() { return { func: n => { return [d1, d2 >x180 : () => Genric >Genric : Genric >Base : Base ->function() { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => Array; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>function() { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1790,8 +1790,8 @@ module x181 { var t: () => Base[] = () => [d1, d2]; } >x181 : typeof x181 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1799,8 +1799,8 @@ module x182 { var t: () => Base[] = function() { return [d1, d2] }; } >x182 : typeof x182 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1808,9 +1808,9 @@ module x183 { var t: () => Base[] = function named() { return [d1, d2] }; } >x183 : typeof x183 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1818,8 +1818,8 @@ module x184 { var t: { (): Base[]; } = () => [d1, d2]; } >x184 : typeof x184 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1827,8 +1827,8 @@ module x185 { var t: { (): Base[]; } = function() { return [d1, d2] }; } >x185 : typeof x185 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1836,9 +1836,9 @@ module x186 { var t: { (): Base[]; } = function named() { return [d1, d2] }; } >x186 : typeof x186 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1846,7 +1846,7 @@ module x187 { var t: Base[] = [d1, d2]; } >x187 : typeof x187 >t : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1855,7 +1855,7 @@ module x188 { var t: Array = [d1, d2]; } >t : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1864,7 +1864,7 @@ module x189 { var t: { [n: number]: Base; } = [d1, d2]; } >t : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1873,9 +1873,9 @@ module x190 { var t: {n: Base[]; } = { n: [d1, d2] }; } >t : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1894,11 +1894,11 @@ module x192 { var t: Genric = { func: n => { return [d1, d2]; } }; } >t : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1906,8 +1906,8 @@ module x193 { export var t: () => Base[] = () => [d1, d2]; } >x193 : typeof x193 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1915,8 +1915,8 @@ module x194 { export var t: () => Base[] = function() { return [d1, d2] }; } >x194 : typeof x194 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1924,9 +1924,9 @@ module x195 { export var t: () => Base[] = function named() { return [d1, d2] }; >x195 : typeof x195 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1934,8 +1934,8 @@ module x196 { export var t: { (): Base[]; } = () => [d1, d2]; } >x196 : typeof x196 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1943,8 +1943,8 @@ module x197 { export var t: { (): Base[]; } = function() { return [d1, d2] }; } >x197 : typeof x197 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1952,9 +1952,9 @@ module x198 { export var t: { (): Base[]; } = function named() { return [d1, d2] >x198 : typeof x198 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1962,7 +1962,7 @@ module x199 { export var t: Base[] = [d1, d2]; } >x199 : typeof x199 >t : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1971,7 +1971,7 @@ module x200 { export var t: Array = [d1, d2]; } >t : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1980,7 +1980,7 @@ module x201 { export var t: { [n: number]: Base; } = [d1, d2]; } >t : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1989,9 +1989,9 @@ module x202 { export var t: {n: Base[]; } = { n: [d1, d2] }; } >t : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2010,11 +2010,11 @@ module x204 { export var t: Genric = { func: n => { return [d1, d2]; } }; >t : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2022,8 +2022,8 @@ var x206 = <() => Base[]>function() { return [d1, d2] }; >x206 : () => Base[] ><() => Base[]>function() { return [d1, d2] } : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2031,9 +2031,9 @@ var x207 = <() => Base[]>function named() { return [d1, d2] }; >x207 : () => Base[] ><() => Base[]>function named() { return [d1, d2] } : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2041,8 +2041,8 @@ var x209 = <{ (): Base[]; }>function() { return [d1, d2] }; >x209 : () => Base[] ><{ (): Base[]; }>function() { return [d1, d2] } : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2050,9 +2050,9 @@ var x210 = <{ (): Base[]; }>function named() { return [d1, d2] }; >x210 : () => Base[] ><{ (): Base[]; }>function named() { return [d1, d2] } : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2060,7 +2060,7 @@ var x211 = [d1, d2]; >x211 : Base[] >[d1, d2] : Base[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2069,7 +2069,7 @@ var x212 = >[d1, d2]; >>[d1, d2] : Base[] >Array : T[] >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2078,7 +2078,7 @@ var x213 = <{ [n: number]: Base; }>[d1, d2]; ><{ [n: number]: Base; }>[d1, d2] : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2087,9 +2087,9 @@ var x214 = <{n: Base[]; } >{ n: [d1, d2] }; ><{n: Base[]; } >{ n: [d1, d2] } : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2098,11 +2098,11 @@ var x216 = >{ func: n => { return [d1, d2]; } }; >>{ func: n => { return [d1, d2]; } } : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2113,8 +2113,8 @@ var x217 = (<() => Base[]>undefined) || function() { return [d1, d2] }; ><() => Base[]>undefined : () => Base[] >Base : Base >undefined : undefined ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2125,9 +2125,9 @@ var x218 = (<() => Base[]>undefined) || function named() { return [d1, d2] }; ><() => Base[]>undefined : () => Base[] >Base : Base >undefined : undefined ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2138,8 +2138,8 @@ var x219 = (<{ (): Base[]; }>undefined) || function() { return [d1, d2] }; ><{ (): Base[]; }>undefined : () => Base[] >Base : Base >undefined : undefined ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2150,9 +2150,9 @@ var x220 = (<{ (): Base[]; }>undefined) || function named() { return [d1, d2] }; ><{ (): Base[]; }>undefined : () => Base[] >Base : Base >undefined : undefined ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2163,7 +2163,7 @@ var x221 = (undefined) || [d1, d2]; >undefined : Base[] >Base : Base >undefined : undefined ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2175,7 +2175,7 @@ var x222 = (>undefined) || [d1, d2]; >Array : T[] >Base : Base >undefined : undefined ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2187,7 +2187,7 @@ var x223 = (<{ [n: number]: Base; }>undefined) || [d1, d2]; >n : number >Base : Base >undefined : undefined ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2199,80 +2199,80 @@ var x224 = (<{n: Base[]; } >undefined) || { n: [d1, d2] }; >n : Base[] >Base : Base >undefined : undefined ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x225: () => Base[]; x225 = () => [d1, d2]; >x225 : () => Base[] >Base : Base ->x225 = () => [d1, d2] : () => Array +>x225 = () => [d1, d2] : () => (Derived1 | Derived2)[] >x225 : () => Base[] ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x226: () => Base[]; x226 = function() { return [d1, d2] }; >x226 : () => Base[] >Base : Base ->x226 = function() { return [d1, d2] } : () => Array +>x226 = function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >x226 : () => Base[] ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x227: () => Base[]; x227 = function named() { return [d1, d2] }; >x227 : () => Base[] >Base : Base ->x227 = function named() { return [d1, d2] } : () => Array +>x227 = function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >x227 : () => Base[] ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x228: { (): Base[]; }; x228 = () => [d1, d2]; >x228 : () => Base[] >Base : Base ->x228 = () => [d1, d2] : () => Array +>x228 = () => [d1, d2] : () => (Derived1 | Derived2)[] >x228 : () => Base[] ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x229: { (): Base[]; }; x229 = function() { return [d1, d2] }; >x229 : () => Base[] >Base : Base ->x229 = function() { return [d1, d2] } : () => Array +>x229 = function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >x229 : () => Base[] ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x230: { (): Base[]; }; x230 = function named() { return [d1, d2] }; >x230 : () => Base[] >Base : Base ->x230 = function named() { return [d1, d2] } : () => Array +>x230 = function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >x230 : () => Base[] ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x231: Base[]; x231 = [d1, d2]; >x231 : Base[] >Base : Base ->x231 = [d1, d2] : Array +>x231 = [d1, d2] : (Derived1 | Derived2)[] >x231 : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2280,9 +2280,9 @@ var x232: Array; x232 = [d1, d2]; >x232 : Base[] >Array : T[] >Base : Base ->x232 = [d1, d2] : Array +>x232 = [d1, d2] : (Derived1 | Derived2)[] >x232 : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2290,9 +2290,9 @@ var x233: { [n: number]: Base; }; x233 = [d1, d2]; >x233 : { [x: number]: Base; } >n : number >Base : Base ->x233 = [d1, d2] : Array +>x233 = [d1, d2] : (Derived1 | Derived2)[] >x233 : { [x: number]: Base; } ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2300,11 +2300,11 @@ var x234: {n: Base[]; } ; x234 = { n: [d1, d2] }; >x234 : { n: Base[]; } >n : Base[] >Base : Base ->x234 = { n: [d1, d2] } : { n: Array; } +>x234 = { n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } >x234 : { n: Base[]; } ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2323,13 +2323,13 @@ var x236: Genric; x236 = { func: n => { return [d1, d2]; } }; >x236 : Genric >Genric : Genric >Base : Base ->x236 = { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>x236 = { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } >x236 : Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2337,10 +2337,10 @@ var x237: { n: () => Base[]; } = { n: () => [d1, d2] }; >x237 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: () => [d1, d2] } : { n: () => Array; } ->n : () => Array ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>{ n: () => [d1, d2] } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2348,10 +2348,10 @@ var x238: { n: () => Base[]; } = { n: function() { return [d1, d2] } }; >x238 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function() { return [d1, d2] } } : { n: () => Array; } ->n : () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>{ n: function() { return [d1, d2] } } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2359,11 +2359,11 @@ var x239: { n: () => Base[]; } = { n: function named() { return [d1, d2] } }; >x239 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function named() { return [d1, d2] } } : { n: () => Array; } ->n : () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>{ n: function named() { return [d1, d2] } } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2371,10 +2371,10 @@ var x240: { n: { (): Base[]; }; } = { n: () => [d1, d2] }; >x240 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: () => [d1, d2] } : { n: () => Array; } ->n : () => Array ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>{ n: () => [d1, d2] } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2382,10 +2382,10 @@ var x241: { n: { (): Base[]; }; } = { n: function() { return [d1, d2] } }; >x241 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function() { return [d1, d2] } } : { n: () => Array; } ->n : () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>{ n: function() { return [d1, d2] } } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2393,11 +2393,11 @@ var x242: { n: { (): Base[]; }; } = { n: function named() { return [d1, d2] } }; >x242 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function named() { return [d1, d2] } } : { n: () => Array; } ->n : () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>{ n: function named() { return [d1, d2] } } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2405,9 +2405,9 @@ var x243: { n: Base[]; } = { n: [d1, d2] }; >x243 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2416,9 +2416,9 @@ var x244: { n: Array; } = { n: [d1, d2] }; >n : Base[] >Array : T[] >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2427,9 +2427,9 @@ var x245: { n: { [n: number]: Base; }; } = { n: [d1, d2] }; >n : { [x: number]: Base; } >n : number >Base : Base ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2438,11 +2438,11 @@ var x246: { n: {n: Base[]; } ; } = { n: { n: [d1, d2] } }; >n : { n: Base[]; } >n : Base[] >Base : Base ->{ n: { n: [d1, d2] } } : { n: { n: Array; }; } ->n : { n: Array; } ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: { n: [d1, d2] } } : { n: { n: (Derived1 | Derived2)[]; }; } +>n : { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2463,49 +2463,49 @@ var x248: { n: Genric; } = { n: { func: n => { return [d1, d2]; } } }; >n : Genric >Genric : Genric >Base : Base ->{ n: { func: n => { return [d1, d2]; } } } : { n: { func: (n: Base[]) => Array; }; } ->n : { func: (n: Base[]) => Array; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ n: { func: n => { return [d1, d2]; } } } : { n: { func: (n: Base[]) => (Derived1 | Derived2)[]; }; } +>n : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x252: { (): Base[]; }[] = [() => [d1, d2]]; ->x252 : { (): Base[]; }[] +>x252 : (() => Base[])[] >Base : Base ->[() => [d1, d2]] : { (): Array; }[] ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>[() => [d1, d2]] : (() => (Derived1 | Derived2)[])[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x253: { (): Base[]; }[] = [function() { return [d1, d2] }]; ->x253 : { (): Base[]; }[] +>x253 : (() => Base[])[] >Base : Base ->[function() { return [d1, d2] }] : { (): Array; }[] ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>[function() { return [d1, d2] }] : (() => (Derived1 | Derived2)[])[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x254: { (): Base[]; }[] = [function named() { return [d1, d2] }]; ->x254 : { (): Base[]; }[] +>x254 : (() => Base[])[] >Base : Base ->[function named() { return [d1, d2] }] : { (): Array; }[] ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>[function named() { return [d1, d2] }] : (() => (Derived1 | Derived2)[])[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x255: Base[][] = [[d1, d2]]; >x255 : Base[][] >Base : Base ->[[d1, d2]] : Array[] ->[d1, d2] : Array +>[[d1, d2]] : (Derived1 | Derived2)[][] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2513,8 +2513,8 @@ var x256: Array[] = [[d1, d2]]; >x256 : Base[][] >Array : T[] >Base : Base ->[[d1, d2]] : Array[] ->[d1, d2] : Array +>[[d1, d2]] : (Derived1 | Derived2)[][] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2522,8 +2522,8 @@ var x257: { [n: number]: Base; }[] = [[d1, d2]]; >x257 : { [x: number]: Base; }[] >n : number >Base : Base ->[[d1, d2]] : Array[] ->[d1, d2] : Array +>[[d1, d2]] : (Derived1 | Derived2)[][] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2531,10 +2531,10 @@ var x258: {n: Base[]; } [] = [{ n: [d1, d2] }]; >x258 : { n: Base[]; }[] >n : Base[] >Base : Base ->[{ n: [d1, d2] }] : { n: Array; }[] ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>[{ n: [d1, d2] }] : { n: (Derived1 | Derived2)[]; }[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2542,21 +2542,21 @@ var x260: Genric[] = [{ func: n => { return [d1, d2]; } }]; >x260 : Genric[] >Genric : Genric >Base : Base ->[{ func: n => { return [d1, d2]; } }] : { func: (n: Base[]) => Array; }[] ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>[{ func: n => { return [d1, d2]; } }] : { func: (n: Base[]) => (Derived1 | Derived2)[]; }[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x261: () => Base[] = function() { return [d1, d2] } || undefined; >x261 : () => Base[] >Base : Base ->function() { return [d1, d2] } || undefined : () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } || undefined : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2564,10 +2564,10 @@ var x261: () => Base[] = function() { return [d1, d2] } || undefined; var x262: () => Base[] = function named() { return [d1, d2] } || undefined; >x262 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || undefined : () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } || undefined : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2575,9 +2575,9 @@ var x262: () => Base[] = function named() { return [d1, d2] } || undefined; var x263: { (): Base[]; } = function() { return [d1, d2] } || undefined; >x263 : () => Base[] >Base : Base ->function() { return [d1, d2] } || undefined : () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } || undefined : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2585,10 +2585,10 @@ var x263: { (): Base[]; } = function() { return [d1, d2] } || undefined; var x264: { (): Base[]; } = function named() { return [d1, d2] } || undefined; >x264 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || undefined : () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } || undefined : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2596,8 +2596,8 @@ var x264: { (): Base[]; } = function named() { return [d1, d2] } || undefined; var x265: Base[] = [d1, d2] || undefined; >x265 : Base[] >Base : Base ->[d1, d2] || undefined : Array ->[d1, d2] : Array +>[d1, d2] || undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2606,8 +2606,8 @@ var x266: Array = [d1, d2] || undefined; >x266 : Base[] >Array : T[] >Base : Base ->[d1, d2] || undefined : Array ->[d1, d2] : Array +>[d1, d2] || undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2616,8 +2616,8 @@ var x267: { [n: number]: Base; } = [d1, d2] || undefined; >x267 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] || undefined : Array ->[d1, d2] : Array +>[d1, d2] || undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2626,10 +2626,10 @@ var x268: {n: Base[]; } = { n: [d1, d2] } || undefined; >x268 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } || undefined : { n: Array; } ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } || undefined : { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2637,51 +2637,51 @@ var x268: {n: Base[]; } = { n: [d1, d2] } || undefined; var x269: () => Base[] = undefined || function() { return [d1, d2] }; >x269 : () => Base[] >Base : Base ->undefined || function() { return [d1, d2] } : () => Array +>undefined || function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x270: () => Base[] = undefined || function named() { return [d1, d2] }; >x270 : () => Base[] >Base : Base ->undefined || function named() { return [d1, d2] } : () => Array +>undefined || function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x271: { (): Base[]; } = undefined || function() { return [d1, d2] }; >x271 : () => Base[] >Base : Base ->undefined || function() { return [d1, d2] } : () => Array +>undefined || function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x272: { (): Base[]; } = undefined || function named() { return [d1, d2] }; >x272 : () => Base[] >Base : Base ->undefined || function named() { return [d1, d2] } : () => Array +>undefined || function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x273: Base[] = undefined || [d1, d2]; >x273 : Base[] >Base : Base ->undefined || [d1, d2] : Array +>undefined || [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2689,9 +2689,9 @@ var x274: Array = undefined || [d1, d2]; >x274 : Base[] >Array : T[] >Base : Base ->undefined || [d1, d2] : Array +>undefined || [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2699,9 +2699,9 @@ var x275: { [n: number]: Base; } = undefined || [d1, d2]; >x275 : { [x: number]: Base; } >n : number >Base : Base ->undefined || [d1, d2] : Array +>undefined || [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2709,78 +2709,78 @@ var x276: {n: Base[]; } = undefined || { n: [d1, d2] }; >x276 : { n: Base[]; } >n : Base[] >Base : Base ->undefined || { n: [d1, d2] } : { n: Array; } +>undefined || { n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } >undefined : undefined ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x277: () => Base[] = function() { return [d1, d2] } || function() { return [d1, d2] }; >x277 : () => Base[] >Base : Base ->function() { return [d1, d2] } || function() { return [d1, d2] } : () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } || function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x278: () => Base[] = function named() { return [d1, d2] } || function named() { return [d1, d2] }; >x278 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x279: { (): Base[]; } = function() { return [d1, d2] } || function() { return [d1, d2] }; >x279 : () => Base[] >Base : Base ->function() { return [d1, d2] } || function() { return [d1, d2] } : () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } || function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x280: { (): Base[]; } = function named() { return [d1, d2] } || function named() { return [d1, d2] }; >x280 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x281: Base[] = [d1, d2] || [d1, d2]; >x281 : Base[] >Base : Base ->[d1, d2] || [d1, d2] : Array ->[d1, d2] : Array +>[d1, d2] || [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2788,11 +2788,11 @@ var x282: Array = [d1, d2] || [d1, d2]; >x282 : Base[] >Array : T[] >Base : Base ->[d1, d2] || [d1, d2] : Array ->[d1, d2] : Array +>[d1, d2] || [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2800,11 +2800,11 @@ var x283: { [n: number]: Base; } = [d1, d2] || [d1, d2]; >x283 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] || [d1, d2] : Array ->[d1, d2] : Array +>[d1, d2] || [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2812,108 +2812,108 @@ var x284: {n: Base[]; } = { n: [d1, d2] } || { n: [d1, d2] }; >x284 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } || { n: [d1, d2] } : { n: Array; } ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } || { n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x285: () => Base[] = true ? () => [d1, d2] : () => [d1, d2]; >x285 : () => Base[] >Base : Base ->true ? () => [d1, d2] : () => [d1, d2] : () => Array ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>true ? () => [d1, d2] : () => [d1, d2] : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x286: () => Base[] = true ? function() { return [d1, d2] } : function() { return [d1, d2] }; >x286 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x287: () => Base[] = true ? function named() { return [d1, d2] } : function named() { return [d1, d2] }; >x287 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x288: { (): Base[]; } = true ? () => [d1, d2] : () => [d1, d2]; >x288 : () => Base[] >Base : Base ->true ? () => [d1, d2] : () => [d1, d2] : () => Array ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>true ? () => [d1, d2] : () => [d1, d2] : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x289: { (): Base[]; } = true ? function() { return [d1, d2] } : function() { return [d1, d2] }; >x289 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x290: { (): Base[]; } = true ? function named() { return [d1, d2] } : function named() { return [d1, d2] }; >x290 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x291: Base[] = true ? [d1, d2] : [d1, d2]; >x291 : Base[] >Base : Base ->true ? [d1, d2] : [d1, d2] : Array ->[d1, d2] : Array +>true ? [d1, d2] : [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2921,11 +2921,11 @@ var x292: Array = true ? [d1, d2] : [d1, d2]; >x292 : Base[] >Array : T[] >Base : Base ->true ? [d1, d2] : [d1, d2] : Array ->[d1, d2] : Array +>true ? [d1, d2] : [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2933,11 +2933,11 @@ var x293: { [n: number]: Base; } = true ? [d1, d2] : [d1, d2]; >x293 : { [x: number]: Base; } >n : number >Base : Base ->true ? [d1, d2] : [d1, d2] : Array ->[d1, d2] : Array +>true ? [d1, d2] : [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2945,15 +2945,15 @@ var x294: {n: Base[]; } = true ? { n: [d1, d2] } : { n: [d1, d2] }; >x294 : { n: Base[]; } >n : Base[] >Base : Base ->true ? { n: [d1, d2] } : { n: [d1, d2] } : { n: Array; } ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>true ? { n: [d1, d2] } : { n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2975,90 +2975,90 @@ var x296: Genric = true ? { func: n => { return [d1, d2]; } } : { func: n >x296 : Genric >Genric : Genric >Base : Base ->true ? { func: n => { return [d1, d2]; } } : { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>true ? { func: n => { return [d1, d2]; } } : { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x297: () => Base[] = true ? undefined : () => [d1, d2]; >x297 : () => Base[] >Base : Base ->true ? undefined : () => [d1, d2] : () => Array +>true ? undefined : () => [d1, d2] : () => (Derived1 | Derived2)[] >undefined : undefined ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x298: () => Base[] = true ? undefined : function() { return [d1, d2] }; >x298 : () => Base[] >Base : Base ->true ? undefined : function() { return [d1, d2] } : () => Array +>true ? undefined : function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x299: () => Base[] = true ? undefined : function named() { return [d1, d2] }; >x299 : () => Base[] >Base : Base ->true ? undefined : function named() { return [d1, d2] } : () => Array +>true ? undefined : function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x300: { (): Base[]; } = true ? undefined : () => [d1, d2]; >x300 : () => Base[] >Base : Base ->true ? undefined : () => [d1, d2] : () => Array +>true ? undefined : () => [d1, d2] : () => (Derived1 | Derived2)[] >undefined : undefined ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x301: { (): Base[]; } = true ? undefined : function() { return [d1, d2] }; >x301 : () => Base[] >Base : Base ->true ? undefined : function() { return [d1, d2] } : () => Array +>true ? undefined : function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x302: { (): Base[]; } = true ? undefined : function named() { return [d1, d2] }; >x302 : () => Base[] >Base : Base ->true ? undefined : function named() { return [d1, d2] } : () => Array +>true ? undefined : function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x303: Base[] = true ? undefined : [d1, d2]; >x303 : Base[] >Base : Base ->true ? undefined : [d1, d2] : Array +>true ? undefined : [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3066,9 +3066,9 @@ var x304: Array = true ? undefined : [d1, d2]; >x304 : Base[] >Array : T[] >Base : Base ->true ? undefined : [d1, d2] : Array +>true ? undefined : [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3076,9 +3076,9 @@ var x305: { [n: number]: Base; } = true ? undefined : [d1, d2]; >x305 : { [x: number]: Base; } >n : number >Base : Base ->true ? undefined : [d1, d2] : Array +>true ? undefined : [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3086,11 +3086,11 @@ var x306: {n: Base[]; } = true ? undefined : { n: [d1, d2] }; >x306 : { n: Base[]; } >n : Base[] >Base : Base ->true ? undefined : { n: [d1, d2] } : { n: Array; } +>true ? undefined : { n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } >undefined : undefined ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3109,22 +3109,22 @@ var x308: Genric = true ? undefined : { func: n => { return [d1, d2]; } }; >x308 : Genric >Genric : Genric >Base : Base ->true ? undefined : { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>true ? undefined : { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } >undefined : undefined ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x309: () => Base[] = true ? () => [d1, d2] : undefined; >x309 : () => Base[] >Base : Base ->true ? () => [d1, d2] : undefined : () => Array ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>true ? () => [d1, d2] : undefined : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3132,9 +3132,9 @@ var x309: () => Base[] = true ? () => [d1, d2] : undefined; var x310: () => Base[] = true ? function() { return [d1, d2] } : undefined; >x310 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : undefined : () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>true ? function() { return [d1, d2] } : undefined : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3142,10 +3142,10 @@ var x310: () => Base[] = true ? function() { return [d1, d2] } : undefined; var x311: () => Base[] = true ? function named() { return [d1, d2] } : undefined; >x311 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : undefined : () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>true ? function named() { return [d1, d2] } : undefined : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3153,9 +3153,9 @@ var x311: () => Base[] = true ? function named() { return [d1, d2] } : undefined var x312: { (): Base[]; } = true ? () => [d1, d2] : undefined; >x312 : () => Base[] >Base : Base ->true ? () => [d1, d2] : undefined : () => Array ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>true ? () => [d1, d2] : undefined : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3163,9 +3163,9 @@ var x312: { (): Base[]; } = true ? () => [d1, d2] : undefined; var x313: { (): Base[]; } = true ? function() { return [d1, d2] } : undefined; >x313 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : undefined : () => Array ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>true ? function() { return [d1, d2] } : undefined : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3173,10 +3173,10 @@ var x313: { (): Base[]; } = true ? function() { return [d1, d2] } : undefined; var x314: { (): Base[]; } = true ? function named() { return [d1, d2] } : undefined; >x314 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : undefined : () => Array ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>true ? function named() { return [d1, d2] } : undefined : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3184,8 +3184,8 @@ var x314: { (): Base[]; } = true ? function named() { return [d1, d2] } : undefi var x315: Base[] = true ? [d1, d2] : undefined; >x315 : Base[] >Base : Base ->true ? [d1, d2] : undefined : Array ->[d1, d2] : Array +>true ? [d1, d2] : undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3194,8 +3194,8 @@ var x316: Array = true ? [d1, d2] : undefined; >x316 : Base[] >Array : T[] >Base : Base ->true ? [d1, d2] : undefined : Array ->[d1, d2] : Array +>true ? [d1, d2] : undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3204,8 +3204,8 @@ var x317: { [n: number]: Base; } = true ? [d1, d2] : undefined; >x317 : { [x: number]: Base; } >n : number >Base : Base ->true ? [d1, d2] : undefined : Array ->[d1, d2] : Array +>true ? [d1, d2] : undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3214,10 +3214,10 @@ var x318: {n: Base[]; } = true ? { n: [d1, d2] } : undefined; >x318 : { n: Base[]; } >n : Base[] >Base : Base ->true ? { n: [d1, d2] } : undefined : { n: Array; } ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>true ? { n: [d1, d2] } : undefined : { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3237,12 +3237,12 @@ var x320: Genric = true ? { func: n => { return [d1, d2]; } } : undefined; >x320 : Genric >Genric : Genric >Base : Base ->true ? { func: n => { return [d1, d2]; } } : undefined : { func: (n: Base[]) => Array; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>true ? { func: n => { return [d1, d2]; } } : undefined : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3253,8 +3253,8 @@ function x321(n: () => Base[]) { }; x321(() => [d1, d2]); >Base : Base >x321(() => [d1, d2]) : void >x321 : (n: () => Base[]) => void ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3264,8 +3264,8 @@ function x322(n: () => Base[]) { }; x322(function() { return [d1, d2] }); >Base : Base >x322(function() { return [d1, d2] }) : void >x322 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3275,9 +3275,9 @@ function x323(n: () => Base[]) { }; x323(function named() { return [d1, d2] }); >Base : Base >x323(function named() { return [d1, d2] }) : void >x323 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3287,8 +3287,8 @@ function x324(n: { (): Base[]; }) { }; x324(() => [d1, d2]); >Base : Base >x324(() => [d1, d2]) : void >x324 : (n: () => Base[]) => void ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3298,8 +3298,8 @@ function x325(n: { (): Base[]; }) { }; x325(function() { return [d1, d2] }); >Base : Base >x325(function() { return [d1, d2] }) : void >x325 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3309,9 +3309,9 @@ function x326(n: { (): Base[]; }) { }; x326(function named() { return [d1, d2] } >Base : Base >x326(function named() { return [d1, d2] }) : void >x326 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3321,7 +3321,7 @@ function x327(n: Base[]) { }; x327([d1, d2]); >Base : Base >x327([d1, d2]) : void >x327 : (n: Base[]) => void ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3332,7 +3332,7 @@ function x328(n: Array) { }; x328([d1, d2]); >Base : Base >x328([d1, d2]) : void >x328 : (n: Base[]) => void ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3343,7 +3343,7 @@ function x329(n: { [n: number]: Base; }) { }; x329([d1, d2]); >Base : Base >x329([d1, d2]) : void >x329 : (n: { [x: number]: Base; }) => void ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3354,9 +3354,9 @@ function x330(n: {n: Base[]; } ) { }; x330({ n: [d1, d2] }); >Base : Base >x330({ n: [d1, d2] }) : void >x330 : (n: { n: Base[]; }) => void ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3379,11 +3379,11 @@ function x332(n: Genric) { }; x332({ func: n => { return [d1, d2]; } }); >Base : Base >x332({ func: n => { return [d1, d2]; } }) : void >x332 : (n: Genric) => void ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3395,8 +3395,8 @@ var x333 = (n: () => Base[]) => n; x333(() => [d1, d2]); >n : () => Base[] >x333(() => [d1, d2]) : () => Base[] >x333 : (n: () => Base[]) => () => Base[] ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3408,8 +3408,8 @@ var x334 = (n: () => Base[]) => n; x334(function() { return [d1, d2] }); >n : () => Base[] >x334(function() { return [d1, d2] }) : () => Base[] >x334 : (n: () => Base[]) => () => Base[] ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3421,9 +3421,9 @@ var x335 = (n: () => Base[]) => n; x335(function named() { return [d1, d2] }); >n : () => Base[] >x335(function named() { return [d1, d2] }) : () => Base[] >x335 : (n: () => Base[]) => () => Base[] ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3435,8 +3435,8 @@ var x336 = (n: { (): Base[]; }) => n; x336(() => [d1, d2]); >n : () => Base[] >x336(() => [d1, d2]) : () => Base[] >x336 : (n: () => Base[]) => () => Base[] ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3448,8 +3448,8 @@ var x337 = (n: { (): Base[]; }) => n; x337(function() { return [d1, d2] }); >n : () => Base[] >x337(function() { return [d1, d2] }) : () => Base[] >x337 : (n: () => Base[]) => () => Base[] ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3461,9 +3461,9 @@ var x338 = (n: { (): Base[]; }) => n; x338(function named() { return [d1, d2] }) >n : () => Base[] >x338(function named() { return [d1, d2] }) : () => Base[] >x338 : (n: () => Base[]) => () => Base[] ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3475,7 +3475,7 @@ var x339 = (n: Base[]) => n; x339([d1, d2]); >n : Base[] >x339([d1, d2]) : Base[] >x339 : (n: Base[]) => Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3488,7 +3488,7 @@ var x340 = (n: Array) => n; x340([d1, d2]); >n : Base[] >x340([d1, d2]) : Base[] >x340 : (n: Base[]) => Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3501,7 +3501,7 @@ var x341 = (n: { [n: number]: Base; }) => n; x341([d1, d2]); >n : { [x: number]: Base; } >x341([d1, d2]) : { [x: number]: Base; } >x341 : (n: { [x: number]: Base; }) => { [x: number]: Base; } ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3514,9 +3514,9 @@ var x342 = (n: {n: Base[]; } ) => n; x342({ n: [d1, d2] }); >n : { n: Base[]; } >x342({ n: [d1, d2] }) : { n: Base[]; } >x342 : (n: { n: Base[]; }) => { n: Base[]; } ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3543,11 +3543,11 @@ var x344 = (n: Genric) => n; x344({ func: n => { return [d1, d2]; } }); >n : Genric >x344({ func: n => { return [d1, d2]; } }) : Genric >x344 : (n: Genric) => Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3558,8 +3558,8 @@ var x345 = function(n: () => Base[]) { }; x345(() => [d1, d2]); >Base : Base >x345(() => [d1, d2]) : void >x345 : (n: () => Base[]) => void ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3570,8 +3570,8 @@ var x346 = function(n: () => Base[]) { }; x346(function() { return [d1, d2] }); >Base : Base >x346(function() { return [d1, d2] }) : void >x346 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3582,9 +3582,9 @@ var x347 = function(n: () => Base[]) { }; x347(function named() { return [d1, d2 >Base : Base >x347(function named() { return [d1, d2] }) : void >x347 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3595,8 +3595,8 @@ var x348 = function(n: { (): Base[]; }) { }; x348(() => [d1, d2]); >Base : Base >x348(() => [d1, d2]) : void >x348 : (n: () => Base[]) => void ->() => [d1, d2] : () => Array ->[d1, d2] : Array +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3607,8 +3607,8 @@ var x349 = function(n: { (): Base[]; }) { }; x349(function() { return [d1, d2] } >Base : Base >x349(function() { return [d1, d2] }) : void >x349 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Array ->[d1, d2] : Array +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3619,9 +3619,9 @@ var x350 = function(n: { (): Base[]; }) { }; x350(function named() { return [d1, >Base : Base >x350(function named() { return [d1, d2] }) : void >x350 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Array ->named : () => Array ->[d1, d2] : Array +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3632,7 +3632,7 @@ var x351 = function(n: Base[]) { }; x351([d1, d2]); >Base : Base >x351([d1, d2]) : void >x351 : (n: Base[]) => void ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3644,7 +3644,7 @@ var x352 = function(n: Array) { }; x352([d1, d2]); >Base : Base >x352([d1, d2]) : void >x352 : (n: Base[]) => void ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3656,7 +3656,7 @@ var x353 = function(n: { [n: number]: Base; }) { }; x353([d1, d2]); >Base : Base >x353([d1, d2]) : void >x353 : (n: { [x: number]: Base; }) => void ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3668,9 +3668,9 @@ var x354 = function(n: {n: Base[]; } ) { }; x354({ n: [d1, d2] }); >Base : Base >x354({ n: [d1, d2] }) : void >x354 : (n: { n: Base[]; }) => void ->{ n: [d1, d2] } : { n: Array; } ->n : Array ->[d1, d2] : Array +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3695,11 +3695,11 @@ var x356 = function(n: Genric) { }; x356({ func: n => { return [d1, d2]; } >Base : Base >x356({ func: n => { return [d1, d2]; } }) : void >x356 : (n: Genric) => void ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } ->func : (n: Base[]) => Array ->n => { return [d1, d2]; } : (n: Base[]) => Array +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : Array +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 diff --git a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types index f16e747d41e..768b8846880 100644 --- a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types +++ b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types @@ -49,7 +49,7 @@ _.all([true, 1, null, 'yes'], _.identity); >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => boolean >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => boolean ->[true, 1, null, 'yes'] : Array +>[true, 1, null, 'yes'] : (string | number | boolean)[] >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T diff --git a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types index 84082a68ebd..f4965940436 100644 --- a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types +++ b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types @@ -40,21 +40,21 @@ var r3 = foo([]); // number[] >[] : undefined[] var r4 = foo([1, '']); // {}[] ->r4 : Array ->foo([1, '']) : Array +>r4 : (string | number)[] +>foo([1, '']) : (string | number)[] >foo : (t: T) => T ->[1, ''] : Array +>[1, ''] : (string | number)[] var r5 = foo([1, '']); // any[] >r5 : any[] >foo([1, '']) : any[] >foo : (t: T) => T ->[1, ''] : Array +>[1, ''] : (string | number)[] var r6 = foo([1, '']); // Object[] >r6 : Object[] >foo([1, '']) : Object[] >foo : (t: T) => T >Object : Object ->[1, ''] : Array +>[1, ''] : (string | number)[] diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments.errors.txt new file mode 100644 index 00000000000..43bad8f6a1d --- /dev/null +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments.errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts(18,10): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts(19,10): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts (2 errors) ==== + // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, + // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. + + function foo(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + //var r1 = foo((x: number) => 1, (x: string) => ''); // error + var r1b = foo((x) => 1, (x) => ''); // {} => {} + var r2 = foo((x: Object) => null, (x: string) => ''); // Object => Object + var r3 = foo((x: number) => 1, (x: Object) => null); // number => number + var r3ii = foo((x: number) => 1, (x: number) => 1); // number => number + + var a: { x: number; y?: number; }; + var b: { x: number; z?: number; }; + + var r4 = foo((x: typeof a) => a, (x: typeof b) => b); // typeof a => typeof a + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r5 = foo((x: typeof b) => b, (x: typeof a) => a); // typeof b => typeof b + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + + function other(x: T) { + var r6 = foo((a: T) => a, (b: T) => b); // T => T + var r6b = foo((a) => a, (b) => b); // {} => {} + } + + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); // T => T + var r7b = foo((a) => a, (b) => b); // {} => {} + var r8 = r7(null); + // BUG 835518 + //var r9 = r7(new Date()); + } + + + function foo2(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + function other3(x: T) { + var r8 = foo2((a: Date) => a, (b: Date) => b); // Date => Date + } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments.types b/tests/baselines/reference/genericCallWithGenericSignatureArguments.types deleted file mode 100644 index 9f634070b56..00000000000 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments.types +++ /dev/null @@ -1,216 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts === -// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, -// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. - -function foo(a: (x: T) => T, b: (x: T) => T) { ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->T : T ->a : (x: T) => T ->x : T ->T : T ->T : T ->b : (x: T) => T ->x : T ->T : T ->T : T - - var r: (x: T) => T; ->r : (x: T) => T ->x : T ->T : T ->T : T - - return r; ->r : (x: T) => T -} - -//var r1 = foo((x: number) => 1, (x: string) => ''); // error -var r1b = foo((x) => 1, (x) => ''); // {} => {} ->r1b : (x: {}) => {} ->foo((x) => 1, (x) => '') : (x: {}) => {} ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x) => 1 : (x: {}) => number ->x : {} ->(x) => '' : (x: {}) => string ->x : {} - -var r2 = foo((x: Object) => null, (x: string) => ''); // Object => Object ->r2 : (x: any) => any ->foo((x: Object) => null, (x: string) => '') : (x: any) => any ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: Object) => null : (x: Object) => any ->x : Object ->Object : Object ->(x: string) => '' : (x: string) => string ->x : string - -var r3 = foo((x: number) => 1, (x: Object) => null); // number => number ->r3 : (x: any) => any ->foo((x: number) => 1, (x: Object) => null) : (x: any) => any ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: number) => 1 : (x: number) => number ->x : number ->(x: Object) => null : (x: Object) => any ->x : Object ->Object : Object - -var r3ii = foo((x: number) => 1, (x: number) => 1); // number => number ->r3ii : (x: number) => number ->foo((x: number) => 1, (x: number) => 1) : (x: number) => number ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: number) => 1 : (x: number) => number ->x : number ->(x: number) => 1 : (x: number) => number ->x : number - -var a: { x: number; y?: number; }; ->a : { x: number; y?: number; } ->x : number ->y : number - -var b: { x: number; z?: number; }; ->b : { x: number; z?: number; } ->x : number ->z : number - -var r4 = foo((x: typeof a) => a, (x: typeof b) => b); // typeof a => typeof a ->r4 : (x: { x: number; y?: number; }) => { x: number; y?: number; } ->foo((x: typeof a) => a, (x: typeof b) => b) : (x: { x: number; y?: number; }) => { x: number; y?: number; } ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: typeof a) => a : (x: { x: number; y?: number; }) => { x: number; y?: number; } ->x : { x: number; y?: number; } ->a : { x: number; y?: number; } ->a : { x: number; y?: number; } ->(x: typeof b) => b : (x: { x: number; z?: number; }) => { x: number; z?: number; } ->x : { x: number; z?: number; } ->b : { x: number; z?: number; } ->b : { x: number; z?: number; } - -var r5 = foo((x: typeof b) => b, (x: typeof a) => a); // typeof b => typeof b ->r5 : (x: { x: number; z?: number; }) => { x: number; z?: number; } ->foo((x: typeof b) => b, (x: typeof a) => a) : (x: { x: number; z?: number; }) => { x: number; z?: number; } ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: typeof b) => b : (x: { x: number; z?: number; }) => { x: number; z?: number; } ->x : { x: number; z?: number; } ->b : { x: number; z?: number; } ->b : { x: number; z?: number; } ->(x: typeof a) => a : (x: { x: number; y?: number; }) => { x: number; y?: number; } ->x : { x: number; y?: number; } ->a : { x: number; y?: number; } ->a : { x: number; y?: number; } - -function other(x: T) { ->other : (x: T) => void ->T : T ->x : T ->T : T - - var r6 = foo((a: T) => a, (b: T) => b); // T => T ->r6 : (x: T) => T ->foo((a: T) => a, (b: T) => b) : (x: T) => T ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(a: T) => a : (a: T) => T ->a : T ->T : T ->a : T ->(b: T) => b : (b: T) => T ->b : T ->T : T ->b : T - - var r6b = foo((a) => a, (b) => b); // {} => {} ->r6b : (x: {}) => {} ->foo((a) => a, (b) => b) : (x: {}) => {} ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(a) => a : (a: {}) => {} ->a : {} ->a : {} ->(b) => b : (b: {}) => {} ->b : {} ->b : {} -} - -function other2(x: T) { ->other2 : (x: T) => void ->T : T ->Date : Date ->x : T ->T : T - - var r7 = foo((a: T) => a, (b: T) => b); // T => T ->r7 : (x: T) => T ->foo((a: T) => a, (b: T) => b) : (x: T) => T ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(a: T) => a : (a: T) => T ->a : T ->T : T ->a : T ->(b: T) => b : (b: T) => T ->b : T ->T : T ->b : T - - var r7b = foo((a) => a, (b) => b); // {} => {} ->r7b : (x: {}) => {} ->foo((a) => a, (b) => b) : (x: {}) => {} ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(a) => a : (a: {}) => {} ->a : {} ->a : {} ->(b) => b : (b: {}) => {} ->b : {} ->b : {} - - var r8 = r7(null); ->r8 : T ->r7(null) : T ->r7 : (x: T) => T - - // BUG 835518 - //var r9 = r7(new Date()); -} - - -function foo2(a: (x: T) => T, b: (x: T) => T) { ->foo2 : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->T : T ->Date : Date ->a : (x: T) => T ->x : T ->T : T ->T : T ->b : (x: T) => T ->x : T ->T : T ->T : T - - var r: (x: T) => T; ->r : (x: T) => T ->x : T ->T : T ->T : T - - return r; ->r : (x: T) => T -} - -function other3(x: T) { ->other3 : (x: T) => void ->T : T ->RegExp : RegExp ->x : T ->T : T - - var r8 = foo2((a: Date) => a, (b: Date) => b); // Date => Date ->r8 : (x: Date) => Date ->foo2((a: Date) => a, (b: Date) => b) : (x: Date) => Date ->foo2 : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(a: Date) => a : (a: Date) => Date ->a : Date ->Date : Date ->a : Date ->(b: Date) => b : (b: Date) => Date ->b : Date ->Date : Date ->b : Date -} diff --git a/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.errors.txt b/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.errors.txt new file mode 100644 index 00000000000..c14db877073 --- /dev/null +++ b/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.errors.txt @@ -0,0 +1,40 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts(12,9): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts(13,10): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts (2 errors) ==== + // generic type argument inference where inference leads to two candidates that are both supertypes of all candidates + // we choose the first candidate so the result is dependent on the order of the arguments provided + + function foo(x: T, y: T) { + var r: T; + return r; + } + + var a: { x: number; y?: number; }; + var b: { x: number; z?: number; }; + + var r = foo(a, b); // { x: number; y?: number; }; + ~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r2 = foo(b, a); // { x: number; z?: number; }; + ~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + + var x: { x: number; }; + var y: { x?: number; }; + + var r3 = foo(a, x); // { x: number; y?: number; }; + var r4 = foo(x, a); // { x: number; }; + + var r5 = foo(a, y); // { x?: number; }; + var r5 = foo(y, a); // { x?: number; }; + + var r6 = foo(x, y); // { x?: number; }; + var r6 = foo(y, x); // { x?: number; }; + + var s1: (x: Object) => string; + var s2: (x: string) => string; + + var r7 = foo(s1, s2); // (x: Object) => string; + var r8 = foo(s2, s1); // (x: string) => string; \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.types b/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.types deleted file mode 100644 index e37a010baed..00000000000 --- a/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.types +++ /dev/null @@ -1,117 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts === -// generic type argument inference where inference leads to two candidates that are both supertypes of all candidates -// we choose the first candidate so the result is dependent on the order of the arguments provided - -function foo(x: T, y: T) { ->foo : (x: T, y: T) => T ->T : T ->x : T ->T : T ->y : T ->T : T - - var r: T; ->r : T ->T : T - - return r; ->r : T -} - -var a: { x: number; y?: number; }; ->a : { x: number; y?: number; } ->x : number ->y : number - -var b: { x: number; z?: number; }; ->b : { x: number; z?: number; } ->x : number ->z : number - -var r = foo(a, b); // { x: number; y?: number; }; ->r : { x: number; y?: number; } ->foo(a, b) : { x: number; y?: number; } ->foo : (x: T, y: T) => T ->a : { x: number; y?: number; } ->b : { x: number; z?: number; } - -var r2 = foo(b, a); // { x: number; z?: number; }; ->r2 : { x: number; z?: number; } ->foo(b, a) : { x: number; z?: number; } ->foo : (x: T, y: T) => T ->b : { x: number; z?: number; } ->a : { x: number; y?: number; } - -var x: { x: number; }; ->x : { x: number; } ->x : number - -var y: { x?: number; }; ->y : { x?: number; } ->x : number - -var r3 = foo(a, x); // { x: number; y?: number; }; ->r3 : { x: number; y?: number; } ->foo(a, x) : { x: number; y?: number; } ->foo : (x: T, y: T) => T ->a : { x: number; y?: number; } ->x : { x: number; } - -var r4 = foo(x, a); // { x: number; }; ->r4 : { x: number; } ->foo(x, a) : { x: number; } ->foo : (x: T, y: T) => T ->x : { x: number; } ->a : { x: number; y?: number; } - -var r5 = foo(a, y); // { x?: number; }; ->r5 : { x?: number; } ->foo(a, y) : { x?: number; } ->foo : (x: T, y: T) => T ->a : { x: number; y?: number; } ->y : { x?: number; } - -var r5 = foo(y, a); // { x?: number; }; ->r5 : { x?: number; } ->foo(y, a) : { x?: number; } ->foo : (x: T, y: T) => T ->y : { x?: number; } ->a : { x: number; y?: number; } - -var r6 = foo(x, y); // { x?: number; }; ->r6 : { x?: number; } ->foo(x, y) : { x?: number; } ->foo : (x: T, y: T) => T ->x : { x: number; } ->y : { x?: number; } - -var r6 = foo(y, x); // { x?: number; }; ->r6 : { x?: number; } ->foo(y, x) : { x?: number; } ->foo : (x: T, y: T) => T ->y : { x?: number; } ->x : { x: number; } - -var s1: (x: Object) => string; ->s1 : (x: Object) => string ->x : Object ->Object : Object - -var s2: (x: string) => string; ->s2 : (x: string) => string ->x : string - -var r7 = foo(s1, s2); // (x: Object) => string; ->r7 : (x: Object) => string ->foo(s1, s2) : (x: Object) => string ->foo : (x: T, y: T) => T ->s1 : (x: Object) => string ->s2 : (x: string) => string - -var r8 = foo(s2, s1); // (x: string) => string; ->r8 : (x: string) => string ->foo(s2, s1) : (x: string) => string ->foo : (x: T, y: T) => T ->s2 : (x: string) => string ->s1 : (x: Object) => string - diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types index aa1eeaf4670..3e178a7062d 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types +++ b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types @@ -22,7 +22,7 @@ class Derived2 extends Base { // returns {}[] function f(a: { x: T; y: U }) { ->f : (a: { x: T; y: U; }) => Array +>f : (a: { x: T; y: U; }) => (T | U)[] >T : T >Base : Base >U : U @@ -34,7 +34,7 @@ function f(a: { x: T; y: U }) { >U : U return [a.x, a.y]; ->[a.x, a.y] : Array +>[a.x, a.y] : (T | U)[] >a.x : T >a : { x: T; y: U; } >x : T @@ -44,9 +44,9 @@ function f(a: { x: T; y: U }) { } var r = f({ x: new Derived(), y: new Derived2() }); // {}[] ->r : Array ->f({ x: new Derived(), y: new Derived2() }) : Array ->f : (a: { x: T; y: U; }) => Array +>r : (Derived | Derived2)[] +>f({ x: new Derived(), y: new Derived2() }) : (Derived | Derived2)[] +>f : (a: { x: T; y: U; }) => (T | U)[] >{ x: new Derived(), y: new Derived2() } : { x: Derived; y: Derived2; } >x : Derived >new Derived() : Derived @@ -57,8 +57,8 @@ var r = f({ x: new Derived(), y: new Derived2() }); // {}[] var r2 = f({ x: new Base(), y: new Derived2() }); // {}[] >r2 : Base[] ->f({ x: new Base(), y: new Derived2() }) : Array ->f : (a: { x: T; y: U; }) => Array +>f({ x: new Base(), y: new Derived2() }) : (Base | Derived2)[] +>f : (a: { x: T; y: U; }) => (T | U)[] >{ x: new Base(), y: new Derived2() } : { x: Base; y: Derived2; } >x : Base >new Base() : Base diff --git a/tests/baselines/reference/genericTypeArgumentInference1.types b/tests/baselines/reference/genericTypeArgumentInference1.types index be7a3e9226d..c718ccca620 100644 --- a/tests/baselines/reference/genericTypeArgumentInference1.types +++ b/tests/baselines/reference/genericTypeArgumentInference1.types @@ -47,7 +47,7 @@ var r = _.all([true, 1, null, 'yes'], _.identity); >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T ->[true, 1, null, 'yes'] : Array +>[true, 1, null, 'yes'] : (string | number | boolean)[] >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T diff --git a/tests/baselines/reference/genericsManyTypeParameters.types b/tests/baselines/reference/genericsManyTypeParameters.types index df2144de866..cb492c30623 100644 --- a/tests/baselines/reference/genericsManyTypeParameters.types +++ b/tests/baselines/reference/genericsManyTypeParameters.types @@ -1,6 +1,6 @@ === tests/cases/compiler/genericsManyTypeParameters.ts === function Foo< ->Foo : (x1: a1, y1: a21, z1: a31, a1: a41, b1: a51, c1: a61, x2: a119, y2: a22, z2: a32, a2: a42, b2: a52, c2: a62, x3: a219, y3: a23, z3: a33, a3: a43, b3: a53, c3: a63, x4: a319, y4: a24, z4: a34, a4: a44, b4: a54, c4: a64, x5: a419, y5: a25, z5: a35, a5: a45, b5: a55, c5: a65, x6: a519, y6: a26, z6: a36, a6: a46, b6: a56, c6: a66, x7: a619, y7: a27, z7: a37, a7: a47, b7: a57, c7: a67, x8: a71, y8: a28, z8: a38, a8: a48, b8: a58, c8: a68, x9: a81, y9: a29, z9: a39, a9: a49, b9: a59, c9: a69, x10: a91, y12: a210, z10: a310, a10: a410, b10: a510, c10: a610, x11: a111, y13: a211, z11: a311, a11: a411, b11: a511, c11: a611, x12: a112, y14: a212, z12: a312, a12: a412, b12: a512, c12: a612, x13: a113, y15: a213, z13: a313, a13: a413, b13: a513, c13: a613, x14: a114, y16: a214, z14: a314, a14: a414, b14: a514, c14: a614, x15: a115, y17: a215, z15: a315, a15: a415, b15: a515, c15: a615, x16: a116, y18: a216, z16: a316, a16: a416, b16: a516, c16: a616, x17: a117, y19: a217, z17: a317, a17: a417, b17: a517, c17: a617, x18: a118, y10: a218, z18: a318, a18: a418, b18: a518, c18: a618) => Array +>Foo : (x1: a1, y1: a21, z1: a31, a1: a41, b1: a51, c1: a61, x2: a119, y2: a22, z2: a32, a2: a42, b2: a52, c2: a62, x3: a219, y3: a23, z3: a33, a3: a43, b3: a53, c3: a63, x4: a319, y4: a24, z4: a34, a4: a44, b4: a54, c4: a64, x5: a419, y5: a25, z5: a35, a5: a45, b5: a55, c5: a65, x6: a519, y6: a26, z6: a36, a6: a46, b6: a56, c6: a66, x7: a619, y7: a27, z7: a37, a7: a47, b7: a57, c7: a67, x8: a71, y8: a28, z8: a38, a8: a48, b8: a58, c8: a68, x9: a81, y9: a29, z9: a39, a9: a49, b9: a59, c9: a69, x10: a91, y12: a210, z10: a310, a10: a410, b10: a510, c10: a610, x11: a111, y13: a211, z11: a311, a11: a411, b11: a511, c11: a611, x12: a112, y14: a212, z12: a312, a12: a412, b12: a512, c12: a612, x13: a113, y15: a213, z13: a313, a13: a413, b13: a513, c13: a613, x14: a114, y16: a214, z14: a314, a14: a414, b14: a514, c14: a614, x15: a115, y17: a215, z15: a315, a15: a415, b15: a515, c15: a615, x16: a116, y18: a216, z16: a316, a16: a416, b16: a516, c16: a616, x17: a117, y19: a217, z17: a317, a17: a417, b17: a517, c17: a617, x18: a118, y10: a218, z18: a318, a18: a418, b18: a518, c18: a618) => (a1 | a21 | a31 | a41 | a51 | a61 | a119 | a22 | a32 | a42 | a52 | a62 | a219 | a23 | a33 | a43 | a53 | a63 | a319 | a24 | a34 | a44 | a54 | a64 | a419 | a25 | a35 | a45 | a55 | a65 | a519 | a26 | a36 | a46 | a56 | a66 | a619 | a27 | a37 | a47 | a57 | a67 | a71 | a28 | a38 | a48 | a58 | a68 | a81 | a29 | a39 | a49 | a59 | a69 | a91 | a210 | a310 | a410 | a510 | a610 | a111 | a211 | a311 | a411 | a511 | a611 | a112 | a212 | a312 | a412 | a512 | a612 | a113 | a213 | a313 | a413 | a513 | a613 | a114 | a214 | a314 | a414 | a514 | a614 | a115 | a215 | a315 | a415 | a515 | a615 | a116 | a216 | a316 | a416 | a516 | a616 | a117 | a217 | a317 | a417 | a517 | a617 | a118 | a218 | a318 | a418 | a518 | a618)[] a1, a21, a31, a41, a51, a61, >a1 : a1 @@ -402,7 +402,7 @@ function Foo< ) { return [x1 , y1 , z1 , a1 , b1 , c1, ->[x1 , y1 , z1 , a1 , b1 , c1, x2 , y2 , z2 , a2 , b2 , c2, x3 , y3 , z3 , a3 , b3 , c3, x4 , y4 , z4 , a4 , b4 , c4, x5 , y5 , z5 , a5 , b5 , c5, x6 , y6 , z6 , a6 , b6 , c6, x7 , y7 , z7 , a7 , b7 , c7, x8 , y8 , z8 , a8 , b8 , c8, x9 , y9 , z9 , a9 , b9 , c9, x10 , y12 , z10 , a10 , b10 , c10, x11 , y13 , z11 , a11 , b11 , c11, x12 , y14 , z12 , a12 , b12 , c12, x13 , y15 , z13 , a13 , b13 , c13, x14 , y16 , z14 , a14 , b14 , c14, x15 , y17 , z15 , a15 , b15 , c15, x16 , y18 , z16 , a16 , b16 , c16, x17 , y19 , z17 , a17 , b17 , c17, x18 , y10 , z18 , a18 , b18 , c18] : Array +>[x1 , y1 , z1 , a1 , b1 , c1, x2 , y2 , z2 , a2 , b2 , c2, x3 , y3 , z3 , a3 , b3 , c3, x4 , y4 , z4 , a4 , b4 , c4, x5 , y5 , z5 , a5 , b5 , c5, x6 , y6 , z6 , a6 , b6 , c6, x7 , y7 , z7 , a7 , b7 , c7, x8 , y8 , z8 , a8 , b8 , c8, x9 , y9 , z9 , a9 , b9 , c9, x10 , y12 , z10 , a10 , b10 , c10, x11 , y13 , z11 , a11 , b11 , c11, x12 , y14 , z12 , a12 , b12 , c12, x13 , y15 , z13 , a13 , b13 , c13, x14 , y16 , z14 , a14 , b14 , c14, x15 , y17 , z15 , a15 , b15 , c15, x16 , y18 , z16 , a16 , b16 , c16, x17 , y19 , z17 , a17 , b17 , c17, x18 , y10 , z18 , a18 , b18 , c18] : (a1 | a21 | a31 | a41 | a51 | a61 | a119 | a22 | a32 | a42 | a52 | a62 | a219 | a23 | a33 | a43 | a53 | a63 | a319 | a24 | a34 | a44 | a54 | a64 | a419 | a25 | a35 | a45 | a55 | a65 | a519 | a26 | a36 | a46 | a56 | a66 | a619 | a27 | a37 | a47 | a57 | a67 | a71 | a28 | a38 | a48 | a58 | a68 | a81 | a29 | a39 | a49 | a59 | a69 | a91 | a210 | a310 | a410 | a510 | a610 | a111 | a211 | a311 | a411 | a511 | a611 | a112 | a212 | a312 | a412 | a512 | a612 | a113 | a213 | a313 | a413 | a513 | a613 | a114 | a214 | a314 | a414 | a514 | a614 | a115 | a215 | a315 | a415 | a515 | a615 | a116 | a216 | a316 | a416 | a516 | a616 | a117 | a217 | a317 | a417 | a517 | a617 | a118 | a218 | a318 | a418 | a518 | a618)[] >x1 : a1 >y1 : a21 >z1 : a31 diff --git a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt index 985aaa7948c..15f8f21b8f3 100644 --- a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt +++ b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'string[]'. +tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'string[]'. Type 'string | number' is not assignable to type 'string': Type 'number' is not assignable to type 'string'. @@ -14,7 +14,7 @@ tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argu this.test([]); this.test([1, 2, "hi", 5]); // Error ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'string[]'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'string[]'. !!! error TS2345: Type 'string | number' is not assignable to type 'string': !!! error TS2345: Type 'number' is not assignable to type 'string'. } diff --git a/tests/baselines/reference/heterogeneousArrayLiterals.types b/tests/baselines/reference/heterogeneousArrayLiterals.types index c236fe7ff6d..7ea7d4196a6 100644 --- a/tests/baselines/reference/heterogeneousArrayLiterals.types +++ b/tests/baselines/reference/heterogeneousArrayLiterals.types @@ -2,16 +2,16 @@ // type of an array is the best common type of its elements (plus its contextual type if it exists) var a = [1, '']; // {}[] ->a : Array ->[1, ''] : Array +>a : (string | number)[] +>[1, ''] : (string | number)[] var b = [1, null]; // number[] >b : number[] >[1, null] : number[] var c = [1, '', null]; // {}[] ->c : Array ->[1, '', null] : Array +>c : (string | number)[] +>[1, '', null] : (string | number)[] var d = [{}, 1]; // {}[] >d : {}[] @@ -31,8 +31,8 @@ var f = [[], [1]]; // number[][] >[1] : number[] var g = [[1], ['']]; // {}[] ->g : Array ->[[1], ['']] : Array +>g : (string[] | number[])[] +>[[1], ['']] : (string[] | number[])[] >[1] : number[] >[''] : string[] @@ -46,8 +46,8 @@ var h = [{ foo: 1, bar: '' }, { foo: 2 }]; // {foo: number}[] >foo : number var i = [{ foo: 1, bar: '' }, { foo: '' }]; // {}[] ->i : Array<{ foo: number; bar: string; } | { foo: string; }> ->[{ foo: 1, bar: '' }, { foo: '' }] : Array<{ foo: number; bar: string; } | { foo: string; }> +>i : ({ foo: number; bar: string; } | { foo: string; })[] +>[{ foo: 1, bar: '' }, { foo: '' }] : ({ foo: number; bar: string; } | { foo: string; })[] >{ foo: 1, bar: '' } : { foo: number; bar: string; } >foo : number >bar : string @@ -55,36 +55,36 @@ var i = [{ foo: 1, bar: '' }, { foo: '' }]; // {}[] >foo : string var j = [() => 1, () => '']; // {}[] ->j : Array<{ (): number; } | { (): string; }> ->[() => 1, () => ''] : Array<{ (): number; } | { (): string; }> +>j : ((() => number) | (() => string))[] +>[() => 1, () => ''] : ((() => number) | (() => string))[] >() => 1 : () => number >() => '' : () => string var k = [() => 1, () => 1]; // { (): number }[] ->k : { (): number; }[] ->[() => 1, () => 1] : { (): number; }[] +>k : (() => number)[] +>[() => 1, () => 1] : (() => number)[] >() => 1 : () => number >() => 1 : () => number var l = [() => 1, () => null]; // { (): any }[] ->l : { (): any; }[] ->[() => 1, () => null] : { (): any; }[] +>l : (() => any)[] +>[() => 1, () => null] : (() => any)[] >() => 1 : () => number >() => null : () => any var m = [() => 1, () => '', () => null]; // { (): any }[] ->m : { (): any; }[] ->[() => 1, () => '', () => null] : { (): any; }[] +>m : (() => any)[] +>[() => 1, () => '', () => null] : (() => any)[] >() => 1 : () => number >() => '' : () => string >() => null : () => any var n = [[() => 1], [() => '']]; // {}[] ->n : Array<{ (): number; }[] | { (): string; }[]> ->[[() => 1], [() => '']] : Array<{ (): number; }[] | { (): string; }[]> ->[() => 1] : { (): number; }[] +>n : ((() => number)[] | (() => string)[])[] +>[[() => 1], [() => '']] : ((() => number)[] | (() => string)[])[] +>[() => 1] : (() => number)[] >() => 1 : () => number ->[() => ''] : { (): string; }[] +>[() => ''] : (() => string)[] >() => '' : () => string class Base { foo: string; } @@ -129,8 +129,8 @@ module Derived { >base : Base var i = [{ foo: base, basear: derived }, { foo: derived }]; // {foo: Derived}[] ->i : Array<{ foo: Base; basear: Derived; } | { foo: Derived; }> ->[{ foo: base, basear: derived }, { foo: derived }] : Array<{ foo: Base; basear: Derived; } | { foo: Derived; }> +>i : ({ foo: Base; basear: Derived; } | { foo: Derived; })[] +>[{ foo: base, basear: derived }, { foo: derived }] : ({ foo: Base; basear: Derived; } | { foo: Derived; })[] >{ foo: base, basear: derived } : { foo: Base; basear: Derived; } >foo : Base >base : Base @@ -141,30 +141,30 @@ module Derived { >derived : Derived var j = [() => base, () => derived]; // { {}: Base } ->j : { (): Base; }[] ->[() => base, () => derived] : { (): Base; }[] +>j : (() => Base)[] +>[() => base, () => derived] : (() => Base)[] >() => base : () => Base >base : Base >() => derived : () => Derived >derived : Derived var k = [() => base, () => 1]; // {}[]~ ->k : Array<{ (): Base; } | { (): number; }> ->[() => base, () => 1] : Array<{ (): Base; } | { (): number; }> +>k : ((() => Base) | (() => number))[] +>[() => base, () => 1] : ((() => Base) | (() => number))[] >() => base : () => Base >base : Base >() => 1 : () => number var l = [() => base, () => null]; // { (): any }[] ->l : { (): any; }[] ->[() => base, () => null] : { (): any; }[] +>l : (() => any)[] +>[() => base, () => null] : (() => any)[] >() => base : () => Base >base : Base >() => null : () => any var m = [() => base, () => derived, () => null]; // { (): any }[] ->m : { (): any; }[] ->[() => base, () => derived, () => null] : { (): any; }[] +>m : (() => any)[] +>[() => base, () => derived, () => null] : (() => any)[] >() => base : () => Base >base : Base >() => derived : () => Derived @@ -172,18 +172,18 @@ module Derived { >() => null : () => any var n = [[() => base], [() => derived]]; // { (): Base }[] ->n : { (): Base; }[][] ->[[() => base], [() => derived]] : { (): Base; }[][] ->[() => base] : { (): Base; }[] +>n : (() => Base)[][] +>[[() => base], [() => derived]] : (() => Base)[][] +>[() => base] : (() => Base)[] >() => base : () => Base >base : Base ->[() => derived] : { (): Derived; }[] +>[() => derived] : (() => Derived)[] >() => derived : () => Derived >derived : Derived var o = [derived, derived2]; // {}[] ->o : Array ->[derived, derived2] : Array +>o : (Derived | Derived2)[] +>[derived, derived2] : (Derived | Derived2)[] >derived : Derived >derived2 : Derived2 @@ -195,12 +195,12 @@ module Derived { >base : Base var q = [[() => derived2], [() => derived]]; // {}[] ->q : Array<{ (): Derived2; }[] | { (): Derived; }[]> ->[[() => derived2], [() => derived]] : Array<{ (): Derived2; }[] | { (): Derived; }[]> ->[() => derived2] : { (): Derived2; }[] +>q : ((() => Derived2)[] | (() => Derived)[])[] +>[[() => derived2], [() => derived]] : ((() => Derived2)[] | (() => Derived)[])[] +>[() => derived2] : (() => Derived2)[] >() => derived2 : () => Derived2 >derived2 : Derived2 ->[() => derived] : { (): Derived; }[] +>[() => derived] : (() => Derived)[] >() => derived : () => Derived >derived : Derived } @@ -212,7 +212,7 @@ module WithContextualType { var a: Base[] = [derived, derived2]; >a : Base[] >Base : Base ->[derived, derived2] : Array +>[derived, derived2] : (Derived | Derived2)[] >derived : Derived >derived2 : Derived2 @@ -227,9 +227,9 @@ module WithContextualType { >[] : undefined[] var d: { (): Base }[] = [() => derived, () => derived2]; ->d : { (): Base; }[] +>d : (() => Base)[] >Base : Base ->[() => derived, () => derived2] : Array<{ (): Derived; } | { (): Derived2; }> +>[() => derived, () => derived2] : ((() => Derived) | (() => Derived2))[] >() => derived : () => Derived >derived : Derived >() => derived2 : () => Derived2 @@ -257,27 +257,27 @@ function foo(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : Array ->[t, u] : Array +>c : (T | U)[] +>[t, u] : (T | U)[] >t : T >u : U var d = [t, 1]; // {}[] ->d : Array ->[t, 1] : Array +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T var e = [() => t, () => u]; // {}[] ->e : Array<{ (): T; } | { (): U; }> ->[() => t, () => u] : Array<{ (): T; } | { (): U; }> +>e : ((() => T) | (() => U))[] +>[() => t, () => u] : ((() => T) | (() => U))[] >() => t : () => T >t : T >() => u : () => U >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : { (): any; }[] ->[() => t, () => u, () => null] : { (): any; }[] +>f : (() => any)[] +>[() => t, () => u, () => null] : (() => any)[] >() => t : () => T >t : T >() => u : () => U @@ -308,27 +308,27 @@ function foo2(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : Array ->[t, u] : Array +>c : (T | U)[] +>[t, u] : (T | U)[] >t : T >u : U var d = [t, 1]; // {}[] ->d : Array ->[t, 1] : Array +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T var e = [() => t, () => u]; // {}[] ->e : Array<{ (): T; } | { (): U; }> ->[() => t, () => u] : Array<{ (): T; } | { (): U; }> +>e : ((() => T) | (() => U))[] +>[() => t, () => u] : ((() => T) | (() => U))[] >() => t : () => T >t : T >() => u : () => U >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : { (): any; }[] ->[() => t, () => u, () => null] : { (): any; }[] +>f : (() => any)[] +>[() => t, () => u, () => null] : (() => any)[] >() => t : () => T >t : T >() => u : () => U @@ -342,8 +342,8 @@ function foo2(t: T, u: U) { >base : Base var h = [t, derived]; // Derived[] ->h : Array ->[t, derived] : Array +>h : (Derived | T)[] +>[t, derived] : (Derived | T)[] >t : T >derived : Derived @@ -383,27 +383,27 @@ function foo3(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : Array ->[t, u] : Array +>c : (T | U)[] +>[t, u] : (T | U)[] >t : T >u : U var d = [t, 1]; // {}[] ->d : Array ->[t, 1] : Array +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T var e = [() => t, () => u]; // {}[] ->e : Array<{ (): T; } | { (): U; }> ->[() => t, () => u] : Array<{ (): T; } | { (): U; }> +>e : ((() => T) | (() => U))[] +>[() => t, () => u] : ((() => T) | (() => U))[] >() => t : () => T >t : T >() => u : () => U >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : { (): any; }[] ->[() => t, () => u, () => null] : { (): any; }[] +>f : (() => any)[] +>[() => t, () => u, () => null] : (() => any)[] >() => t : () => T >t : T >() => u : () => U @@ -458,27 +458,27 @@ function foo4(t: T, u: U) { >t : T var c = [t, u]; // BUG 821629 ->c : Array ->[t, u] : Array +>c : (T | U)[] +>[t, u] : (T | U)[] >t : T >u : U var d = [t, 1]; // {}[] ->d : Array ->[t, 1] : Array +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T var e = [() => t, () => u]; // {}[] ->e : Array<{ (): T; } | { (): U; }> ->[() => t, () => u] : Array<{ (): T; } | { (): U; }> +>e : ((() => T) | (() => U))[] +>[() => t, () => u] : ((() => T) | (() => U))[] >() => t : () => T >t : T >() => u : () => U >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : { (): any; }[] ->[() => t, () => u, () => null] : { (): any; }[] +>f : (() => any)[] +>[() => t, () => u, () => null] : (() => any)[] >() => t : () => T >t : T >() => u : () => U @@ -492,8 +492,8 @@ function foo4(t: T, u: U) { >base : Base var h = [t, derived]; // Derived[] ->h : Array ->[t, derived] : Array +>h : (Derived | T)[] +>[t, derived] : (Derived | T)[] >t : T >derived : Derived @@ -504,15 +504,15 @@ function foo4(t: T, u: U) { >base : Base var j = [u, derived]; // Derived[] ->j : Array ->[u, derived] : Array +>j : (Derived | U)[] +>[u, derived] : (Derived | U)[] >u : U >derived : Derived var k: Base[] = [t, u]; >k : Base[] >Base : Base ->[t, u] : Array +>[t, u] : (T | U)[] >t : T >u : U } diff --git a/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt b/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt index 9411d016dcb..5f538eef40c 100644 --- a/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt +++ b/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt @@ -7,7 +7,6 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(18,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(19,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(20,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(29,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(30,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(31,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(32,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter @@ -16,11 +15,13 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(35,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(36,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(37,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(40,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(40,17): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(38,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(39,17): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(43,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(43,17): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter -==== tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts (20 errors) ==== +==== tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts (21 errors) ==== enum E { a } var x: any; @@ -66,6 +67,7 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv var b2: boolean; var b3: string; var b4: void; + var b5: string | number; var rb1 = x in b1; ~~ @@ -79,22 +81,26 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv var rb4 = x in b4; ~~ !!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter - var rb5 = x in 0; - ~ -!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter - var rb6 = x in false; - ~~~~~ -!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter - var rb7 = x in ''; + var rb5 = x in b5; ~~ !!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter - var rb8 = x in null; + var rb6 = x in 0; + ~ +!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter + var rb7 = x in false; + ~~~~~ +!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter + var rb8 = x in ''; + ~~ +!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter + var rb9 = x in null; ~~~~ !!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter - var rb9 = x in undefined; - ~~~~~~~~~ + var rb10 = x in undefined; + ~~~~~~~~~ !!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter + // both operands are invalid var rc1 = {} in ''; ~~ diff --git a/tests/baselines/reference/inOperatorWithInvalidOperands.js b/tests/baselines/reference/inOperatorWithInvalidOperands.js index eb117aafde3..29293f880ed 100644 --- a/tests/baselines/reference/inOperatorWithInvalidOperands.js +++ b/tests/baselines/reference/inOperatorWithInvalidOperands.js @@ -26,16 +26,19 @@ var b1: number; var b2: boolean; var b3: string; var b4: void; +var b5: string | number; var rb1 = x in b1; var rb2 = x in b2; var rb3 = x in b3; var rb4 = x in b4; -var rb5 = x in 0; -var rb6 = x in false; -var rb7 = x in ''; -var rb8 = x in null; -var rb9 = x in undefined; +var rb5 = x in b5; +var rb6 = x in 0; +var rb7 = x in false; +var rb8 = x in ''; +var rb9 = x in null; +var rb10 = x in undefined; + // both operands are invalid var rc1 = {} in ''; @@ -67,14 +70,16 @@ var b1; var b2; var b3; var b4; +var b5; var rb1 = x in b1; var rb2 = x in b2; var rb3 = x in b3; var rb4 = x in b4; -var rb5 = x in 0; -var rb6 = x in false; -var rb7 = x in ''; -var rb8 = x in null; -var rb9 = x in undefined; +var rb5 = x in b5; +var rb6 = x in 0; +var rb7 = x in false; +var rb8 = x in ''; +var rb9 = x in null; +var rb10 = x in undefined; // both operands are invalid var rc1 = {} in ''; diff --git a/tests/baselines/reference/inOperatorWithValidOperands.js b/tests/baselines/reference/inOperatorWithValidOperands.js index 16df96f22fb..561abbe340b 100644 --- a/tests/baselines/reference/inOperatorWithValidOperands.js +++ b/tests/baselines/reference/inOperatorWithValidOperands.js @@ -21,7 +21,18 @@ var rb2 = x in {}; function foo(t: T) { var rb3 = x in t; -} +} + +interface X { x: number } +interface Y { y: number } + +var c1: X | Y; +var c2: X; +var c3: Y; + +var rc1 = x in c1; +var rc2 = x in (c2 || c3); + //// [inOperatorWithValidOperands.js] var x; @@ -42,3 +53,8 @@ var rb2 = x in {}; function foo(t) { var rb3 = x in t; } +var c1; +var c2; +var c3; +var rc1 = x in c1; +var rc2 = x in (c2 || c3); diff --git a/tests/baselines/reference/inOperatorWithValidOperands.types b/tests/baselines/reference/inOperatorWithValidOperands.types index f621c3bf55d..27ba22055bf 100644 --- a/tests/baselines/reference/inOperatorWithValidOperands.types +++ b/tests/baselines/reference/inOperatorWithValidOperands.types @@ -67,3 +67,40 @@ function foo(t: T) { >x : any >t : T } + +interface X { x: number } +>X : X +>x : number + +interface Y { y: number } +>Y : Y +>y : number + +var c1: X | Y; +>c1 : X | Y +>X : X +>Y : Y + +var c2: X; +>c2 : X +>X : X + +var c3: Y; +>c3 : Y +>Y : Y + +var rc1 = x in c1; +>rc1 : boolean +>x in c1 : boolean +>x : any +>c1 : X | Y + +var rc2 = x in (c2 || c3); +>rc2 : boolean +>x in (c2 || c3) : boolean +>x : any +>(c2 || c3) : X | Y +>c2 || c3 : X | Y +>c2 : X +>c3 : Y + diff --git a/tests/baselines/reference/instanceofOperator.errors.txt b/tests/baselines/reference/instanceofOperator.errors.txt index 15d55188741..2fa517c53be 100644 --- a/tests/baselines/reference/instanceofOperator.errors.txt +++ b/tests/baselines/reference/instanceofOperator.errors.txt @@ -1,43 +1,42 @@ -tests/cases/compiler/instanceofOperator.ts(6,7): error TS2300: Duplicate identifier 'Object'. -tests/cases/compiler/instanceofOperator.ts(11,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. -tests/cases/compiler/instanceofOperator.ts(14,16): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. -tests/cases/compiler/instanceofOperator.ts(15,19): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. -tests/cases/compiler/instanceofOperator.ts(18,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. -tests/cases/compiler/instanceofOperator.ts(20,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. +tests/cases/compiler/instanceofOperator.ts(12,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. +tests/cases/compiler/instanceofOperator.ts(15,20): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. +tests/cases/compiler/instanceofOperator.ts(16,23): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. +tests/cases/compiler/instanceofOperator.ts(19,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. +tests/cases/compiler/instanceofOperator.ts(21,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. -==== tests/cases/compiler/instanceofOperator.ts (6 errors) ==== +==== tests/cases/compiler/instanceofOperator.ts (5 errors) ==== // Spec: // 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. The result is always of the // Boolean primitive type. - class Object { } - ~~~~~~ -!!! error TS2300: Duplicate identifier 'Object'. - var obj: Object; + module test { + class Object { } + var obj: Object; - 4 instanceof null; - ~ + 4 instanceof null; + ~ !!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. - // Error and should be error - obj instanceof 4; - ~ + // Error and should be error + obj instanceof 4; + ~ !!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. - Object instanceof obj; - ~~~ + Object instanceof obj; + ~~~ !!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. - // Error on left hand side - null instanceof null; - ~~~~ + // Error on left hand side + null instanceof null; + ~~~~ !!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. - obj instanceof Object; - undefined instanceof undefined; - ~~~~~~~~~ + obj instanceof Object; + undefined instanceof undefined; + ~~~~~~~~~ !!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. + } \ No newline at end of file diff --git a/tests/baselines/reference/instanceofOperator.js b/tests/baselines/reference/instanceofOperator.js index 7620c3e83f4..3c6970b66a4 100644 --- a/tests/baselines/reference/instanceofOperator.js +++ b/tests/baselines/reference/instanceofOperator.js @@ -4,21 +4,23 @@ // operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the // Boolean primitive type. -class Object { } -var obj: Object; +module test { + class Object { } + var obj: Object; -4 instanceof null; + 4 instanceof null; -// Error and should be error -obj instanceof 4; -Object instanceof obj; + // Error and should be error + obj instanceof 4; + Object instanceof obj; -// Error on left hand side -null instanceof null; -obj instanceof Object; -undefined instanceof undefined; + // Error on left hand side + null instanceof null; + obj instanceof Object; + undefined instanceof undefined; +} @@ -27,17 +29,20 @@ undefined instanceof undefined; // 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. The result is always of the // Boolean primitive type. -var Object = (function () { - function Object() { - } - return Object; -})(); -var obj; -4 instanceof null; -// Error and should be error -obj instanceof 4; -Object instanceof obj; -// Error on left hand side -null instanceof null; -obj instanceof Object; -undefined instanceof undefined; +var test; +(function (test) { + var Object = (function () { + function Object() { + } + return Object; + })(); + var obj; + 4 instanceof null; + // Error and should be error + obj instanceof 4; + Object instanceof obj; + // Error on left hand side + null instanceof null; + obj instanceof Object; + undefined instanceof undefined; +})(test || (test = {})); diff --git a/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt b/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt index b82c82b9eb5..3ec718f3b25 100644 --- a/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt +++ b/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDec tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(40,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C2'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(43,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '(x: string) => number', but here has type '(x: number) => string'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(46,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. -tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(47,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. +tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(47,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | D)[]'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(50,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'D[]', but here has type 'D[]'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(53,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. @@ -79,7 +79,7 @@ tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDec !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. var arr = [new C(), new C2(), new D()]; ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | D)[]'. var arr2 = [new D()]; var arr2 = new Array>(); diff --git a/tests/baselines/reference/letDeclarations-access.js b/tests/baselines/reference/letDeclarations-access.js new file mode 100644 index 00000000000..404c2876310 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-access.js @@ -0,0 +1,70 @@ +//// [letDeclarations-access.ts] + +let x = 0 + +// No errors + +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; + +x++; +x--; +++x; +--x; + +var a = x + 1; + +function f(v: number) { } +f(x); + +if (x) { } + +x; +(x); + +-x; ++x; + +x.toString(); + + +//// [letDeclarations-access.js] +let x = 0; +// No errors +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; +x++; +x--; +++x; +--x; +var a = x + 1; +function f(v) { +} +f(x); +if (x) { +} +x; +(x); +-x; ++x; +x.toString(); diff --git a/tests/baselines/reference/letDeclarations-access.types b/tests/baselines/reference/letDeclarations-access.types new file mode 100644 index 00000000000..f26d07ca5f8 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-access.types @@ -0,0 +1,109 @@ +=== tests/cases/compiler/letDeclarations-access.ts === + +let x = 0 +>x : number + +// No errors + +x = 1; +>x = 1 : number +>x : number + +x += 2; +>x += 2 : number +>x : number + +x -= 3; +>x -= 3 : number +>x : number + +x *= 4; +>x *= 4 : number +>x : number + +x /= 5; +>x /= 5 : number +>x : number + +x %= 6; +>x %= 6 : number +>x : number + +x <<= 7; +>x <<= 7 : number +>x : number + +x >>= 8; +>x >>= 8 : number +>x : number + +x >>>= 9; +>x >>>= 9 : number +>x : number + +x &= 10; +>x &= 10 : number +>x : number + +x |= 11; +>x |= 11 : number +>x : number + +x ^= 12; +>x ^= 12 : number +>x : number + +x++; +>x++ : number +>x : number + +x--; +>x-- : number +>x : number + +++x; +>++x : number +>x : number + +--x; +>--x : number +>x : number + +var a = x + 1; +>a : number +>x + 1 : number +>x : number + +function f(v: number) { } +>f : (v: number) => void +>v : number + +f(x); +>f(x) : void +>f : (v: number) => void +>x : number + +if (x) { } +>x : number + +x; +>x : number + +(x); +>(x) : number +>x : number + +-x; +>-x : number +>x : number + ++x; +>+x : number +>x : number + +x.toString(); +>x.toString() : string +>x.toString : (radix?: number) => string +>x : number +>toString : (radix?: number) => string + diff --git a/tests/baselines/reference/letDeclarations-es5.errors.txt b/tests/baselines/reference/letDeclarations-es5.errors.txt new file mode 100644 index 00000000000..be1a56a8b7f --- /dev/null +++ b/tests/baselines/reference/letDeclarations-es5.errors.txt @@ -0,0 +1,40 @@ +tests/cases/compiler/letDeclarations-es5.ts(2,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(3,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(4,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(6,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(7,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(8,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(10,8): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(12,8): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + + +==== tests/cases/compiler/letDeclarations-es5.ts (8 errors) ==== + + let l1; + ~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l2: number; + ~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l3, l4, l5 :string, l6; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + + let l7 = false; + ~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l8: number = 23; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l9 = 0, l10 :string = "", l11 = null; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + + for(let l11 in {}) { } + ~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + + for(let l12 = 0; l12 < 9; l12++) { } + ~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt b/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt new file mode 100644 index 00000000000..ad0c0f741b5 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt @@ -0,0 +1,66 @@ +tests/cases/compiler/letDeclarations-invalidContexts.ts(4,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(6,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(9,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(12,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(17,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(20,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(23,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(26,12): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(29,29): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/letDeclarations-invalidContexts.ts (10 errors) ==== + + // Errors, let must be defined inside a block + if (true) + let l1 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + else + let l2 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + while (true) + let l3 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + do + let l4 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + while (true); + + var obj; + with (obj) + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + let l5 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + for (var i = 0; i < 10; i++) + let l6 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + for (var i2 in {}) + let l7 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + if (true) + label: let l8 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + while (false) + label2: label3: label4: let l9 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + + + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt new file mode 100644 index 00000000000..b3b620a4c9e --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt @@ -0,0 +1,152 @@ +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(3,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(4,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(6,5): error TS2451: Cannot redeclare block-scoped variable 'var2'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(7,7): error TS2451: Cannot redeclare block-scoped variable 'var2'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(9,7): error TS2451: Cannot redeclare block-scoped variable 'var3'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(10,5): error TS2451: Cannot redeclare block-scoped variable 'var3'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(12,7): error TS2451: Cannot redeclare block-scoped variable 'var4'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(13,7): error TS2451: Cannot redeclare block-scoped variable 'var4'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(15,5): error TS2300: Duplicate identifier 'var5'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(16,5): error TS2300: Duplicate identifier 'var5'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(18,5): error TS2451: Cannot redeclare block-scoped variable 'var6'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(19,5): error TS2451: Cannot redeclare block-scoped variable 'var6'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(22,9): error TS2451: Cannot redeclare block-scoped variable 'var7'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(23,9): error TS2451: Cannot redeclare block-scoped variable 'var7'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(25,13): error TS2451: Cannot redeclare block-scoped variable 'var8'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(26,15): error TS2451: Cannot redeclare block-scoped variable 'var8'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(32,13): error TS2451: Cannot redeclare block-scoped variable 'var9'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(33,13): error TS2451: Cannot redeclare block-scoped variable 'var9'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(37,11): error TS2451: Cannot redeclare block-scoped variable 'var10'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(38,11): error TS2451: Cannot redeclare block-scoped variable 'var10'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(41,9): error TS2451: Cannot redeclare block-scoped variable 'var11'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(42,9): error TS2451: Cannot redeclare block-scoped variable 'var11'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(46,9): error TS2451: Cannot redeclare block-scoped variable 'var12'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(47,9): error TS2451: Cannot redeclare block-scoped variable 'var12'. + + +==== tests/cases/compiler/letDeclarations-scopes-duplicates.ts (24 errors) ==== + + // Errors: redeclaration + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + let var1 = 0; // error + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + + let var2 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var2'. + const var2 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var2'. + + const var3 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var3'. + let var3 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var3'. + + const var4 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var4'. + const var4 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var4'. + + var var5 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var5'. + let var5 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var5'. + + let var6 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var6'. + var var6 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var6'. + + { + let var7 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var7'. + let var7 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var7'. + { + let var8 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var8'. + const var8 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var8'. + } + } + + switch (0) { + default: + let var9 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var9'. + let var9 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var9'. + } + + try { + const var10 = 0; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var10'. + const var10 = 0; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var10'. + } + catch (e) { + let var11 = 0; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var11'. + let var11 = 0; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var11'. + } + + function F1() { + let var12; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var12'. + let var12; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var12'. + } + + // OK + var var20 = 0; + + var var20 = 0 + { + let var20 = 0; + { + let var20 = 0; + } + } + + switch (0) { + default: + let var20 = 0; + } + + try { + let var20 = 0; + } + catch (e) { + let var20 = 0; + } + + function F() { + let var20; + } + + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt new file mode 100644 index 00000000000..72b8b5609b6 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt new file mode 100644 index 00000000000..6ed2fb66195 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + const var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt new file mode 100644 index 00000000000..ec87809b0cd --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + const var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt new file mode 100644 index 00000000000..ce3a9da598a --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + const var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + const var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt new file mode 100644 index 00000000000..d09eda28075 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + var var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt new file mode 100644 index 00000000000..dad85f9f819 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + var var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes.errors.txt b/tests/baselines/reference/letDeclarations-scopes.errors.txt new file mode 100644 index 00000000000..5c89ea98049 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes.errors.txt @@ -0,0 +1,163 @@ +tests/cases/compiler/letDeclarations-scopes.ts(28,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/letDeclarations-scopes.ts (1 errors) ==== + + // global + let l = "string"; + + var n: number; + + // Control flow statements with blocks + if (true) { + let l = 0; + n = l; + } + else { + let l = 0; + n = l; + } + + while (true) { + let l = 0; + n = l; + } + + do { + let l = 0; + n = l; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + let l = 0; + n = l; + } + + for (var i = 0; i < 10; i++) { + let l = 0; + n = l; + } + + for (var i2 in {}) { + let l = 0; + n = l; + } + + if (true) { + label: let l = 0; + n = l; + } + + while (false) { + label2: label3: label4: let l = 0; + n = l; + } + + for (let l = 0; n = l; l++) { + let l = true; + var b3: boolean = l; + } + + for (let l in {}) { + + } + + // Try/catch/finally + try { + let l = 0; + n = l; + } + catch (e) { + let l = 0; + n = l; + } + finally { + let l = 0; + n = l; + } + + // Switch + switch (0) { + case 0: + let l = 0; + n = l; + break; + } + + // blocks + { + let l = 0; + n = l; + { + let l = false; + var b: boolean = l; + } + } + + // functions + function F() { + let l = 0; + n = l; + } + + var F2 = () => { + let l = 0; + n = l; + }; + + var F3 = function () { + let l = 0; + n = l; + }; + + // modules + module m { + let l = 0; + n = l; + + { + let l = false; + var b2: boolean = l; + } + + lable: let l2 = 0; + } + + // methods + class C { + constructor() { + let l = 0; + n = l; + } + + method() { + let l = 0; + n = l; + } + + get v() { + let l = 0; + n = l; + return n; + } + + set v(value) { + let l = 0; + n = l; + } + } + + // object literals + var o = { + f() { + let l = 0; + n = l; + }, + f2: () => { + let l = 0; + n = l; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes.js b/tests/baselines/reference/letDeclarations-scopes.js new file mode 100644 index 00000000000..fb16a03f569 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes.js @@ -0,0 +1,293 @@ +//// [letDeclarations-scopes.ts] + +// global +let l = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + let l = 0; + n = l; +} +else { + let l = 0; + n = l; +} + +while (true) { + let l = 0; + n = l; +} + +do { + let l = 0; + n = l; +} while (true); + +var obj; +with (obj) { + let l = 0; + n = l; +} + +for (var i = 0; i < 10; i++) { + let l = 0; + n = l; +} + +for (var i2 in {}) { + let l = 0; + n = l; +} + +if (true) { + label: let l = 0; + n = l; +} + +while (false) { + label2: label3: label4: let l = 0; + n = l; +} + +for (let l = 0; n = l; l++) { + let l = true; + var b3: boolean = l; +} + +for (let l in {}) { + +} + +// Try/catch/finally +try { + let l = 0; + n = l; +} +catch (e) { + let l = 0; + n = l; +} +finally { + let l = 0; + n = l; +} + +// Switch +switch (0) { + case 0: + let l = 0; + n = l; + break; +} + +// blocks +{ + let l = 0; + n = l; + { + let l = false; + var b: boolean = l; + } +} + +// functions +function F() { + let l = 0; + n = l; +} + +var F2 = () => { + let l = 0; + n = l; +}; + +var F3 = function () { + let l = 0; + n = l; +}; + +// modules +module m { + let l = 0; + n = l; + + { + let l = false; + var b2: boolean = l; + } + + lable: let l2 = 0; +} + +// methods +class C { + constructor() { + let l = 0; + n = l; + } + + method() { + let l = 0; + n = l; + } + + get v() { + let l = 0; + n = l; + return n; + } + + set v(value) { + let l = 0; + n = l; + } +} + +// object literals +var o = { + f() { + let l = 0; + n = l; + }, + f2: () => { + let l = 0; + n = l; + } +} + +//// [letDeclarations-scopes.js] +// global +let l = "string"; +var n; +// Control flow statements with blocks +if (true) { + let l = 0; + n = l; +} +else { + let l = 0; + n = l; +} +while (true) { + let l = 0; + n = l; +} +do { + let l = 0; + n = l; +} while (true); +var obj; +with (obj) { + let l = 0; + n = l; +} +for (var i = 0; i < 10; i++) { + let l = 0; + n = l; +} +for (var i2 in {}) { + let l = 0; + n = l; +} +if (true) { + label: let l = 0; + n = l; +} +while (false) { + label2: label3: label4: let l = 0; + n = l; +} +for (let l = 0; n = l; l++) { + let l = true; + var b3 = l; +} +for (let l in {}) { +} +try { + let l = 0; + n = l; +} +catch (e) { + let l = 0; + n = l; +} +finally { + let l = 0; + n = l; +} +switch (0) { + case 0: + let l = 0; + n = l; + break; +} +{ + let l = 0; + n = l; + { + let l = false; + var b = l; + } +} +// functions +function F() { + let l = 0; + n = l; +} +var F2 = function () { + let l = 0; + n = l; +}; +var F3 = function () { + let l = 0; + n = l; +}; +// modules +var m; +(function (m) { + let l = 0; + n = l; + { + let l = false; + var b2 = l; + } + lable: let l2 = 0; +})(m || (m = {})); +// methods +var C = (function () { + function C() { + let l = 0; + n = l; + } + C.prototype.method = function () { + let l = 0; + n = l; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + let l = 0; + n = l; + return n; + }, + set: function (value) { + let l = 0; + n = l; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + let l = 0; + n = l; + }, + f2: function () { + let l = 0; + n = l; + } +}; diff --git a/tests/baselines/reference/letDeclarations-scopes2.errors.txt b/tests/baselines/reference/letDeclarations-scopes2.errors.txt new file mode 100644 index 00000000000..a786db1104b --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes2.errors.txt @@ -0,0 +1,42 @@ +tests/cases/compiler/letDeclarations-scopes2.ts(9,5): error TS2304: Cannot find name 'local2'. +tests/cases/compiler/letDeclarations-scopes2.ts(21,5): error TS2304: Cannot find name 'local2'. +tests/cases/compiler/letDeclarations-scopes2.ts(24,1): error TS2304: Cannot find name 'local'. +tests/cases/compiler/letDeclarations-scopes2.ts(26,1): error TS2304: Cannot find name 'local2'. + + +==== tests/cases/compiler/letDeclarations-scopes2.ts (4 errors) ==== + + let global = 0; + + { + let local = 0; + + local; // OK + global; // OK + local2; // Error + ~~~~~~ +!!! error TS2304: Cannot find name 'local2'. + + { + let local2 = 0; + + local; // OK + global; // OK + local2; // OK + } + + local; // OK + global; // OK + local2; // Error + ~~~~~~ +!!! error TS2304: Cannot find name 'local2'. + } + + local; // Error + ~~~~~ +!!! error TS2304: Cannot find name 'local'. + global; // OK + local2; // Error + ~~~~~~ +!!! error TS2304: Cannot find name 'local2'. + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes2.js b/tests/baselines/reference/letDeclarations-scopes2.js new file mode 100644 index 00000000000..98d0e791832 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes2.js @@ -0,0 +1,49 @@ +//// [letDeclarations-scopes2.ts] + +let global = 0; + +{ + let local = 0; + + local; // OK + global; // OK + local2; // Error + + { + let local2 = 0; + + local; // OK + global; // OK + local2; // OK + } + + local; // OK + global; // OK + local2; // Error +} + +local; // Error +global; // OK +local2; // Error + + +//// [letDeclarations-scopes2.js] +let global = 0; +{ + let local = 0; + local; // OK + global; // OK + local2; // Error + { + let local2 = 0; + local; // OK + global; // OK + local2; // OK + } + local; // OK + global; // OK + local2; // Error +} +local; // Error +global; // OK +local2; // Error diff --git a/tests/baselines/reference/letDeclarations-useBeforeDefinition.errors.txt b/tests/baselines/reference/letDeclarations-useBeforeDefinition.errors.txt new file mode 100644 index 00000000000..74c354f4ff2 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-useBeforeDefinition.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/letDeclarations-useBeforeDefinition.ts(3,5): error TS2448: Block-scoped variable 'l1' used before its declaration. +tests/cases/compiler/letDeclarations-useBeforeDefinition.ts(9,5): error TS2448: Block-scoped variable 'v1' used before its declaration. + + +==== tests/cases/compiler/letDeclarations-useBeforeDefinition.ts (2 errors) ==== + + { + l1; + ~~ +!!! error TS2448: Block-scoped variable 'l1' used before its declaration. + let l1; + } + + var v1; + { + v1; + ~~ +!!! error TS2448: Block-scoped variable 'v1' used before its declaration. + let v1 = 0; + } + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-useBeforeDefinition2.errors.txt b/tests/baselines/reference/letDeclarations-useBeforeDefinition2.errors.txt new file mode 100644 index 00000000000..5b8633312d9 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-useBeforeDefinition2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file1.ts(2,1): error TS2448: Block-scoped variable 'l' used before its declaration. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + l; + ~ +!!! error TS2448: Block-scoped variable 'l' used before its declaration. + +==== tests/cases/compiler/file2.ts (0 errors) ==== + const l = 0; \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-validContexts.errors.txt b/tests/baselines/reference/letDeclarations-validContexts.errors.txt new file mode 100644 index 00000000000..3f3b7a2634f --- /dev/null +++ b/tests/baselines/reference/letDeclarations-validContexts.errors.txt @@ -0,0 +1,149 @@ +tests/cases/compiler/letDeclarations-validContexts.ts(20,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/letDeclarations-validContexts.ts (1 errors) ==== + + + // Control flow statements with blocks + if (true) { + let l1 = 0; + } + else { + let l2 = 0; + } + + while (true) { + let l3 = 0; + } + + do { + let l4 = 0; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + let l5 = 0; + } + + for (var i = 0; i < 10; i++) { + let l6 = 0; + } + + for (var i2 in {}) { + let l7 = 0; + } + + if (true) { + label: let l8 = 0; + } + + while (false) { + label2: label3: label4: let l9 = 0; + } + + // Try/catch/finally + try { + let l10 = 0; + } + catch (e) { + let l11 = 0; + } + finally { + let l12 = 0; + } + + // Switch + switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; + } + + // blocks + { + let l15 = 0; + { + let l16 = 0 + label17: let l17 = 0; + } + } + + // global + let l18 = 0; + + // functions + function F() { + let l19 = 0; + } + + var F2 = () => { + let l20 = 0; + }; + + var F3 = function () { + let l21 = 0; + }; + + // modules + module m { + let l22 = 0; + + { + let l23 = 0; + } + } + + // methods + class C { + constructor() { + let l24 = 0; + } + + method() { + let l25 = 0; + } + + get v() { + let l26 = 0; + return l26; + } + + set v(value) { + let l27 = value; + } + } + + // object literals + var o = { + f() { + let l28 = 0; + }, + f2: () => { + let l29 = 0; + } + } + + // labels + label: let l30 = 0; + { + label2: let l31 = 0; + } + + function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } + } + + module m3 { + label: let l34 = 0; + { + label2: let l35 = 0; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-validContexts.js b/tests/baselines/reference/letDeclarations-validContexts.js new file mode 100644 index 00000000000..13eaafb0712 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-validContexts.js @@ -0,0 +1,266 @@ +//// [letDeclarations-validContexts.ts] + + +// Control flow statements with blocks +if (true) { + let l1 = 0; +} +else { + let l2 = 0; +} + +while (true) { + let l3 = 0; +} + +do { + let l4 = 0; +} while (true); + +var obj; +with (obj) { + let l5 = 0; +} + +for (var i = 0; i < 10; i++) { + let l6 = 0; +} + +for (var i2 in {}) { + let l7 = 0; +} + +if (true) { + label: let l8 = 0; +} + +while (false) { + label2: label3: label4: let l9 = 0; +} + +// Try/catch/finally +try { + let l10 = 0; +} +catch (e) { + let l11 = 0; +} +finally { + let l12 = 0; +} + +// Switch +switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; +} + +// blocks +{ + let l15 = 0; + { + let l16 = 0 + label17: let l17 = 0; + } +} + +// global +let l18 = 0; + +// functions +function F() { + let l19 = 0; +} + +var F2 = () => { + let l20 = 0; +}; + +var F3 = function () { + let l21 = 0; +}; + +// modules +module m { + let l22 = 0; + + { + let l23 = 0; + } +} + +// methods +class C { + constructor() { + let l24 = 0; + } + + method() { + let l25 = 0; + } + + get v() { + let l26 = 0; + return l26; + } + + set v(value) { + let l27 = value; + } +} + +// object literals +var o = { + f() { + let l28 = 0; + }, + f2: () => { + let l29 = 0; + } +} + +// labels +label: let l30 = 0; +{ + label2: let l31 = 0; +} + +function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } +} + +module m3 { + label: let l34 = 0; + { + label2: let l35 = 0; + } +} + +//// [letDeclarations-validContexts.js] +// Control flow statements with blocks +if (true) { + let l1 = 0; +} +else { + let l2 = 0; +} +while (true) { + let l3 = 0; +} +do { + let l4 = 0; +} while (true); +var obj; +with (obj) { + let l5 = 0; +} +for (var i = 0; i < 10; i++) { + let l6 = 0; +} +for (var i2 in {}) { + let l7 = 0; +} +if (true) { + label: let l8 = 0; +} +while (false) { + label2: label3: label4: let l9 = 0; +} +try { + let l10 = 0; +} +catch (e) { + let l11 = 0; +} +finally { + let l12 = 0; +} +switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; +} +{ + let l15 = 0; + { + let l16 = 0; + label17: let l17 = 0; + } +} +// global +let l18 = 0; +// functions +function F() { + let l19 = 0; +} +var F2 = function () { + let l20 = 0; +}; +var F3 = function () { + let l21 = 0; +}; +// modules +var m; +(function (m) { + let l22 = 0; + { + let l23 = 0; + } +})(m || (m = {})); +// methods +var C = (function () { + function C() { + let l24 = 0; + } + C.prototype.method = function () { + let l25 = 0; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + let l26 = 0; + return l26; + }, + set: function (value) { + let l27 = value; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + let l28 = 0; + }, + f2: function () { + let l29 = 0; + } +}; +label: let l30 = 0; +{ + label2: let l31 = 0; +} +function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } +} +var m3; +(function (m3) { + label: let l34 = 0; + { + label2: let l35 = 0; + } +})(m3 || (m3 = {})); diff --git a/tests/baselines/reference/letDeclarations.js b/tests/baselines/reference/letDeclarations.js new file mode 100644 index 00000000000..bc186b732f5 --- /dev/null +++ b/tests/baselines/reference/letDeclarations.js @@ -0,0 +1,35 @@ +//// [letDeclarations.ts] + +let l1; +let l2: number; +let l3, l4, l5 :string, l6; + +let l7 = false; +let l8: number = 23; +let l9 = 0, l10 :string = "", l11 = null; + +for(let l11 in {}) { } + +for(let l12 = 0; l12 < 9; l12++) { } + + +//// [letDeclarations.js] +let l1; +let l2; +let l3, l4, l5, l6; +let l7 = false; +let l8 = 23; +let l9 = 0, l10 = "", l11 = null; +for (let l11 in {}) { +} +for (let l12 = 0; l12 < 9; l12++) { +} + + +//// [letDeclarations.d.ts] +declare let l1: any; +declare let l2: number; +declare let l3: any, l4: any, l5: string, l6: any; +declare let l7: boolean; +declare let l8: number; +declare let l9: number, l10: string, l11: any; diff --git a/tests/baselines/reference/letDeclarations.types b/tests/baselines/reference/letDeclarations.types new file mode 100644 index 00000000000..aa47a7f0006 --- /dev/null +++ b/tests/baselines/reference/letDeclarations.types @@ -0,0 +1,36 @@ +=== tests/cases/compiler/letDeclarations.ts === + +let l1; +>l1 : any + +let l2: number; +>l2 : number + +let l3, l4, l5 :string, l6; +>l3 : any +>l4 : any +>l5 : string +>l6 : any + +let l7 = false; +>l7 : boolean + +let l8: number = 23; +>l8 : number + +let l9 = 0, l10 :string = "", l11 = null; +>l9 : number +>l10 : string +>l11 : any + +for(let l11 in {}) { } +>l11 : any +>{} : {} + +for(let l12 = 0; l12 < 9; l12++) { } +>l12 : number +>l12 < 9 : boolean +>l12 : number +>l12++ : number +>l12 : number + diff --git a/tests/baselines/reference/letDeclarations2.js b/tests/baselines/reference/letDeclarations2.js new file mode 100644 index 00000000000..8a6f039f2ca --- /dev/null +++ b/tests/baselines/reference/letDeclarations2.js @@ -0,0 +1,19 @@ +//// [letDeclarations2.ts] + +module M { + let l1 = "s"; + export let l2 = 0; +} + +//// [letDeclarations2.js] +var M; +(function (M) { + let l1 = "s"; + M.l2 = 0; +})(M || (M = {})); + + +//// [letDeclarations2.d.ts] +declare module M { + let l2: number; +} diff --git a/tests/baselines/reference/letDeclarations2.types b/tests/baselines/reference/letDeclarations2.types new file mode 100644 index 00000000000..2fa08b6d940 --- /dev/null +++ b/tests/baselines/reference/letDeclarations2.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/letDeclarations2.ts === + +module M { +>M : typeof M + + let l1 = "s"; +>l1 : string + + export let l2 = 0; +>l2 : number +} diff --git a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt index ed4f45ec1de..cc93b716d2e 100644 --- a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt +++ b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. Type 'string | number' is not assignable to type 'number': Type 'string' is not assignable to type 'number'. tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): error TS2346: Supplied parameters do not match any signature of call target. @@ -16,7 +16,7 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): e var r6 = map([1, ""], (x) => x.toString()); var r7 = map([1, ""], (x) => x.toString()); // error ~~~~~~~ -!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. !!! error TS2345: Type 'string | number' is not assignable to type 'number': !!! error TS2345: Type 'string' is not assignable to type 'number'. var r7b = map([1, ""], (x) => x.toString()); // error diff --git a/tests/baselines/reference/nameOrDottedSpan_classes.baseline b/tests/baselines/reference/nameOrDottedSpan_classes.baseline new file mode 100644 index 00000000000..88383c638a8 --- /dev/null +++ b/tests/baselines/reference/nameOrDottedSpan_classes.baseline @@ -0,0 +1,522 @@ + +1 >module Foo.Bar { + + ~~~~~~~ => Pos: (0 to 6) SpanInfo: undefined +1 >module Foo.Bar { + + ~~~~ => Pos: (7 to 10) SpanInfo: {"start":7,"length":3} + >Foo + >:=> (line 1, col 7) to (line 1, col 10) +1 >module Foo.Bar { + + ~~~~ => Pos: (11 to 14) SpanInfo: {"start":7,"length":7} + >Foo.Bar + >:=> (line 1, col 7) to (line 1, col 14) +1 >module Foo.Bar { + + ~~ => Pos: (15 to 16) SpanInfo: undefined +-------------------------------- +2 > "use strict"; + + ~~~~ => Pos: (17 to 20) SpanInfo: undefined +2 > "use strict"; + + ~~~~~~~~~~~~~ => Pos: (21 to 33) SpanInfo: {"start":21,"length":12} + >"use strict" + >:=> (line 2, col 4) to (line 2, col 16) +2 > "use strict"; + + ~ => Pos: (34 to 34) SpanInfo: undefined +-------------------------------- +3 > + + ~ => Pos: (35 to 35) SpanInfo: undefined +-------------------------------- +4 > class Greeter { + + ~~~~~~~~~~ => Pos: (36 to 45) SpanInfo: undefined +4 > class Greeter { + + ~~~~~~~~ => Pos: (46 to 53) SpanInfo: {"start":46,"length":7} + >Greeter + >:=> (line 4, col 10) to (line 4, col 17) +4 > class Greeter { + + ~~ => Pos: (54 to 55) SpanInfo: undefined +-------------------------------- +5 > constructor(public greeting: string) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (56 to 82) SpanInfo: undefined +5 > constructor(public greeting: string) { + + ~~~~~~~~~ => Pos: (83 to 91) SpanInfo: {"start":83,"length":8} + >greeting + >:=> (line 5, col 27) to (line 5, col 35) +5 > constructor(public greeting: string) { + + ~~~~~~~~~~~=> Pos: (92 to 102) SpanInfo: undefined +-------------------------------- +6 > } + + ~~~~~~~~~~ => Pos: (103 to 112) SpanInfo: undefined +-------------------------------- +7 > + + ~ => Pos: (113 to 113) SpanInfo: undefined +-------------------------------- +8 > greet() { + + ~~~~~~~~ => Pos: (114 to 121) SpanInfo: undefined +8 > greet() { + + ~~~~~~ => Pos: (122 to 127) SpanInfo: {"start":122,"length":5} + >greet + >:=> (line 8, col 8) to (line 8, col 13) +8 > greet() { + + ~~~~ => Pos: (128 to 131) SpanInfo: undefined +-------------------------------- +9 > return "

" + this.greeting + "

"; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (132 to 150) SpanInfo: undefined +9 > return "

" + this.greeting + "

"; + + ~~~~~~~ => Pos: (151 to 157) SpanInfo: {"start":151,"length":6} + >"

" + >:=> (line 9, col 19) to (line 9, col 25) +9 > return "

" + this.greeting + "

"; + + ~~ => Pos: (158 to 159) SpanInfo: undefined +9 > return "

" + this.greeting + "

"; + + ~~~~~ => Pos: (160 to 164) SpanInfo: {"start":160,"length":4} + >this + >:=> (line 9, col 28) to (line 9, col 32) +9 > return "

" + this.greeting + "

"; + + ~~~~~~~~~ => Pos: (165 to 173) SpanInfo: {"start":160,"length":13} + >this.greeting + >:=> (line 9, col 28) to (line 9, col 41) +9 > return "

" + this.greeting + "

"; + + ~~ => Pos: (174 to 175) SpanInfo: undefined +9 > return "

" + this.greeting + "

"; + + ~~~~~~~~=> Pos: (176 to 183) SpanInfo: {"start":176,"length":7} + >"" + >:=> (line 9, col 44) to (line 9, col 51) +9 > return "

" + this.greeting + "

"; + + ~=> Pos: (184 to 184) SpanInfo: undefined +-------------------------------- +10 > } + + ~~~~~~~~~~ => Pos: (185 to 194) SpanInfo: undefined +-------------------------------- +11 > } + + ~~~~~~ => Pos: (195 to 200) SpanInfo: undefined +-------------------------------- +12 > + + ~ => Pos: (201 to 201) SpanInfo: undefined +-------------------------------- +13 > + + ~ => Pos: (202 to 202) SpanInfo: undefined +-------------------------------- +14 > function foo(greeting: string): Greeter { + + ~~~~~~~~~~~~~ => Pos: (203 to 215) SpanInfo: undefined +14 > function foo(greeting: string): Greeter { + + ~~~~ => Pos: (216 to 219) SpanInfo: {"start":216,"length":3} + >foo + >:=> (line 14, col 13) to (line 14, col 16) +14 > function foo(greeting: string): Greeter { + + ~~~~~~~~~ => Pos: (220 to 228) SpanInfo: {"start":220,"length":8} + >greeting + >:=> (line 14, col 17) to (line 14, col 25) +14 > function foo(greeting: string): Greeter { + + ~~~~~~~~~~ => Pos: (229 to 238) SpanInfo: undefined +14 > function foo(greeting: string): Greeter { + + ~~~~~~~~ => Pos: (239 to 246) SpanInfo: {"start":239,"length":7} + >Greeter + >:=> (line 14, col 36) to (line 14, col 43) +14 > function foo(greeting: string): Greeter { + + ~~=> Pos: (247 to 248) SpanInfo: undefined +-------------------------------- +15 > return new Greeter(greeting); + + ~~~~~~~~~~~~~~~~~~~ => Pos: (249 to 267) SpanInfo: undefined +15 > return new Greeter(greeting); + + ~~~~~~~~ => Pos: (268 to 275) SpanInfo: {"start":268,"length":7} + >Greeter + >:=> (line 15, col 19) to (line 15, col 26) +15 > return new Greeter(greeting); + + ~~~~~~~~~ => Pos: (276 to 284) SpanInfo: {"start":276,"length":8} + >greeting + >:=> (line 15, col 27) to (line 15, col 35) +15 > return new Greeter(greeting); + + ~~ => Pos: (285 to 286) SpanInfo: undefined +-------------------------------- +16 > } + + ~~~~~~ => Pos: (287 to 292) SpanInfo: undefined +-------------------------------- +17 > + + ~ => Pos: (293 to 293) SpanInfo: undefined +-------------------------------- +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~ => Pos: (294 to 301) SpanInfo: undefined +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~ => Pos: (302 to 309) SpanInfo: {"start":302,"length":7} + >greeter + >:=> (line 18, col 8) to (line 18, col 15) +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~ => Pos: (310 to 315) SpanInfo: undefined +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~ => Pos: (316 to 323) SpanInfo: {"start":316,"length":7} + >Greeter + >:=> (line 18, col 22) to (line 18, col 29) +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~~~~~~~~~=> Pos: (324 to 339) SpanInfo: {"start":324,"length":15} + >"Hello, world!" + >:=> (line 18, col 30) to (line 18, col 45) +18 > var greeter = new Greeter("Hello, world!"); + + ~~=> Pos: (340 to 341) SpanInfo: undefined +-------------------------------- +19 > var str = greeter.greet(); + + ~~~~~~~~ => Pos: (342 to 349) SpanInfo: undefined +19 > var str = greeter.greet(); + + ~~~~ => Pos: (350 to 353) SpanInfo: {"start":350,"length":3} + >str + >:=> (line 19, col 8) to (line 19, col 11) +19 > var str = greeter.greet(); + + ~~ => Pos: (354 to 355) SpanInfo: undefined +19 > var str = greeter.greet(); + + ~~~~~~~~ => Pos: (356 to 363) SpanInfo: {"start":356,"length":7} + >greeter + >:=> (line 19, col 14) to (line 19, col 21) +19 > var str = greeter.greet(); + + ~~~~~~ => Pos: (364 to 369) SpanInfo: {"start":356,"length":13} + >greeter.greet + >:=> (line 19, col 14) to (line 19, col 27) +19 > var str = greeter.greet(); + + ~~~ => Pos: (370 to 372) SpanInfo: undefined +-------------------------------- +20 > + + ~ => Pos: (373 to 373) SpanInfo: undefined +-------------------------------- +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~~ => Pos: (374 to 386) SpanInfo: undefined +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~ => Pos: (387 to 391) SpanInfo: {"start":387,"length":4} + >foo2 + >:=> (line 21, col 13) to (line 21, col 17) +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~ => Pos: (392 to 400) SpanInfo: {"start":392,"length":8} + >greeting + >:=> (line 21, col 18) to (line 21, col 26) +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~ => Pos: (401 to 412) SpanInfo: undefined +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~~~=> Pos: (413 to 426) SpanInfo: {"start":413,"length":13} + >restGreetings + >:=> (line 21, col 39) to (line 21, col 52) +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (427 to 459) SpanInfo: undefined +-------------------------------- +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~~~~~~~~~~~~ => Pos: (460 to 471) SpanInfo: undefined +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~~~~~~~~~ => Pos: (472 to 480) SpanInfo: {"start":472,"length":8} + >greeters + >:=> (line 22, col 12) to (line 22, col 20) +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~ => Pos: (481 to 481) SpanInfo: undefined +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~~~~~~~~ => Pos: (482 to 489) SpanInfo: {"start":482,"length":7} + >Greeter + >:=> (line 22, col 22) to (line 22, col 29) +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (490 to 524) SpanInfo: undefined +-------------------------------- +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~ => Pos: (525 to 532) SpanInfo: undefined +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~~ => Pos: (533 to 541) SpanInfo: {"start":533,"length":8} + >greeters + >:=> (line 23, col 8) to (line 23, col 16) +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~~ => Pos: (542 to 550) SpanInfo: undefined +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~ => Pos: (551 to 558) SpanInfo: {"start":551,"length":7} + >Greeter + >:=> (line 23, col 26) to (line 23, col 33) +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~~ => Pos: (559 to 567) SpanInfo: {"start":559,"length":8} + >greeting + >:=> (line 23, col 34) to (line 23, col 42) +23 > greeters[0] = new Greeter(greeting); + + ~~ => Pos: (568 to 569) SpanInfo: undefined +-------------------------------- +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~~~~~~~~~~~ => Pos: (570 to 586) SpanInfo: undefined +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~ => Pos: (587 to 588) SpanInfo: {"start":587,"length":1} + >i + >:=> (line 24, col 17) to (line 24, col 18) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~ => Pos: (589 to 593) SpanInfo: undefined +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~ => Pos: (594 to 595) SpanInfo: {"start":594,"length":1} + >i + >:=> (line 24, col 24) to (line 24, col 25) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~ => Pos: (596 to 597) SpanInfo: undefined +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~~~~~~~~ => Pos: (598 to 611) SpanInfo: {"start":598,"length":13} + >restGreetings + >:=> (line 24, col 28) to (line 24, col 41) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~=> Pos: (612 to 618) SpanInfo: {"start":598,"length":20} + >restGreetings.length + >:=> (line 24, col 28) to (line 24, col 48) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~=> Pos: (619 to 619) SpanInfo: undefined +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~=> Pos: (620 to 621) SpanInfo: {"start":620,"length":1} + >i + >:=> (line 24, col 50) to (line 24, col 51) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~=> Pos: (622 to 626) SpanInfo: undefined +-------------------------------- +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~~~~~ => Pos: (627 to 638) SpanInfo: undefined +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~~ => Pos: (639 to 647) SpanInfo: {"start":639,"length":8} + >greeters + >:=> (line 25, col 12) to (line 25, col 20) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~ => Pos: (648 to 652) SpanInfo: {"start":639,"length":13} + >greeters.push + >:=> (line 25, col 12) to (line 25, col 25) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~ => Pos: (653 to 656) SpanInfo: undefined +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~ => Pos: (657 to 664) SpanInfo: {"start":657,"length":7} + >Greeter + >:=> (line 25, col 30) to (line 25, col 37) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~~~~~~~=> Pos: (665 to 678) SpanInfo: {"start":665,"length":13} + >restGreetings + >:=> (line 25, col 38) to (line 25, col 51) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~=> Pos: (679 to 680) SpanInfo: {"start":679,"length":1} + >i + >:=> (line 25, col 52) to (line 25, col 53) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~=> Pos: (681 to 684) SpanInfo: undefined +-------------------------------- +26 > } + + ~~~~~~~~~~ => Pos: (685 to 694) SpanInfo: undefined +-------------------------------- +27 > + + ~ => Pos: (695 to 695) SpanInfo: undefined +-------------------------------- +28 > return greeters; + + ~~~~~~~~~~~~~~~ => Pos: (696 to 710) SpanInfo: undefined +28 > return greeters; + + ~~~~~~~~~ => Pos: (711 to 719) SpanInfo: {"start":711,"length":8} + >greeters + >:=> (line 28, col 15) to (line 28, col 23) +28 > return greeters; + + ~ => Pos: (720 to 720) SpanInfo: undefined +-------------------------------- +29 > } + + ~~~~~~ => Pos: (721 to 726) SpanInfo: undefined +-------------------------------- +30 > + + ~ => Pos: (727 to 727) SpanInfo: undefined +-------------------------------- +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~~~~ => Pos: (728 to 735) SpanInfo: undefined +31 > var b = foo2("Hello", "World", "!"); + + ~~ => Pos: (736 to 737) SpanInfo: {"start":736,"length":1} + >b + >:=> (line 31, col 8) to (line 31, col 9) +31 > var b = foo2("Hello", "World", "!"); + + ~~ => Pos: (738 to 739) SpanInfo: undefined +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~ => Pos: (740 to 744) SpanInfo: {"start":740,"length":4} + >foo2 + >:=> (line 31, col 12) to (line 31, col 16) +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~~~~ => Pos: (745 to 752) SpanInfo: {"start":745,"length":7} + >"Hello" + >:=> (line 31, col 17) to (line 31, col 24) +31 > var b = foo2("Hello", "World", "!"); + + ~ => Pos: (753 to 753) SpanInfo: undefined +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~~~~ => Pos: (754 to 761) SpanInfo: {"start":754,"length":7} + >"World" + >:=> (line 31, col 26) to (line 31, col 33) +31 > var b = foo2("Hello", "World", "!"); + + ~ => Pos: (762 to 762) SpanInfo: undefined +31 > var b = foo2("Hello", "World", "!"); + + ~~~~ => Pos: (763 to 766) SpanInfo: {"start":763,"length":3} + >"!" + >:=> (line 31, col 35) to (line 31, col 38) +31 > var b = foo2("Hello", "World", "!"); + + ~~ => Pos: (767 to 768) SpanInfo: undefined +-------------------------------- +32 > // This is simple signle line comment + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (769 to 810) SpanInfo: undefined +-------------------------------- +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~~~~~~~~~ => Pos: (811 to 823) SpanInfo: undefined +33 > for (var j = 0; j < b.length; j++) { + + ~~ => Pos: (824 to 825) SpanInfo: {"start":824,"length":1} + >j + >:=> (line 33, col 13) to (line 33, col 14) +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~ => Pos: (826 to 830) SpanInfo: undefined +33 > for (var j = 0; j < b.length; j++) { + + ~~ => Pos: (831 to 832) SpanInfo: {"start":831,"length":1} + >j + >:=> (line 33, col 20) to (line 33, col 21) +33 > for (var j = 0; j < b.length; j++) { + + ~~ => Pos: (833 to 834) SpanInfo: undefined +33 > for (var j = 0; j < b.length; j++) { + + ~~ => Pos: (835 to 836) SpanInfo: {"start":835,"length":1} + >b + >:=> (line 33, col 24) to (line 33, col 25) +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~~~ => Pos: (837 to 843) SpanInfo: {"start":835,"length":8} + >b.length + >:=> (line 33, col 24) to (line 33, col 32) +33 > for (var j = 0; j < b.length; j++) { + + ~ => Pos: (844 to 844) SpanInfo: undefined +33 > for (var j = 0; j < b.length; j++) { + + ~~ => Pos: (845 to 846) SpanInfo: {"start":845,"length":1} + >j + >:=> (line 33, col 34) to (line 33, col 35) +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~ => Pos: (847 to 851) SpanInfo: undefined +-------------------------------- +34 > b[j].greet(); + + ~~~~~~~~ => Pos: (852 to 859) SpanInfo: undefined +34 > b[j].greet(); + + ~~ => Pos: (860 to 861) SpanInfo: {"start":860,"length":1} + >b + >:=> (line 34, col 8) to (line 34, col 9) +34 > b[j].greet(); + + ~~ => Pos: (862 to 863) SpanInfo: {"start":862,"length":1} + >j + >:=> (line 34, col 10) to (line 34, col 11) +34 > b[j].greet(); + + ~ => Pos: (864 to 864) SpanInfo: undefined +34 > b[j].greet(); + + ~~~~~~ => Pos: (865 to 870) SpanInfo: {"start":860,"length":10} + >b[j].greet + >:=> (line 34, col 8) to (line 34, col 18) +34 > b[j].greet(); + + ~~~ => Pos: (871 to 873) SpanInfo: undefined +-------------------------------- +35 > } + + ~~~~~~ => Pos: (874 to 879) SpanInfo: undefined +-------------------------------- +36 >} + ~ => Pos: (880 to 880) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/nameOrDottedSpan_stmts.baseline b/tests/baselines/reference/nameOrDottedSpan_stmts.baseline new file mode 100644 index 00000000000..d0d35199e81 --- /dev/null +++ b/tests/baselines/reference/nameOrDottedSpan_stmts.baseline @@ -0,0 +1,884 @@ + +1 >function f() { + + ~~~~~~~~~ => Pos: (0 to 8) SpanInfo: undefined +1 >function f() { + + ~~ => Pos: (9 to 10) SpanInfo: {"start":9,"length":1} + >f + >:=> (line 1, col 9) to (line 1, col 10) +1 >function f() { + + ~~~~ => Pos: (11 to 14) SpanInfo: undefined +-------------------------------- +2 > var y; + + ~~~~~~~~ => Pos: (15 to 22) SpanInfo: undefined +2 > var y; + + ~~ => Pos: (23 to 24) SpanInfo: {"start":23,"length":1} + >y + >:=> (line 2, col 8) to (line 2, col 9) +2 > var y; + + ~ => Pos: (25 to 25) SpanInfo: undefined +-------------------------------- +3 > var x = 0; + + ~~~~~~~~ => Pos: (26 to 33) SpanInfo: undefined +3 > var x = 0; + + ~~ => Pos: (34 to 35) SpanInfo: {"start":34,"length":1} + >x + >:=> (line 3, col 8) to (line 3, col 9) +3 > var x = 0; + + ~~~~~ => Pos: (36 to 40) SpanInfo: undefined +-------------------------------- +4 > for (var i = 0; i < 10; i++) { + + ~~~~~~~~~~~~~ => Pos: (41 to 53) SpanInfo: undefined +4 > for (var i = 0; i < 10; i++) { + + ~~ => Pos: (54 to 55) SpanInfo: {"start":54,"length":1} + >i + >:=> (line 4, col 13) to (line 4, col 14) +4 > for (var i = 0; i < 10; i++) { + + ~~~~~ => Pos: (56 to 60) SpanInfo: undefined +4 > for (var i = 0; i < 10; i++) { + + ~~ => Pos: (61 to 62) SpanInfo: {"start":61,"length":1} + >i + >:=> (line 4, col 20) to (line 4, col 21) +4 > for (var i = 0; i < 10; i++) { + + ~~~~~~ => Pos: (63 to 68) SpanInfo: undefined +4 > for (var i = 0; i < 10; i++) { + + ~~ => Pos: (69 to 70) SpanInfo: {"start":69,"length":1} + >i + >:=> (line 4, col 28) to (line 4, col 29) +4 > for (var i = 0; i < 10; i++) { + + ~~~~~ => Pos: (71 to 75) SpanInfo: undefined +-------------------------------- +5 > x += i; + + ~~~~~~~~ => Pos: (76 to 83) SpanInfo: undefined +5 > x += i; + + ~~ => Pos: (84 to 85) SpanInfo: {"start":84,"length":1} + >x + >:=> (line 5, col 8) to (line 5, col 9) +5 > x += i; + + ~~~ => Pos: (86 to 88) SpanInfo: undefined +5 > x += i; + + ~~ => Pos: (89 to 90) SpanInfo: {"start":89,"length":1} + >i + >:=> (line 5, col 13) to (line 5, col 14) +5 > x += i; + + ~ => Pos: (91 to 91) SpanInfo: undefined +-------------------------------- +6 > x *= 0; + + ~~~~~~~~ => Pos: (92 to 99) SpanInfo: undefined +6 > x *= 0; + + ~~ => Pos: (100 to 101) SpanInfo: {"start":100,"length":1} + >x + >:=> (line 6, col 8) to (line 6, col 9) +6 > x *= 0; + + ~~~~~~ => Pos: (102 to 107) SpanInfo: undefined +-------------------------------- +7 > } + + ~~~~~~ => Pos: (108 to 113) SpanInfo: undefined +-------------------------------- +8 > if (x > 17) { + + ~~~~~~~~ => Pos: (114 to 121) SpanInfo: undefined +8 > if (x > 17) { + + ~~ => Pos: (122 to 123) SpanInfo: {"start":122,"length":1} + >x + >:=> (line 8, col 8) to (line 8, col 9) +8 > if (x > 17) { + + ~~~~~~~~ => Pos: (124 to 131) SpanInfo: undefined +-------------------------------- +9 > x /= 9; + + ~~~~~~~~ => Pos: (132 to 139) SpanInfo: undefined +9 > x /= 9; + + ~~ => Pos: (140 to 141) SpanInfo: {"start":140,"length":1} + >x + >:=> (line 9, col 8) to (line 9, col 9) +9 > x /= 9; + + ~~~~~~ => Pos: (142 to 147) SpanInfo: undefined +-------------------------------- +10 > } else { + + ~~~~~~~~~~~~~ => Pos: (148 to 160) SpanInfo: undefined +-------------------------------- +11 > x += 10; + + ~~~~~~~~ => Pos: (161 to 168) SpanInfo: undefined +11 > x += 10; + + ~~ => Pos: (169 to 170) SpanInfo: {"start":169,"length":1} + >x + >:=> (line 11, col 8) to (line 11, col 9) +11 > x += 10; + + ~~~~~~~ => Pos: (171 to 177) SpanInfo: undefined +-------------------------------- +12 > x++; + + ~~~~~~~~ => Pos: (178 to 185) SpanInfo: undefined +12 > x++; + + ~~ => Pos: (186 to 187) SpanInfo: {"start":186,"length":1} + >x + >:=> (line 12, col 8) to (line 12, col 9) +12 > x++; + + ~~~ => Pos: (188 to 190) SpanInfo: undefined +-------------------------------- +13 > } + + ~~~~~~ => Pos: (191 to 196) SpanInfo: undefined +-------------------------------- +14 > var a = [ + + ~~~~~~~~ => Pos: (197 to 204) SpanInfo: undefined +14 > var a = [ + + ~~ => Pos: (205 to 206) SpanInfo: {"start":205,"length":1} + >a + >:=> (line 14, col 8) to (line 14, col 9) +14 > var a = [ + + ~~~~ => Pos: (207 to 210) SpanInfo: undefined +-------------------------------- +15 > 1, + + ~~~~~~~~~~~ => Pos: (211 to 221) SpanInfo: undefined +-------------------------------- +16 > 2, + + ~~~~~~~~~~~ => Pos: (222 to 232) SpanInfo: undefined +-------------------------------- +17 > 3 + + ~~~~~~~~~~ => Pos: (233 to 242) SpanInfo: undefined +-------------------------------- +18 > ]; + + ~~~~~~~ => Pos: (243 to 249) SpanInfo: undefined +-------------------------------- +19 > var obj = { + + ~~~~~~~~ => Pos: (250 to 257) SpanInfo: undefined +19 > var obj = { + + ~~~~ => Pos: (258 to 261) SpanInfo: {"start":258,"length":3} + >obj + >:=> (line 19, col 8) to (line 19, col 11) +19 > var obj = { + + ~~~~ => Pos: (262 to 265) SpanInfo: undefined +-------------------------------- +20 > z: 1, + + ~~~~~~~~ => Pos: (266 to 273) SpanInfo: undefined +20 > z: 1, + + ~~ => Pos: (274 to 275) SpanInfo: {"start":274,"length":1} + >z + >:=> (line 20, col 8) to (line 20, col 9) +20 > z: 1, + + ~~~~ => Pos: (276 to 279) SpanInfo: undefined +-------------------------------- +21 > q: "hello" + + ~~~~~~~~ => Pos: (280 to 287) SpanInfo: undefined +21 > q: "hello" + + ~~ => Pos: (288 to 289) SpanInfo: {"start":288,"length":1} + >q + >:=> (line 21, col 8) to (line 21, col 9) +21 > q: "hello" + + ~ => Pos: (290 to 290) SpanInfo: undefined +21 > q: "hello" + + ~~~~~~~~ => Pos: (291 to 298) SpanInfo: {"start":291,"length":7} + >"hello" + >:=> (line 21, col 11) to (line 21, col 18) +-------------------------------- +22 > }; + + ~~~~~~~ => Pos: (299 to 305) SpanInfo: undefined +-------------------------------- +23 > for (var j in a) { + + ~~~~~~~~~~~~~ => Pos: (306 to 318) SpanInfo: undefined +23 > for (var j in a) { + + ~~ => Pos: (319 to 320) SpanInfo: {"start":319,"length":1} + >j + >:=> (line 23, col 13) to (line 23, col 14) +23 > for (var j in a) { + + ~~~ => Pos: (321 to 323) SpanInfo: undefined +23 > for (var j in a) { + + ~~ => Pos: (324 to 325) SpanInfo: {"start":324,"length":1} + >a + >:=> (line 23, col 18) to (line 23, col 19) +23 > for (var j in a) { + + ~~~ => Pos: (326 to 328) SpanInfo: undefined +-------------------------------- +24 > obj.z = a[j]; + + ~~~~~~~~ => Pos: (329 to 336) SpanInfo: undefined +24 > obj.z = a[j]; + + ~~~~ => Pos: (337 to 340) SpanInfo: {"start":337,"length":3} + >obj + >:=> (line 24, col 8) to (line 24, col 11) +24 > obj.z = a[j]; + + ~~ => Pos: (341 to 342) SpanInfo: {"start":337,"length":5} + >obj.z + >:=> (line 24, col 8) to (line 24, col 13) +24 > obj.z = a[j]; + + ~~ => Pos: (343 to 344) SpanInfo: undefined +24 > obj.z = a[j]; + + ~~ => Pos: (345 to 346) SpanInfo: {"start":345,"length":1} + >a + >:=> (line 24, col 16) to (line 24, col 17) +24 > obj.z = a[j]; + + ~~ => Pos: (347 to 348) SpanInfo: {"start":347,"length":1} + >j + >:=> (line 24, col 18) to (line 24, col 19) +24 > obj.z = a[j]; + + ~~ => Pos: (349 to 350) SpanInfo: undefined +-------------------------------- +25 > var v = 10; + + ~~~~~~~~~~~~ => Pos: (351 to 362) SpanInfo: undefined +25 > var v = 10; + + ~~ => Pos: (363 to 364) SpanInfo: {"start":363,"length":1} + >v + >:=> (line 25, col 12) to (line 25, col 13) +25 > var v = 10; + + ~~~~~~ => Pos: (365 to 370) SpanInfo: undefined +-------------------------------- +26 > } + + ~~~~~~ => Pos: (371 to 376) SpanInfo: undefined +-------------------------------- +27 > try { + + ~~~~~~~~~~ => Pos: (377 to 386) SpanInfo: undefined +-------------------------------- +28 > obj.q = "ohhh"; + + ~~~~~~~~ => Pos: (387 to 394) SpanInfo: undefined +28 > obj.q = "ohhh"; + + ~~~~ => Pos: (395 to 398) SpanInfo: {"start":395,"length":3} + >obj + >:=> (line 28, col 8) to (line 28, col 11) +28 > obj.q = "ohhh"; + + ~~ => Pos: (399 to 400) SpanInfo: {"start":395,"length":5} + >obj.q + >:=> (line 28, col 8) to (line 28, col 13) +28 > obj.q = "ohhh"; + + ~~ => Pos: (401 to 402) SpanInfo: undefined +28 > obj.q = "ohhh"; + + ~~~~~~~ => Pos: (403 to 409) SpanInfo: {"start":403,"length":6} + >"ohhh" + >:=> (line 28, col 16) to (line 28, col 22) +28 > obj.q = "ohhh"; + + ~ => Pos: (410 to 410) SpanInfo: undefined +-------------------------------- +29 > } catch (e) { + + ~~~~~~~~~~~~~ => Pos: (411 to 423) SpanInfo: undefined +29 > } catch (e) { + + ~~ => Pos: (424 to 425) SpanInfo: {"start":424,"length":1} + >e + >:=> (line 29, col 13) to (line 29, col 14) +29 > } catch (e) { + + ~~~ => Pos: (426 to 428) SpanInfo: undefined +-------------------------------- +30 > if (obj.z < 10) { + + ~~~~~~~~~~~~ => Pos: (429 to 440) SpanInfo: undefined +30 > if (obj.z < 10) { + + ~~~~ => Pos: (441 to 444) SpanInfo: {"start":441,"length":3} + >obj + >:=> (line 30, col 12) to (line 30, col 15) +30 > if (obj.z < 10) { + + ~~ => Pos: (445 to 446) SpanInfo: {"start":441,"length":5} + >obj.z + >:=> (line 30, col 12) to (line 30, col 17) +30 > if (obj.z < 10) { + + ~~~~~~~~ => Pos: (447 to 454) SpanInfo: undefined +-------------------------------- +31 > obj.z = 12; + + ~~~~~~~~~~~~ => Pos: (455 to 466) SpanInfo: undefined +31 > obj.z = 12; + + ~~~~ => Pos: (467 to 470) SpanInfo: {"start":467,"length":3} + >obj + >:=> (line 31, col 12) to (line 31, col 15) +31 > obj.z = 12; + + ~~ => Pos: (471 to 472) SpanInfo: {"start":467,"length":5} + >obj.z + >:=> (line 31, col 12) to (line 31, col 17) +31 > obj.z = 12; + + ~~~~~~ => Pos: (473 to 478) SpanInfo: undefined +-------------------------------- +32 > } else { + + ~~~~~~~~~~~~~~~~~ => Pos: (479 to 495) SpanInfo: undefined +-------------------------------- +33 > obj.q = "hmm"; + + ~~~~~~~~~~~~ => Pos: (496 to 507) SpanInfo: undefined +33 > obj.q = "hmm"; + + ~~~~ => Pos: (508 to 511) SpanInfo: {"start":508,"length":3} + >obj + >:=> (line 33, col 12) to (line 33, col 15) +33 > obj.q = "hmm"; + + ~~ => Pos: (512 to 513) SpanInfo: {"start":508,"length":5} + >obj.q + >:=> (line 33, col 12) to (line 33, col 17) +33 > obj.q = "hmm"; + + ~~ => Pos: (514 to 515) SpanInfo: undefined +33 > obj.q = "hmm"; + + ~~~~~~ => Pos: (516 to 521) SpanInfo: {"start":516,"length":5} + >"hmm" + >:=> (line 33, col 20) to (line 33, col 25) +33 > obj.q = "hmm"; + + ~ => Pos: (522 to 522) SpanInfo: undefined +-------------------------------- +34 > } + + ~~~~~~~~~~ => Pos: (523 to 532) SpanInfo: undefined +-------------------------------- +35 > } + + ~~~~~~ => Pos: (533 to 538) SpanInfo: undefined +-------------------------------- +36 > try { + + ~~~~~~~~~~ => Pos: (539 to 548) SpanInfo: undefined +-------------------------------- +37 > throw new Error(); + + ~~~~~~~~~~~~~~~~~~ => Pos: (549 to 566) SpanInfo: undefined +37 > throw new Error(); + + ~~~~~~ => Pos: (567 to 572) SpanInfo: {"start":567,"length":5} + >Error + >:=> (line 37, col 18) to (line 37, col 23) +37 > throw new Error(); + + ~~~ => Pos: (573 to 575) SpanInfo: undefined +-------------------------------- +38 > } catch (e1) { + + ~~~~~~~~~~~~~ => Pos: (576 to 588) SpanInfo: undefined +38 > } catch (e1) { + + ~~~ => Pos: (589 to 591) SpanInfo: {"start":589,"length":2} + >e1 + >:=> (line 38, col 13) to (line 38, col 15) +38 > } catch (e1) { + + ~~~ => Pos: (592 to 594) SpanInfo: undefined +-------------------------------- +39 > var b = e1; + + ~~~~~~~~~~~~ => Pos: (595 to 606) SpanInfo: undefined +39 > var b = e1; + + ~~ => Pos: (607 to 608) SpanInfo: {"start":607,"length":1} + >b + >:=> (line 39, col 12) to (line 39, col 13) +39 > var b = e1; + + ~~ => Pos: (609 to 610) SpanInfo: undefined +39 > var b = e1; + + ~~~ => Pos: (611 to 613) SpanInfo: {"start":611,"length":2} + >e1 + >:=> (line 39, col 16) to (line 39, col 18) +39 > var b = e1; + + ~ => Pos: (614 to 614) SpanInfo: undefined +-------------------------------- +40 > } finally { + + ~~~~~~~~~~~~~~~~ => Pos: (615 to 630) SpanInfo: undefined +-------------------------------- +41 > y = 70; + + ~~~~~~~~ => Pos: (631 to 638) SpanInfo: undefined +41 > y = 70; + + ~~ => Pos: (639 to 640) SpanInfo: {"start":639,"length":1} + >y + >:=> (line 41, col 8) to (line 41, col 9) +41 > y = 70; + + ~~~~~~ => Pos: (641 to 646) SpanInfo: undefined +-------------------------------- +42 > } + + ~~~~~~ => Pos: (647 to 652) SpanInfo: undefined +-------------------------------- +43 > with (obj) { + + ~~~~~~~~~~ => Pos: (653 to 662) SpanInfo: undefined +43 > with (obj) { + + ~~~~ => Pos: (663 to 666) SpanInfo: {"start":663,"length":3} + >obj + >:=> (line 43, col 10) to (line 43, col 13) +43 > with (obj) { + + ~~~ => Pos: (667 to 669) SpanInfo: undefined +-------------------------------- +44 > i = 2; + + ~~~~~~~~ => Pos: (670 to 677) SpanInfo: undefined +44 > i = 2; + + ~~ => Pos: (678 to 679) SpanInfo: {"start":678,"length":1} + >i + >:=> (line 44, col 8) to (line 44, col 9) +44 > i = 2; + + ~~~~~ => Pos: (680 to 684) SpanInfo: undefined +-------------------------------- +45 > z = 10; + + ~~~~~~~~ => Pos: (685 to 692) SpanInfo: undefined +45 > z = 10; + + ~~ => Pos: (693 to 694) SpanInfo: {"start":693,"length":1} + >z + >:=> (line 45, col 8) to (line 45, col 9) +45 > z = 10; + + ~~~~~~ => Pos: (695 to 700) SpanInfo: undefined +-------------------------------- +46 > } + + ~~~~~~ => Pos: (701 to 706) SpanInfo: undefined +-------------------------------- +47 > switch (obj.z) { + + ~~~~~~~~~~~~ => Pos: (707 to 718) SpanInfo: undefined +47 > switch (obj.z) { + + ~~~~ => Pos: (719 to 722) SpanInfo: {"start":719,"length":3} + >obj + >:=> (line 47, col 12) to (line 47, col 15) +47 > switch (obj.z) { + + ~~ => Pos: (723 to 724) SpanInfo: {"start":719,"length":5} + >obj.z + >:=> (line 47, col 12) to (line 47, col 17) +47 > switch (obj.z) { + + ~~~ => Pos: (725 to 727) SpanInfo: undefined +-------------------------------- +48 > case 0: { + + ~~~~~~~~~~~~~~~~~~ => Pos: (728 to 745) SpanInfo: undefined +-------------------------------- +49 > x++; + + ~~~~~~~~~~~~ => Pos: (746 to 757) SpanInfo: undefined +49 > x++; + + ~~ => Pos: (758 to 759) SpanInfo: {"start":758,"length":1} + >x + >:=> (line 49, col 12) to (line 49, col 13) +49 > x++; + + ~~~ => Pos: (760 to 762) SpanInfo: undefined +-------------------------------- +50 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (763 to 781) SpanInfo: undefined +-------------------------------- +51 > + + ~ => Pos: (782 to 782) SpanInfo: undefined +-------------------------------- +52 > } + + ~~~~~~~~~~ => Pos: (783 to 792) SpanInfo: undefined +-------------------------------- +53 > case 1: { + + ~~~~~~~~~~~~~~~~~~ => Pos: (793 to 810) SpanInfo: undefined +-------------------------------- +54 > x--; + + ~~~~~~~~~~~~ => Pos: (811 to 822) SpanInfo: undefined +54 > x--; + + ~~ => Pos: (823 to 824) SpanInfo: {"start":823,"length":1} + >x + >:=> (line 54, col 12) to (line 54, col 13) +54 > x--; + + ~~~ => Pos: (825 to 827) SpanInfo: undefined +-------------------------------- +55 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (828 to 846) SpanInfo: undefined +-------------------------------- +56 > + + ~ => Pos: (847 to 847) SpanInfo: undefined +-------------------------------- +57 > } + + ~~~~~~~~~~ => Pos: (848 to 857) SpanInfo: undefined +-------------------------------- +58 > default: { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (858 to 876) SpanInfo: undefined +-------------------------------- +59 > x *= 2; + + ~~~~~~~~~~~~ => Pos: (877 to 888) SpanInfo: undefined +59 > x *= 2; + + ~~ => Pos: (889 to 890) SpanInfo: {"start":889,"length":1} + >x + >:=> (line 59, col 12) to (line 59, col 13) +59 > x *= 2; + + ~~~~~~ => Pos: (891 to 896) SpanInfo: undefined +-------------------------------- +60 > x = 50; + + ~~~~~~~~~~~~ => Pos: (897 to 908) SpanInfo: undefined +60 > x = 50; + + ~~ => Pos: (909 to 910) SpanInfo: {"start":909,"length":1} + >x + >:=> (line 60, col 12) to (line 60, col 13) +60 > x = 50; + + ~~~~~~ => Pos: (911 to 916) SpanInfo: undefined +-------------------------------- +61 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (917 to 935) SpanInfo: undefined +-------------------------------- +62 > + + ~ => Pos: (936 to 936) SpanInfo: undefined +-------------------------------- +63 > } + + ~~~~~~~~~~ => Pos: (937 to 946) SpanInfo: undefined +-------------------------------- +64 > } + + ~~~~~~ => Pos: (947 to 952) SpanInfo: undefined +-------------------------------- +65 > while (x < 10) { + + ~~~~~~~~~~~ => Pos: (953 to 963) SpanInfo: undefined +65 > while (x < 10) { + + ~~ => Pos: (964 to 965) SpanInfo: {"start":964,"length":1} + >x + >:=> (line 65, col 11) to (line 65, col 12) +65 > while (x < 10) { + + ~~~~~~~~ => Pos: (966 to 973) SpanInfo: undefined +-------------------------------- +66 > x++; + + ~~~~~~~~ => Pos: (974 to 981) SpanInfo: undefined +66 > x++; + + ~~ => Pos: (982 to 983) SpanInfo: {"start":982,"length":1} + >x + >:=> (line 66, col 8) to (line 66, col 9) +66 > x++; + + ~~~ => Pos: (984 to 986) SpanInfo: undefined +-------------------------------- +67 > } + + ~~~~~~ => Pos: (987 to 992) SpanInfo: undefined +-------------------------------- +68 > do { + + ~~~~~~~~~ => Pos: (993 to 1001) SpanInfo: undefined +-------------------------------- +69 > x--; + + ~~~~~~~~ => Pos: (1002 to 1009) SpanInfo: undefined +69 > x--; + + ~~ => Pos: (1010 to 1011) SpanInfo: {"start":1010,"length":1} + >x + >:=> (line 69, col 8) to (line 69, col 9) +69 > x--; + + ~~~ => Pos: (1012 to 1014) SpanInfo: undefined +-------------------------------- +70 > } while (x > 4) + + ~~~~~~~~~~~~~ => Pos: (1015 to 1027) SpanInfo: undefined +70 > } while (x > 4) + + ~~ => Pos: (1028 to 1029) SpanInfo: {"start":1028,"length":1} + >x + >:=> (line 70, col 13) to (line 70, col 14) +70 > } while (x > 4) + + ~~~~~ => Pos: (1030 to 1034) SpanInfo: undefined +-------------------------------- +71 > x = y; + + ~~~~ => Pos: (1035 to 1038) SpanInfo: undefined +71 > x = y; + + ~~ => Pos: (1039 to 1040) SpanInfo: {"start":1039,"length":1} + >x + >:=> (line 71, col 4) to (line 71, col 5) +71 > x = y; + + ~~ => Pos: (1041 to 1042) SpanInfo: undefined +71 > x = y; + + ~~ => Pos: (1043 to 1044) SpanInfo: {"start":1043,"length":1} + >y + >:=> (line 71, col 8) to (line 71, col 9) +71 > x = y; + + ~ => Pos: (1045 to 1045) SpanInfo: undefined +-------------------------------- +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~~~~~~ => Pos: (1046 to 1053) SpanInfo: undefined +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1054 to 1055) SpanInfo: {"start":1054,"length":1} + >z + >:=> (line 72, col 8) to (line 72, col 9) +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~ => Pos: (1056 to 1058) SpanInfo: undefined +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1059 to 1060) SpanInfo: {"start":1059,"length":1} + >x + >:=> (line 72, col 13) to (line 72, col 14) +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~~~~~~ => Pos: (1061 to 1068) SpanInfo: undefined +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1069 to 1070) SpanInfo: {"start":1069,"length":1} + >x + >:=> (line 72, col 23) to (line 72, col 24) +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~~~~ => Pos: (1071 to 1076) SpanInfo: undefined +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1077 to 1078) SpanInfo: {"start":1077,"length":1} + >x + >:=> (line 72, col 31) to (line 72, col 32) +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~~~ => Pos: (1079 to 1083) SpanInfo: undefined +-------------------------------- +73 > (x == 1) ? x + 1 : x - 1; + + ~~~~~ => Pos: (1084 to 1088) SpanInfo: undefined +73 > (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1089 to 1090) SpanInfo: {"start":1089,"length":1} + >x + >:=> (line 73, col 5) to (line 73, col 6) +73 > (x == 1) ? x + 1 : x - 1; + + ~~~~~~~~ => Pos: (1091 to 1098) SpanInfo: undefined +73 > (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1099 to 1100) SpanInfo: {"start":1099,"length":1} + >x + >:=> (line 73, col 15) to (line 73, col 16) +73 > (x == 1) ? x + 1 : x - 1; + + ~~~~~~ => Pos: (1101 to 1106) SpanInfo: undefined +73 > (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1107 to 1108) SpanInfo: {"start":1107,"length":1} + >x + >:=> (line 73, col 23) to (line 73, col 24) +73 > (x == 1) ? x + 1 : x - 1; + + ~~~~~ => Pos: (1109 to 1113) SpanInfo: undefined +-------------------------------- +74 > x === 1; + + ~~~~ => Pos: (1114 to 1117) SpanInfo: undefined +74 > x === 1; + + ~~ => Pos: (1118 to 1119) SpanInfo: {"start":1118,"length":1} + >x + >:=> (line 74, col 4) to (line 74, col 5) +74 > x === 1; + + ~~~~~~~ => Pos: (1120 to 1126) SpanInfo: undefined +-------------------------------- +75 > x = z = 40; + + ~~~~ => Pos: (1127 to 1130) SpanInfo: undefined +75 > x = z = 40; + + ~~ => Pos: (1131 to 1132) SpanInfo: {"start":1131,"length":1} + >x + >:=> (line 75, col 4) to (line 75, col 5) +75 > x = z = 40; + + ~~ => Pos: (1133 to 1134) SpanInfo: undefined +75 > x = z = 40; + + ~~ => Pos: (1135 to 1136) SpanInfo: {"start":1135,"length":1} + >z + >:=> (line 75, col 8) to (line 75, col 9) +75 > x = z = 40; + + ~~~~~~ => Pos: (1137 to 1142) SpanInfo: undefined +-------------------------------- +76 > eval("y"); + + ~~~~ => Pos: (1143 to 1146) SpanInfo: undefined +76 > eval("y"); + + ~~~~~ => Pos: (1147 to 1151) SpanInfo: {"start":1147,"length":4} + >eval + >:=> (line 76, col 4) to (line 76, col 8) +76 > eval("y"); + + ~~~~ => Pos: (1152 to 1155) SpanInfo: {"start":1152,"length":3} + >"y" + >:=> (line 76, col 9) to (line 76, col 12) +76 > eval("y"); + + ~~ => Pos: (1156 to 1157) SpanInfo: undefined +-------------------------------- +77 > return; + + ~~~~~~~~~~~~ => Pos: (1158 to 1169) SpanInfo: undefined +-------------------------------- +78 >} + + ~~ => Pos: (1170 to 1171) SpanInfo: undefined +-------------------------------- +79 >var b = function () { + + ~~~~ => Pos: (1172 to 1175) SpanInfo: undefined +79 >var b = function () { + + ~~ => Pos: (1176 to 1177) SpanInfo: {"start":1176,"length":1} + >b + >:=> (line 79, col 4) to (line 79, col 5) +79 >var b = function () { + + ~~~~~~~~~~~~~~~~ => Pos: (1178 to 1193) SpanInfo: undefined +-------------------------------- +80 > var x = 10; + + ~~~~~~~~ => Pos: (1194 to 1201) SpanInfo: undefined +80 > var x = 10; + + ~~ => Pos: (1202 to 1203) SpanInfo: {"start":1202,"length":1} + >x + >:=> (line 80, col 8) to (line 80, col 9) +80 > var x = 10; + + ~~~~~~ => Pos: (1204 to 1209) SpanInfo: undefined +-------------------------------- +81 > x = x + 1; + + ~~~~ => Pos: (1210 to 1213) SpanInfo: undefined +81 > x = x + 1; + + ~~ => Pos: (1214 to 1215) SpanInfo: {"start":1214,"length":1} + >x + >:=> (line 81, col 4) to (line 81, col 5) +81 > x = x + 1; + + ~~ => Pos: (1216 to 1217) SpanInfo: undefined +81 > x = x + 1; + + ~~ => Pos: (1218 to 1219) SpanInfo: {"start":1218,"length":1} + >x + >:=> (line 81, col 8) to (line 81, col 9) +81 > x = x + 1; + + ~~~~~ => Pos: (1220 to 1224) SpanInfo: undefined +-------------------------------- +82 >}; + + ~~~ => Pos: (1225 to 1227) SpanInfo: undefined +-------------------------------- +83 >f(); + ~~ => Pos: (1228 to 1229) SpanInfo: {"start":1228,"length":1} + >f + >:=> (line 83, col 0) to (line 83, col 1) +83 >f(); + ~~ => Pos: (1230 to 1231) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/nestedRecursiveLambda.types b/tests/baselines/reference/nestedRecursiveLambda.types index 358ebda8abf..864daea3e1f 100644 --- a/tests/baselines/reference/nestedRecursiveLambda.types +++ b/tests/baselines/reference/nestedRecursiveLambda.types @@ -35,7 +35,7 @@ void(r =>(r => r)); >r : any [(r =>(r => r))] ->[(r =>(r => r))] : { (r: any): (r: any) => any; }[] +>[(r =>(r => r))] : ((r: any) => (r: any) => any)[] >(r =>(r => r)) : (r: any) => (r: any) => any >r =>(r => r) : (r: any) => (r: any) => any >r : any diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index b59b734b3d0..9965709713d 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -4,12 +4,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(90,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(93,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(18,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(20,5): error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(21,5): error TS2412: Property '3.0' of type 'MyNumber' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(55,5): error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': Index signatures are incompatible: Type 'string | number' is not assignable to type 'string': @@ -17,7 +14,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(88,9): error TS2304: Cannot find name 'Myn'. -==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts (14 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts (11 errors) ==== // String indexer types constrain the types of named properties in their containing type interface MyNumber extends Number { @@ -40,8 +37,6 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo !!! error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. "3.0": string; // ok "4.0": number; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. 3.0: MyNumber // error ~~~~~~~~~~~~~ !!! error TS2412: Property '3.0' of type 'MyNumber' is not assignable to numeric index type 'string'. @@ -87,8 +82,6 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo foo(): string; // ok "3.0": string; // ok "4.0": number; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. f: MyNumber; // error } @@ -109,8 +102,6 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo foo(): string; // ok "3.0": string; // ok "4.0": number; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. f: MyNumber; // error } diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt index 4d0488ec80f..327a09d8813 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt @@ -1,16 +1,13 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(16,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(17,5): error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(25,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(26,5): error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(34,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(35,5): error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ [x: number]: string | number | A; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ [x: number]: number | A; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': Index signatures are incompatible: - Type 'string | number | A' is not assignable to type 'A': - Type 'string' is not assignable to type 'A'. + Type 'number | A' is not assignable to type 'A': + Type 'number' is not assignable to type 'A'. -==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts (7 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts (4 errors) ==== // String indexer providing a constraint of a user defined type class A { @@ -30,8 +27,6 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo ~~~~~~~~~~~~ !!! error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. "4.0": string; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. } interface Foo2 { @@ -43,8 +38,6 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo ~~~~~~~~~~~~ !!! error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. "4.0": string; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. } var a: { @@ -56,17 +49,15 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo ~~~~~~~~~~~~ !!! error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. "4.0": string; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. }; // error var b: { [x: number]: A } = { ~ -!!! error TS2322: Type '{ [x: number]: string | number | A; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': +!!! error TS2322: Type '{ [x: number]: number | A; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type 'string | number | A' is not assignable to type 'A': -!!! error TS2322: Type 'string' is not assignable to type 'A'. +!!! error TS2322: Type 'number | A' is not assignable to type 'A': +!!! error TS2322: Type 'number' is not assignable to type 'A'. 1.0: new A(), 2.0: new B(), "2.5": new B(), diff --git a/tests/baselines/reference/parenthesizedTypes.js b/tests/baselines/reference/parenthesizedTypes.js new file mode 100644 index 00000000000..a80d9d98c31 --- /dev/null +++ b/tests/baselines/reference/parenthesizedTypes.js @@ -0,0 +1,52 @@ +//// [parenthesizedTypes.ts] +var a: string; +var a: (string); +var a: ((string) | string | (((string)))); +var a: ((((((((((((((((((((((((((((((((((((((((string)))))))))))))))))))))))))))))))))))))))); + +var b: (x: string) => string; +var b: ((x: (string)) => (string)); + +var c: string[] | number[]; +var c: (string)[] | (number)[]; +var c: ((string)[]) | ((number)[]); + +var d: (((x: string) => string) | ((x: number) => number))[]; +var d: ({ (x: string): string } | { (x: number): number })[]; +var d: Array<((x: string) => string) | ((x: number) => number)>; +var d: Array<{ (x: string): string } | { (x: number): number }>; +var d: (Array<{ (x: string): string } | { (x: number): number }>); + +var e: typeof a[]; +var e: (typeof a)[]; + +var f: (string) => string; +var f: (string: any) => string; + +var g: [string, string]; +var g: [(string), string]; +var g: [(string), (((typeof a)))]; + + +//// [parenthesizedTypes.js] +var a; +var a; +var a; +var a; +var b; +var b; +var c; +var c; +var c; +var d; +var d; +var d; +var d; +var d; +var e; +var e; +var f; +var f; +var g; +var g; +var g; diff --git a/tests/baselines/reference/parenthesizedTypes.types b/tests/baselines/reference/parenthesizedTypes.types new file mode 100644 index 00000000000..4b7129b3782 --- /dev/null +++ b/tests/baselines/reference/parenthesizedTypes.types @@ -0,0 +1,84 @@ +=== tests/cases/conformance/types/specifyingTypes/typeLiterals/parenthesizedTypes.ts === +var a: string; +>a : string + +var a: (string); +>a : string + +var a: ((string) | string | (((string)))); +>a : string + +var a: ((((((((((((((((((((((((((((((((((((((((string)))))))))))))))))))))))))))))))))))))))); +>a : string + +var b: (x: string) => string; +>b : (x: string) => string +>x : string + +var b: ((x: (string)) => (string)); +>b : (x: string) => string +>x : string + +var c: string[] | number[]; +>c : string[] | number[] + +var c: (string)[] | (number)[]; +>c : string[] | number[] + +var c: ((string)[]) | ((number)[]); +>c : string[] | number[] + +var d: (((x: string) => string) | ((x: number) => number))[]; +>d : (((x: string) => string) | ((x: number) => number))[] +>x : string +>x : number + +var d: ({ (x: string): string } | { (x: number): number })[]; +>d : (((x: string) => string) | ((x: number) => number))[] +>x : string +>x : number + +var d: Array<((x: string) => string) | ((x: number) => number)>; +>d : (((x: string) => string) | ((x: number) => number))[] +>Array : T[] +>x : string +>x : number + +var d: Array<{ (x: string): string } | { (x: number): number }>; +>d : (((x: string) => string) | ((x: number) => number))[] +>Array : T[] +>x : string +>x : number + +var d: (Array<{ (x: string): string } | { (x: number): number }>); +>d : (((x: string) => string) | ((x: number) => number))[] +>Array : T[] +>x : string +>x : number + +var e: typeof a[]; +>e : string[] +>a : string + +var e: (typeof a)[]; +>e : string[] +>a : string + +var f: (string) => string; +>f : (string: any) => string +>string : any + +var f: (string: any) => string; +>f : (string: any) => string +>string : any + +var g: [string, string]; +>g : [string, string] + +var g: [(string), string]; +>g : [string, string] + +var g: [(string), (((typeof a)))]; +>g : [string, string] +>a : string + diff --git a/tests/baselines/reference/parserEnum5.errors.txt b/tests/baselines/reference/parserEnum5.errors.txt index 40c2c933955..b98fdfbfba5 100644 --- a/tests/baselines/reference/parserEnum5.errors.txt +++ b/tests/baselines/reference/parserEnum5.errors.txt @@ -1,9 +1,9 @@ tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(2,12): error TS1005: ',' expected. tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,15): error TS1005: ',' expected. tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,24): error TS1005: ',' expected. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(2,14): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,17): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,26): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(2,14): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,17): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,26): error TS2452: An enum member cannot have a numeric name. ==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts (6 errors) ==== @@ -12,13 +12,13 @@ tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,26) ~ !!! error TS1005: ',' expected. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. enum E1 { a, b: 1, c, d: 2 = 3 } ~ !!! error TS1005: ',' expected. ~ !!! error TS1005: ',' expected. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. ~ -!!! error TS1151: An enum member cannot have a numeric name. \ No newline at end of file +!!! error TS2452: An enum member cannot have a numeric name. \ No newline at end of file diff --git a/tests/baselines/reference/parserEnum7.errors.txt b/tests/baselines/reference/parserEnum7.errors.txt index a4a2326546a..1a7f26df8db 100644 --- a/tests/baselines/reference/parserEnum7.errors.txt +++ b/tests/baselines/reference/parserEnum7.errors.txt @@ -1,15 +1,15 @@ -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,3): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,6): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,9): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,3): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,6): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,9): error TS2452: An enum member cannot have a numeric name. ==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts (3 errors) ==== enum E { 1, 2, 3 ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. } \ No newline at end of file diff --git a/tests/baselines/reference/parserOptionalTypeMembers1.errors.txt b/tests/baselines/reference/parserOptionalTypeMembers1.errors.txt deleted file mode 100644 index 0279ad37777..00000000000 --- a/tests/baselines/reference/parserOptionalTypeMembers1.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(2,5): error TS2300: Duplicate identifier 'configurable'. -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(3,5): error TS2300: Duplicate identifier 'enumerable'. -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(4,5): error TS2300: Duplicate identifier 'value'. -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(5,5): error TS2300: Duplicate identifier 'writable'. - - -==== tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts (4 errors) ==== - interface PropertyDescriptor { - configurable?: boolean; - ~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'configurable'. - enumerable?: boolean; - ~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'enumerable'. - value?: any; - ~~~~~ -!!! error TS2300: Duplicate identifier 'value'. - writable?: boolean; - ~~~~~~~~ -!!! error TS2300: Duplicate identifier 'writable'. - get?(): any; - set?(v: any): void; - } \ No newline at end of file diff --git a/tests/baselines/reference/parserOptionalTypeMembers1.js b/tests/baselines/reference/parserOptionalTypeMembers1.js index 5dfb0adfe82..757887e5409 100644 --- a/tests/baselines/reference/parserOptionalTypeMembers1.js +++ b/tests/baselines/reference/parserOptionalTypeMembers1.js @@ -1,5 +1,5 @@ //// [parserOptionalTypeMembers1.ts] -interface PropertyDescriptor { +interface PropertyDescriptor2 { configurable?: boolean; enumerable?: boolean; value?: any; diff --git a/tests/baselines/reference/parserOptionalTypeMembers1.types b/tests/baselines/reference/parserOptionalTypeMembers1.types new file mode 100644 index 00000000000..7ede18a1d92 --- /dev/null +++ b/tests/baselines/reference/parserOptionalTypeMembers1.types @@ -0,0 +1,23 @@ +=== tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts === +interface PropertyDescriptor2 { +>PropertyDescriptor2 : PropertyDescriptor2 + + configurable?: boolean; +>configurable : boolean + + enumerable?: boolean; +>enumerable : boolean + + value?: any; +>value : any + + writable?: boolean; +>writable : boolean + + get?(): any; +>get : () => any + + set?(v: any): void; +>set : (v: any) => void +>v : any +} diff --git a/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt b/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt index 5dc0a63d7eb..64ec399fabf 100644 --- a/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt +++ b/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt @@ -1,3 +1,4 @@ +in1.d.ts(1,8): error TS2300: Duplicate identifier 'a'. in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. @@ -14,8 +15,10 @@ in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. class MyClass{ } } } -==== in1.d.ts (0 errors) ==== +==== in1.d.ts (1 errors) ==== import a = A; + ~ +!!! error TS2300: Duplicate identifier 'a'. ==== in2.d.ts (1 errors) ==== import a = A; ~ diff --git a/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt b/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt index 5dc0a63d7eb..64ec399fabf 100644 --- a/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt +++ b/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt @@ -1,3 +1,4 @@ +in1.d.ts(1,8): error TS2300: Duplicate identifier 'a'. in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. @@ -14,8 +15,10 @@ in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. class MyClass{ } } } -==== in1.d.ts (0 errors) ==== +==== in1.d.ts (1 errors) ==== import a = A; + ~ +!!! error TS2300: Duplicate identifier 'a'. ==== in2.d.ts (1 errors) ==== import a = A; ~ diff --git a/tests/baselines/reference/propertiesAndIndexers2.errors.txt b/tests/baselines/reference/propertiesAndIndexers2.errors.txt new file mode 100644 index 00000000000..e1ab8c9d13d --- /dev/null +++ b/tests/baselines/reference/propertiesAndIndexers2.errors.txt @@ -0,0 +1,46 @@ +tests/cases/compiler/propertiesAndIndexers2.ts(2,5): error TS2413: Numeric index type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(8,5): error TS2411: Property 'c' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(9,5): error TS2411: Property '3' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(10,5): error TS2411: Property 'Infinity' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(11,5): error TS2411: Property '"-Infinity"' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(12,5): error TS2411: Property 'NaN' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(13,5): error TS2411: Property '"-NaN"' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(14,5): error TS2411: Property '6' of type '() => string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(14,5): error TS2412: Property '6' of type '() => string' is not assignable to numeric index type 'string'. + + +==== tests/cases/compiler/propertiesAndIndexers2.ts (9 errors) ==== + interface A { + [n: number]: string; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2413: Numeric index type 'string' is not assignable to string index type 'number'. + [s: string]: number; + } + + // All of these should fail. + interface B extends A { + c: string; + ~~~~~~~~~~ +!!! error TS2411: Property 'c' of type 'string' is not assignable to string index type 'number'. + 3: string; + ~~~~~~~~~~ +!!! error TS2411: Property '3' of type 'string' is not assignable to string index type 'number'. + Infinity: string; + ~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property 'Infinity' of type 'string' is not assignable to string index type 'number'. + "-Infinity": string; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '"-Infinity"' of type 'string' is not assignable to string index type 'number'. + NaN: string; + ~~~~~~~~~~~~ +!!! error TS2411: Property 'NaN' of type 'string' is not assignable to string index type 'number'. + "-NaN": string; + ~~~~~~~~~~~~~~~ +!!! error TS2411: Property '"-NaN"' of type 'string' is not assignable to string index type 'number'. + 6(): string; + ~~~~~~~~~~~~ +!!! error TS2411: Property '6' of type '() => string' is not assignable to string index type 'number'. + ~~~~~~~~~~~~ +!!! error TS2412: Property '6' of type '() => string' is not assignable to numeric index type 'string'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/propertiesAndIndexers2.js b/tests/baselines/reference/propertiesAndIndexers2.js new file mode 100644 index 00000000000..74485a89248 --- /dev/null +++ b/tests/baselines/reference/propertiesAndIndexers2.js @@ -0,0 +1,19 @@ +//// [propertiesAndIndexers2.ts] +interface A { + [n: number]: string; + [s: string]: number; +} + +// All of these should fail. +interface B extends A { + c: string; + 3: string; + Infinity: string; + "-Infinity": string; + NaN: string; + "-NaN": string; + 6(): string; +} + + +//// [propertiesAndIndexers2.js] diff --git a/tests/baselines/reference/propertiesAndIndexersForNumericNames.errors.txt b/tests/baselines/reference/propertiesAndIndexersForNumericNames.errors.txt new file mode 100644 index 00000000000..01dcb61c70c --- /dev/null +++ b/tests/baselines/reference/propertiesAndIndexersForNumericNames.errors.txt @@ -0,0 +1,69 @@ +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(6,5): error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(7,5): error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(8,5): error TS2412: Property '"-2.5"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(9,5): error TS2412: Property '"3.141592"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(10,5): error TS2412: Property '"1.2e-20"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(11,5): error TS2412: Property '"Infinity"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(12,5): error TS2412: Property '"-Infinity"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(13,5): error TS2412: Property '"NaN"' of type 'string' is not assignable to numeric index type 'number'. + + +==== tests/cases/compiler/propertiesAndIndexersForNumericNames.ts (8 errors) ==== + class C { + [i: number]: number; + + // These all have numeric names; they should error + // because their types are not compatible with the numeric indexer. + public "1": string = "number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'. + public "-1": string = "negative number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'. + public "-2.5": string = "negative number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"-2.5"' of type 'string' is not assignable to numeric index type 'number'. + public "3.141592": string = "pi-sitive number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"3.141592"' of type 'string' is not assignable to numeric index type 'number'. + public "1.2e-20": string = "really small number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"1.2e-20"' of type 'string' is not assignable to numeric index type 'number'. + public "Infinity": string = "A gillion"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"Infinity"' of type 'string' is not assignable to numeric index type 'number'. + public "-Infinity": string = "Negative-a-gillion"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"-Infinity"' of type 'string' is not assignable to numeric index type 'number'. + public "NaN": string = "not a number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"NaN"' of type 'string' is not assignable to numeric index type 'number'. + + // These all have *partially* numeric names, + // but should really be treated as plain string literals. + public " 1": string = "leading space"; // No error + public "1 ": string = "trailing space"; // No error + public "": string = "no nothing"; // No error + public " ": string = "just space"; // No error + public "1 0 1": string = "several numbers and spaces"; // No error + public "hunter2": string = "not a password"; // No error + public "+Infinity": string = "A gillion"; // No error + public "+NaN": string = "not a positive number"; // No error + public "-NaN": string = "not a negative number"; // No error + + + // These fall into the above category, however, they are "trickier"; + // these all are *scanned* as numeric literals, but they are not written in + // "canonical" numeric representations. + public "+1": string = "positive number (for the paranoid)"; // No error + public "1e0": string = "just one"; // No error + public "-0": string = "just zero"; // No error + public "-0e0": string = "just zero"; // No error + public "0xF00D": string = "hex food"; // No error + public "0xBEEF": string = "hex beef"; // No error + public "0123": string = "oct 83"; // No error + public "0o123": string = "explicit oct 83"; // No error + public "0b101101001010": string = "explicit binary"; // No error + public "0.000000000000000000012": string = "should've been in exponential form"; // No error + } + \ No newline at end of file diff --git a/tests/baselines/reference/propertiesAndIndexersForNumericNames.js b/tests/baselines/reference/propertiesAndIndexersForNumericNames.js new file mode 100644 index 00000000000..975abdc00ec --- /dev/null +++ b/tests/baselines/reference/propertiesAndIndexersForNumericNames.js @@ -0,0 +1,84 @@ +//// [propertiesAndIndexersForNumericNames.ts] +class C { + [i: number]: number; + + // These all have numeric names; they should error + // because their types are not compatible with the numeric indexer. + public "1": string = "number"; // Error + public "-1": string = "negative number"; // Error + public "-2.5": string = "negative number"; // Error + public "3.141592": string = "pi-sitive number"; // Error + public "1.2e-20": string = "really small number"; // Error + public "Infinity": string = "A gillion"; // Error + public "-Infinity": string = "Negative-a-gillion"; // Error + public "NaN": string = "not a number"; // Error + + // These all have *partially* numeric names, + // but should really be treated as plain string literals. + public " 1": string = "leading space"; // No error + public "1 ": string = "trailing space"; // No error + public "": string = "no nothing"; // No error + public " ": string = "just space"; // No error + public "1 0 1": string = "several numbers and spaces"; // No error + public "hunter2": string = "not a password"; // No error + public "+Infinity": string = "A gillion"; // No error + public "+NaN": string = "not a positive number"; // No error + public "-NaN": string = "not a negative number"; // No error + + + // These fall into the above category, however, they are "trickier"; + // these all are *scanned* as numeric literals, but they are not written in + // "canonical" numeric representations. + public "+1": string = "positive number (for the paranoid)"; // No error + public "1e0": string = "just one"; // No error + public "-0": string = "just zero"; // No error + public "-0e0": string = "just zero"; // No error + public "0xF00D": string = "hex food"; // No error + public "0xBEEF": string = "hex beef"; // No error + public "0123": string = "oct 83"; // No error + public "0o123": string = "explicit oct 83"; // No error + public "0b101101001010": string = "explicit binary"; // No error + public "0.000000000000000000012": string = "should've been in exponential form"; // No error +} + + +//// [propertiesAndIndexersForNumericNames.js] +var C = (function () { + function C() { + // These all have numeric names; they should error + // because their types are not compatible with the numeric indexer. + this["1"] = "number"; // Error + this["-1"] = "negative number"; // Error + this["-2.5"] = "negative number"; // Error + this["3.141592"] = "pi-sitive number"; // Error + this["1.2e-20"] = "really small number"; // Error + this["Infinity"] = "A gillion"; // Error + this["-Infinity"] = "Negative-a-gillion"; // Error + this["NaN"] = "not a number"; // Error + // These all have *partially* numeric names, + // but should really be treated as plain string literals. + this[" 1"] = "leading space"; // No error + this["1 "] = "trailing space"; // No error + this[""] = "no nothing"; // No error + this[" "] = "just space"; // No error + this["1 0 1"] = "several numbers and spaces"; // No error + this["hunter2"] = "not a password"; // No error + this["+Infinity"] = "A gillion"; // No error + this["+NaN"] = "not a positive number"; // No error + this["-NaN"] = "not a negative number"; // No error + // These fall into the above category, however, they are "trickier"; + // these all are *scanned* as numeric literals, but they are not written in + // "canonical" numeric representations. + this["+1"] = "positive number (for the paranoid)"; // No error + this["1e0"] = "just one"; // No error + this["-0"] = "just zero"; // No error + this["-0e0"] = "just zero"; // No error + this["0xF00D"] = "hex food"; // No error + this["0xBEEF"] = "hex beef"; // No error + this["0123"] = "oct 83"; // No error + this["0o123"] = "explicit oct 83"; // No error + this["0b101101001010"] = "explicit binary"; // No error + this["0.000000000000000000012"] = "should've been in exponential form"; // No error + } + return C; +})(); diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index b71b04263b1..8039cdf01f0 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -24,9 +24,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(71,5): error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(74,5): error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | MyString | { (): void; }; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': Index signatures are incompatible: - Type 'string | number | MyString | { (): void; }' is not assignable to type 'string': + Type 'string | number | MyString | (() => void)' is not assignable to type 'string': Type 'number' is not assignable to type 'string'. @@ -160,9 +160,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [x: string]: string; } = { ~ -!!! error TS2322: Type '{ [x: string]: string | number | MyString | { (): void; }; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': +!!! error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type 'string | number | MyString | { (): void; }' is not assignable to type 'string': +!!! error TS2322: Type 'string | number | MyString | (() => void)' is not assignable to type 'string': !!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, diff --git a/tests/baselines/reference/subtypingWithCallSignatures2.types b/tests/baselines/reference/subtypingWithCallSignatures2.types index 12344a46f3f..a2669bf6e65 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures2.types +++ b/tests/baselines/reference/subtypingWithCallSignatures2.types @@ -330,14 +330,14 @@ var r1 = foo1(r1arg1); // any, return types are not subtype of first overload >r1arg1 : (x: T) => T[] var r1a = [r1arg2, r1arg1]; // generic signature, subtype in both directions ->r1a : { (x: T): T[]; }[] ->[r1arg2, r1arg1] : { (x: T): T[]; }[] +>r1a : ((x: T) => T[])[] +>[r1arg2, r1arg1] : ((x: T) => T[])[] >r1arg2 : (x: number) => number[] >r1arg1 : (x: T) => T[] var r1b = [r1arg1, r1arg2]; // generic signature, subtype in both directions ->r1b : { (x: T): T[]; }[] ->[r1arg1, r1arg2] : { (x: T): T[]; }[] +>r1b : ((x: T) => T[])[] +>[r1arg1, r1arg2] : ((x: T) => T[])[] >r1arg1 : (x: T) => T[] >r1arg2 : (x: number) => number[] @@ -362,14 +362,14 @@ var r2 = foo2(r2arg1); >r2arg1 : (x: T) => string[] var r2a = [r2arg1, r2arg2]; ->r2a : { (x: T): string[]; }[] ->[r2arg1, r2arg2] : { (x: T): string[]; }[] +>r2a : ((x: T) => string[])[] +>[r2arg1, r2arg2] : ((x: T) => string[])[] >r2arg1 : (x: T) => string[] >r2arg2 : (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : { (x: T): string[]; }[] ->[r2arg2, r2arg1] : { (x: T): string[]; }[] +>r2b : ((x: T) => string[])[] +>[r2arg2, r2arg1] : ((x: T) => string[])[] >r2arg2 : (x: number) => string[] >r2arg1 : (x: T) => string[] @@ -393,14 +393,14 @@ var r3 = foo3(r3arg1); >r3arg1 : (x: T) => T var r3a = [r3arg1, r3arg2]; ->r3a : { (x: T): T; }[] ->[r3arg1, r3arg2] : { (x: T): T; }[] +>r3a : ((x: T) => T)[] +>[r3arg1, r3arg2] : ((x: T) => T)[] >r3arg1 : (x: T) => T >r3arg2 : (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : { (x: T): T; }[] ->[r3arg2, r3arg1] : { (x: T): T; }[] +>r3b : ((x: T) => T)[] +>[r3arg2, r3arg1] : ((x: T) => T)[] >r3arg2 : (x: number) => void >r3arg1 : (x: T) => T @@ -428,14 +428,14 @@ var r4 = foo4(r4arg1); // any >r4arg1 : (x: T, y: U) => T var r4a = [r4arg1, r4arg2]; ->r4a : { (x: T, y: U): T; }[] ->[r4arg1, r4arg2] : { (x: T, y: U): T; }[] +>r4a : ((x: T, y: U) => T)[] +>[r4arg1, r4arg2] : ((x: T, y: U) => T)[] >r4arg1 : (x: T, y: U) => T >r4arg2 : (x: string, y: number) => string var r4b = [r4arg2, r4arg1]; ->r4b : { (x: T, y: U): T; }[] ->[r4arg2, r4arg1] : { (x: T, y: U): T; }[] +>r4b : ((x: T, y: U) => T)[] +>[r4arg2, r4arg1] : ((x: T, y: U) => T)[] >r4arg2 : (x: string, y: number) => string >r4arg1 : (x: T, y: U) => T @@ -464,14 +464,14 @@ var r5 = foo5(r5arg1); // any >r5arg1 : (x: (arg: T) => U) => T var r5a = [r5arg1, r5arg2]; ->r5a : { (x: (arg: T) => U): T; }[] ->[r5arg1, r5arg2] : { (x: (arg: T) => U): T; }[] +>r5a : ((x: (arg: T) => U) => T)[] +>[r5arg1, r5arg2] : ((x: (arg: T) => U) => T)[] >r5arg1 : (x: (arg: T) => U) => T >r5arg2 : (x: (arg: string) => number) => string var r5b = [r5arg2, r5arg1]; ->r5b : { (x: (arg: T) => U): T; }[] ->[r5arg2, r5arg1] : { (x: (arg: T) => U): T; }[] +>r5b : ((x: (arg: T) => U) => T)[] +>[r5arg2, r5arg1] : ((x: (arg: T) => U) => T)[] >r5arg2 : (x: (arg: string) => number) => string >r5arg1 : (x: (arg: T) => U) => T @@ -506,14 +506,14 @@ var r6 = foo6(r6arg1); // any >r6arg1 : (x: (arg: T) => U) => T var r6a = [r6arg1, r6arg2]; ->r6a : { (x: (arg: T) => U): T; }[] ->[r6arg1, r6arg2] : { (x: (arg: T) => U): T; }[] +>r6a : ((x: (arg: T) => U) => T)[] +>[r6arg1, r6arg2] : ((x: (arg: T) => U) => T)[] >r6arg1 : (x: (arg: T) => U) => T >r6arg2 : (x: (arg: Base) => Derived) => Base var r6b = [r6arg2, r6arg1]; ->r6b : { (x: (arg: T) => U): T; }[] ->[r6arg2, r6arg1] : { (x: (arg: T) => U): T; }[] +>r6b : ((x: (arg: T) => U) => T)[] +>[r6arg2, r6arg1] : ((x: (arg: T) => U) => T)[] >r6arg2 : (x: (arg: Base) => Derived) => Base >r6arg1 : (x: (arg: T) => U) => T @@ -554,14 +554,14 @@ var r7 = foo7(r7arg1); // any >r7arg1 : (x: (arg: T) => U) => (r: T) => U var r7a = [r7arg1, r7arg2]; ->r7a : { (x: (arg: T) => U): (r: T) => U; }[] ->[r7arg1, r7arg2] : { (x: (arg: T) => U): (r: T) => U; }[] +>r7a : ((x: (arg: T) => U) => (r: T) => U)[] +>[r7arg1, r7arg2] : ((x: (arg: T) => U) => (r: T) => U)[] >r7arg1 : (x: (arg: T) => U) => (r: T) => U >r7arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived var r7b = [r7arg2, r7arg1]; ->r7b : { (x: (arg: T) => U): (r: T) => U; }[] ->[r7arg2, r7arg1] : { (x: (arg: T) => U): (r: T) => U; }[] +>r7b : ((x: (arg: T) => U) => (r: T) => U)[] +>[r7arg2, r7arg1] : ((x: (arg: T) => U) => (r: T) => U)[] >r7arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived >r7arg1 : (x: (arg: T) => U) => (r: T) => U @@ -610,14 +610,14 @@ var r8 = foo8(r8arg1); // any >r8arg1 : (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U var r8a = [r8arg1, r8arg2]; ->r8a : { (x: (arg: T) => U, y: (arg2: T) => U): (r: T) => U; }[] ->[r8arg1, r8arg2] : { (x: (arg: T) => U, y: (arg2: T) => U): (r: T) => U; }[] +>r8a : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] +>[r8arg1, r8arg2] : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] >r8arg1 : (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U >r8arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived var r8b = [r8arg2, r8arg1]; ->r8b : { (x: (arg: T) => U, y: (arg2: T) => U): (r: T) => U; }[] ->[r8arg2, r8arg1] : { (x: (arg: T) => U, y: (arg2: T) => U): (r: T) => U; }[] +>r8b : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] +>[r8arg2, r8arg1] : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] >r8arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r8arg1 : (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U @@ -667,14 +667,14 @@ var r9 = foo9(r9arg1); // any >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U var r9a = [r9arg1, r9arg2]; ->r9a : { (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): (r: T) => U; }[] ->[r9arg1, r9arg2] : { (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): (r: T) => U; }[] +>r9a : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] +>[r9arg1, r9arg2] : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U >r9arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived var r9b = [r9arg2, r9arg1]; ->r9b : { (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): (r: T) => U; }[] ->[r9arg2, r9arg1] : { (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): (r: T) => U; }[] +>r9b : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] +>[r9arg2, r9arg1] : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] >r9arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U @@ -703,14 +703,14 @@ var r10 = foo10(r10arg1); // any >r10arg1 : (...x: T[]) => T var r10a = [r10arg1, r10arg2]; ->r10a : { (...x: T[]): T; }[] ->[r10arg1, r10arg2] : { (...x: T[]): T; }[] +>r10a : ((...x: T[]) => T)[] +>[r10arg1, r10arg2] : ((...x: T[]) => T)[] >r10arg1 : (...x: T[]) => T >r10arg2 : (...x: Derived[]) => Derived var r10b = [r10arg2, r10arg1]; ->r10b : { (...x: T[]): T; }[] ->[r10arg2, r10arg1] : { (...x: T[]): T; }[] +>r10b : ((...x: T[]) => T)[] +>[r10arg2, r10arg1] : ((...x: T[]) => T)[] >r10arg2 : (...x: Derived[]) => Derived >r10arg1 : (...x: T[]) => T @@ -743,14 +743,14 @@ var r11 = foo11(r11arg1); // any >r11arg1 : (x: T, y: T) => T var r11a = [r11arg1, r11arg2]; ->r11a : { (x: T, y: T): T; }[] ->[r11arg1, r11arg2] : { (x: T, y: T): T; }[] +>r11a : ((x: T, y: T) => T)[] +>[r11arg1, r11arg2] : ((x: T, y: T) => T)[] >r11arg1 : (x: T, y: T) => T >r11arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base var r11b = [r11arg2, r11arg1]; ->r11b : { (x: T, y: T): T; }[] ->[r11arg2, r11arg1] : { (x: T, y: T): T; }[] +>r11b : ((x: T, y: T) => T)[] +>[r11arg2, r11arg1] : ((x: T, y: T) => T)[] >r11arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r11arg1 : (x: T, y: T) => T @@ -789,14 +789,14 @@ var r12 = foo12(r12arg1); // any >r12arg1 : (x: Base[], y: T) => Derived[] var r12a = [r12arg1, r12arg2]; ->r12a : { (x: Base[], y: T): Derived[]; }[] ->[r12arg1, r12arg2] : { (x: Base[], y: T): Derived[]; }[] +>r12a : ((x: Base[], y: T) => Derived[])[] +>[r12arg1, r12arg2] : ((x: Base[], y: T) => Derived[])[] >r12arg1 : (x: Base[], y: T) => Derived[] >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : { (x: Base[], y: T): Derived[]; }[] ->[r12arg2, r12arg1] : { (x: Base[], y: T): Derived[]; }[] +>r12b : ((x: Base[], y: T) => Derived[])[] +>[r12arg2, r12arg1] : ((x: Base[], y: T) => Derived[])[] >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : (x: Base[], y: T) => Derived[] @@ -833,14 +833,14 @@ var r13 = foo13(r13arg1); // any >r13arg1 : (x: Base[], y: T) => T var r13a = [r13arg1, r13arg2]; ->r13a : { (x: Base[], y: T): T; }[] ->[r13arg1, r13arg2] : { (x: Base[], y: T): T; }[] +>r13a : ((x: Base[], y: T) => T)[] +>[r13arg1, r13arg2] : ((x: Base[], y: T) => T)[] >r13arg1 : (x: Base[], y: T) => T >r13arg2 : (x: Base[], y: Derived[]) => Derived[] var r13b = [r13arg2, r13arg1]; ->r13b : { (x: Base[], y: T): T; }[] ->[r13arg2, r13arg1] : { (x: Base[], y: T): T; }[] +>r13b : ((x: Base[], y: T) => T)[] +>[r13arg2, r13arg1] : ((x: Base[], y: T) => T)[] >r13arg2 : (x: Base[], y: Derived[]) => Derived[] >r13arg1 : (x: Base[], y: T) => T @@ -873,14 +873,14 @@ var r14 = foo14(r14arg1); // any >r14arg1 : (x: { a: T; b: T; }) => T var r14a = [r14arg1, r14arg2]; ->r14a : { (x: { a: T; b: T; }): T; }[] ->[r14arg1, r14arg2] : { (x: { a: T; b: T; }): T; }[] +>r14a : ((x: { a: T; b: T; }) => T)[] +>[r14arg1, r14arg2] : ((x: { a: T; b: T; }) => T)[] >r14arg1 : (x: { a: T; b: T; }) => T >r14arg2 : (x: { a: string; b: number; }) => Object var r14b = [r14arg2, r14arg1]; ->r14b : { (x: { a: T; b: T; }): T; }[] ->[r14arg2, r14arg1] : { (x: { a: T; b: T; }): T; }[] +>r14b : ((x: { a: T; b: T; }) => T)[] +>[r14arg2, r14arg1] : ((x: { a: T; b: T; }) => T)[] >r14arg2 : (x: { a: string; b: number; }) => Object >r14arg1 : (x: { a: T; b: T; }) => T diff --git a/tests/baselines/reference/subtypingWithCallSignatures3.types b/tests/baselines/reference/subtypingWithCallSignatures3.types index be5fb44c9c7..cc2d47d3a33 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures3.types +++ b/tests/baselines/reference/subtypingWithCallSignatures3.types @@ -218,8 +218,8 @@ module Errors { >U : U var r1a = [(x: number) => [''], (x: T) => null]; ->r1a : { (x: T): U[]; }[] ->[(x: number) => [''], (x: T) => null] : { (x: T): U[]; }[] +>r1a : ((x: T) => U[])[] +>[(x: number) => [''], (x: T) => null] : ((x: T) => U[])[] >(x: number) => [''] : (x: number) => string[] >x : number >[''] : string[] @@ -232,8 +232,8 @@ module Errors { >U : U var r1b = [(x: T) => null, (x: number) => ['']]; ->r1b : { (x: T): U[]; }[] ->[(x: T) => null, (x: number) => ['']] : { (x: T): U[]; }[] +>r1b : ((x: T) => U[])[] +>[(x: T) => null, (x: number) => ['']] : ((x: T) => U[])[] >(x: T) => null : (x: T) => U[] >T : T >U : U @@ -284,14 +284,14 @@ module Errors { >r2arg : (x: (arg: T) => U) => (r: T) => V var r2a = [r2arg2, r2arg]; ->r2a : { (x: (arg: T) => U): (r: T) => V; }[] ->[r2arg2, r2arg] : { (x: (arg: T) => U): (r: T) => V; }[] +>r2a : ((x: (arg: T) => U) => (r: T) => V)[] +>[r2arg2, r2arg] : ((x: (arg: T) => U) => (r: T) => V)[] >r2arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived2 >r2arg : (x: (arg: T) => U) => (r: T) => V var r2b = [r2arg, r2arg2]; ->r2b : { (x: (arg: T) => U): (r: T) => V; }[] ->[r2arg, r2arg2] : { (x: (arg: T) => U): (r: T) => V; }[] +>r2b : ((x: (arg: T) => U) => (r: T) => V)[] +>[r2arg, r2arg2] : ((x: (arg: T) => U) => (r: T) => V)[] >r2arg : (x: (arg: T) => U) => (r: T) => V >r2arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived2 @@ -340,14 +340,14 @@ module Errors { >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U var r3a = [r3arg2, r3arg]; ->r3a : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> ->[r3arg2, r3arg] : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> +>r3a : (((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] +>[r3arg2, r3arg] : (((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] >r3arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U var r3b = [r3arg, r3arg2]; ->r3b : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> ->[r3arg, r3arg2] : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> +>r3b : (((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] +>[r3arg, r3arg2] : (((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U >r3arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived @@ -376,14 +376,14 @@ module Errors { >r4arg : (...x: T[]) => T var r4a = [r4arg2, r4arg]; ->r4a : { (...x: T[]): T; }[] ->[r4arg2, r4arg] : { (...x: T[]): T; }[] +>r4a : ((...x: T[]) => T)[] +>[r4arg2, r4arg] : ((...x: T[]) => T)[] >r4arg2 : (...x: Base[]) => Base >r4arg : (...x: T[]) => T var r4b = [r4arg, r4arg2]; ->r4b : { (...x: T[]): T; }[] ->[r4arg, r4arg2] : { (...x: T[]): T; }[] +>r4b : ((...x: T[]) => T)[] +>[r4arg, r4arg2] : ((...x: T[]) => T)[] >r4arg : (...x: T[]) => T >r4arg2 : (...x: Base[]) => Base @@ -417,14 +417,14 @@ module Errors { >r5arg : (x: T, y: T) => T var r5a = [r5arg2, r5arg]; ->r5a : { (x: T, y: T): T; }[] ->[r5arg2, r5arg] : { (x: T, y: T): T; }[] +>r5a : ((x: T, y: T) => T)[] +>[r5arg2, r5arg] : ((x: T, y: T) => T)[] >r5arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r5arg : (x: T, y: T) => T var r5b = [r5arg, r5arg2]; ->r5b : { (x: T, y: T): T; }[] ->[r5arg, r5arg2] : { (x: T, y: T): T; }[] +>r5b : ((x: T, y: T) => T)[] +>[r5arg, r5arg2] : ((x: T, y: T) => T)[] >r5arg : (x: T, y: T) => T >r5arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base @@ -463,14 +463,14 @@ module Errors { >r6arg : (x: Base[], y: Derived2[]) => Derived[] var r6a = [r6arg2, r6arg]; ->r6a : { (x: Base[], y: Base[]): T; }[] ->[r6arg2, r6arg] : { (x: Base[], y: Base[]): T; }[] +>r6a : ((x: Base[], y: Base[]) => T)[] +>[r6arg2, r6arg] : ((x: Base[], y: Base[]) => T)[] >r6arg2 : (x: Base[], y: Base[]) => T >r6arg : (x: Base[], y: Derived2[]) => Derived[] var r6b = [r6arg, r6arg2]; ->r6b : { (x: Base[], y: Base[]): T; }[] ->[r6arg, r6arg2] : { (x: Base[], y: Base[]): T; }[] +>r6b : ((x: Base[], y: Base[]) => T)[] +>[r6arg, r6arg2] : ((x: Base[], y: Base[]) => T)[] >r6arg : (x: Base[], y: Derived2[]) => Derived[] >r6arg2 : (x: Base[], y: Base[]) => T @@ -500,14 +500,14 @@ module Errors { >r7arg : (x: { a: T; b: T; }) => T var r7a = [r7arg2, r7arg]; ->r7a : { (x: { a: T; b: T; }): T; }[] ->[r7arg2, r7arg] : { (x: { a: T; b: T; }): T; }[] +>r7a : ((x: { a: T; b: T; }) => T)[] +>[r7arg2, r7arg] : ((x: { a: T; b: T; }) => T)[] >r7arg2 : (x: { a: string; b: number; }) => number >r7arg : (x: { a: T; b: T; }) => T var r7b = [r7arg, r7arg2]; ->r7b : { (x: { a: T; b: T; }): T; }[] ->[r7arg, r7arg2] : { (x: { a: T; b: T; }): T; }[] +>r7b : ((x: { a: T; b: T; }) => T)[] +>[r7arg, r7arg2] : ((x: { a: T; b: T; }) => T)[] >r7arg : (x: { a: T; b: T; }) => T >r7arg2 : (x: { a: string; b: number; }) => number @@ -529,14 +529,14 @@ module Errors { >r7arg3 : (x: { a: T; b: T; }) => number var r7d = [r7arg2, r7arg3]; ->r7d : { (x: { a: string; b: number; }): number; }[] ->[r7arg2, r7arg3] : { (x: { a: string; b: number; }): number; }[] +>r7d : ((x: { a: string; b: number; }) => number)[] +>[r7arg2, r7arg3] : ((x: { a: string; b: number; }) => number)[] >r7arg2 : (x: { a: string; b: number; }) => number >r7arg3 : (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : { (x: { a: string; b: number; }): number; }[] ->[r7arg3, r7arg2] : { (x: { a: string; b: number; }): number; }[] +>r7e : ((x: { a: string; b: number; }) => number)[] +>[r7arg3, r7arg2] : ((x: { a: string; b: number; }) => number)[] >r7arg3 : (x: { a: T; b: T; }) => number >r7arg2 : (x: { a: string; b: number; }) => number diff --git a/tests/baselines/reference/subtypingWithCallSignatures4.types b/tests/baselines/reference/subtypingWithCallSignatures4.types index f31a4fa928e..0325552187b 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures4.types +++ b/tests/baselines/reference/subtypingWithCallSignatures4.types @@ -244,14 +244,14 @@ var r1 = foo1(r1arg); >r1arg : (x: T) => T[] var r1a = [r1arg, r1arg2]; ->r1a : { (x: T): T[]; }[] ->[r1arg, r1arg2] : { (x: T): T[]; }[] +>r1a : ((x: T) => T[])[] +>[r1arg, r1arg2] : ((x: T) => T[])[] >r1arg : (x: T) => T[] >r1arg2 : (x: T) => T[] var r1b = [r1arg2, r1arg]; ->r1b : { (x: T): T[]; }[] ->[r1arg2, r1arg] : { (x: T): T[]; }[] +>r1b : ((x: T) => T[])[] +>[r1arg2, r1arg] : ((x: T) => T[])[] >r1arg2 : (x: T) => T[] >r1arg : (x: T) => T[] @@ -278,14 +278,14 @@ var r2 = foo2(r2arg); >r2arg : (x: T) => string[] var r2a = [r2arg, r2arg2]; ->r2a : { (x: T): string[]; }[] ->[r2arg, r2arg2] : { (x: T): string[]; }[] +>r2a : ((x: T) => string[])[] +>[r2arg, r2arg2] : ((x: T) => string[])[] >r2arg : (x: T) => string[] >r2arg2 : (x: T) => string[] var r2b = [r2arg2, r2arg]; ->r2b : { (x: T): string[]; }[] ->[r2arg2, r2arg] : { (x: T): string[]; }[] +>r2b : ((x: T) => string[])[] +>[r2arg2, r2arg] : ((x: T) => string[])[] >r2arg2 : (x: T) => string[] >r2arg : (x: T) => string[] @@ -312,14 +312,14 @@ var r3 = foo3(r3arg); >r3arg : (x: T) => T var r3a = [r3arg, r3arg2]; ->r3a : { (x: T): T; }[] ->[r3arg, r3arg2] : { (x: T): T; }[] +>r3a : ((x: T) => T)[] +>[r3arg, r3arg2] : ((x: T) => T)[] >r3arg : (x: T) => T >r3arg2 : (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : { (x: T): T; }[] ->[r3arg2, r3arg] : { (x: T): T; }[] +>r3b : ((x: T) => T)[] +>[r3arg2, r3arg] : ((x: T) => T)[] >r3arg2 : (x: T) => void >r3arg : (x: T) => T @@ -350,14 +350,14 @@ var r4 = foo4(r4arg); >r4arg : (x: T, y: U) => string var r4a = [r4arg, r4arg2]; ->r4a : { (x: T, y: U): string; }[] ->[r4arg, r4arg2] : { (x: T, y: U): string; }[] +>r4a : ((x: T, y: U) => string)[] +>[r4arg, r4arg2] : ((x: T, y: U) => string)[] >r4arg : (x: T, y: U) => string >r4arg2 : (x: T, y: U) => string var r4b = [r4arg2, r4arg]; ->r4b : { (x: T, y: U): string; }[] ->[r4arg2, r4arg] : { (x: T, y: U): string; }[] +>r4b : ((x: T, y: U) => string)[] +>[r4arg2, r4arg] : ((x: T, y: U) => string)[] >r4arg2 : (x: T, y: U) => string >r4arg : (x: T, y: U) => string @@ -392,14 +392,14 @@ var r5 = foo5(r5arg); >r5arg : (x: (arg: T) => U) => T var r5a = [r5arg, r5arg2]; ->r5a : { (x: (arg: T) => U): T; }[] ->[r5arg, r5arg2] : { (x: (arg: T) => U): T; }[] +>r5a : ((x: (arg: T) => U) => T)[] +>[r5arg, r5arg2] : ((x: (arg: T) => U) => T)[] >r5arg : (x: (arg: T) => U) => T >r5arg2 : (x: (arg: T) => U) => T var r5b = [r5arg2, r5arg]; ->r5b : { (x: (arg: T) => U): T; }[] ->[r5arg2, r5arg] : { (x: (arg: T) => U): T; }[] +>r5b : ((x: (arg: T) => U) => T)[] +>[r5arg2, r5arg] : ((x: (arg: T) => U) => T)[] >r5arg2 : (x: (arg: T) => U) => T >r5arg : (x: (arg: T) => U) => T @@ -436,14 +436,14 @@ var r6 = foo6(r6arg); >r6arg : (x: (arg: T) => U) => T var r6a = [r6arg, r6arg2]; ->r6a : { (x: (arg: T) => U): T; }[] ->[r6arg, r6arg2] : { (x: (arg: T) => U): T; }[] +>r6a : ((x: (arg: T) => U) => T)[] +>[r6arg, r6arg2] : ((x: (arg: T) => U) => T)[] >r6arg : (x: (arg: T) => U) => T >r6arg2 : (x: (arg: T) => Derived) => T var r6b = [r6arg2, r6arg]; ->r6b : { (x: (arg: T) => U): T; }[] ->[r6arg2, r6arg] : { (x: (arg: T) => U): T; }[] +>r6b : ((x: (arg: T) => U) => T)[] +>[r6arg2, r6arg] : ((x: (arg: T) => U) => T)[] >r6arg2 : (x: (arg: T) => Derived) => T >r6arg : (x: (arg: T) => U) => T @@ -485,14 +485,14 @@ var r11 = foo11(r11arg); >r11arg : (x: { foo: T; }, y: { foo: U; bar: U; }) => Base var r11a = [r11arg, r11arg2]; ->r11a : { (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] ->[r11arg, r11arg2] : { (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] +>r11a : ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>[r11arg, r11arg2] : ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] >r11arg : (x: { foo: T; }, y: { foo: U; bar: U; }) => Base >r11arg2 : (x: { foo: T; }, y: { foo: T; bar: T; }) => Base var r11b = [r11arg2, r11arg]; ->r11b : { (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] ->[r11arg2, r11arg] : { (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] +>r11b : ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>[r11arg2, r11arg] : ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] >r11arg2 : (x: { foo: T; }, y: { foo: T; bar: T; }) => Base >r11arg : (x: { foo: T; }, y: { foo: U; bar: U; }) => Base @@ -528,14 +528,14 @@ var r15 = foo15(r15arg); >r15arg : (x: { a: U; b: V; }) => U[] var r15a = [r15arg, r15arg2]; ->r15a : { (x: { a: U; b: V; }): U[]; }[] ->[r15arg, r15arg2] : { (x: { a: U; b: V; }): U[]; }[] +>r15a : ((x: { a: U; b: V; }) => U[])[] +>[r15arg, r15arg2] : ((x: { a: U; b: V; }) => U[])[] >r15arg : (x: { a: U; b: V; }) => U[] >r15arg2 : (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : { (x: { a: U; b: V; }): U[]; }[] ->[r15arg2, r15arg] : { (x: { a: U; b: V; }): U[]; }[] +>r15b : ((x: { a: U; b: V; }) => U[])[] +>[r15arg2, r15arg] : ((x: { a: U; b: V; }) => U[])[] >r15arg2 : (x: { a: T; b: T; }) => T[] >r15arg : (x: { a: U; b: V; }) => U[] @@ -572,14 +572,14 @@ var r16 = foo16(r16arg); >r16arg : (x: { a: T; b: T; }) => T[] var r16a = [r16arg, r16arg2]; ->r16a : { (x: { a: T; b: T; }): T[]; }[] ->[r16arg, r16arg2] : { (x: { a: T; b: T; }): T[]; }[] +>r16a : ((x: { a: T; b: T; }) => T[])[] +>[r16arg, r16arg2] : ((x: { a: T; b: T; }) => T[])[] >r16arg : (x: { a: T; b: T; }) => T[] >r16arg2 : (x: { a: T; b: T; }) => T[] var r16b = [r16arg2, r16arg]; ->r16b : { (x: { a: T; b: T; }): T[]; }[] ->[r16arg2, r16arg] : { (x: { a: T; b: T; }): T[]; }[] +>r16b : ((x: { a: T; b: T; }) => T[])[] +>[r16arg2, r16arg] : ((x: { a: T; b: T; }) => T[])[] >r16arg2 : (x: { a: T; b: T; }) => T[] >r16arg : (x: { a: T; b: T; }) => T[] diff --git a/tests/baselines/reference/subtypingWithConstructSignatures2.types b/tests/baselines/reference/subtypingWithConstructSignatures2.types index 3832697d04c..d723a367ecb 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures2.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures2.types @@ -326,14 +326,14 @@ var r1 = foo1(r1arg1); // any, return types are not subtype of first overload >r1arg1 : new (x: T) => T[] var r1a = [r1arg2, r1arg1]; // generic signature, subtype in both directions ->r1a : { new (x: T): T[]; }[] ->[r1arg2, r1arg1] : { new (x: T): T[]; }[] +>r1a : (new (x: T) => T[])[] +>[r1arg2, r1arg1] : (new (x: T) => T[])[] >r1arg2 : new (x: number) => number[] >r1arg1 : new (x: T) => T[] var r1b = [r1arg1, r1arg2]; // generic signature, subtype in both directions ->r1b : { new (x: T): T[]; }[] ->[r1arg1, r1arg2] : { new (x: T): T[]; }[] +>r1b : (new (x: T) => T[])[] +>[r1arg1, r1arg2] : (new (x: T) => T[])[] >r1arg1 : new (x: T) => T[] >r1arg2 : new (x: number) => number[] @@ -354,14 +354,14 @@ var r2 = foo2(r2arg1); >r2arg1 : new (x: T) => string[] var r2a = [r2arg1, r2arg2]; ->r2a : { new (x: T): string[]; }[] ->[r2arg1, r2arg2] : { new (x: T): string[]; }[] +>r2a : (new (x: T) => string[])[] +>[r2arg1, r2arg2] : (new (x: T) => string[])[] >r2arg1 : new (x: T) => string[] >r2arg2 : new (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : { new (x: T): string[]; }[] ->[r2arg2, r2arg1] : { new (x: T): string[]; }[] +>r2b : (new (x: T) => string[])[] +>[r2arg2, r2arg1] : (new (x: T) => string[])[] >r2arg2 : new (x: number) => string[] >r2arg1 : new (x: T) => string[] @@ -383,14 +383,14 @@ var r3 = foo3(r3arg1); >r3arg1 : new (x: T) => T var r3a = [r3arg1, r3arg2]; ->r3a : { new (x: T): T; }[] ->[r3arg1, r3arg2] : { new (x: T): T; }[] +>r3a : (new (x: T) => T)[] +>[r3arg1, r3arg2] : (new (x: T) => T)[] >r3arg1 : new (x: T) => T >r3arg2 : new (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : { new (x: T): T; }[] ->[r3arg2, r3arg1] : { new (x: T): T; }[] +>r3b : (new (x: T) => T)[] +>[r3arg2, r3arg1] : (new (x: T) => T)[] >r3arg2 : new (x: number) => void >r3arg1 : new (x: T) => T @@ -416,14 +416,14 @@ var r4 = foo4(r4arg1); // any >r4arg1 : new (x: T, y: U) => T var r4a = [r4arg1, r4arg2]; ->r4a : { new (x: T, y: U): T; }[] ->[r4arg1, r4arg2] : { new (x: T, y: U): T; }[] +>r4a : (new (x: T, y: U) => T)[] +>[r4arg1, r4arg2] : (new (x: T, y: U) => T)[] >r4arg1 : new (x: T, y: U) => T >r4arg2 : new (x: string, y: number) => string var r4b = [r4arg2, r4arg1]; ->r4b : { new (x: T, y: U): T; }[] ->[r4arg2, r4arg1] : { new (x: T, y: U): T; }[] +>r4b : (new (x: T, y: U) => T)[] +>[r4arg2, r4arg1] : (new (x: T, y: U) => T)[] >r4arg2 : new (x: string, y: number) => string >r4arg1 : new (x: T, y: U) => T @@ -449,14 +449,14 @@ var r5 = foo5(r5arg1); // any >r5arg1 : new (x: new (arg: T) => U) => T var r5a = [r5arg1, r5arg2]; ->r5a : { new (x: new (arg: T) => U): T; }[] ->[r5arg1, r5arg2] : { new (x: new (arg: T) => U): T; }[] +>r5a : (new (x: new (arg: T) => U) => T)[] +>[r5arg1, r5arg2] : (new (x: new (arg: T) => U) => T)[] >r5arg1 : new (x: new (arg: T) => U) => T >r5arg2 : new (x: new (arg: string) => number) => string var r5b = [r5arg2, r5arg1]; ->r5b : { new (x: new (arg: T) => U): T; }[] ->[r5arg2, r5arg1] : { new (x: new (arg: T) => U): T; }[] +>r5b : (new (x: new (arg: T) => U) => T)[] +>[r5arg2, r5arg1] : (new (x: new (arg: T) => U) => T)[] >r5arg2 : new (x: new (arg: string) => number) => string >r5arg1 : new (x: new (arg: T) => U) => T @@ -487,14 +487,14 @@ var r6 = foo6(r6arg1); // any >r6arg1 : new (x: new (arg: T) => U) => T var r6a = [r6arg1, r6arg2]; ->r6a : { new (x: new (arg: T) => U): T; }[] ->[r6arg1, r6arg2] : { new (x: new (arg: T) => U): T; }[] +>r6a : (new (x: new (arg: T) => U) => T)[] +>[r6arg1, r6arg2] : (new (x: new (arg: T) => U) => T)[] >r6arg1 : new (x: new (arg: T) => U) => T >r6arg2 : new (x: new (arg: Base) => Derived) => Base var r6b = [r6arg2, r6arg1]; ->r6b : { new (x: new (arg: T) => U): T; }[] ->[r6arg2, r6arg1] : { new (x: new (arg: T) => U): T; }[] +>r6b : (new (x: new (arg: T) => U) => T)[] +>[r6arg2, r6arg1] : (new (x: new (arg: T) => U) => T)[] >r6arg2 : new (x: new (arg: Base) => Derived) => Base >r6arg1 : new (x: new (arg: T) => U) => T @@ -529,14 +529,14 @@ var r7 = foo7(r7arg1); // any >r7arg1 : new (x: new (arg: T) => U) => new (r: T) => U var r7a = [r7arg1, r7arg2]; ->r7a : { new (x: new (arg: T) => U): new (r: T) => U; }[] ->[r7arg1, r7arg2] : { new (x: new (arg: T) => U): new (r: T) => U; }[] +>r7a : (new (x: new (arg: T) => U) => new (r: T) => U)[] +>[r7arg1, r7arg2] : (new (x: new (arg: T) => U) => new (r: T) => U)[] >r7arg1 : new (x: new (arg: T) => U) => new (r: T) => U >r7arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived var r7b = [r7arg2, r7arg1]; ->r7b : { new (x: new (arg: T) => U): new (r: T) => U; }[] ->[r7arg2, r7arg1] : { new (x: new (arg: T) => U): new (r: T) => U; }[] +>r7b : (new (x: new (arg: T) => U) => new (r: T) => U)[] +>[r7arg2, r7arg1] : (new (x: new (arg: T) => U) => new (r: T) => U)[] >r7arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived >r7arg1 : new (x: new (arg: T) => U) => new (r: T) => U @@ -579,14 +579,14 @@ var r8 = foo8(r8arg1); // any >r8arg1 : new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U var r8a = [r8arg1, r8arg2]; ->r8a : { new (x: new (arg: T) => U, y: new (arg2: T) => U): new (r: T) => U; }[] ->[r8arg1, r8arg2] : { new (x: new (arg: T) => U, y: new (arg2: T) => U): new (r: T) => U; }[] +>r8a : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] +>[r8arg1, r8arg2] : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] >r8arg1 : new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U >r8arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived var r8b = [r8arg2, r8arg1]; ->r8b : { new (x: new (arg: T) => U, y: new (arg2: T) => U): new (r: T) => U; }[] ->[r8arg2, r8arg1] : { new (x: new (arg: T) => U, y: new (arg2: T) => U): new (r: T) => U; }[] +>r8b : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] +>[r8arg2, r8arg1] : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] >r8arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r8arg1 : new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U @@ -630,14 +630,14 @@ var r9 = foo9(r9arg1); // any >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U var r9a = [r9arg1, r9arg2]; ->r9a : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> ->[r9arg1, r9arg2] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>r9a : ((new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U) | (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] +>[r9arg1, r9arg2] : ((new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U) | (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U >r9arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived var r9b = [r9arg2, r9arg1]; ->r9b : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> ->[r9arg2, r9arg1] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>r9b : ((new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U) | (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] +>[r9arg2, r9arg1] : ((new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U) | (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] >r9arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U @@ -662,14 +662,14 @@ var r10 = foo10(r10arg1); // any >r10arg1 : new (...x: T[]) => T var r10a = [r10arg1, r10arg2]; ->r10a : { new (...x: T[]): T; }[] ->[r10arg1, r10arg2] : { new (...x: T[]): T; }[] +>r10a : (new (...x: T[]) => T)[] +>[r10arg1, r10arg2] : (new (...x: T[]) => T)[] >r10arg1 : new (...x: T[]) => T >r10arg2 : new (...x: Derived[]) => Derived var r10b = [r10arg2, r10arg1]; ->r10b : { new (...x: T[]): T; }[] ->[r10arg2, r10arg1] : { new (...x: T[]): T; }[] +>r10b : (new (...x: T[]) => T)[] +>[r10arg2, r10arg1] : (new (...x: T[]) => T)[] >r10arg2 : new (...x: Derived[]) => Derived >r10arg1 : new (...x: T[]) => T @@ -699,14 +699,14 @@ var r11 = foo11(r11arg1); // any >r11arg1 : new (x: T, y: T) => T var r11a = [r11arg1, r11arg2]; ->r11a : { new (x: T, y: T): T; }[] ->[r11arg1, r11arg2] : { new (x: T, y: T): T; }[] +>r11a : (new (x: T, y: T) => T)[] +>[r11arg1, r11arg2] : (new (x: T, y: T) => T)[] >r11arg1 : new (x: T, y: T) => T >r11arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base var r11b = [r11arg2, r11arg1]; ->r11b : { new (x: T, y: T): T; }[] ->[r11arg2, r11arg1] : { new (x: T, y: T): T; }[] +>r11b : (new (x: T, y: T) => T)[] +>[r11arg2, r11arg1] : (new (x: T, y: T) => T)[] >r11arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r11arg1 : new (x: T, y: T) => T @@ -741,14 +741,14 @@ var r12 = foo12(r12arg1); // any >r12arg1 : new (x: Base[], y: T) => Derived[] var r12a = [r12arg1, r12arg2]; ->r12a : { new (x: Base[], y: T): Derived[]; }[] ->[r12arg1, r12arg2] : { new (x: Base[], y: T): Derived[]; }[] +>r12a : (new (x: Base[], y: T) => Derived[])[] +>[r12arg1, r12arg2] : (new (x: Base[], y: T) => Derived[])[] >r12arg1 : new (x: Base[], y: T) => Derived[] >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : { new (x: Base[], y: T): Derived[]; }[] ->[r12arg2, r12arg1] : { new (x: Base[], y: T): Derived[]; }[] +>r12b : (new (x: Base[], y: T) => Derived[])[] +>[r12arg2, r12arg1] : (new (x: Base[], y: T) => Derived[])[] >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : new (x: Base[], y: T) => Derived[] @@ -782,14 +782,14 @@ var r13 = foo13(r13arg1); // any >r13arg1 : new (x: Base[], y: T) => T var r13a = [r13arg1, r13arg2]; ->r13a : { new (x: Base[], y: T): T; }[] ->[r13arg1, r13arg2] : { new (x: Base[], y: T): T; }[] +>r13a : (new (x: Base[], y: T) => T)[] +>[r13arg1, r13arg2] : (new (x: Base[], y: T) => T)[] >r13arg1 : new (x: Base[], y: T) => T >r13arg2 : new (x: Base[], y: Derived[]) => Derived[] var r13b = [r13arg2, r13arg1]; ->r13b : { new (x: Base[], y: T): T; }[] ->[r13arg2, r13arg1] : { new (x: Base[], y: T): T; }[] +>r13b : (new (x: Base[], y: T) => T)[] +>[r13arg2, r13arg1] : (new (x: Base[], y: T) => T)[] >r13arg2 : new (x: Base[], y: Derived[]) => Derived[] >r13arg1 : new (x: Base[], y: T) => T @@ -817,14 +817,14 @@ var r14 = foo14(r14arg1); // any >r14arg1 : new (x: { a: T; b: T; }) => T var r14a = [r14arg1, r14arg2]; ->r14a : { new (x: { a: T; b: T; }): T; }[] ->[r14arg1, r14arg2] : { new (x: { a: T; b: T; }): T; }[] +>r14a : (new (x: { a: T; b: T; }) => T)[] +>[r14arg1, r14arg2] : (new (x: { a: T; b: T; }) => T)[] >r14arg1 : new (x: { a: T; b: T; }) => T >r14arg2 : new (x: { a: string; b: number; }) => Object var r14b = [r14arg2, r14arg1]; ->r14b : { new (x: { a: T; b: T; }): T; }[] ->[r14arg2, r14arg1] : { new (x: { a: T; b: T; }): T; }[] +>r14b : (new (x: { a: T; b: T; }) => T)[] +>[r14arg2, r14arg1] : (new (x: { a: T; b: T; }) => T)[] >r14arg2 : new (x: { a: string; b: number; }) => Object >r14arg1 : new (x: { a: T; b: T; }) => T diff --git a/tests/baselines/reference/subtypingWithConstructSignatures3.types b/tests/baselines/reference/subtypingWithConstructSignatures3.types index ff6b9adef0a..b0f0680c7a0 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures3.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures3.types @@ -224,14 +224,14 @@ module Errors { >r1arg1 : new (x: T) => U[] var r1a = [r1arg2, r1arg1]; ->r1a : { new (x: T): U[]; }[] ->[r1arg2, r1arg1] : { new (x: T): U[]; }[] +>r1a : (new (x: T) => U[])[] +>[r1arg2, r1arg1] : (new (x: T) => U[])[] >r1arg2 : new (x: number) => string[] >r1arg1 : new (x: T) => U[] var r1b = [r1arg1, r1arg2]; ->r1b : { new (x: T): U[]; }[] ->[r1arg1, r1arg2] : { new (x: T): U[]; }[] +>r1b : (new (x: T) => U[])[] +>[r1arg1, r1arg2] : (new (x: T) => U[])[] >r1arg1 : new (x: T) => U[] >r1arg2 : new (x: number) => string[] @@ -268,14 +268,14 @@ module Errors { >r2arg1 : new (x: new (arg: T) => U) => new (r: T) => V var r2a = [r2arg2, r2arg1]; ->r2a : { new (x: new (arg: T) => U): new (r: T) => V; }[] ->[r2arg2, r2arg1] : { new (x: new (arg: T) => U): new (r: T) => V; }[] +>r2a : (new (x: new (arg: T) => U) => new (r: T) => V)[] +>[r2arg2, r2arg1] : (new (x: new (arg: T) => U) => new (r: T) => V)[] >r2arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2 >r2arg1 : new (x: new (arg: T) => U) => new (r: T) => V var r2b = [r2arg1, r2arg2]; ->r2b : { new (x: new (arg: T) => U): new (r: T) => V; }[] ->[r2arg1, r2arg2] : { new (x: new (arg: T) => U): new (r: T) => V; }[] +>r2b : (new (x: new (arg: T) => U) => new (r: T) => V)[] +>[r2arg1, r2arg2] : (new (x: new (arg: T) => U) => new (r: T) => V)[] >r2arg1 : new (x: new (arg: T) => U) => new (r: T) => V >r2arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2 @@ -318,14 +318,14 @@ module Errors { >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U var r3a = [r3arg2, r3arg1]; ->r3a : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> ->[r3arg2, r3arg1] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>r3a : ((new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U) | (new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] +>[r3arg2, r3arg1] : ((new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U) | (new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] >r3arg2 : new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U var r3b = [r3arg1, r3arg2]; ->r3b : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> ->[r3arg1, r3arg2] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>r3b : ((new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U) | (new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] +>[r3arg1, r3arg2] : ((new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U) | (new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U >r3arg2 : new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived @@ -350,14 +350,14 @@ module Errors { >r4arg1 : new (...x: T[]) => T var r4a = [r4arg2, r4arg1]; ->r4a : { new (...x: T[]): T; }[] ->[r4arg2, r4arg1] : { new (...x: T[]): T; }[] +>r4a : (new (...x: T[]) => T)[] +>[r4arg2, r4arg1] : (new (...x: T[]) => T)[] >r4arg2 : new (...x: Base[]) => Base >r4arg1 : new (...x: T[]) => T var r4b = [r4arg1, r4arg2]; ->r4b : { new (...x: T[]): T; }[] ->[r4arg1, r4arg2] : { new (...x: T[]): T; }[] +>r4b : (new (...x: T[]) => T)[] +>[r4arg1, r4arg2] : (new (...x: T[]) => T)[] >r4arg1 : new (...x: T[]) => T >r4arg2 : new (...x: Base[]) => Base @@ -387,14 +387,14 @@ module Errors { >r5arg1 : new (x: T, y: T) => T var r5a = [r5arg2, r5arg1]; ->r5a : { new (x: T, y: T): T; }[] ->[r5arg2, r5arg1] : { new (x: T, y: T): T; }[] +>r5a : (new (x: T, y: T) => T)[] +>[r5arg2, r5arg1] : (new (x: T, y: T) => T)[] >r5arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r5arg1 : new (x: T, y: T) => T var r5b = [r5arg1, r5arg2]; ->r5b : { new (x: T, y: T): T; }[] ->[r5arg1, r5arg2] : { new (x: T, y: T): T; }[] +>r5b : (new (x: T, y: T) => T)[] +>[r5arg1, r5arg2] : (new (x: T, y: T) => T)[] >r5arg1 : new (x: T, y: T) => T >r5arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base @@ -429,14 +429,14 @@ module Errors { >r6arg1 : new (x: Base[], y: Derived2[]) => Derived[] var r6a = [r6arg2, r6arg1]; ->r6a : { new (x: Base[], y: Base[]): T; }[] ->[r6arg2, r6arg1] : { new (x: Base[], y: Base[]): T; }[] +>r6a : (new (x: Base[], y: Base[]) => T)[] +>[r6arg2, r6arg1] : (new (x: Base[], y: Base[]) => T)[] >r6arg2 : new (x: Base[], y: Base[]) => T >r6arg1 : new (x: Base[], y: Derived2[]) => Derived[] var r6b = [r6arg1, r6arg2]; ->r6b : { new (x: Base[], y: Base[]): T; }[] ->[r6arg1, r6arg2] : { new (x: Base[], y: Base[]): T; }[] +>r6b : (new (x: Base[], y: Base[]) => T)[] +>[r6arg1, r6arg2] : (new (x: Base[], y: Base[]) => T)[] >r6arg1 : new (x: Base[], y: Derived2[]) => Derived[] >r6arg2 : new (x: Base[], y: Base[]) => T @@ -463,14 +463,14 @@ module Errors { >r7arg1 : new (x: { a: T; b: T; }) => T var r7a = [r7arg2, r7arg1]; ->r7a : { new (x: { a: T; b: T; }): T; }[] ->[r7arg2, r7arg1] : { new (x: { a: T; b: T; }): T; }[] +>r7a : (new (x: { a: T; b: T; }) => T)[] +>[r7arg2, r7arg1] : (new (x: { a: T; b: T; }) => T)[] >r7arg2 : new (x: { a: string; b: number; }) => number >r7arg1 : new (x: { a: T; b: T; }) => T var r7b = [r7arg1, r7arg2]; ->r7b : { new (x: { a: T; b: T; }): T; }[] ->[r7arg1, r7arg2] : { new (x: { a: T; b: T; }): T; }[] +>r7b : (new (x: { a: T; b: T; }) => T)[] +>[r7arg1, r7arg2] : (new (x: { a: T; b: T; }) => T)[] >r7arg1 : new (x: { a: T; b: T; }) => T >r7arg2 : new (x: { a: string; b: number; }) => number @@ -491,14 +491,14 @@ module Errors { >r7arg3 : new (x: { a: T; b: T; }) => number var r7d = [r7arg2, r7arg3]; ->r7d : { new (x: { a: string; b: number; }): number; }[] ->[r7arg2, r7arg3] : { new (x: { a: string; b: number; }): number; }[] +>r7d : (new (x: { a: string; b: number; }) => number)[] +>[r7arg2, r7arg3] : (new (x: { a: string; b: number; }) => number)[] >r7arg2 : new (x: { a: string; b: number; }) => number >r7arg3 : new (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : { new (x: { a: string; b: number; }): number; }[] ->[r7arg3, r7arg2] : { new (x: { a: string; b: number; }): number; }[] +>r7e : (new (x: { a: string; b: number; }) => number)[] +>[r7arg3, r7arg2] : (new (x: { a: string; b: number; }) => number)[] >r7arg3 : new (x: { a: T; b: T; }) => number >r7arg2 : new (x: { a: string; b: number; }) => number diff --git a/tests/baselines/reference/subtypingWithConstructSignatures4.types b/tests/baselines/reference/subtypingWithConstructSignatures4.types index 473bbe9a205..21a40ecf7fc 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures4.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures4.types @@ -240,14 +240,14 @@ var r1 = foo1(r1arg); >r1arg : new (x: T) => T[] var r1a = [r1arg, r1arg2]; ->r1a : { new (x: T): T[]; }[] ->[r1arg, r1arg2] : { new (x: T): T[]; }[] +>r1a : (new (x: T) => T[])[] +>[r1arg, r1arg2] : (new (x: T) => T[])[] >r1arg : new (x: T) => T[] >r1arg2 : new (x: T) => T[] var r1b = [r1arg2, r1arg]; ->r1b : { new (x: T): T[]; }[] ->[r1arg2, r1arg] : { new (x: T): T[]; }[] +>r1b : (new (x: T) => T[])[] +>[r1arg2, r1arg] : (new (x: T) => T[])[] >r1arg2 : new (x: T) => T[] >r1arg : new (x: T) => T[] @@ -270,14 +270,14 @@ var r2 = foo2(r2arg); >r2arg : new (x: T) => string[] var r2a = [r2arg, r2arg2]; ->r2a : { new (x: T): string[]; }[] ->[r2arg, r2arg2] : { new (x: T): string[]; }[] +>r2a : (new (x: T) => string[])[] +>[r2arg, r2arg2] : (new (x: T) => string[])[] >r2arg : new (x: T) => string[] >r2arg2 : new (x: T) => string[] var r2b = [r2arg2, r2arg]; ->r2b : { new (x: T): string[]; }[] ->[r2arg2, r2arg] : { new (x: T): string[]; }[] +>r2b : (new (x: T) => string[])[] +>[r2arg2, r2arg] : (new (x: T) => string[])[] >r2arg2 : new (x: T) => string[] >r2arg : new (x: T) => string[] @@ -301,14 +301,14 @@ var r3 = foo3(r3arg); >r3arg : new (x: T) => T var r3a = [r3arg, r3arg2]; ->r3a : { new (x: T): T; }[] ->[r3arg, r3arg2] : { new (x: T): T; }[] +>r3a : (new (x: T) => T)[] +>[r3arg, r3arg2] : (new (x: T) => T)[] >r3arg : new (x: T) => T >r3arg2 : new (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : { new (x: T): T; }[] ->[r3arg2, r3arg] : { new (x: T): T; }[] +>r3b : (new (x: T) => T)[] +>[r3arg2, r3arg] : (new (x: T) => T)[] >r3arg2 : new (x: T) => void >r3arg : new (x: T) => T @@ -337,14 +337,14 @@ var r4 = foo4(r4arg); >r4arg : new (x: T, y: U) => string var r4a = [r4arg, r4arg2]; ->r4a : { new (x: T, y: U): string; }[] ->[r4arg, r4arg2] : { new (x: T, y: U): string; }[] +>r4a : (new (x: T, y: U) => string)[] +>[r4arg, r4arg2] : (new (x: T, y: U) => string)[] >r4arg : new (x: T, y: U) => string >r4arg2 : new (x: T, y: U) => string var r4b = [r4arg2, r4arg]; ->r4b : { new (x: T, y: U): string; }[] ->[r4arg2, r4arg] : { new (x: T, y: U): string; }[] +>r4b : (new (x: T, y: U) => string)[] +>[r4arg2, r4arg] : (new (x: T, y: U) => string)[] >r4arg2 : new (x: T, y: U) => string >r4arg : new (x: T, y: U) => string @@ -375,14 +375,14 @@ var r5 = foo5(r5arg); >r5arg : new (x: new (arg: T) => U) => T var r5a = [r5arg, r5arg2]; ->r5a : { new (x: new (arg: T) => U): T; }[] ->[r5arg, r5arg2] : { new (x: new (arg: T) => U): T; }[] +>r5a : (new (x: new (arg: T) => U) => T)[] +>[r5arg, r5arg2] : (new (x: new (arg: T) => U) => T)[] >r5arg : new (x: new (arg: T) => U) => T >r5arg2 : new (x: new (arg: T) => U) => T var r5b = [r5arg2, r5arg]; ->r5b : { new (x: new (arg: T) => U): T; }[] ->[r5arg2, r5arg] : { new (x: new (arg: T) => U): T; }[] +>r5b : (new (x: new (arg: T) => U) => T)[] +>[r5arg2, r5arg] : (new (x: new (arg: T) => U) => T)[] >r5arg2 : new (x: new (arg: T) => U) => T >r5arg : new (x: new (arg: T) => U) => T @@ -415,14 +415,14 @@ var r6 = foo6(r6arg); >r6arg : new (x: new (arg: T) => U) => T var r6a = [r6arg, r6arg2]; ->r6a : { new (x: new (arg: T) => U): T; }[] ->[r6arg, r6arg2] : { new (x: new (arg: T) => U): T; }[] +>r6a : (new (x: new (arg: T) => U) => T)[] +>[r6arg, r6arg2] : (new (x: new (arg: T) => U) => T)[] >r6arg : new (x: new (arg: T) => U) => T >r6arg2 : new (x: new (arg: T) => Derived) => T var r6b = [r6arg2, r6arg]; ->r6b : { new (x: new (arg: T) => U): T; }[] ->[r6arg2, r6arg] : { new (x: new (arg: T) => U): T; }[] +>r6b : (new (x: new (arg: T) => U) => T)[] +>[r6arg2, r6arg] : (new (x: new (arg: T) => U) => T)[] >r6arg2 : new (x: new (arg: T) => Derived) => T >r6arg : new (x: new (arg: T) => U) => T @@ -460,14 +460,14 @@ var r11 = foo11(r11arg); >r11arg : new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base var r11a = [r11arg, r11arg2]; ->r11a : { new (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] ->[r11arg, r11arg2] : { new (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] +>r11a : (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>[r11arg, r11arg2] : (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] >r11arg : new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base >r11arg2 : new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base var r11b = [r11arg2, r11arg]; ->r11b : { new (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] ->[r11arg2, r11arg] : { new (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] +>r11b : (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>[r11arg2, r11arg] : (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] >r11arg2 : new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base >r11arg : new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base @@ -499,14 +499,14 @@ var r15 = foo15(r15arg); >r15arg : new (x: { a: U; b: V; }) => U[] var r15a = [r15arg, r15arg2]; ->r15a : { new (x: { a: U; b: V; }): U[]; }[] ->[r15arg, r15arg2] : { new (x: { a: U; b: V; }): U[]; }[] +>r15a : (new (x: { a: U; b: V; }) => U[])[] +>[r15arg, r15arg2] : (new (x: { a: U; b: V; }) => U[])[] >r15arg : new (x: { a: U; b: V; }) => U[] >r15arg2 : new (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : { new (x: { a: U; b: V; }): U[]; }[] ->[r15arg2, r15arg] : { new (x: { a: U; b: V; }): U[]; }[] +>r15b : (new (x: { a: U; b: V; }) => U[])[] +>[r15arg2, r15arg] : (new (x: { a: U; b: V; }) => U[])[] >r15arg2 : new (x: { a: T; b: T; }) => T[] >r15arg : new (x: { a: U; b: V; }) => U[] @@ -539,14 +539,14 @@ var r16 = foo16(r16arg); >r16arg : new (x: { a: T; b: T; }) => T[] var r16a = [r16arg, r16arg2]; ->r16a : { new (x: { a: T; b: T; }): T[]; }[] ->[r16arg, r16arg2] : { new (x: { a: T; b: T; }): T[]; }[] +>r16a : (new (x: { a: T; b: T; }) => T[])[] +>[r16arg, r16arg2] : (new (x: { a: T; b: T; }) => T[])[] >r16arg : new (x: { a: T; b: T; }) => T[] >r16arg2 : new (x: { a: T; b: T; }) => T[] var r16b = [r16arg2, r16arg]; ->r16b : { new (x: { a: T; b: T; }): T[]; }[] ->[r16arg2, r16arg] : { new (x: { a: T; b: T; }): T[]; }[] +>r16b : (new (x: { a: T; b: T; }) => T[])[] +>[r16arg2, r16arg] : (new (x: { a: T; b: T; }) => T[])[] >r16arg2 : new (x: { a: T; b: T; }) => T[] >r16arg : new (x: { a: T; b: T; }) => T[] diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality3.types b/tests/baselines/reference/subtypingWithObjectMembersOptionality3.types index f4bd9f447a8..055863e0bfa 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality3.types +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality3.types @@ -69,8 +69,8 @@ var b: { Foo2: Derived; } >Derived : Derived var r = true ? a : b; // ok ->r : { Foo?: Base; } ->true ? a : b : { Foo?: Base; } +>r : { Foo?: Base; } | { Foo2: Derived; } +>true ? a : b : { Foo?: Base; } | { Foo2: Derived; } >a : { Foo?: Base; } >b : { Foo2: Derived; } diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality4.types b/tests/baselines/reference/subtypingWithObjectMembersOptionality4.types index 7ad4580090c..96204004b64 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality4.types +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality4.types @@ -69,8 +69,8 @@ var b: { Foo2?: Derived; } >Derived : Derived var r = true ? a : b; // ok ->r : { Foo2?: Derived; } ->true ? a : b : { Foo2?: Derived; } +>r : { Foo: Base; } | { Foo2?: Derived; } +>true ? a : b : { Foo: Base; } | { Foo2?: Derived; } >a : { Foo: Base; } >b : { Foo2?: Derived; } diff --git a/tests/baselines/reference/targetTypeTest2.types b/tests/baselines/reference/targetTypeTest2.types index f40d68d075a..0000e65b8a7 100644 --- a/tests/baselines/reference/targetTypeTest2.types +++ b/tests/baselines/reference/targetTypeTest2.types @@ -4,7 +4,7 @@ var a : any[] = [1,2,"3"]; >a : any[] ->[1,2,"3"] : Array +>[1,2,"3"] : (string | number)[] function func1(stuff:any[]) { return stuff; } @@ -21,7 +21,7 @@ function func2(stuff1:string, stuff2:number, stuff3:number) { return func1([stuff1, stuff2, stuff3]); >func1([stuff1, stuff2, stuff3]) : any[] >func1 : (stuff: any[]) => any[] ->[stuff1, stuff2, stuff3] : Array +>[stuff1, stuff2, stuff3] : (string | number)[] >stuff1 : string >stuff2 : number >stuff3 : number diff --git a/tests/baselines/reference/targetTypeTest3.errors.txt b/tests/baselines/reference/targetTypeTest3.errors.txt index d9dbec41150..41b2d027fb5 100644 --- a/tests/baselines/reference/targetTypeTest3.errors.txt +++ b/tests/baselines/reference/targetTypeTest3.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type 'Array' is not assignable to type 'string[]': +tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '(string | number)[]' is not assignable to type 'string[]': Type 'string | number' is not assignable to type 'string': Type 'number' is not assignable to type 'string'. @@ -9,7 +9,7 @@ tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type 'Array' is not assignable to type 'string[]': +!!! error TS2322: Type '(string | number)[]' is not assignable to type 'string[]': !!! error TS2322: Type 'string | number' is not assignable to type 'string': !!! error TS2322: Type 'number' is not assignable to type 'string'. diff --git a/tests/baselines/reference/thisInPropertyBoundDeclarations.types b/tests/baselines/reference/thisInPropertyBoundDeclarations.types index 899aa41a684..196cf4e2ddc 100644 --- a/tests/baselines/reference/thisInPropertyBoundDeclarations.types +++ b/tests/baselines/reference/thisInPropertyBoundDeclarations.types @@ -8,7 +8,7 @@ class Bug { private static func: Function[] = [ >func : Function[] >Function : Function ->[ (that: Bug, name: string) => { that.foo(name); } ] : { (that: Bug, name: string): void; }[] +>[ (that: Bug, name: string) => { that.foo(name); } ] : ((that: Bug, name: string) => void)[] (that: Bug, name: string) => { >(that: Bug, name: string) => { that.foo(name); } : (that: Bug, name: string) => void diff --git a/tests/baselines/reference/throwStatements.types b/tests/baselines/reference/throwStatements.types index 7f106daced9..eeef863f6eb 100644 --- a/tests/baselines/reference/throwStatements.types +++ b/tests/baselines/reference/throwStatements.types @@ -219,7 +219,7 @@ throw []; >[] : undefined[] throw ['a', ['b']]; ->['a', ['b']] : Array +>['a', ['b']] : (string | string[])[] >['b'] : string[] throw /[a-z]/; diff --git a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt index 823bf93e535..9b068b62e68 100644 --- a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt +++ b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. Type 'string | number' is not assignable to type 'number': Type 'string' is not assignable to type 'number'. -tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. Type 'string | number' is not assignable to type 'number': Type 'string' is not assignable to type 'number'. @@ -13,12 +13,12 @@ tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS // these two should give the same error this.test([1, 2, "hi", 5, ]); ~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. !!! error TS2345: Type 'string | number' is not assignable to type 'number': !!! error TS2345: Type 'string' is not assignable to type 'number'. this.test([1, 2, "hi", 5]); ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. !!! error TS2345: Type 'string | number' is not assignable to type 'number': !!! error TS2345: Type 'string' is not assignable to type 'number'. } diff --git a/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types b/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types index 1cee9140a01..27fcd05bb28 100644 --- a/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types +++ b/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types @@ -23,7 +23,7 @@ interface IMenuItem { var menuData: IMenuItem[] = [ >menuData : IMenuItem[] >IMenuItem : IMenuItem ->[ { "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { "id": "productName", "type": "default", "link": "", "text": "Product Name" }] : Array<{ "id": string; "type": string; "link": string; "icon": string; } | { "id": string; "type": string; "link": string; "text": string; }> +>[ { "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { "id": "productName", "type": "default", "link": "", "text": "Product Name" }] : ({ "id": string; "type": string; "link": string; "icon": string; } | { "id": string; "type": string; "link": string; "text": string; })[] { >{ "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" } : { "id": string; "type": string; "link": string; "icon": string; } diff --git a/tests/baselines/reference/typeParameterAsElementType.types b/tests/baselines/reference/typeParameterAsElementType.types index 828c7034a58..5cbad56c5f1 100644 --- a/tests/baselines/reference/typeParameterAsElementType.types +++ b/tests/baselines/reference/typeParameterAsElementType.types @@ -8,7 +8,7 @@ function fee() { >T : T var arr = [t, ""]; ->arr : Array ->[t, ""] : Array +>arr : (string | T)[] +>[t, ""] : (string | T)[] >t : T } diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index 5337a4971d1..752c39b5e51 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -176,7 +176,7 @@ _.all([true, 1, null, 'yes'], _.identity); >_.all : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } >_ : Underscore.Static >all : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } ->[true, 1, null, 'yes'] : Array +>[true, 1, null, 'yes'] : (string | number | boolean)[] >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T @@ -186,7 +186,7 @@ _.any([null, 0, 'yes', false]); >_.any : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } >_ : Underscore.Static >any : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } ->[null, 0, 'yes', false] : Array +>[null, 0, 'yes', false] : (string | number | boolean)[] _.contains([1, 2, 3], 3); >_.contains([1, 2, 3], 3) : boolean @@ -364,11 +364,11 @@ _.rest([5, 4, 3, 2, 1]); >[5, 4, 3, 2, 1] : number[] _.compact([0, 1, false, 2, '', 3]); ->_.compact([0, 1, false, 2, '', 3]) : Array +>_.compact([0, 1, false, 2, '', 3]) : (string | number | boolean)[] >_.compact : (list: T[]) => T[] >_ : Underscore.Static >compact : (list: T[]) => T[] ->[0, 1, false, 2, '', 3] : Array +>[0, 1, false, 2, '', 3] : (string | number | boolean)[] _.flatten([1, 2, 3, 4]); >_.flatten([1, 2, 3, 4]) : {}[] @@ -382,7 +382,7 @@ _.flatten([1, [2]]); >_.flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >_ : Underscore.Static >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } ->[1, [2]] : Array +>[1, [2]] : (number | number[])[] >[2] : number[] // typescript doesn't like the elements being different @@ -391,9 +391,9 @@ _.flatten([1, [2], [3, [[4]]]]); >_.flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >_ : Underscore.Static >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } ->[1, [2], [3, [[4]]]] : Array> +>[1, [2], [3, [[4]]]] : (number | (number | number[][])[])[] >[2] : number[] ->[3, [[4]]] : Array +>[3, [[4]]] : (number | number[][])[] >[[4]] : number[][] >[4] : number[] @@ -402,9 +402,9 @@ _.flatten([1, [2], [3, [[4]]]], true); >_.flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >_ : Underscore.Static >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } ->[1, [2], [3, [[4]]]] : Array> +>[1, [2], [3, [[4]]]] : (number | (number | number[][])[])[] >[2] : number[] ->[3, [[4]]] : Array +>[3, [[4]]] : (number | number[][])[] >[[4]] : number[][] >[4] : number[] @@ -470,10 +470,10 @@ _.object([['moe', 30], ['larry', 40], ['curly', 50]]); >_.object : { (list: any[][]): any; (keys: string[], values: any[]): any; } >_ : Underscore.Static >object : { (list: any[][]): any; (keys: string[], values: any[]): any; } ->[['moe', 30], ['larry', 40], ['curly', 50]] : Array[] ->['moe', 30] : Array ->['larry', 40] : Array ->['curly', 50] : Array +>[['moe', 30], ['larry', 40], ['curly', 50]] : (string | number)[][] +>['moe', 30] : (string | number)[] +>['larry', 40] : (string | number)[] +>['curly', 50] : (string | number)[] _.indexOf([1, 2, 3], 2); >_.indexOf([1, 2, 3], 2) : number diff --git a/tests/baselines/reference/varArgParamTypeCheck.types b/tests/baselines/reference/varArgParamTypeCheck.types index 1b5b20adbec..9cd2fad7aca 100644 --- a/tests/baselines/reference/varArgParamTypeCheck.types +++ b/tests/baselines/reference/varArgParamTypeCheck.types @@ -1,7 +1,7 @@ === tests/cases/compiler/varArgParamTypeCheck.ts === function sequence(...sequences:{():void;}[]) { ->sequence : (...sequences: { (): void; }[]) => void ->sequences : { (): void; }[] +>sequence : (...sequences: (() => void)[]) => void +>sequences : (() => void)[] } function callback(clb:()=>void) { @@ -11,7 +11,7 @@ function callback(clb:()=>void) { sequence( >sequence( function bar() { }, function foo() { callback(()=>{ this(); }); }, function baz() { callback(()=>{ this(); }); }) : void ->sequence : (...sequences: { (): void; }[]) => void +>sequence : (...sequences: (() => void)[]) => void function bar() { >function bar() { } : () => void diff --git a/tests/baselines/reference/varArgsOnConstructorTypes.types b/tests/baselines/reference/varArgsOnConstructorTypes.types index 17993a32fda..5ac9babd426 100644 --- a/tests/baselines/reference/varArgsOnConstructorTypes.types +++ b/tests/baselines/reference/varArgsOnConstructorTypes.types @@ -45,14 +45,14 @@ export interface I1 { >I1 : I1 register(inputClass: new(...params: any[]) => A); ->register : { (inputClass: new (...params: any[]) => A): any; (inputClass: { new (...params: any[]): A; }[]): any; } +>register : { (inputClass: new (...params: any[]) => A): any; (inputClass: (new (...params: any[]) => A)[]): any; } >inputClass : new (...params: any[]) => A >params : any[] >A : A register(inputClass: { new (...params: any[]): A; }[]); ->register : { (inputClass: new (...params: any[]) => A): any; (inputClass: { new (...params: any[]): A; }[]): any; } ->inputClass : { new (...params: any[]): A; }[] +>register : { (inputClass: new (...params: any[]) => A): any; (inputClass: (new (...params: any[]) => A)[]): any; } +>inputClass : (new (...params: any[]) => A)[] >params : any[] >A : A } @@ -64,8 +64,8 @@ var reg: I1; reg.register(B); >reg.register(B) : any ->reg.register : { (inputClass: new (...params: any[]) => A): any; (inputClass: { new (...params: any[]): A; }[]): any; } +>reg.register : { (inputClass: new (...params: any[]) => A): any; (inputClass: (new (...params: any[]) => A)[]): any; } >reg : I1 ->register : { (inputClass: new (...params: any[]) => A): any; (inputClass: { new (...params: any[]): A; }[]): any; } +>register : { (inputClass: new (...params: any[]) => A): any; (inputClass: (new (...params: any[]) => A)[]): any; } >B : typeof B diff --git a/tests/baselines/reference/vardecl.js b/tests/baselines/reference/vardecl.js index 326a639ca91..5ce8e095020 100644 --- a/tests/baselines/reference/vardecl.js +++ b/tests/baselines/reference/vardecl.js @@ -213,9 +213,7 @@ declare var d2: { }; }; declare var n2: () => void; -declare var n4: { - (): void; -}[]; +declare var n4: (() => void)[]; declare var d4: { foo(n: string, x: { x: number; diff --git a/tests/baselines/reference/vardecl.types b/tests/baselines/reference/vardecl.types index f757562c103..25257e57d78 100644 --- a/tests/baselines/reference/vardecl.types +++ b/tests/baselines/reference/vardecl.types @@ -107,7 +107,7 @@ var n2: { (): void; } var n4: { ->n4 : { (): void; }[] +>n4 : (() => void)[] (): void; }[]; diff --git a/tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts new file mode 100644 index 00000000000..a4d39233847 --- /dev/null +++ b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts @@ -0,0 +1,24 @@ +// @target: ES6 + +// Error as declaration of var would cause a write to the const value +var x = 0; +{ + const x = 0; + + var x = 0; +} + + +var y = 0; +{ + const y = 0; + { + var y = 0; + } +} + + +{ + const z = 0; + var z = 0 +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts new file mode 100644 index 00000000000..98930953996 --- /dev/null +++ b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts @@ -0,0 +1,9 @@ +// @target: ES6 + +// No errors, const declaration is not shadowed +function outer() { + const x = 0; + function inner() { + var x = "inner"; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts new file mode 100644 index 00000000000..5b4229a8e54 --- /dev/null +++ b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts @@ -0,0 +1,9 @@ +// Ensure only checking for const declarations shadowed by vars +class Rule { + public regex: RegExp = new RegExp(''); + public name: string = ''; + + constructor(name: string) { + this.name = name; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-access.ts b/tests/cases/compiler/constDeclarations-access.ts new file mode 100644 index 00000000000..665d6753a6d --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +const x = 0 + +// @Filename: file2.ts +x++; \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-access2.ts b/tests/cases/compiler/constDeclarations-access2.ts new file mode 100644 index 00000000000..e3f83940d1d --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access2.ts @@ -0,0 +1,40 @@ +// @target: ES6 + +const x = 0 + +// Errors +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; + +x++; +x--; +++x; +--x; + +++((x)); + +// OK +var a = x + 1; + +function f(v: number) { } +f(x); + +if (x) { } + +x; +(x); + +-x; ++x; + +x.toString(); diff --git a/tests/cases/compiler/constDeclarations-access3.ts b/tests/cases/compiler/constDeclarations-access3.ts new file mode 100644 index 00000000000..370288dab97 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access3.ts @@ -0,0 +1,45 @@ +// @target: ES6 + + +module M { + export const x = 0; +} + +// Errors +M.x = 1; +M.x += 2; +M.x -= 3; +M.x *= 4; +M.x /= 5; +M.x %= 6; +M.x <<= 7; +M.x >>= 8; +M.x >>>= 9; +M.x &= 10; +M.x |= 11; +M.x ^= 12; + +M.x++; +M.x--; +++M.x; +--M.x; + +++((M.x)); + +M["x"] = 0; + +// OK +var a = M.x + 1; + +function f(v: number) { } +f(M.x); + +if (M.x) { } + +M.x; +(M.x); + +-M.x; ++M.x; + +M.x.toString(); diff --git a/tests/cases/compiler/constDeclarations-access4.ts b/tests/cases/compiler/constDeclarations-access4.ts new file mode 100644 index 00000000000..492f6a31d6d --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access4.ts @@ -0,0 +1,45 @@ +// @target: ES6 + + +declare module M { + const x: number; +} + +// Errors +M.x = 1; +M.x += 2; +M.x -= 3; +M.x *= 4; +M.x /= 5; +M.x %= 6; +M.x <<= 7; +M.x >>= 8; +M.x >>>= 9; +M.x &= 10; +M.x |= 11; +M.x ^= 12; + +M.x++; +M.x--; +++M.x; +--M.x; + +++((M.x)); + +M["x"] = 0; + +// OK +var a = M.x + 1; + +function f(v: number) { } +f(M.x); + +if (M.x) { } + +M.x; +(M.x); + +-M.x; ++M.x; + +M.x.toString(); diff --git a/tests/cases/compiler/constDeclarations-access5.ts b/tests/cases/compiler/constDeclarations-access5.ts new file mode 100644 index 00000000000..1590d9289ef --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access5.ts @@ -0,0 +1,48 @@ +// @target: ES6 +// @module: amd + + +// @Filename: constDeclarations_access_1.ts +export const x = 0; + +// @Filename: constDeclarations_access_2.ts +/// +import m = require('constDeclarations_access_1'); +// Errors +m.x = 1; +m.x += 2; +m.x -= 3; +m.x *= 4; +m.x /= 5; +m.x %= 6; +m.x <<= 7; +m.x >>= 8; +m.x >>>= 9; +m.x &= 10; +m.x |= 11; +m.x ^= 12; +m +m.x++; +m.x--; +++m.x; +--m.x; + +++((m.x)); + +m["x"] = 0; + +// OK +var a = m.x + 1; + +function f(v: number) { } +f(m.x); + +if (m.x) { } + +m.x; +(m.x); + +-m.x; ++m.x; + +m.x.toString(); diff --git a/tests/cases/compiler/constDeclarations-ambient-errors.ts b/tests/cases/compiler/constDeclarations-ambient-errors.ts new file mode 100644 index 00000000000..c07bfb01810 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-ambient-errors.ts @@ -0,0 +1,11 @@ +// @target: ES6 + +// error: no intialization expected in ambient declarations +declare const c1: boolean = true; +declare const c2: number = 0; +declare const c3 = null, c4 :string = "", c5: any = 0; + +declare module M { + const c6 = 0; + const c7: number = 7; +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-ambient.ts b/tests/cases/compiler/constDeclarations-ambient.ts new file mode 100644 index 00000000000..dcd4cb9fc72 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-ambient.ts @@ -0,0 +1,11 @@ +// @target: ES6 + +// No error +declare const c1: boolean; +declare const c2: number; +declare const c3, c4 :string, c5: any; + +declare module M { + const c6; + const c7: number; +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-errors.ts b/tests/cases/compiler/constDeclarations-errors.ts new file mode 100644 index 00000000000..09dc0e96790 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-errors.ts @@ -0,0 +1,18 @@ +// @target: ES6 + +// error, missing intialicer +const c1; +const c2: number; +const c3, c4, c5 :string, c6; // error, missing initialicer + +// error, can not be unintalized +for(const c in {}) { } + +// error, assigning to a const +for(const c8 = 0; c8 < 1; c8++) { } + +// error, can not be unintalized +for(const c9; c9 < 1;) { } + +// error, can not be unintalized +for(const c10 = 0, c11; c10 < 1;) { } \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-es5.ts b/tests/cases/compiler/constDeclarations-es5.ts new file mode 100644 index 00000000000..0da824a7396 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 + +const z7 = false; +const z8: number = 23; +const z9 = 0, z10 :string = "", z11 = null; diff --git a/tests/cases/compiler/constDeclarations-invalidContexts.ts b/tests/cases/compiler/constDeclarations-invalidContexts.ts new file mode 100644 index 00000000000..3da91a7d1d7 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-invalidContexts.ts @@ -0,0 +1,33 @@ +// @target: ES6 + +// Errors, const must be defined inside a block +if (true) + const c1 = 0; +else + const c2 = 0; + +while (true) + const c3 = 0; + +do + const c4 = 0; +while (true); + +var obj; +with (obj) + const c5 = 0; + +for (var i = 0; i < 10; i++) + const c6 = 0; + +for (var i2 in {}) + const c7 = 0; + +if (true) + label: const c8 = 0; + +while (false) + label2: label3: label4: const c9 = 0; + + + diff --git a/tests/cases/compiler/constDeclarations-scopes.ts b/tests/cases/compiler/constDeclarations-scopes.ts new file mode 100644 index 00000000000..d0c1df425b6 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-scopes.ts @@ -0,0 +1,148 @@ +// @target: ES6 + +// global +const c = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + const c = 0; + n = c; +} +else { + const c = 0; + n = c; +} + +while (true) { + const c = 0; + n = c; +} + +do { + const c = 0; + n = c; +} while (true); + +var obj; +with (obj) { + const c = 0; + n = c; +} + +for (var i = 0; i < 10; i++) { + const c = 0; + n = c; +} + +for (var i2 in {}) { + const c = 0; + n = c; +} + +if (true) { + label: const c = 0; + n = c; +} + +while (false) { + label2: label3: label4: const c = 0; + n = c; +} + +// Try/catch/finally +try { + const c = 0; + n = c; +} +catch (e) { + const c = 0; + n = c; +} +finally { + const c = 0; + n = c; +} + +// Switch +switch (0) { + case 0: + const c = 0; + n = c; + break; +} + +// blocks +{ + const c = 0; + n = c; + { + const c = false; + var b: boolean = c; + } +} + +// functions + +function F() { + const c = 0; + n = c; +} + +var F2 = () => { + const c = 0; + n = c; +}; + +var F3 = function () { + const c = 0; + n = c; +}; + +// modules +module m { + const c = 0; + n = c; + + { + const c = false; + var b2: boolean = c; + } +} + +// methods +class C { + constructor() { + const c = 0; + n = c; + } + + method() { + const c = 0; + n = c; + } + + get v() { + const c = 0; + n = c; + return n; + } + + set v(value) { + const c = 0; + n = c; + } +} + +// object literals +var o = { + f() { + const c = 0; + n = c; + }, + f2: () => { + const c = 0; + n = c; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-scopes2.ts b/tests/cases/compiler/constDeclarations-scopes2.ts new file mode 100644 index 00000000000..fe0ab16409a --- /dev/null +++ b/tests/cases/compiler/constDeclarations-scopes2.ts @@ -0,0 +1,15 @@ +// @target: ES6 + +// global +const c = "string"; + +var n: number; +var b: boolean; + +// for scope +for (const c = 0; c < 10; n = c ) { + // for block + const c = false; + b = c; +} + diff --git a/tests/cases/compiler/constDeclarations-useBeforeDefinition.ts b/tests/cases/compiler/constDeclarations-useBeforeDefinition.ts new file mode 100644 index 00000000000..ec793fda484 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-useBeforeDefinition.ts @@ -0,0 +1,12 @@ +// @target: ES6 + +{ + c1; + const c1 = 0; +} + +var v1; +{ + v1; + const v1 = 0; +} diff --git a/tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts b/tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts new file mode 100644 index 00000000000..c34bb4012bf --- /dev/null +++ b/tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts @@ -0,0 +1,8 @@ +// @target: ES6 +// @out: out.js + +// @Filename: file1.ts +c; + +// @Filename: file2.ts +const c = 0; \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-validContexts.ts b/tests/cases/compiler/constDeclarations-validContexts.ts new file mode 100644 index 00000000000..ffde8e45d6f --- /dev/null +++ b/tests/cases/compiler/constDeclarations-validContexts.ts @@ -0,0 +1,124 @@ +// @target: ES6 + + +// Control flow statements with blocks +if (true) { + const c1 = 0; +} +else { + const c2 = 0; +} + +while (true) { + const c3 = 0; +} + +do { + const c4 = 0; +} while (true); + +var obj; +with (obj) { + const c5 = 0; +} + +for (var i = 0; i < 10; i++) { + const c6 = 0; +} + +for (var i2 in {}) { + const c7 = 0; +} + +if (true) { + label: const c8 = 0; +} + +while (false) { + label2: label3: label4: const c9 = 0; +} + +// Try/catch/finally +try { + const c10 = 0; +} +catch (e) { + const c11 = 0; +} +finally { + const c12 = 0; +} + +// Switch +switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; +} + +// blocks +{ + const c15 = 0; + { + const c16 = 0 + label17: const c17 = 0; + } +} + +// global +const c18 = 0; + +// functions +function F() { + const c19 = 0; +} + +var F2 = () => { + const c20 = 0; +}; + +var F3 = function () { + const c21 = 0; +}; + +// modules +module m { + const c22 = 0; + + { + const c23 = 0; + } +} + +// methods +class C { + constructor() { + const c24 = 0; + } + + method() { + const c25 = 0; + } + + get v() { + const c26 = 0; + return c26; + } + + set v(value) { + const c27 = value; + } +} + +// object literals +var o = { + f() { + const c28 = 0; + }, + f2: () => { + const c29 = 0; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations.ts b/tests/cases/compiler/constDeclarations.ts new file mode 100644 index 00000000000..2b8563b340a --- /dev/null +++ b/tests/cases/compiler/constDeclarations.ts @@ -0,0 +1,13 @@ +// @target: ES6 +// @declaration: true + +// No error +const c1 = false; +const c2: number = 23; +const c3 = 0, c4 :string = "", c5 = null; + + +for(const c4 = 0; c4 < 9; ) { break; } + + +for(const c5 = 0, c6 = 0; c5 < c6; ) { break; } \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations2.ts b/tests/cases/compiler/constDeclarations2.ts new file mode 100644 index 00000000000..a221c3563ba --- /dev/null +++ b/tests/cases/compiler/constDeclarations2.ts @@ -0,0 +1,9 @@ +// @target: ES6 +// @declaration: true + +// No error +module M { + export const c1 = false; + export const c2: number = 23; + export const c3 = 0, c4 :string = "", c5 = null; +} diff --git a/tests/cases/compiler/es6-amd.ts b/tests/cases/compiler/es6-amd.ts new file mode 100644 index 00000000000..a5fb99a8605 --- /dev/null +++ b/tests/cases/compiler/es6-amd.ts @@ -0,0 +1,17 @@ +// @target: ES6 +// @sourcemap: false +// @declaration: false +// @module: amd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6-declaration-amd.ts b/tests/cases/compiler/es6-declaration-amd.ts new file mode 100644 index 00000000000..1dcfeca8497 --- /dev/null +++ b/tests/cases/compiler/es6-declaration-amd.ts @@ -0,0 +1,17 @@ +// @target: ES6 +// @sourcemap: false +// @declaration: true +// @module: amd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6-sourcemap-amd.ts b/tests/cases/compiler/es6-sourcemap-amd.ts new file mode 100644 index 00000000000..c00a697de94 --- /dev/null +++ b/tests/cases/compiler/es6-sourcemap-amd.ts @@ -0,0 +1,16 @@ +// @target: ES6 +// @sourcemap: true +// @module: amd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts b/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts index 77fbb74d7ad..91cf2d551b9 100644 --- a/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts +++ b/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts @@ -1,8 +1,10 @@ -interface Array { - foo: T; - length: number; -} +module test { + interface Array { + foo: T; + length: number; + } -function map() { -var ys: U[] = []; + function map() { + var ys: U[] = []; + } } diff --git a/tests/cases/compiler/instanceofOperator.ts b/tests/cases/compiler/instanceofOperator.ts index 60b724149ce..f9b304de113 100644 Binary files a/tests/cases/compiler/instanceofOperator.ts and b/tests/cases/compiler/instanceofOperator.ts differ diff --git a/tests/cases/compiler/letDeclarations-access.ts b/tests/cases/compiler/letDeclarations-access.ts new file mode 100644 index 00000000000..6ed655f1cb2 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-access.ts @@ -0,0 +1,38 @@ +// @target: ES6 + +let x = 0 + +// No errors + +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; + +x++; +x--; +++x; +--x; + +var a = x + 1; + +function f(v: number) { } +f(x); + +if (x) { } + +x; +(x); + +-x; ++x; + +x.toString(); diff --git a/tests/cases/compiler/letDeclarations-es5.ts b/tests/cases/compiler/letDeclarations-es5.ts new file mode 100644 index 00000000000..b115c260a91 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-es5.ts @@ -0,0 +1,13 @@ +// @target: ES5 + +let l1; +let l2: number; +let l3, l4, l5 :string, l6; + +let l7 = false; +let l8: number = 23; +let l9 = 0, l10 :string = "", l11 = null; + +for(let l11 in {}) { } + +for(let l12 = 0; l12 < 9; l12++) { } diff --git a/tests/cases/compiler/letDeclarations-invalidContexts.ts b/tests/cases/compiler/letDeclarations-invalidContexts.ts new file mode 100644 index 00000000000..4d165ba2cda --- /dev/null +++ b/tests/cases/compiler/letDeclarations-invalidContexts.ts @@ -0,0 +1,33 @@ +// @target: ES6 + +// Errors, let must be defined inside a block +if (true) + let l1 = 0; +else + let l2 = 0; + +while (true) + let l3 = 0; + +do + let l4 = 0; +while (true); + +var obj; +with (obj) + let l5 = 0; + +for (var i = 0; i < 10; i++) + let l6 = 0; + +for (var i2 in {}) + let l7 = 0; + +if (true) + label: let l8 = 0; + +while (false) + label2: label3: label4: let l9 = 0; + + + diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates.ts new file mode 100644 index 00000000000..841b55af168 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates.ts @@ -0,0 +1,77 @@ +// @target: ES6 + +// Errors: redeclaration +let var1 = 0; +let var1 = 0; // error + +let var2 = 0; +const var2 = 0; + +const var3 = 0; +let var3 = 0; + +const var4 = 0; +const var4 = 0; + +var var5 = 0; +let var5 = 0; + +let var6 = 0; +var var6 = 0; + +{ + let var7 = 0; + let var7 = 0; + { + let var8 = 0; + const var8 = 0; + } +} + +switch (0) { + default: + let var9 = 0; + let var9 = 0; +} + +try { + const var10 = 0; + const var10 = 0; +} +catch (e) { + let var11 = 0; + let var11 = 0; +} + +function F1() { + let var12; + let var12; +} + +// OK +var var20 = 0; + +var var20 = 0 +{ + let var20 = 0; + { + let var20 = 0; + } +} + +switch (0) { + default: + let var20 = 0; +} + +try { + let var20 = 0; +} +catch (e) { + let var20 = 0; +} + +function F() { + let var20; +} + diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates2.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates2.ts new file mode 100644 index 00000000000..40ddc14fc3f --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates2.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +let var1 = 0; + +// @Filename: file2.ts +let var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates3.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates3.ts new file mode 100644 index 00000000000..1f10efa5385 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates3.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +let var1 = 0; + +// @Filename: file2.ts +const var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates4.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates4.ts new file mode 100644 index 00000000000..150d434a2bc --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates4.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +const var1 = 0; + +// @Filename: file2.ts +let var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates5.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates5.ts new file mode 100644 index 00000000000..da249853499 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates5.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +const var1 = 0; + +// @Filename: file2.ts +const var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates6.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates6.ts new file mode 100644 index 00000000000..f71b7623790 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates6.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +var var1 = 0; + +// @Filename: file2.ts +let var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates7.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates7.ts new file mode 100644 index 00000000000..829fda0c927 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates7.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +let var1 = 0; + +// @Filename: file2.ts +var var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes.ts b/tests/cases/compiler/letDeclarations-scopes.ts new file mode 100644 index 00000000000..93f4ce5b4ed --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes.ts @@ -0,0 +1,158 @@ +// @target: ES6 + +// global +let l = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + let l = 0; + n = l; +} +else { + let l = 0; + n = l; +} + +while (true) { + let l = 0; + n = l; +} + +do { + let l = 0; + n = l; +} while (true); + +var obj; +with (obj) { + let l = 0; + n = l; +} + +for (var i = 0; i < 10; i++) { + let l = 0; + n = l; +} + +for (var i2 in {}) { + let l = 0; + n = l; +} + +if (true) { + label: let l = 0; + n = l; +} + +while (false) { + label2: label3: label4: let l = 0; + n = l; +} + +for (let l = 0; n = l; l++) { + let l = true; + var b3: boolean = l; +} + +for (let l in {}) { + +} + +// Try/catch/finally +try { + let l = 0; + n = l; +} +catch (e) { + let l = 0; + n = l; +} +finally { + let l = 0; + n = l; +} + +// Switch +switch (0) { + case 0: + let l = 0; + n = l; + break; +} + +// blocks +{ + let l = 0; + n = l; + { + let l = false; + var b: boolean = l; + } +} + +// functions +function F() { + let l = 0; + n = l; +} + +var F2 = () => { + let l = 0; + n = l; +}; + +var F3 = function () { + let l = 0; + n = l; +}; + +// modules +module m { + let l = 0; + n = l; + + { + let l = false; + var b2: boolean = l; + } + + lable: let l2 = 0; +} + +// methods +class C { + constructor() { + let l = 0; + n = l; + } + + method() { + let l = 0; + n = l; + } + + get v() { + let l = 0; + n = l; + return n; + } + + set v(value) { + let l = 0; + n = l; + } +} + +// object literals +var o = { + f() { + let l = 0; + n = l; + }, + f2: () => { + let l = 0; + n = l; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes2.ts b/tests/cases/compiler/letDeclarations-scopes2.ts new file mode 100644 index 00000000000..6f1200a0cb2 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes2.ts @@ -0,0 +1,27 @@ +// @target: ES6 + +let global = 0; + +{ + let local = 0; + + local; // OK + global; // OK + local2; // Error + + { + let local2 = 0; + + local; // OK + global; // OK + local2; // OK + } + + local; // OK + global; // OK + local2; // Error +} + +local; // Error +global; // OK +local2; // Error diff --git a/tests/cases/compiler/letDeclarations-useBeforeDefinition.ts b/tests/cases/compiler/letDeclarations-useBeforeDefinition.ts new file mode 100644 index 00000000000..671762d4a45 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-useBeforeDefinition.ts @@ -0,0 +1,12 @@ +// @target: ES6 + +{ + l1; + let l1; +} + +var v1; +{ + v1; + let v1 = 0; +} diff --git a/tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts b/tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts new file mode 100644 index 00000000000..a6cbc729b94 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts @@ -0,0 +1,8 @@ +// @target: ES6 +// @out: out.js + +// @Filename: file1.ts +l; + +// @Filename: file2.ts +const l = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-validContexts.ts b/tests/cases/compiler/letDeclarations-validContexts.ts new file mode 100644 index 00000000000..baedfa2644c --- /dev/null +++ b/tests/cases/compiler/letDeclarations-validContexts.ts @@ -0,0 +1,144 @@ +// @target: ES6 + + +// Control flow statements with blocks +if (true) { + let l1 = 0; +} +else { + let l2 = 0; +} + +while (true) { + let l3 = 0; +} + +do { + let l4 = 0; +} while (true); + +var obj; +with (obj) { + let l5 = 0; +} + +for (var i = 0; i < 10; i++) { + let l6 = 0; +} + +for (var i2 in {}) { + let l7 = 0; +} + +if (true) { + label: let l8 = 0; +} + +while (false) { + label2: label3: label4: let l9 = 0; +} + +// Try/catch/finally +try { + let l10 = 0; +} +catch (e) { + let l11 = 0; +} +finally { + let l12 = 0; +} + +// Switch +switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; +} + +// blocks +{ + let l15 = 0; + { + let l16 = 0 + label17: let l17 = 0; + } +} + +// global +let l18 = 0; + +// functions +function F() { + let l19 = 0; +} + +var F2 = () => { + let l20 = 0; +}; + +var F3 = function () { + let l21 = 0; +}; + +// modules +module m { + let l22 = 0; + + { + let l23 = 0; + } +} + +// methods +class C { + constructor() { + let l24 = 0; + } + + method() { + let l25 = 0; + } + + get v() { + let l26 = 0; + return l26; + } + + set v(value) { + let l27 = value; + } +} + +// object literals +var o = { + f() { + let l28 = 0; + }, + f2: () => { + let l29 = 0; + } +} + +// labels +label: let l30 = 0; +{ + label2: let l31 = 0; +} + +function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } +} + +module m3 { + label: let l34 = 0; + { + label2: let l35 = 0; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations.ts b/tests/cases/compiler/letDeclarations.ts new file mode 100644 index 00000000000..e90e355ba68 --- /dev/null +++ b/tests/cases/compiler/letDeclarations.ts @@ -0,0 +1,14 @@ +// @target: ES6 +// @declaration: true + +let l1; +let l2: number; +let l3, l4, l5 :string, l6; + +let l7 = false; +let l8: number = 23; +let l9 = 0, l10 :string = "", l11 = null; + +for(let l11 in {}) { } + +for(let l12 = 0; l12 < 9; l12++) { } diff --git a/tests/cases/compiler/letDeclarations2.ts b/tests/cases/compiler/letDeclarations2.ts new file mode 100644 index 00000000000..e7e09f0849a --- /dev/null +++ b/tests/cases/compiler/letDeclarations2.ts @@ -0,0 +1,7 @@ +// @target: ES6 +// @declaration: true + +module M { + let l1 = "s"; + export let l2 = 0; +} \ No newline at end of file diff --git a/tests/cases/compiler/propertiesAndIndexers2.ts b/tests/cases/compiler/propertiesAndIndexers2.ts new file mode 100644 index 00000000000..188635bf1dd --- /dev/null +++ b/tests/cases/compiler/propertiesAndIndexers2.ts @@ -0,0 +1,15 @@ +interface A { + [n: number]: string; + [s: string]: number; +} + +// All of these should fail. +interface B extends A { + c: string; + 3: string; + Infinity: string; + "-Infinity": string; + NaN: string; + "-NaN": string; + 6(): string; +} diff --git a/tests/cases/compiler/propertiesAndIndexersForNumericNames.ts b/tests/cases/compiler/propertiesAndIndexersForNumericNames.ts new file mode 100644 index 00000000000..3a6f4afd52b --- /dev/null +++ b/tests/cases/compiler/propertiesAndIndexersForNumericNames.ts @@ -0,0 +1,41 @@ +class C { + [i: number]: number; + + // These all have numeric names; they should error + // because their types are not compatible with the numeric indexer. + public "1": string = "number"; // Error + public "-1": string = "negative number"; // Error + public "-2.5": string = "negative number"; // Error + public "3.141592": string = "pi-sitive number"; // Error + public "1.2e-20": string = "really small number"; // Error + public "Infinity": string = "A gillion"; // Error + public "-Infinity": string = "Negative-a-gillion"; // Error + public "NaN": string = "not a number"; // Error + + // These all have *partially* numeric names, + // but should really be treated as plain string literals. + public " 1": string = "leading space"; // No error + public "1 ": string = "trailing space"; // No error + public "": string = "no nothing"; // No error + public " ": string = "just space"; // No error + public "1 0 1": string = "several numbers and spaces"; // No error + public "hunter2": string = "not a password"; // No error + public "+Infinity": string = "A gillion"; // No error + public "+NaN": string = "not a positive number"; // No error + public "-NaN": string = "not a negative number"; // No error + + + // These fall into the above category, however, they are "trickier"; + // these all are *scanned* as numeric literals, but they are not written in + // "canonical" numeric representations. + public "+1": string = "positive number (for the paranoid)"; // No error + public "1e0": string = "just one"; // No error + public "-0": string = "just zero"; // No error + public "-0e0": string = "just zero"; // No error + public "0xF00D": string = "hex food"; // No error + public "0xBEEF": string = "hex beef"; // No error + public "0123": string = "oct 83"; // No error + public "0o123": string = "explicit oct 83"; // No error + public "0b101101001010": string = "explicit binary"; // No error + public "0.000000000000000000012": string = "should've been in exponential form"; // No error +} diff --git a/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts b/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts index c0c93155671..0c6f1403220 100644 --- a/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts +++ b/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts @@ -25,16 +25,19 @@ var b1: number; var b2: boolean; var b3: string; var b4: void; +var b5: string | number; var rb1 = x in b1; var rb2 = x in b2; var rb3 = x in b3; var rb4 = x in b4; -var rb5 = x in 0; -var rb6 = x in false; -var rb7 = x in ''; -var rb8 = x in null; -var rb9 = x in undefined; +var rb5 = x in b5; +var rb6 = x in 0; +var rb7 = x in false; +var rb8 = x in ''; +var rb9 = x in null; +var rb10 = x in undefined; + // both operands are invalid var rc1 = {} in ''; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts b/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts index 400d59fff65..a4cdfd00a6b 100644 --- a/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts +++ b/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts @@ -20,4 +20,14 @@ var rb2 = x in {}; function foo(t: T) { var rb3 = x in t; -} \ No newline at end of file +} + +interface X { x: number } +interface Y { y: number } + +var c1: X | Y; +var c2: X; +var c3: Y; + +var rc1 = x in c1; +var rc2 = x in (c2 || c3); diff --git a/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts b/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts index fb3b96952fe..331d0faed9e 100644 --- a/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts +++ b/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts @@ -1,4 +1,4 @@ -interface PropertyDescriptor { +interface PropertyDescriptor2 { configurable?: boolean; enumerable?: boolean; value?: any; diff --git a/tests/cases/conformance/types/specifyingTypes/typeLiterals/parenthesizedTypes.ts b/tests/cases/conformance/types/specifyingTypes/typeLiterals/parenthesizedTypes.ts new file mode 100644 index 00000000000..92959698885 --- /dev/null +++ b/tests/cases/conformance/types/specifyingTypes/typeLiterals/parenthesizedTypes.ts @@ -0,0 +1,27 @@ +var a: string; +var a: (string); +var a: ((string) | string | (((string)))); +var a: ((((((((((((((((((((((((((((((((((((((((string)))))))))))))))))))))))))))))))))))))))); + +var b: (x: string) => string; +var b: ((x: (string)) => (string)); + +var c: string[] | number[]; +var c: (string)[] | (number)[]; +var c: ((string)[]) | ((number)[]); + +var d: (((x: string) => string) | ((x: number) => number))[]; +var d: ({ (x: string): string } | { (x: number): number })[]; +var d: Array<((x: string) => string) | ((x: number) => number)>; +var d: Array<{ (x: string): string } | { (x: number): number }>; +var d: (Array<{ (x: string): string } | { (x: number): number }>); + +var e: typeof a[]; +var e: (typeof a)[]; + +var f: (string) => string; +var f: (string: any) => string; + +var g: [string, string]; +var g: [(string), string]; +var g: [(string), (((typeof a)))]; diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts b/tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts new file mode 100644 index 00000000000..393d0e10d37 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts @@ -0,0 +1,28 @@ +// TypeScript Spec, section 4.12.2: +// If e is an expression of a function type that contains exactly one generic call signature and no other members, +// and T is a function type with exactly one non - generic call signature and no other members, then any inferences +// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed +// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5). + +declare function foo(cb: (x: number, y: string) => T): T; +declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V; +declare function baz(x: T, y: T, cb: (x: T, y: T) => U): U; + +declare function g(x: T, y: T): T; +declare function h(x: T, y: U): T[] | U[]; + +var a: number; +var a = bar(1, 1, g); // Should be number +var a = baz(1, 1, g); // Should be number + +var b: number | string; +var b = foo(g); // Should be number | string +var b = bar(1, "one", g); // Should be number | string +var b = bar("one", 1, g); // Should be number | string +var b = baz(b, b, g); // Should be number | string + +var d: number[] | string[]; +var d = foo(h); // Should be number[] | string[] +var d = bar(1, "one", h); // Should be number[] | string[] +var d = bar("one", 1, h); // Should be number[] | string[] +var d = baz(d, d, g); // Should be number[] | string[] diff --git a/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts b/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts index 917ed526d69..79d3174b542 100644 --- a/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts +++ b/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts @@ -28,7 +28,7 @@ goTo.marker('2'); verify.quickInfoIs('(var) c1: {\n name: string;\n age: number;\n}[]'); goTo.marker('3'); -verify.quickInfoIs('(var) c2: Array<{\n\ +verify.quickInfoIs('(var) c2: ({\n\ name: string;\n\ age: number;\n\ address: string;\n\ @@ -36,7 +36,7 @@ verify.quickInfoIs('(var) c2: Array<{\n\ name: string;\n\ age: number;\n\ dob: Date;\n\ -}>'); +})[]'); goTo.marker('4'); verify.quickInfoIs('(var) c2a: {\n name: string;\n age: number;\n}[]'); diff --git a/tests/cases/fourslash/breakpointValidationArrayLiteralExpressions.ts b/tests/cases/fourslash/breakpointValidationArrayLiteralExpressions.ts new file mode 100644 index 00000000000..efa3e6fbef2 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationArrayLiteralExpressions.ts @@ -0,0 +1,23 @@ +/// + +// @BaselineFile: bpSpan_arrayLiteralExpressions.baseline +// @Filename: bpSpan_arrayLiteralExpressions.ts +////var a = [10, 20, 30]; +////function foo(a: number) { +//// return a; +////} +////a = [foo(30), (function () { +//// return 30; +////})()]; +////function bar() { +//// return a; +////} +////var x = bar()[0]; +////x = (function () { +//// return a; +////})()[x]; +////a[(function () { +//// return x; +////})()]; + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationBinaryExpressions.ts b/tests/cases/fourslash/breakpointValidationBinaryExpressions.ts new file mode 100644 index 00000000000..55cc6ea3ee7 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationBinaryExpressions.ts @@ -0,0 +1,17 @@ +/// + +// @BaselineFile: bpSpan_binaryExpressions.baseline +// @Filename: bpSpan_binaryExpressions.ts +////var x = 10; +////var y = 20; +////x += 30; +////x *= 0; +////x = x + 1; +////x = (function foo() { +//// return y; +////})() + y; +////x = y + 30 + (function foo() { +//// return y; +////})() * 40; + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationBreakOrContinue.ts b/tests/cases/fourslash/breakpointValidationBreakOrContinue.ts new file mode 100644 index 00000000000..f3e92a88dfb --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationBreakOrContinue.ts @@ -0,0 +1,17 @@ +/// + +// @BaselineFile: bpSpan_breakOrContinue.baseline +// @Filename: bpSpan_breakOrContinue.ts +////while (true) { +//// break; +////} +////y: while (true) { +//// break y; +////} +////while (true) { +//// continue; +////} +////z: while (true) { +//// continue z; +////} +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationClass.ts b/tests/cases/fourslash/breakpointValidationClass.ts new file mode 100644 index 00000000000..99209c465b2 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationClass.ts @@ -0,0 +1,53 @@ +/// + +// @BaselineFile: bpSpan_class.baseline +// @Filename: bpSpan_class.ts +////class Greeter { +//// constructor(public greeting: string, ...b: string[]) { +//// } +//// greet() { +//// return "

" + this.greeting + "

"; +//// } +//// private x: string; +//// private x1: number = 10; +//// private fn() { +//// return this.greeting; +//// } +//// get greetings() { +//// return this.greeting; +//// } +//// set greetings(greetings: string) { +//// this.greeting = greetings; +//// } +////} +////class Greeter2 { +////} +////class Greeter1 +////{ +//// constructor(public greeting: string, ...b: string[]) +//// { +//// } +//// greet() +//// { +//// return "

" + this.greeting + "

"; +//// } +//// private x: string; +//// private x1: number = 10; +//// private fn() +//// { +//// return this.greeting; +//// } +//// get greetings() +//// { +//// return this.greeting; +//// } +//// set greetings(greetings: string) +//// { +//// this.greeting = greetings; +//// } +////} +////class Greeter12 +////{ +////} + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationClassAmbient.ts b/tests/cases/fourslash/breakpointValidationClassAmbient.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationClassAmbient.ts rename to tests/cases/fourslash/breakpointValidationClassAmbient.ts diff --git a/tests/cases/fourslash_old/breakpointValidationClasses.ts b/tests/cases/fourslash/breakpointValidationClasses.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationClasses.ts rename to tests/cases/fourslash/breakpointValidationClasses.ts diff --git a/tests/cases/fourslash/breakpointValidationConditionalExpressions.ts b/tests/cases/fourslash/breakpointValidationConditionalExpressions.ts new file mode 100644 index 00000000000..81a19f3fab1 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationConditionalExpressions.ts @@ -0,0 +1,16 @@ +/// + +// @BaselineFile: bpSpan_conditionalExpressions.baseline +// @Filename: bpSpan_conditionalExpressions.ts +////var x = 10; +////var y = x ? x + 10 : 30; +////var z = (function foo() { +//// return x; +////})() ? y : function bar() { +//// return x; +////} (); +////x = y ? (function () { +//// return z; +////})() : 10; + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationDebugger.ts b/tests/cases/fourslash/breakpointValidationDebugger.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationDebugger.ts rename to tests/cases/fourslash/breakpointValidationDebugger.ts diff --git a/tests/cases/fourslash/breakpointValidationDo.ts b/tests/cases/fourslash/breakpointValidationDo.ts new file mode 100644 index 00000000000..ce7863a78e2 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationDo.ts @@ -0,0 +1,22 @@ +/// + +// @BaselineFile: bpSpan_do.baseline +// @Filename: bpSpan_do.ts +////var i = 0; +////do +////{ +//// i++; +////} while (i < 10); +////do { +//// i++; +////} while (i < 20); +////do { +//// i++; +////} +////while (i < 30); +////do { +//// i--; +////} while ((function () { +//// return 30 * i; +//// })() !== i); +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationEnums.ts b/tests/cases/fourslash/breakpointValidationEnums.ts new file mode 100644 index 00000000000..9d45462013a --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationEnums.ts @@ -0,0 +1,48 @@ +/// + +// @BaselineFile: bpSpan_enums.baseline +// @Filename: bpSpan_enums.ts +////enum e { +//// x, +//// y, +//// x +////} +////enum e2 { +//// x = 10, +//// y = 10, +//// z, +//// x2 +////} +////enum e3 { +////} +////declare enum e4 { +//// x, +//// y, +//// z, +//// x2 +////} +////enum e11 +////{ +//// x, +//// y, +//// x +////} +////enum e12 +////{ +//// x = 10, +//// y = 10, +//// z, +//// x2 +////} +////enum e13 +////{ +////} +////declare enum e14 +////{ +//// x, +//// y, +//// z, +//// x2 +////} + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationExportAssignment.ts b/tests/cases/fourslash/breakpointValidationExportAssignment.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationExportAssignment.ts rename to tests/cases/fourslash/breakpointValidationExportAssignment.ts diff --git a/tests/cases/fourslash_old/breakpointValidationFor.ts b/tests/cases/fourslash/breakpointValidationFor.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationFor.ts rename to tests/cases/fourslash/breakpointValidationFor.ts diff --git a/tests/cases/fourslash_old/breakpointValidationForIn.ts b/tests/cases/fourslash/breakpointValidationForIn.ts similarity index 66% rename from tests/cases/fourslash_old/breakpointValidationForIn.ts rename to tests/cases/fourslash/breakpointValidationForIn.ts index da15dd61f10..924433520c7 100644 --- a/tests/cases/fourslash_old/breakpointValidationForIn.ts +++ b/tests/cases/fourslash/breakpointValidationForIn.ts @@ -16,5 +16,11 @@ ////{ //// WScript.Echo(x); ////} +////var z = 10; +////for (x in function foo() { +//// return new String(); +////}) { +//// z++; +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationFunctionExpressions.ts b/tests/cases/fourslash/breakpointValidationFunctionExpressions.ts similarity index 50% rename from tests/cases/fourslash_old/breakpointValidationFunctionExpressions.ts rename to tests/cases/fourslash/breakpointValidationFunctionExpressions.ts index e47a56cc08f..c4b145270a8 100644 --- a/tests/cases/fourslash_old/breakpointValidationFunctionExpressions.ts +++ b/tests/cases/fourslash/breakpointValidationFunctionExpressions.ts @@ -10,5 +10,17 @@ ////greet("Hello"); ////var incrGreetings = () => greetings++; ////var greetNewMsg = msg => greet(msg); -debugger; +////greetNewMsg = function (msg: string) { +//// return greet(msg); +////}; +////function bar(a = function foo() { +//// return greetings; +////}) { +//// if (!a()) { +//// return a; +//// } +//// return function bar() { +//// return -greetings; +//// }; +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationFunctions.ts b/tests/cases/fourslash/breakpointValidationFunctions.ts new file mode 100644 index 00000000000..0f38394d8e0 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationFunctions.ts @@ -0,0 +1,49 @@ +/// + +// @BaselineFile: bpSpan_functions.baseline +// @Filename: bpSpan_functions.ts +////var greetings = 0; +////function greet(greeting: string): number { +//// greetings++; +//// return greetings; +////} +////function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { +//// greetings++; +//// return greetings; +////} +////function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) +////{ +//// return; +////} +////module m { +//// var greetings = 0; +//// function greet(greeting: string): number { +//// greetings++; +//// return greetings; +//// } +//// function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { +//// greetings++; +//// return greetings; +//// } +//// function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) +//// { +//// return; +//// } +////} +////module m1 { +//// var greetings = 0; +//// export function greet(greeting: string): number { +//// greetings++; +//// return greetings; +//// } +//// export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { +//// greetings++; +//// return greetings; +//// } +//// export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) +//// { +//// return; +//// } +////} + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationIfElse.ts b/tests/cases/fourslash/breakpointValidationIfElse.ts similarity index 69% rename from tests/cases/fourslash_old/breakpointValidationIfElse.ts rename to tests/cases/fourslash/breakpointValidationIfElse.ts index 6df1b844a70..1b5bbc93fb8 100644 --- a/tests/cases/fourslash_old/breakpointValidationIfElse.ts +++ b/tests/cases/fourslash/breakpointValidationIfElse.ts @@ -19,4 +19,9 @@ ////} else { //// i--; ////} +////if (function foo() { +//// return 30; +////} ()) { +//// i++; +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationImport.ts b/tests/cases/fourslash/breakpointValidationImport.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationImport.ts rename to tests/cases/fourslash/breakpointValidationImport.ts diff --git a/tests/cases/fourslash/breakpointValidationInBlankLine.ts b/tests/cases/fourslash/breakpointValidationInBlankLine.ts new file mode 100644 index 00000000000..03814fd8157 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationInBlankLine.ts @@ -0,0 +1,9 @@ +/// + +// @BaselineFile: bpSpan_inBlankLine.baseline +// @Filename: bpSpan_inBlankLine.ts +////var x = 10; +//// +////var y = 10; + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationInComments.ts b/tests/cases/fourslash/breakpointValidationInComments.ts new file mode 100644 index 00000000000..3369db00eeb --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationInComments.ts @@ -0,0 +1,10 @@ +/// + +// @BaselineFile: bpSpan_inComments.baseline +// @Filename: bpSpan_inComments.ts +/////*comment here*/ var x = 10; /*comment here*/ +////// comment only line +/////*multiline comment +////another line of multiline comment */ var y = 10; // comment here + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationInterface.ts b/tests/cases/fourslash/breakpointValidationInterface.ts new file mode 100644 index 00000000000..07c34190fa8 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationInterface.ts @@ -0,0 +1,29 @@ +/// + +// @BaselineFile: bpSpan_interface.baseline +// @Filename: bpSpan_interface.ts +////interface I { +//// property: string; +//// method(): number; +//// (a: string): string; +//// new (a: string): I; +//// [a: number]: number; +////} +////module m { +//// interface I1 { +//// property: string; +//// method(): number; +//// (a: string): string; +//// new (a: string): I; +//// [a: number]: number; +//// } +//// export interface I2 { +//// property: string; +//// method(): number; +//// (a: string): string; +//// new (a: string): I; +//// [a: number]: number; +//// } +////} + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationLabeled.ts b/tests/cases/fourslash/breakpointValidationLabeled.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationLabeled.ts rename to tests/cases/fourslash/breakpointValidationLabeled.ts diff --git a/tests/cases/fourslash/breakpointValidationModule.ts b/tests/cases/fourslash/breakpointValidationModule.ts new file mode 100644 index 00000000000..3427cef72b3 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationModule.ts @@ -0,0 +1,42 @@ +/// + +// @BaselineFile: bpSpan_module.baseline +// @Filename: bpSpan_module.ts +////module m2 { +//// var a = 10; +//// a++; +////} +////module m3 { +//// module m4 { +//// export var x = 30; +//// } +//// +//// export function foo() { +//// return m4.x; +//// } +////} +////module m4 { +//// interface I { } +////} +////module m12 +////{ +//// var a = 10; +//// a++; +////} +////module m13 +////{ +//// module m14 +//// { +//// export var x = 30; +//// } +//// +//// export function foo() { +//// return m4.x; +//// } +////} +////module m14 +////{ +//// interface I { } +////} + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationModuleAmbient.ts b/tests/cases/fourslash/breakpointValidationModuleAmbient.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationModuleAmbient.ts rename to tests/cases/fourslash/breakpointValidationModuleAmbient.ts diff --git a/tests/cases/fourslash_old/breakpointValidationModuleEmpty.ts b/tests/cases/fourslash/breakpointValidationModuleEmpty.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationModuleEmpty.ts rename to tests/cases/fourslash/breakpointValidationModuleEmpty.ts diff --git a/tests/cases/fourslash/breakpointValidationObjectLiteralExpressions.ts b/tests/cases/fourslash/breakpointValidationObjectLiteralExpressions.ts new file mode 100644 index 00000000000..fa05a09187c --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationObjectLiteralExpressions.ts @@ -0,0 +1,33 @@ +/// + +// @BaselineFile: bpSpan_objectLiteralExpressions.baseline +// @Filename: bpSpan_objectLiteralExpressions.ts +////var x = { +//// a: 10, +//// b: () => 10, +//// someMethod() { +//// return "Hello"; +//// }, +//// get y() { +//// return 30; +//// }, +//// set z(x: number) { +//// var bar = x; +//// } +////}; +////var a = ({ +//// a: 10, +//// b: () => 10, +//// someMethod() { +//// return "Hello"; +//// }, +//// get y() { +//// return 30; +//// }, +//// set z(x: number) { +//// var bar = x; +//// } +////}).someMethod; +////a(); + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationParenCallOrNewExpressions.ts b/tests/cases/fourslash/breakpointValidationParenCallOrNewExpressions.ts new file mode 100644 index 00000000000..874a848f461 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationParenCallOrNewExpressions.ts @@ -0,0 +1,35 @@ +/// + +// @BaselineFile: bpSpan_parenCallOrNewExpressions.baseline +// @Filename: bpSpan_parenCallOrNewExpressions.ts +////function foo(a: number) { +//// return a; +////} +////foo((function bar() { +//// return foo(40); +////})()); +////var y = foo((function () { +//// return foo(40); +////})());; +////class greeter { +//// constructor(a: number) { +//// } +////} +////foo(30); +////foo(40 + y); +////y = foo(30); +////y = foo(500 + y); +////new greeter((function bar() { +//// return foo(40); +////})()); +////var anotherGreeter = new greeter((function bar() { +//// return foo(40); +////})()); +////anotherGreeter = new greeter(30); +////anotherGreeter = new greeter(40 + y); +////new greeter(30); +////new greeter(40 + y); +////function foo2(x: number, y: string) { +////} +////foo2(foo(30), foo(40).toString()); +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationStatements.ts b/tests/cases/fourslash/breakpointValidationStatements.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationStatements.ts rename to tests/cases/fourslash/breakpointValidationStatements.ts diff --git a/tests/cases/fourslash_old/breakpointValidationSwitch.ts b/tests/cases/fourslash/breakpointValidationSwitch.ts similarity index 70% rename from tests/cases/fourslash_old/breakpointValidationSwitch.ts rename to tests/cases/fourslash/breakpointValidationSwitch.ts index 82c5fff9dea..6fbe676d67a 100644 --- a/tests/cases/fourslash_old/breakpointValidationSwitch.ts +++ b/tests/cases/fourslash/breakpointValidationSwitch.ts @@ -31,4 +31,12 @@ //// x = x * 10; //// } ////} +////switch ((function foo() { +//// return x * 30; +////})()) { +//// case (function bar() { +//// return 30; +//// })(): +//// x++; +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationTryCatchFinally.ts b/tests/cases/fourslash/breakpointValidationTryCatchFinally.ts similarity index 65% rename from tests/cases/fourslash_old/breakpointValidationTryCatchFinally.ts rename to tests/cases/fourslash/breakpointValidationTryCatchFinally.ts index bbeab4f6b00..3aa2b499542 100644 --- a/tests/cases/fourslash_old/breakpointValidationTryCatchFinally.ts +++ b/tests/cases/fourslash/breakpointValidationTryCatchFinally.ts @@ -24,5 +24,13 @@ ////{ //// x = x * 10; ////} +////try { +//// throw (function foo() { +//// new Error(x.toString()); +//// })(); +////} +////finally { +//// x++; +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationTypeAssertionExpressions.ts b/tests/cases/fourslash/breakpointValidationTypeAssertionExpressions.ts new file mode 100644 index 00000000000..9d79f1e3fb3 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationTypeAssertionExpressions.ts @@ -0,0 +1,13 @@ +/// + +// @BaselineFile: bpSpan_typeAssertionExpressions.baseline +// @Filename: bpSpan_typeAssertionExpressions.ts +////class Greeter { +////} +////var a = new Greeter(); +////a = ( new Greeter()); +////a = (function foo() { +//// return new Greeter(); +////})(); + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationUnaryExpressions.ts b/tests/cases/fourslash/breakpointValidationUnaryExpressions.ts new file mode 100644 index 00000000000..8b937154516 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationUnaryExpressions.ts @@ -0,0 +1,15 @@ +/// + +// @BaselineFile: bpSpan_unaryExpressions.baseline +// @Filename: bpSpan_unaryExpressions.ts +////var x = 10; +////var y = 20; +////x++; +////y--; +////typeof (function foo() { +//// return y; +////})(); +////++x; +////++y; + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationVariables.ts b/tests/cases/fourslash/breakpointValidationVariables.ts new file mode 100644 index 00000000000..054826e7e09 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationVariables.ts @@ -0,0 +1,18 @@ +/// + +// @BaselineFile: bpSpan_variables.baseline +// @Filename: bpSpan_variables.ts +////var a = 10; +////var b; +////var c = 10, d, e; +////var c2, d2 = 10; +////module m { +//// var x1; +//// var x2 = 10, x3 = 10; +//// var x4, x5; +//// export var xx1; +//// export var xx2 = 10, xx3 = 10; +//// export var xx4, xx5; +////} + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationWhile.ts b/tests/cases/fourslash/breakpointValidationWhile.ts new file mode 100644 index 00000000000..fa472b77ed3 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationWhile.ts @@ -0,0 +1,22 @@ +/// + +// @BaselineFile: bpSpan_while.baseline +// @Filename: bpSpan_while.ts +////var a = 10; +////while (a == 10) { +//// a++; +////} +////while (a == 10) +////{ +//// a++; +////} +////while (a == 10) a++; +////while (a == 10) +//// a++; +////while ((function () { +//// return 30 * a; +////})() !== a) { +//// a--; +////} + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationWith.ts b/tests/cases/fourslash/breakpointValidationWith.ts new file mode 100644 index 00000000000..84e729d8efe --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationWith.ts @@ -0,0 +1,10 @@ +/// + +// @BaselineFile: bpSpan_with.baseline +// @Filename: bpSpan_with.ts +////var obj: string; +////with (obj) { +//// x = 10; +////} + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/completionEntryForConst.ts b/tests/cases/fourslash/completionEntryForConst.ts new file mode 100644 index 00000000000..f6b7cc42d63 --- /dev/null +++ b/tests/cases/fourslash/completionEntryForConst.ts @@ -0,0 +1,7 @@ +/// + +////const c = "s"; +/////**/ + +goTo.marker(); +verify.completionListContains("c", /*text*/ undefined, /*documentation*/ undefined, "constant"); \ No newline at end of file diff --git a/tests/cases/fourslash/contextualTyping.ts b/tests/cases/fourslash/contextualTyping.ts index dad6ee8b587..13fb4dc2450 100644 --- a/tests/cases/fourslash/contextualTyping.ts +++ b/tests/cases/fourslash/contextualTyping.ts @@ -242,7 +242,7 @@ verify.quickInfoIs("(var) c3t9: number[][]"); goTo.marker('23'); verify.quickInfoIs("(var) c3t10: IFoo[]"); goTo.marker('24'); -verify.quickInfoIs("(var) c3t11: {\n (n: number, s: string): string;\n}[]"); +verify.quickInfoIs("(var) c3t11: ((n: number, s: string) => string)[]"); goTo.marker('25'); verify.quickInfoIs("(parameter) n: number"); goTo.marker('26'); @@ -314,7 +314,7 @@ verify.quickInfoIs("(property) t9: number[][]"); goTo.marker('59'); verify.quickInfoIs("(property) t10: IFoo[]"); goTo.marker('60'); -verify.quickInfoIs("(property) t11: {\n (n: number, s: string): string;\n}[]"); +verify.quickInfoIs("(property) t11: ((n: number, s: string) => string)[]"); goTo.marker('61'); verify.quickInfoIs("(parameter) n: number"); goTo.marker('62'); @@ -374,7 +374,7 @@ verify.quickInfoIs("(var) c12t9: number[][]"); goTo.marker('89'); verify.quickInfoIs("(var) c12t10: IFoo[]"); goTo.marker('90'); -verify.quickInfoIs("(var) c12t11: {\n (n: number, s: string): string;\n}[]"); +verify.quickInfoIs("(var) c12t11: ((n: number, s: string) => string)[]"); goTo.marker('91'); verify.quickInfoIs("(parameter) n: number"); goTo.marker('92'); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 7be7dd63c92..c71f8987bdf 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -80,6 +80,10 @@ module FourSlashInterface { return FourSlash.currentTestState.getMarkers(); } + public marker(name?: string): Marker { + return FourSlash.currentTestState.getMarkerByName(name); + } + public ranges(): Range[] { return FourSlash.currentTestState.getRanges(); } @@ -401,11 +405,17 @@ module FourSlashInterface { FourSlash.currentTestState.verifyCompletionEntryDetails(entryName, text, documentation, kind); } + /** + * This method *requires* a contiguous, complete, and ordered stream of classifications for a file. + */ public syntacticClassificationsAre(...classifications: { classificationType: string; text: string }[]) { FourSlash.currentTestState.verifySyntacticClassifications(classifications); } - public semanticClassificationsAre(...classifications: { classificationType: string; text: string }[]) { + /** + * This method *requires* an ordered stream of classifications for a file, and spans are highly recommended. + */ + public semanticClassificationsAre(...classifications: { classificationType: string; text: string; textSpan?: TextSpan }[]) { FourSlash.currentTestState.verifySemanticClassifications(classifications); } @@ -563,61 +573,69 @@ module FourSlashInterface { } } - export class classification { - public static comment(text: string): { classificationType: string; text: string } { - return { classificationType: "comment", text: text }; + export module classification { + export function comment(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("comment", text, position); } - public static identifier(text: string): { classificationType: string; text: string } { - return { classificationType: "identifier", text: text }; + export function identifier(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("identifier", text, position); } - public static keyword(text: string): { classificationType: string; text: string } { - return { classificationType: "keyword", text: text }; + export function keyword(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("keyword", text, position); } - public static numericLiteral(text: string): { classificationType: string; text: string } { - return { classificationType: "numericLiteral", text: text }; + export function numericLiteral(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("numericLiteral", text, position); } - public static operator(text: string): { classificationType: string; text: string } { - return { classificationType: "operator", text: text }; + export function operator(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("operator", text, position); } - public static stringLiteral(text: string): { classificationType: string; text: string } { - return { classificationType: "stringLiteral", text: text }; + export function stringLiteral(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("stringLiteral", text, position); } - public static whiteSpace(text: string): { classificationType: string; text: string } { - return { classificationType: "whiteSpace", text: text }; + export function whiteSpace(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("whiteSpace", text, position); } - public static text(text: string): { classificationType: string; text: string } { - return { classificationType: "text", text: text }; + export function text(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("text", text, position); } - public static punctuation(text: string): { classificationType: string; text: string } { - return { classificationType: "punctuation", text: text }; + export function punctuation(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("punctuation", text, position); } - public static className(text: string): { classificationType: string; text: string } { - return { classificationType: "className", text: text }; + export function className(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("className", text, position); } - public static enumName(text: string): { classificationType: string; text: string } { - return { classificationType: "enumName", text: text }; + export function enumName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("enumName", text, position); } - public static interfaceName(text: string): { classificationType: string; text: string } { - return { classificationType: "interfaceName", text: text }; + export function interfaceName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("interfaceName", text, position); } - public static moduleName(text: string): { classificationType: string; text: string } { - return { classificationType: "moduleName", text: text }; + export function moduleName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("moduleName", text, position); } - public static typeParameterName(text: string): { classificationType: string; text: string } { - return { classificationType: "typeParameterName", text: text }; + export function typeParameterName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("typeParameterName", text, position); + } + + function getClassification(type: string, text: string, position?: number) { + return { + classificationType: type, + text: text, + textSpan: position === undefined ? undefined : { start: position, end: position + text.length } + }; } } } @@ -635,6 +653,7 @@ module fs { function verifyOperationIsCancelled(f) { FourSlash.verifyOperationIsCancelled(f); } + var test = new FourSlashInterface.test_(); var goTo = new FourSlashInterface.goTo(); var verify = new FourSlashInterface.verify(); diff --git a/tests/cases/fourslash/genericParameterHelp.ts b/tests/cases/fourslash/genericParameterHelp.ts index a1df1cc2f32..17882485fd7 100644 --- a/tests/cases/fourslash/genericParameterHelp.ts +++ b/tests/cases/fourslash/genericParameterHelp.ts @@ -6,26 +6,12 @@ //// return null; ////} //// -////class testClass { -//// constructor(a:T, b:U, c:M){ } -////} ////// Function calls ////testFunction(/*3*/ ////testFunction(null, null, null); ////testFunction<, ,/*5*/>(null, null, null); -////// Constructor calls -////new testClass(null, null, null) -////new testClass<,,/*construcor4*/>(null, null, null) -////new testClass(null, null, null) -////// Generic types -////testClass extends testClass; // goTo.marker("1"); // verify.currentSignatureParamterCountIs(3); @@ -38,56 +24,14 @@ // verify.currentParameterHelpArgumentNameIs("U"); // verify.currentParameterSpanIs("U"); - goTo.marker("3"); - verify.currentParameterHelpArgumentNameIs("a"); - verify.currentParameterSpanIs("a: T"); +goTo.marker("3"); +verify.currentParameterHelpArgumentNameIs("a"); +verify.currentParameterSpanIs("a: T"); - // goTo.marker("4"); - // verify.currentParameterHelpArgumentNameIs("M"); - // verify.currentParameterSpanIs("M extends IFoo"); +goTo.marker("4"); +verify.currentParameterHelpArgumentNameIs("M"); +verify.currentParameterSpanIs("M extends IFoo"); - // goTo.marker("5"); - // verify.currentParameterHelpArgumentNameIs("M"); - // verify.currentParameterSpanIs("M extends IFoo"); - - // goTo.marker("construcor1"); - // verify.currentSignatureHelpIs("testClass(a: T, b: U, c: M): testClass"); - // verify.currentParameterHelpArgumentNameIs("T"); - // verify.currentParameterSpanIs("T extends IFoo"); - - // goTo.marker("construcor2"); - // verify.currentParameterHelpArgumentNameIs("U"); - // verify.currentParameterSpanIs("U"); - - //goTo.marker("construcor3"); - //verify.currentParameterHelpArgumentNameIs("T"); - //verify.currentParameterSpanIs("T extends IFoo"); - - // goTo.marker("construcor4"); - // verify.currentParameterHelpArgumentNameIs("M"); - // verify.currentParameterSpanIs("M extends IFoo"); - - // goTo.marker("construcor5"); - // verify.currentParameterHelpArgumentNameIs("U"); - // verify.currentParameterSpanIs("U"); - - // goTo.marker("type1"); - // verify.signatureHelpCountIs(1); - // verify.currentSignatureHelpIs("testClass"); - // verify.currentParameterHelpArgumentNameIs("T"); - // verify.currentParameterSpanIs("T extends IFoo"); - - // goTo.marker("type2"); - // verify.signatureHelpCountIs(1); - // verify.currentParameterHelpArgumentNameIs("T"); - // verify.currentParameterSpanIs("T extends IFoo"); - - // goTo.marker("type3"); - // verify.signatureHelpCountIs(1); - // verify.currentParameterHelpArgumentNameIs("T"); - // verify.currentParameterSpanIs("T extends IFoo"); - - // goTo.marker("type4"); - // verify.signatureHelpCountIs(1); - // verify.currentParameterHelpArgumentNameIs("M"); - // verify.currentParameterSpanIs("M extends IFoo"); \ No newline at end of file +goTo.marker("5"); +verify.currentParameterHelpArgumentNameIs("M"); +verify.currentParameterSpanIs("M extends IFoo"); \ No newline at end of file diff --git a/tests/cases/fourslash/genericParameterHelpConstructorCalls.ts b/tests/cases/fourslash/genericParameterHelpConstructorCalls.ts new file mode 100644 index 00000000000..4cbe141fcce --- /dev/null +++ b/tests/cases/fourslash/genericParameterHelpConstructorCalls.ts @@ -0,0 +1,35 @@ +/// + +////interface IFoo { } +//// +////class testClass { +//// constructor(a:T, b:U, c:M){ } +////} +//// +////// Constructor calls +////new testClass(null, null, null) +////new testClass<,,/*construcor4*/>(null, null, null) +////new testClass(null, null, null) + + // goTo.marker("construcor1"); + // verify.currentSignatureHelpIs("testClass(a: T, b: U, c: M): testClass"); + // verify.currentParameterHelpArgumentNameIs("T"); + // verify.currentParameterSpanIs("T extends IFoo"); + + // goTo.marker("construcor2"); + // verify.currentParameterHelpArgumentNameIs("U"); + // verify.currentParameterSpanIs("U"); + +goTo.marker("construcor3"); +verify.currentParameterHelpArgumentNameIs("T"); +verify.currentParameterSpanIs("T extends IFoo"); + +goTo.marker("construcor4"); +verify.currentParameterHelpArgumentNameIs("M"); +verify.currentParameterSpanIs("M extends IFoo"); + +goTo.marker("construcor5"); +verify.currentParameterHelpArgumentNameIs("U"); +verify.currentParameterSpanIs("U"); diff --git a/tests/cases/fourslash/genericParameterHelpTypeReferences.ts b/tests/cases/fourslash/genericParameterHelpTypeReferences.ts new file mode 100644 index 00000000000..346cf7191c1 --- /dev/null +++ b/tests/cases/fourslash/genericParameterHelpTypeReferences.ts @@ -0,0 +1,34 @@ +/// + +////interface IFoo { } +//// +////class testClass { +//// constructor(a:T, b:U, c:M){ } +////} +//// +////// Generic types +////testClass extends testClass; + + // goTo.marker("type1"); + // verify.signatureHelpCountIs(1); + // verify.currentSignatureHelpIs("testClass"); + // verify.currentParameterHelpArgumentNameIs("T"); + // verify.currentParameterSpanIs("T extends IFoo"); + + // goTo.marker("type2"); + // verify.signatureHelpCountIs(1); + // verify.currentParameterHelpArgumentNameIs("T"); + // verify.currentParameterSpanIs("T extends IFoo"); + + // goTo.marker("type3"); + // verify.signatureHelpCountIs(1); + // verify.currentParameterHelpArgumentNameIs("T"); + // verify.currentParameterSpanIs("T extends IFoo"); + + // goTo.marker("type4"); + // verify.signatureHelpCountIs(1); + // verify.currentParameterHelpArgumentNameIs("M"); + // verify.currentParameterSpanIs("M extends IFoo"); \ No newline at end of file diff --git a/tests/cases/fourslash/genericTypeArgumentInference1.ts b/tests/cases/fourslash/genericTypeArgumentInference1.ts index eadec7ad0ce..5c30363d35c 100644 --- a/tests/cases/fourslash/genericTypeArgumentInference1.ts +++ b/tests/cases/fourslash/genericTypeArgumentInference1.ts @@ -20,7 +20,7 @@ goTo.marker('1'); verify.quickInfoIs('(var) r: string | number | boolean'); goTo.marker('11'); -verify.quickInfoIs('(method) Underscore.Static.all(list: Array, iterator?: Underscore.Iterator, context?: any): string | number | boolean'); +verify.quickInfoIs('(method) Underscore.Static.all(list: (string | number | boolean)[], iterator?: Underscore.Iterator, context?: any): string | number | boolean'); goTo.marker('2'); verify.quickInfoIs('(var) r2: boolean'); diff --git a/tests/cases/fourslash/genericTypeArgumentInference2.ts b/tests/cases/fourslash/genericTypeArgumentInference2.ts index a660675c51e..bb59cc8eed6 100644 --- a/tests/cases/fourslash/genericTypeArgumentInference2.ts +++ b/tests/cases/fourslash/genericTypeArgumentInference2.ts @@ -20,7 +20,7 @@ goTo.marker('1'); verify.quickInfoIs('(var) r: string | number | boolean'); goTo.marker('11'); -verify.quickInfoIs('(method) Underscore.Static.all(list: Array, iterator?: Underscore.Iterator, context?: any): string | number | boolean'); +verify.quickInfoIs('(method) Underscore.Static.all(list: (string | number | boolean)[], iterator?: Underscore.Iterator, context?: any): string | number | boolean'); goTo.marker('2'); verify.quickInfoIs('(var) r2: boolean'); diff --git a/tests/cases/fourslash_old/nameOrDottedNameClasses.ts b/tests/cases/fourslash/nameOrDottedNameClasses.ts similarity index 100% rename from tests/cases/fourslash_old/nameOrDottedNameClasses.ts rename to tests/cases/fourslash/nameOrDottedNameClasses.ts diff --git a/tests/cases/fourslash_old/nameOrDottedNameStatements.ts b/tests/cases/fourslash/nameOrDottedNameStatements.ts similarity index 100% rename from tests/cases/fourslash_old/nameOrDottedNameStatements.ts rename to tests/cases/fourslash/nameOrDottedNameStatements.ts diff --git a/tests/cases/fourslash/navbar_const.ts b/tests/cases/fourslash/navbar_const.ts new file mode 100644 index 00000000000..ede2a9cd1d8 --- /dev/null +++ b/tests/cases/fourslash/navbar_const.ts @@ -0,0 +1,13 @@ +/// + +//// {| "itemName": "c", "kind": "constant", "parentName": "" |}const c = 0; + +test.markers().forEach(marker => { + verify.getScriptLexicalStructureListContains( + marker.data.itemName, + marker.data.kind, + marker.fileName, + marker.data.parentName, + marker.data.isAdditionalRange, + marker.position); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForConstDeclaration.ts b/tests/cases/fourslash/quickInfoForConstDeclaration.ts new file mode 100644 index 00000000000..dc234b04050 --- /dev/null +++ b/tests/cases/fourslash/quickInfoForConstDeclaration.ts @@ -0,0 +1,6 @@ +/// + +////const /**/c = 0 ; + +goTo.marker(); +verify.quickInfoIs("(constant) c: number"); \ No newline at end of file diff --git a/tests/cases/fourslash/semanticClassification1.ts b/tests/cases/fourslash/semanticClassification1.ts index ad9e88ea842..4eb7f2a32ed 100644 --- a/tests/cases/fourslash/semanticClassification1.ts +++ b/tests/cases/fourslash/semanticClassification1.ts @@ -1,11 +1,15 @@ /// -//// module M { -//// export interface I { +//// module /*0*/M { +//// export interface /*1*/I { //// } //// } -//// interface X extends M.I { } +//// interface /*2*/X extends /*3*/M./*4*/I { } var c = classification; verify.semanticClassificationsAre( - c.moduleName("M"), c.interfaceName("I"), c.interfaceName("X"), c.moduleName("M"), c.interfaceName("I")); + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.interfaceName("X", test.marker("2").position), + c.moduleName("M", test.marker("3").position), + c.interfaceName("I", test.marker("4").position)); diff --git a/tests/cases/fourslash/semanticClassification2.ts b/tests/cases/fourslash/semanticClassification2.ts index 810636dba3e..f7f6340e5bd 100644 --- a/tests/cases/fourslash/semanticClassification2.ts +++ b/tests/cases/fourslash/semanticClassification2.ts @@ -1,6 +1,6 @@ /// -//// interface Thing { +//// interface /*0*/Thing { //// toExponential(): number; //// } //// @@ -8,4 +8,4 @@ //// Thing.toExponential(); var c = classification; -verify.semanticClassificationsAre(c.interfaceName("Thing")); \ No newline at end of file +verify.semanticClassificationsAre(c.interfaceName("Thing", test.marker("0").position)); \ No newline at end of file diff --git a/tests/cases/fourslash/semanticClassification3.ts b/tests/cases/fourslash/semanticClassification3.ts deleted file mode 100644 index c1d8da243e7..00000000000 --- a/tests/cases/fourslash/semanticClassification3.ts +++ /dev/null @@ -1,12 +0,0 @@ -/// - -////declare module M { -//// interface I { -//// -//// } -////} -//// -////var M = { I: 10 }; - -var c = classification; -verify.semanticClassificationsAre(c.moduleName("M"), c.interfaceName("I"), c.moduleName("M")); \ No newline at end of file diff --git a/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName1.ts b/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName1.ts new file mode 100644 index 00000000000..2b8b6824558 --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName1.ts @@ -0,0 +1,24 @@ +/// + +////module /*0*/M { +//// export interface /*1*/I { +//// } +//// var x = 10; +////} +//// +////var /*2*/M = { +//// foo: 10, +//// bar: 20 +////} +//// +////var v: /*3*/M./*4*/I; +//// +////var x = /*5*/M; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.moduleName("M", test.marker("3").position), + c.interfaceName("I", test.marker("4").position), + c.moduleName("M", test.marker("5").position)); diff --git a/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName2.ts b/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName2.ts new file mode 100644 index 00000000000..5d2ed9844cc --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName2.ts @@ -0,0 +1,28 @@ +/// + +////module /*0*/M { +//// export interface /*1*/I { +//// } +////} +//// +////module /*2*/M { +//// var x = 10; +////} +//// +////var /*3*/M = { +//// foo: 10, +//// bar: 20 +////} +//// +////var v: /*4*/M./*5*/I; +//// +////var x = /*6*/M; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.moduleName("M", test.marker("2").position), + c.moduleName("M", test.marker("4").position), + c.interfaceName("I", test.marker("5").position), + c.moduleName("M", test.marker("6").position)); diff --git a/tests/cases/fourslash/semanticClassificationModules.ts b/tests/cases/fourslash/semanticClassificationModules.ts new file mode 100644 index 00000000000..86c2819983a --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationModules.ts @@ -0,0 +1,19 @@ +/// + +////module /*0*/M { +//// export var v; +//// export interface /*1*/I { +//// } +////} +//// +////var x: /*2*/M./*3*/I = /*4*/M.v; +////var y = /*5*/M; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.moduleName("M", test.marker("2").position), + c.interfaceName("I", test.marker("3").position), + c.moduleName("M", test.marker("4").position), + c.moduleName("M", test.marker("5").position)); \ No newline at end of file diff --git a/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName1.ts b/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName1.ts new file mode 100644 index 00000000000..e7486c2c0cb --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName1.ts @@ -0,0 +1,14 @@ +/// + +////declare module /*0*/M { +//// interface /*1*/I { +//// +//// } +////} +//// +////var M = { I: 10 }; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position)); \ No newline at end of file diff --git a/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName2.ts b/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName2.ts new file mode 100644 index 00000000000..f90efd7518d --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName2.ts @@ -0,0 +1,22 @@ +/// + +////module /*0*/M { +//// export interface /*1*/I { +//// } +////} +//// +////var /*2*/M = { +//// foo: 10, +//// bar: 20 +////} +//// +////var v: /*3*/M./*4*/I; +//// +////var x = /*5*/M; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.moduleName("M", test.marker("3").position), + c.interfaceName("I", test.marker("4").position)); diff --git a/tests/cases/fourslash/semanticClassificationWithUnionTypes.ts b/tests/cases/fourslash/semanticClassificationWithUnionTypes.ts new file mode 100644 index 00000000000..40a7f409685 --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationWithUnionTypes.ts @@ -0,0 +1,24 @@ +////module /*0*/M { +//// export interface /*1*/I { +//// } +////} +//// +////interface /*2*/I { +////} +////class /*3*/C { +////} +//// +////var M: /*4*/M./*5*/I | /*6*/I | /*7*/C; +////var I: typeof M | typeof /*8*/C; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.interfaceName("I", test.marker("2").position), + c.className("C", test.marker("3").position), + c.moduleName("M", test.marker("4").position), + c.interfaceName("I", test.marker("5").position), + c.interfaceName("I", test.marker("6").position), + c.className("C", test.marker("7").position), + c.className("C", test.marker("8").position)); \ No newline at end of file diff --git a/tests/cases/fourslash/signatureHelpOnNestedOverloads.ts b/tests/cases/fourslash/signatureHelpOnNestedOverloads.ts index 476d79a8243..e657000c113 100644 --- a/tests/cases/fourslash/signatureHelpOnNestedOverloads.ts +++ b/tests/cases/fourslash/signatureHelpOnNestedOverloads.ts @@ -15,6 +15,6 @@ verify.currentParameterSpanIs("x: string"); edit.insert("'',"); verify.signatureHelpCountIs(2); -// verify.currentSignatureHelpIs("fn2(x: string, y: number): any"); -// verify.currentParameterHelpArgumentNameIs("y"); -// verify.currentParameterSpanIs("y: number"); +verify.currentSignatureHelpIs("fn2(x: string, y: number): any"); +verify.currentParameterHelpArgumentNameIs("y"); +verify.currentParameterSpanIs("y: number"); diff --git a/tests/cases/fourslash/syntacticClassifications1.ts b/tests/cases/fourslash/syntacticClassifications1.ts index e70a4b672ff..88f655683a3 100644 --- a/tests/cases/fourslash/syntacticClassifications1.ts +++ b/tests/cases/fourslash/syntacticClassifications1.ts @@ -18,7 +18,6 @@ //// } //// } -debugger; var c = classification; verify.syntacticClassificationsAre( c.comment("// comment"), diff --git a/tests/cases/fourslash/syntacticClassificationsFunctionWithComments.ts b/tests/cases/fourslash/syntacticClassificationsFunctionWithComments.ts new file mode 100644 index 00000000000..eeaf4a7033f --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsFunctionWithComments.ts @@ -0,0 +1,25 @@ +/// + +/////** +//// * This is my function. +//// * There are many like it, but this one is mine. +//// */ +////function myFunction(/* x */ x: any) { +//// var y = x ? x++ : ++x; +////} +////// end of file + +var firstCommentText = +"\ +/**\n\ + * This is my function.\n\ + * There are many like it, but this one is mine.\n\ + */"; + +var c = classification; +verify.syntacticClassificationsAre( + c.comment(firstCommentText), + c.keyword("function"), c.text("myFunction"), c.punctuation("("), c.comment("/* x */"), c.text("x"), c.punctuation(":"), c.keyword("any"), c.punctuation(")"), c.punctuation("{"), + c.keyword("var"), c.text("y"), c.operator("="), c.text("x"), c.operator("?"), c.text("x"), c.operator("++"), c.operator(":"), c.operator("++"), c.text("x"), c.punctuation(";"), + c.punctuation("}"), + c.comment("// end of file")); \ No newline at end of file diff --git a/tests/cases/fourslash/syntacticClassificationsObjectLiteral.ts b/tests/cases/fourslash/syntacticClassificationsObjectLiteral.ts new file mode 100644 index 00000000000..a7e8f7b7b07 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsObjectLiteral.ts @@ -0,0 +1,25 @@ +/// + +////var v = 10e0; +////var x = { +//// p1: 1, +//// p2: 2, +//// any: 3, +//// function: 4, +//// var: 5, +//// void: void 0, +//// v: v += v, +////}; + +var c = classification; +verify.syntacticClassificationsAre( + c.keyword("var"), c.text("v"), c.operator("="), c.numericLiteral("10e0"), c.punctuation(";"), + c.keyword("var"), c.text("x"), c.operator("="), c.punctuation("{"), + c.text("p1"), c.punctuation(":"), c.numericLiteral("1"), c.punctuation(","), + c.text("p2"), c.punctuation(":"), c.numericLiteral("2"), c.punctuation(","), + c.text("any"), c.punctuation(":"), c.numericLiteral("3"), c.punctuation(","), + c.text("function"), c.punctuation(":"), c.numericLiteral("4"), c.punctuation(","), + c.text("var"), c.punctuation(":"), c.numericLiteral("5"), c.punctuation(","), + c.text("void"), c.punctuation(":"), c.keyword("void"), c.numericLiteral("0"), c.punctuation(","), + c.text("v"), c.punctuation(":"), c.text("v"), c.operator("+="), c.text("v"), c.punctuation(","), + c.punctuation("}"), c.punctuation(";")); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationClass.ts b/tests/cases/fourslash_old/breakpointValidationClass.ts deleted file mode 100644 index e9104bc6d27..00000000000 --- a/tests/cases/fourslash_old/breakpointValidationClass.ts +++ /dev/null @@ -1,23 +0,0 @@ -/// - -// @BaselineFile: bpSpan_class.baseline -// @Filename: bpSpan_class.ts -////class Greeter { -//// constructor(public greeting: string, ...b: string[]) { -//// } -//// greet() { -//// return "

" + this.greeting + "

"; -//// } -//// private x: string; -//// private x1: number = 10; -//// private fn() { -//// return this.greeting; -//// } -//// get greetings() { -//// return this.greeting; -//// } -//// set greetings(greetings: string) { -//// this.greeting = greetings; -//// } -////} -verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationDo.ts b/tests/cases/fourslash_old/breakpointValidationDo.ts deleted file mode 100644 index 0c1c28b4b44..00000000000 --- a/tests/cases/fourslash_old/breakpointValidationDo.ts +++ /dev/null @@ -1,14 +0,0 @@ -/// - -// @BaselineFile: bpSpan_do.baseline -// @Filename: bpSpan_do.ts -////var i = 0; -////do -////{ -//// i++; -////} while (i < 10); -////do { -//// i++; -////} while (i < 20); - -verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationEnums.ts b/tests/cases/fourslash_old/breakpointValidationEnums.ts deleted file mode 100644 index 4423941b1e4..00000000000 --- a/tests/cases/fourslash_old/breakpointValidationEnums.ts +++ /dev/null @@ -1,19 +0,0 @@ -/// - -// @BaselineFile: bpSpan_enums.baseline -// @Filename: bpSpan_enums.ts -////enum e { -//// x, -//// y, -//// x -////} -////enum e2 { -//// x = 10, -//// y = 10, -//// z, -//// x2 -////} -////enum e3 { -////} - -verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationFunctions.ts b/tests/cases/fourslash_old/breakpointValidationFunctions.ts deleted file mode 100644 index 4ab0c7c577e..00000000000 --- a/tests/cases/fourslash_old/breakpointValidationFunctions.ts +++ /dev/null @@ -1,18 +0,0 @@ -/// - -// @BaselineFile: bpSpan_functions.baseline -// @Filename: bpSpan_functions.ts -////var greetings = 0; -////function greet(greeting: string): number { -//// greetings++; -//// return greetings; -////} -////function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { -//// greetings++; -//// return greetings; -////} -////function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) -////{ -//// return; -////} -verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationModule.ts b/tests/cases/fourslash_old/breakpointValidationModule.ts deleted file mode 100644 index ec862853f84..00000000000 --- a/tests/cases/fourslash_old/breakpointValidationModule.ts +++ /dev/null @@ -1,19 +0,0 @@ -/// - -// @BaselineFile: bpSpan_module.baseline -// @Filename: bpSpan_module.ts -////module m2 { -//// var a = 10; -//// a++; -////} -////module m3 { -//// module m4 { -//// export var x = 30; -//// } -//// -//// export function foo() { -//// return m4.x; -//// } -////} - -verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationVariables.ts b/tests/cases/fourslash_old/breakpointValidationVariables.ts deleted file mode 100644 index 3f581ac80f7..00000000000 --- a/tests/cases/fourslash_old/breakpointValidationVariables.ts +++ /dev/null @@ -1,10 +0,0 @@ -/// - -// @BaselineFile: bpSpan_variables.baseline -// @Filename: bpSpan_variables.ts -////var a = 10; -////var b; -////var c = 10, d, e; -////var c2, d2 = 10; - -verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationWhile.ts b/tests/cases/fourslash_old/breakpointValidationWhile.ts deleted file mode 100644 index 59d3c4fda3b..00000000000 --- a/tests/cases/fourslash_old/breakpointValidationWhile.ts +++ /dev/null @@ -1,13 +0,0 @@ -/// - -// @BaselineFile: bpSpan_while.baseline -// @Filename: bpSpan_while.ts -////var a = 10; -////while (a == 10) { -//// a++; -////} -////while (a == 10) -////{ -//// a++; -////} -verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/nameOrDottedName_Classes.ts b/tests/cases/fourslash_old/nameOrDottedName_Classes.ts deleted file mode 100644 index 9aa63a7a473..00000000000 --- a/tests/cases/fourslash_old/nameOrDottedName_Classes.ts +++ /dev/null @@ -1,43 +0,0 @@ -/// - -// @BaselineFile: nameOrDottedSpan_classes.baseline -// @Filename: nameOrDottedSpan_classes.ts -////module Foo.Bar { -//// "use strict"; -//// -//// class Greeter { -//// constructor(public greeting: string) { -//// } -//// -//// greet() { -//// return "

" + this.greeting + "

"; -//// } -//// } -//// -//// -//// function foo(greeting: string): Greeter { -//// return new Greeter(greeting); -//// } -//// -//// var greeter = new Greeter("Hello, world!"); -//// var str = greeter.greet(); -//// -//// function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { -//// var greeters: Greeter[] = []; /* inline block comment */ -//// greeters[0] = new Greeter(greeting); -//// for (var i = 0; i < restGreetings.length; i++) { -//// greeters.push(new Greeter(restGreetings[i])); -//// } -//// -//// return greeters; -//// } -//// -//// var b = foo2("Hello", "World", "!"); -//// // This is simple signle line comment -//// for (var j = 0; j < b.length; j++) { -//// b[j].greet(); -//// } -////} - - -verify.baselineCurrentFileNameOrDottedNameSpans(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/nameOrDottedName_Statements.ts b/tests/cases/fourslash_old/nameOrDottedName_Statements.ts deleted file mode 100644 index 52c9c30a75d..00000000000 --- a/tests/cases/fourslash_old/nameOrDottedName_Statements.ts +++ /dev/null @@ -1,90 +0,0 @@ -/// - -// @BaselineFile: nameOrDottedSpan_stmts.baseline -// @Filename: nameOrDottedSpan_stmts.ts -////function f() { -//// var y; -//// var x = 0; -//// for (var i = 0; i < 10; i++) { -//// x += i; -//// x *= 0; -//// } -//// if (x > 17) { -//// x /= 9; -//// } else { -//// x += 10; -//// x++; -//// } -//// var a = [ -//// 1, -//// 2, -//// 3 -//// ]; -//// var obj = { -//// z: 1, -//// q: "hello" -//// }; -//// for (var j in a) { -//// obj.z = a[j]; -//// var v = 10; -//// } -//// try { -//// obj.q = "ohhh"; -//// } catch (e) { -//// if (obj.z < 10) { -//// obj.z = 12; -//// } else { -//// obj.q = "hmm"; -//// } -//// } -//// try { -//// throw new Error(); -//// } catch (e1) { -//// var b = e1; -//// } finally { -//// y = 70; -//// } -//// with (obj) { -//// i = 2; -//// z = 10; -//// } -//// switch (obj.z) { -//// case 0: { -//// x++; -//// break; -//// -//// } -//// case 1: { -//// x--; -//// break; -//// -//// } -//// default: { -//// x *= 2; -//// x = 50; -//// break; -//// -//// } -//// } -//// while (x < 10) { -//// x++; -//// } -//// do { -//// x--; -//// } while (x > 4) -//// x = y; -//// var z = (x == 1) ? x + 1 : x - 1; -//// (x == 1) ? x + 1 : x - 1; -//// x === 1; -//// x = z = 40; -//// eval("y"); -//// return; -////} -////var b = function () { -//// var x = 10; -//// x = x + 1; -////}; -////f(); - - -verify.baselineCurrentFileNameOrDottedNameSpans(); \ No newline at end of file diff --git a/tests/cases/unittests/services/colorization.ts b/tests/cases/unittests/services/colorization.ts index ee5350a25eb..3031cefb56c 100644 --- a/tests/cases/unittests/services/colorization.ts +++ b/tests/cases/unittests/services/colorization.ts @@ -1,4 +1,7 @@ -interface Classification { +/// +/// + +interface Classification { position: number; length: number; class: ts.TokenClass; @@ -66,7 +69,7 @@ describe('Colorization', function () { function numberLiteral(text: string) { return { value: text, class: ts.TokenClass.NumberLiteral }; } function stringLiteral(text: string) { return { value: text, class: ts.TokenClass.StringLiteral }; } function regExpLiteral(text: string) { return { value: text, class: ts.TokenClass.RegExpLiteral }; } - function finalEndOfLineState(value: number) { return { value: value, class: undefined }; } + function finalEndOfLineState(value: number) { return { value: value, class: undefined }; } function test(text: string, initialEndOfLineState: ts.EndOfLineState, ...expectedEntries: ClassificationEntry[]): void { var result = getClassifications(text, initialEndOfLineState); @@ -253,7 +256,7 @@ describe('Colorization', function () { identifier("Foo"), operator("<"), identifier("Foo"), - punctuation(","), + operator(","), identifier("Foo"), operator("<"), identifier("number"), @@ -265,8 +268,8 @@ describe('Colorization', function () { identifier("Foo"), operator("<"), identifier("Foo"), - operator(">" - identifier("keyword"), + operator(">"), + keyword("number"), finalEndOfLineState(ts.EndOfLineState.Start)); }); }); diff --git a/tests/cases/unittests/services/documentRegistry.ts b/tests/cases/unittests/services/documentRegistry.ts index a7ed030f44c..88503149715 100644 --- a/tests/cases/unittests/services/documentRegistry.ts +++ b/tests/cases/unittests/services/documentRegistry.ts @@ -5,8 +5,8 @@ describe("DocumentRegistry", () => { var documentRegistry = ts.createDocumentRegistry(); var defaultCompilerOptions = ts.getDefaultCompilerOptions(); - var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); - var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); + var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); + var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); assert(f1 === f2, "DocumentRegistry should return the same document for the same name"); }); @@ -17,21 +17,21 @@ describe("DocumentRegistry", () => { // change compilation setting that doesn't affect parsing - should have the same document compilerOptions.declaration = true; - var f1 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); + var f1 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); compilerOptions.declaration = false; - var f2 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); + var f2 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); assert(f1 === f2, "Expected to have the same document instance"); // change value of compilation setting that is used during production of AST - new document is required compilerOptions.target = ts.ScriptTarget.ES3; - var f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); + var f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); assert(f1 !== f3, "Changed target: Expected to have different instances of document"); compilerOptions.module = ts.ModuleKind.CommonJS; - var f4 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); + var f4 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); assert(f1 !== f4, "Changed module: Expected to have different instances of document"); });