diff --git a/Jakefile b/Jakefile index 059702f214c..15661debff6 100644 --- a/Jakefile +++ b/Jakefile @@ -58,6 +58,7 @@ var servicesSources = [ "checker.ts", "emitter.ts", "program.ts", + "commandLineParser.ts", "diagnosticInformationMap.generated.ts" ].map(function (f) { return path.join(compilerDirectory, f); @@ -102,6 +103,7 @@ var internalDefinitionsRoots = [ "compiler/core.d.ts", "compiler/sys.d.ts", "compiler/utilities.d.ts", + "compiler/commandLineParser.d.ts", "services/utilities.d.ts", ]; @@ -192,7 +194,7 @@ var compilerFilename = "tsc.js"; * @param keepComments: false to compile using --removeComments * @param callback: a function to execute after the compilation process ends */ -function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, keepComments, noResolve, callback) { +function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, preserveConstEnums, keepComments, noResolve, callback) { file(outFile, prereqs, function() { var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory; var options = "--module commonjs -noImplicitAny"; @@ -205,7 +207,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu options += " --declaration"; } - if (useDebugMode) { + if (useDebugMode || preserveConstEnums) { options += " --preserveConstEnums"; } @@ -321,7 +323,15 @@ var tscFile = path.join(builtLocalDirectory, compilerFilename); compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false); var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js"); -compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].concat(servicesSources), [copyright], /*useBuiltCompiler*/ true); +compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].concat(servicesSources), + /*prefixes*/ [copyright], + /*useBuiltCompiler*/ true, + /*noOutFile*/ false, + /*generateDeclarations*/ false, + /*outDir*/ undefined, + /*preserveConstEnums*/ true, + /*keepComments*/ false, + /*noResolve*/ false); var nodeDefinitionsFile = path.join(builtLocalDirectory, "typescript.d.ts"); var standaloneDefinitionsFile = path.join(builtLocalDirectory, "typescriptServices.d.ts"); @@ -334,6 +344,7 @@ compileFile(nodeDefinitionsFile, servicesSources,[builtLocalDirectory, copyright /*noOutFile*/ true, /*generateDeclarations*/ true, /*outDir*/ tempDirPath, + /*preserveConstEnums*/ true, /*keepComments*/ true, /*noResolve*/ true, /*callback*/ function () { diff --git a/bin/tsc.js b/bin/tsc.js index e1b93961fc6..070f5356189 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -36,7 +36,7 @@ var ts; function forEach(array, callback) { if (array) { for (var i = 0, len = array.length; i < len; i++) { - var result = callback(array[i]); + var result = callback(array[i], i); if (result) { return result; } @@ -212,6 +212,12 @@ var ts; return result; } ts.mapToArray = mapToArray; + function copyMap(source, target) { + for (var p in source) { + target[p] = source[p]; + } + } + ts.copyMap = copyMap; function arrayToMap(array, makeKey) { var result = {}; forEach(array, function (value) { @@ -943,7 +949,9 @@ var ts; A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: 1 /* Error */, key: "A destructuring declaration must have an initializer.", isEarly: true }, Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: 1 /* Error */, key: "Destructuring declarations are not allowed in ambient contexts.", isEarly: true }, An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: 1 /* Error */, key: "An implementation cannot be declared in ambient contexts.", isEarly: true }, - Merge_conflict_marker_encountered: { code: 1184, category: 1 /* Error */, key: "Merge conflict marker encountered." }, + Modifiers_cannot_appear_here: { code: 1184, category: 1 /* Error */, key: "Modifiers cannot appear here." }, + Merge_conflict_marker_encountered: { code: 1185, category: 1 /* Error */, key: "Merge conflict marker encountered." }, + A_rest_element_cannot_have_an_initializer: { code: 1186, category: 1 /* Error */, key: "A rest element cannot have an initializer." }, 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." }, @@ -1094,6 +1102,7 @@ var ts; Type_0_has_no_property_1_and_no_string_index_signature: { code: 2459, category: 1 /* Error */, key: "Type '{0}' has no property '{1}' and no string index signature." }, Type_0_has_no_property_1: { code: 2460, category: 1 /* Error */, key: "Type '{0}' has no property '{1}'." }, Type_0_is_not_an_array_type: { code: 2461, category: 1 /* Error */, key: "Type '{0}' is not an array type." }, + A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: 1 /* Error */, key: "A rest element must be last in an array destructuring pattern" }, 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_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: 1 /* Error */, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1177,6 +1186,8 @@ var ts; Could_not_write_file_0_Colon_1: { code: 5033, category: 1 /* Error */, key: "Could not write file '{0}': {1}" }, Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: 1 /* Error */, key: "Option mapRoot cannot be specified without specifying sourcemap option." }, Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: 1 /* Error */, key: "Option sourceRoot cannot be specified without specifying sourcemap option." }, + Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: 1 /* Error */, key: "Option noEmit cannot be specified with option out or outDir." }, + Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: 1 /* Error */, key: "Option noEmit cannot be specified with option declaration." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: 2 /* Message */, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: 2 /* Message */, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: 2 /* Message */, key: "Specifies the location where debugger should locate map files instead of generated locations." }, @@ -1186,6 +1197,7 @@ var ts; Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: 2 /* Message */, key: "Do not erase const enum declarations in generated code." }, Do_not_emit_outputs_if_any_type_checking_errors_were_reported: { code: 6008, category: 2 /* Message */, key: "Do not emit outputs if any type checking errors were reported." }, Do_not_emit_comments_to_output: { code: 6009, category: 2 /* Message */, key: "Do not emit comments to output." }, + Do_not_emit_outputs: { code: 6010, category: 2 /* Message */, key: "Do not emit outputs." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: 2 /* Message */, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: 2 /* Message */, key: "Specify module code generation: 'commonjs' or 'amd'" }, Print_this_message: { code: 6017, category: 2 /* Message */, key: "Print this message." }, @@ -1213,7 +1225,7 @@ var ts; Unsupported_locale_0: { code: 6049, category: 1 /* Error */, key: "Unsupported locale '{0}'." }, Unable_to_open_file_0: { code: 6050, category: 1 /* Error */, key: "Unable to open file '{0}'." }, Corrupted_locale_file_0: { code: 6051, category: 1 /* Error */, key: "Corrupted locale file {0}." }, - Warn_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: 2 /* Message */, key: "Warn on expressions and declarations with an implied 'any' type." }, + Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: 2 /* Message */, key: "Warn on expressions and declarations with an implied 'any' type." }, File_0_not_found: { code: 6053, category: 1 /* Error */, key: "File '{0}' not found." }, File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: 1 /* Error */, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: 2 /* Message */, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, @@ -1521,25 +1533,42 @@ var ts; } } ts.skipTrivia = skipTrivia; + var mergeConflictMarkerLength = "<<<<<<<".length; function isConflictMarkerTrivia(text, pos) { - if (pos > 0 && isLineBreak(text.charCodeAt(pos - 1))) { + ts.Debug.assert(pos >= 0); + if (pos === 0 || isLineBreak(text.charCodeAt(pos - 1))) { var ch = text.charCodeAt(pos); - var markerLength = "<<<<<<<".length; - if ((pos + markerLength) < text.length) { - for (var i = 0, n = markerLength; i < n; i++) { + if ((pos + mergeConflictMarkerLength) < text.length) { + for (var i = 0, n = mergeConflictMarkerLength; i < n; i++) { if (text.charCodeAt(pos + i) !== ch) { return false; } } - return ch === 61 /* equals */ || text.charCodeAt(pos + markerLength) === 32 /* space */; + return ch === 61 /* equals */ || text.charCodeAt(pos + mergeConflictMarkerLength) === 32 /* space */; } } return false; } - function scanConflictMarkerTrivia(text, pos) { + function scanConflictMarkerTrivia(text, pos, error) { + if (error) { + error(ts.Diagnostics.Merge_conflict_marker_encountered, mergeConflictMarkerLength); + } + var ch = text.charCodeAt(pos); var len = text.length; - while (pos < len && !isLineBreak(text.charCodeAt(pos))) { - pos++; + if (ch === 60 /* lessThan */ || ch === 62 /* greaterThan */) { + while (pos < len && !isLineBreak(text.charCodeAt(pos))) { + pos++; + } + } + else { + ts.Debug.assert(ch === 61 /* equals */); + while (pos < len) { + var ch = text.charCodeAt(pos); + if (ch === 62 /* greaterThan */ && isConflictMarkerTrivia(text, pos)) { + break; + } + pos++; + } } return pos; } @@ -1638,9 +1667,9 @@ var ts; var tokenValue; var precedingLineBreak; var tokenIsUnterminated; - function error(message) { + function error(message, length) { if (onError) { - onError(message); + onError(message, length || 0); } } function isIdentifierStart(ch) { @@ -2103,8 +2132,7 @@ var ts; return pos++, token = 22 /* SemicolonToken */; case 60 /* lessThan */: if (isConflictMarkerTrivia(text, pos)) { - error(ts.Diagnostics.Merge_conflict_marker_encountered); - pos = scanConflictMarkerTrivia(text, pos); + pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } @@ -2124,8 +2152,7 @@ var ts; return pos++, token = 24 /* LessThanToken */; case 61 /* equals */: if (isConflictMarkerTrivia(text, pos)) { - error(ts.Diagnostics.Merge_conflict_marker_encountered); - pos = scanConflictMarkerTrivia(text, pos); + pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } @@ -2145,8 +2172,7 @@ var ts; return pos++, token = 52 /* EqualsToken */; case 62 /* greaterThan */: if (isConflictMarkerTrivia(text, pos)) { - error(ts.Diagnostics.Merge_conflict_marker_encountered); - pos = scanConflictMarkerTrivia(text, pos); + pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } @@ -2392,17 +2418,14 @@ var ts; return node.end - node.pos; } ts.getFullWidth = getFullWidth; - function hasFlag(val, flag) { - return (val & flag) !== 0; - } function containsParseError(node) { aggregateChildData(node); - return hasFlag(node.parserContextFlags, 32 /* ThisNodeOrAnySubNodesHasError */); + return (node.parserContextFlags & 32 /* ThisNodeOrAnySubNodesHasError */) !== 0; } ts.containsParseError = containsParseError; function aggregateChildData(node) { - if (!hasFlag(node.parserContextFlags, 64 /* HasAggregatedChildData */)) { - var thisNodeOrAnySubNodesHasError = hasFlag(node.parserContextFlags, 16 /* ThisNodeHasError */) || ts.forEachChild(node, containsParseError); + if (!(node.parserContextFlags & 64 /* HasAggregatedChildData */)) { + var thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & 16 /* ThisNodeHasError */) !== 0) || ts.forEachChild(node, containsParseError); if (thisNodeOrAnySubNodesHasError) { node.parserContextFlags |= 32 /* ThisNodeOrAnySubNodesHasError */; } @@ -2426,19 +2449,26 @@ var ts; return node.pos; } ts.getStartPosOfNode = getStartPosOfNode; - function isMissingNode(node) { + function nodeIsMissing(node) { + if (!node) { + return true; + } return node.pos === node.end && node.kind !== 1 /* EndOfFileToken */; } - ts.isMissingNode = isMissingNode; + ts.nodeIsMissing = nodeIsMissing; + function nodeIsPresent(node) { + return !nodeIsMissing(node); + } + ts.nodeIsPresent = nodeIsPresent; function getTokenPosOfNode(node, sourceFile) { - if (isMissingNode(node)) { + if (nodeIsMissing(node)) { return node.pos; } return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos); } ts.getTokenPosOfNode = getTokenPosOfNode; function getSourceTextOfNodeFromSourceFile(sourceFile, node) { - if (isMissingNode(node)) { + if (nodeIsMissing(node)) { return ""; } var text = sourceFile.text; @@ -2446,7 +2476,7 @@ var ts; } ts.getSourceTextOfNodeFromSourceFile = getSourceTextOfNodeFromSourceFile; function getTextOfNodeFromSourceText(sourceText, node) { - if (isMissingNode(node)) { + if (nodeIsMissing(node)) { return ""; } return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end); @@ -2487,7 +2517,7 @@ var ts; function getErrorSpanForNode(node) { var errorSpan; switch (node.kind) { - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: case 191 /* ClassDeclaration */: case 192 /* InterfaceDeclaration */: @@ -2512,16 +2542,38 @@ var ts; return node.kind === 194 /* EnumDeclaration */ && isConst(node); } ts.isConstEnumDeclaration = isConstEnumDeclaration; + function walkUpBindingElementsAndPatterns(node) { + while (node && (node.kind === 146 /* BindingElement */ || isBindingPattern(node))) { + node = node.parent; + } + return node; + } + function getCombinedNodeFlags(node) { + node = walkUpBindingElementsAndPatterns(node); + var flags = node.flags; + if (node.kind === 188 /* VariableDeclaration */) { + node = node.parent; + } + if (node && node.kind === 189 /* VariableDeclarationList */) { + flags |= node.flags; + node = node.parent; + } + if (node && node.kind === 171 /* VariableStatement */) { + flags |= node.flags; + } + return flags; + } + ts.getCombinedNodeFlags = getCombinedNodeFlags; function isConst(node) { - return !!(node.flags & 4096 /* Const */); + return !!(getCombinedNodeFlags(node) & 4096 /* Const */); } ts.isConst = isConst; function isLet(node) { - return !!(node.flags & 2048 /* Let */); + return !!(getCombinedNodeFlags(node) & 2048 /* Let */); } ts.isLet = isLet; function isPrologueDirective(node) { - return node.kind === 172 /* ExpressionStatement */ && node.expression.kind === 8 /* StringLiteral */; + return node.kind === 173 /* ExpressionStatement */ && node.expression.kind === 8 /* StringLiteral */; } ts.isPrologueDirective = isPrologueDirective; function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { @@ -2546,23 +2598,21 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 180 /* ReturnStatement */: + case 181 /* ReturnStatement */: return visitor(node); - case 169 /* Block */: - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 181 /* WithStatement */: - case 182 /* SwitchStatement */: + case 170 /* Block */: + case 174 /* IfStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 182 /* WithStatement */: + case 183 /* SwitchStatement */: case 200 /* CaseClause */: case 201 /* DefaultClause */: - case 183 /* LabeledStatement */: - case 185 /* TryStatement */: - case 186 /* TryBlock */: + case 184 /* LabeledStatement */: + case 186 /* TryStatement */: case 203 /* CatchClause */: - case 187 /* FinallyBlock */: return ts.forEachChild(node, traverse); } } @@ -2594,7 +2644,7 @@ var ts; } ts.isAnyFunction = isAnyFunction; function isFunctionBlock(node) { - return node && node.kind === 169 /* Block */ && isAnyFunction(node.parent); + return node && node.kind === 170 /* Block */ && isAnyFunction(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { @@ -2690,9 +2740,10 @@ var ts; case 162 /* PostfixUnaryExpression */: case 163 /* BinaryExpression */: case 164 /* ConditionalExpression */: + case 167 /* SpreadElementExpression */: case 165 /* TemplateExpression */: case 10 /* NoSubstitutionTemplateLiteral */: - case 167 /* OmittedExpression */: + case 168 /* OmittedExpression */: return true; case 121 /* QualifiedName */: while (node.parent.kind === 121 /* QualifiedName */) { @@ -2707,7 +2758,7 @@ var ts; case 8 /* StringLiteral */: var parent = node.parent; switch (parent.kind) { - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 124 /* Parameter */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: @@ -2715,24 +2766,26 @@ var ts; case 204 /* PropertyAssignment */: case 146 /* BindingElement */: return parent.initializer === node; - case 172 /* ExpressionStatement */: - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 180 /* ReturnStatement */: - case 181 /* WithStatement */: - case 182 /* SwitchStatement */: + case 173 /* ExpressionStatement */: + case 174 /* IfStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: + case 181 /* ReturnStatement */: + case 182 /* WithStatement */: + case 183 /* SwitchStatement */: case 200 /* CaseClause */: - case 184 /* ThrowStatement */: - case 182 /* SwitchStatement */: + case 185 /* ThrowStatement */: + case 183 /* SwitchStatement */: return parent.expression === node; - case 176 /* ForStatement */: - return parent.initializer === node || parent.condition === node || parent.iterator === node; - case 177 /* ForInStatement */: - return parent.variable === node || parent.expression === node; + case 177 /* ForStatement */: + var forStatement = parent; + return (forStatement.initializer === node && forStatement.initializer.kind !== 189 /* VariableDeclarationList */) || forStatement.condition === node || forStatement.iterator === node; + case 178 /* ForInStatement */: + var forInStatement = parent; + return (forInStatement.initializer === node && forInStatement.initializer.kind !== 189 /* VariableDeclarationList */) || forInStatement.expression === node; case 154 /* TypeAssertionExpression */: return node === parent.expression; - case 168 /* TemplateSpan */: + case 169 /* TemplateSpan */: return node === parent.expression; default: if (isExpression(parent)) { @@ -2743,6 +2796,11 @@ var ts; return false; } ts.isExpression = isExpression; + function isInstantiatedModule(node, preserveConstEnums) { + var moduleState = ts.getModuleInstanceState(node); + return moduleState === 1 /* Instantiated */ || (preserveConstEnums && moduleState === 2 /* ConstEnumOnly */); + } + ts.isInstantiatedModule = isInstantiatedModule; function isExternalModuleImportDeclaration(node) { return node.kind === 197 /* ImportDeclaration */ && node.moduleReference.kind === 199 /* ExternalModuleReference */; } @@ -2800,8 +2858,9 @@ var ts; ts.isBindingPattern = isBindingPattern; function isInAmbientContext(node) { while (node) { - if (node.flags & (2 /* Ambient */ | 1024 /* DeclarationFile */)) + if (node.flags & (2 /* Ambient */ | 1024 /* DeclarationFile */)) { return true; + } node = node.parent; } return false; @@ -2811,7 +2870,7 @@ var ts; switch (node.kind) { case 123 /* TypeParameter */: case 124 /* Parameter */: - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: @@ -2837,23 +2896,23 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 179 /* BreakStatement */: - case 178 /* ContinueStatement */: - case 188 /* DebuggerStatement */: - case 174 /* DoStatement */: - case 172 /* ExpressionStatement */: - case 171 /* EmptyStatement */: - case 177 /* ForInStatement */: - case 176 /* ForStatement */: - case 173 /* IfStatement */: - case 183 /* LabeledStatement */: - case 180 /* ReturnStatement */: - case 182 /* SwitchStatement */: + case 180 /* BreakStatement */: + case 179 /* ContinueStatement */: + case 187 /* DebuggerStatement */: + case 175 /* DoStatement */: + case 173 /* ExpressionStatement */: + case 172 /* EmptyStatement */: + case 178 /* ForInStatement */: + case 177 /* ForStatement */: + case 174 /* IfStatement */: + case 184 /* LabeledStatement */: + case 181 /* ReturnStatement */: + case 183 /* SwitchStatement */: case 93 /* ThrowKeyword */: - case 185 /* TryStatement */: - case 170 /* VariableStatement */: - case 175 /* WhileStatement */: - case 181 /* WithStatement */: + case 186 /* TryStatement */: + case 171 /* VariableStatement */: + case 176 /* WhileStatement */: + case 182 /* WithStatement */: case 198 /* ExportAssignment */: return true; default: @@ -2901,11 +2960,11 @@ var ts; return undefined; } ts.getHeritageClause = getHeritageClause; - function tryResolveScriptReference(program, sourceFile, reference) { - if (!program.getCompilerOptions().noResolve) { + function tryResolveScriptReference(host, sourceFile, reference) { + if (!host.getCompilerOptions().noResolve) { var referenceFileName = ts.isRootedDiskPath(reference.filename) ? reference.filename : ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename); - referenceFileName = ts.getNormalizedAbsolutePath(referenceFileName, program.getCompilerHost().getCurrentDirectory()); - return program.getSourceFile(referenceFileName); + referenceFileName = ts.getNormalizedAbsolutePath(referenceFileName, host.getCurrentDirectory()); + return host.getSourceFile(referenceFileName); } } ts.tryResolveScriptReference = tryResolveScriptReference; @@ -2996,10 +3055,134 @@ var ts; return false; } ts.isModifier = isModifier; + function createEmitHostFromProgram(program) { + var compilerHost = program.getCompilerHost(); + return { + getCanonicalFileName: compilerHost.getCanonicalFileName, + getCommonSourceDirectory: program.getCommonSourceDirectory, + getCompilerOptions: program.getCompilerOptions, + getCurrentDirectory: compilerHost.getCurrentDirectory, + getNewLine: compilerHost.getNewLine, + getSourceFile: program.getSourceFile, + getSourceFiles: program.getSourceFiles, + isEmitBlocked: program.isEmitBlocked, + writeFile: compilerHost.writeFile + }; + } + ts.createEmitHostFromProgram = createEmitHostFromProgram; + function textSpanEnd(span) { + return span.start + span.length; + } + ts.textSpanEnd = textSpanEnd; + function textSpanIsEmpty(span) { + return span.length === 0; + } + ts.textSpanIsEmpty = textSpanIsEmpty; + function textSpanContainsPosition(span, position) { + return position >= span.start && position < textSpanEnd(span); + } + ts.textSpanContainsPosition = textSpanContainsPosition; + function textSpanContainsTextSpan(span, other) { + return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); + } + ts.textSpanContainsTextSpan = textSpanContainsTextSpan; + function textSpanOverlapsWith(span, other) { + var overlapStart = Math.max(span.start, other.start); + var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); + return overlapStart < overlapEnd; + } + ts.textSpanOverlapsWith = textSpanOverlapsWith; + function textSpanOverlap(span1, span2) { + var overlapStart = Math.max(span1.start, span2.start); + var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (overlapStart < overlapEnd) { + return createTextSpanFromBounds(overlapStart, overlapEnd); + } + return undefined; + } + ts.textSpanOverlap = textSpanOverlap; + function textSpanIntersectsWithTextSpan(span, other) { + return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start; + } + ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan; + function textSpanIntersectsWith(span, start, length) { + var end = start + length; + return start <= textSpanEnd(span) && end >= span.start; + } + ts.textSpanIntersectsWith = textSpanIntersectsWith; + function textSpanIntersectsWithPosition(span, position) { + return position <= textSpanEnd(span) && position >= span.start; + } + ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition; + function textSpanIntersection(span1, span2) { + var intersectStart = Math.max(span1.start, span2.start); + var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (intersectStart <= intersectEnd) { + return createTextSpanFromBounds(intersectStart, intersectEnd); + } + return undefined; + } + ts.textSpanIntersection = textSpanIntersection; + function createTextSpan(start, length) { + if (start < 0) { + throw new Error("start < 0"); + } + if (length < 0) { + throw new Error("length < 0"); + } + return { start: start, length: length }; + } + ts.createTextSpan = createTextSpan; + function createTextSpanFromBounds(start, end) { + return createTextSpan(start, end - start); + } + ts.createTextSpanFromBounds = createTextSpanFromBounds; + function textChangeRangeNewSpan(range) { + return createTextSpan(range.span.start, range.newLength); + } + ts.textChangeRangeNewSpan = textChangeRangeNewSpan; + function textChangeRangeIsUnchanged(range) { + return textSpanIsEmpty(range.span) && range.newLength === 0; + } + ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged; + function createTextChangeRange(span, newLength) { + if (newLength < 0) { + throw new Error("newLength < 0"); + } + return { span: span, newLength: newLength }; + } + ts.createTextChangeRange = createTextChangeRange; + ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); + function collapseTextChangeRangesAcrossMultipleVersions(changes) { + if (changes.length === 0) { + return ts.unchangedTextChangeRange; + } + if (changes.length === 1) { + return changes[0]; + } + var change0 = changes[0]; + var oldStartN = change0.span.start; + var oldEndN = textSpanEnd(change0.span); + var newEndN = oldStartN + change0.newLength; + for (var i = 1; i < changes.length; i++) { + var nextChange = changes[i]; + var oldStart1 = oldStartN; + var oldEnd1 = oldEndN; + var newEnd1 = newEndN; + var oldStart2 = nextChange.span.start; + var oldEnd2 = textSpanEnd(nextChange.span); + var newEnd2 = oldStart2 + nextChange.newLength; + oldStartN = Math.min(oldStart1, oldStart2); + oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); + newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); + } + return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); + } + ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; })(ts || (ts = {})); var ts; (function (ts) { - var nodeConstructors = new Array(210 /* Count */); + var nodeConstructors = new Array(209 /* Count */); function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); } @@ -3008,48 +3191,51 @@ var ts; return new (getNodeConstructor(kind))(); } ts.createNode = createNode; - function forEachChild(node, cbNode, cbNodes) { - function child(node) { - if (node) { - return cbNode(node); - } + function visitNode(cbNode, node) { + if (node) { + return cbNode(node); } - function children(nodes) { - if (nodes) { - if (cbNodes) { - return cbNodes(nodes); - } - for (var i = 0, len = nodes.length; i < len; i++) { - var result = cbNode(nodes[i]); - if (result) { - return result; - } + } + function visitNodeArray(cbNodes, nodes) { + if (nodes) { + return cbNodes(nodes); + } + } + function visitEachNode(cbNode, nodes) { + if (nodes) { + for (var i = 0, len = nodes.length; i < len; i++) { + var result = cbNode(nodes[i]); + if (result) { + return result; } - return undefined; } } + } + function forEachChild(node, cbNode, cbNodeArray) { if (!node) { return; } + var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode; + var cbNodes = cbNodeArray || cbNode; switch (node.kind) { case 121 /* QualifiedName */: - return child(node.left) || child(node.right); + return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 123 /* TypeParameter */: - return child(node.name) || child(node.constraint) || child(node.expression); + return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 124 /* Parameter */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: case 204 /* PropertyAssignment */: case 205 /* ShorthandPropertyAssignment */: - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: - return children(node.modifiers) || child(node.propertyName) || child(node.dotDotDotToken) || child(node.name) || child(node.questionToken) || child(node.type) || child(node.initializer); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.dotDotDotToken) || visitNode(cbNode, node.name) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type) || visitNode(cbNode, node.initializer); case 136 /* FunctionType */: case 137 /* ConstructorType */: case 132 /* CallSignature */: case 133 /* ConstructSignature */: case 134 /* IndexSignature */: - return children(node.modifiers) || children(node.typeParameters) || children(node.parameters) || child(node.type); + return visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 128 /* MethodDeclaration */: case 127 /* MethodSignature */: case 129 /* Constructor */: @@ -3058,186 +3244,130 @@ var ts; case 156 /* FunctionExpression */: case 190 /* FunctionDeclaration */: case 157 /* ArrowFunction */: - return children(node.modifiers) || child(node.asteriskToken) || child(node.name) || child(node.questionToken) || children(node.typeParameters) || children(node.parameters) || child(node.type) || child(node.body); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.name) || visitNode(cbNode, node.questionToken) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type) || visitNode(cbNode, node.body); case 135 /* TypeReference */: - return child(node.typeName) || children(node.typeArguments); + return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 138 /* TypeQuery */: - return child(node.exprName); + return visitNode(cbNode, node.exprName); case 139 /* TypeLiteral */: - return children(node.members); + return visitNodes(cbNodes, node.members); case 140 /* ArrayType */: - return child(node.elementType); + return visitNode(cbNode, node.elementType); case 141 /* TupleType */: - return children(node.elementTypes); + return visitNodes(cbNodes, node.elementTypes); case 142 /* UnionType */: - return children(node.types); + return visitNodes(cbNodes, node.types); case 143 /* ParenthesizedType */: - return child(node.type); + return visitNode(cbNode, node.type); case 144 /* ObjectBindingPattern */: case 145 /* ArrayBindingPattern */: - return children(node.elements); + return visitNodes(cbNodes, node.elements); case 147 /* ArrayLiteralExpression */: - return children(node.elements); + return visitNodes(cbNodes, node.elements); case 148 /* ObjectLiteralExpression */: - return children(node.properties); + return visitNodes(cbNodes, node.properties); case 149 /* PropertyAccessExpression */: - return child(node.expression) || child(node.name); + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 150 /* ElementAccessExpression */: - return child(node.expression) || child(node.argumentExpression); + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 151 /* CallExpression */: case 152 /* NewExpression */: - return child(node.expression) || children(node.typeArguments) || children(node.arguments); + return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 153 /* TaggedTemplateExpression */: - return child(node.tag) || child(node.template); + return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 154 /* TypeAssertionExpression */: - return child(node.type) || child(node.expression); + return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 155 /* ParenthesizedExpression */: - return child(node.expression); + return visitNode(cbNode, node.expression); case 158 /* DeleteExpression */: - return child(node.expression); + return visitNode(cbNode, node.expression); case 159 /* TypeOfExpression */: - return child(node.expression); + return visitNode(cbNode, node.expression); case 160 /* VoidExpression */: - return child(node.expression); + return visitNode(cbNode, node.expression); case 161 /* PrefixUnaryExpression */: - return child(node.operand); + return visitNode(cbNode, node.operand); case 166 /* YieldExpression */: - return child(node.asteriskToken) || child(node.expression); + return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 162 /* PostfixUnaryExpression */: - return child(node.operand); + return visitNode(cbNode, node.operand); case 163 /* BinaryExpression */: - return child(node.left) || child(node.right); + return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 164 /* ConditionalExpression */: - return child(node.condition) || child(node.whenTrue) || child(node.whenFalse); - case 169 /* Block */: - case 186 /* TryBlock */: - case 187 /* FinallyBlock */: + return visitNode(cbNode, node.condition) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.whenFalse); + case 167 /* SpreadElementExpression */: + return visitNode(cbNode, node.expression); + case 170 /* Block */: case 196 /* ModuleBlock */: - return children(node.statements); + return visitNodes(cbNodes, node.statements); case 207 /* SourceFile */: - return children(node.statements) || child(node.endOfFileToken); - case 170 /* VariableStatement */: - return children(node.modifiers) || children(node.declarations); - case 172 /* ExpressionStatement */: - return child(node.expression); - case 173 /* IfStatement */: - return child(node.expression) || child(node.thenStatement) || child(node.elseStatement); - case 174 /* DoStatement */: - return child(node.statement) || child(node.expression); - case 175 /* WhileStatement */: - return child(node.expression) || child(node.statement); - case 176 /* ForStatement */: - return children(node.declarations) || child(node.initializer) || child(node.condition) || child(node.iterator) || child(node.statement); - case 177 /* ForInStatement */: - return children(node.declarations) || child(node.variable) || child(node.expression) || child(node.statement); - case 178 /* ContinueStatement */: - case 179 /* BreakStatement */: - return child(node.label); - case 180 /* ReturnStatement */: - return child(node.expression); - case 181 /* WithStatement */: - return child(node.expression) || child(node.statement); - case 182 /* SwitchStatement */: - return child(node.expression) || children(node.clauses); + return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); + case 171 /* VariableStatement */: + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); + case 189 /* VariableDeclarationList */: + return visitNodes(cbNodes, node.declarations); + case 173 /* ExpressionStatement */: + return visitNode(cbNode, node.expression); + case 174 /* IfStatement */: + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); + case 175 /* DoStatement */: + return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); + case 176 /* WhileStatement */: + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); + case 177 /* ForStatement */: + return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.iterator) || visitNode(cbNode, node.statement); + case 178 /* ForInStatement */: + return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); + case 179 /* ContinueStatement */: + case 180 /* BreakStatement */: + return visitNode(cbNode, node.label); + case 181 /* ReturnStatement */: + return visitNode(cbNode, node.expression); + case 182 /* WithStatement */: + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); + case 183 /* SwitchStatement */: + return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.clauses); case 200 /* CaseClause */: - return child(node.expression) || children(node.statements); + return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 201 /* DefaultClause */: - return children(node.statements); - case 183 /* LabeledStatement */: - return child(node.label) || child(node.statement); - case 184 /* ThrowStatement */: - return child(node.expression); - case 185 /* TryStatement */: - return child(node.tryBlock) || child(node.catchClause) || child(node.finallyBlock); + return visitNodes(cbNodes, node.statements); + case 184 /* LabeledStatement */: + return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); + case 185 /* ThrowStatement */: + return visitNode(cbNode, node.expression); + case 186 /* TryStatement */: + return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 203 /* CatchClause */: - return child(node.name) || child(node.type) || child(node.block); + return visitNode(cbNode, node.name) || visitNode(cbNode, node.type) || visitNode(cbNode, node.block); case 191 /* ClassDeclaration */: - return children(node.modifiers) || child(node.name) || children(node.typeParameters) || children(node.heritageClauses) || children(node.members); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); case 192 /* InterfaceDeclaration */: - return children(node.modifiers) || child(node.name) || children(node.typeParameters) || children(node.heritageClauses) || children(node.members); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); case 193 /* TypeAliasDeclaration */: - return children(node.modifiers) || child(node.name) || child(node.type); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 194 /* EnumDeclaration */: - return children(node.modifiers) || child(node.name) || children(node.members); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 206 /* EnumMember */: - return child(node.name) || child(node.initializer); + return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 195 /* ModuleDeclaration */: - return children(node.modifiers) || child(node.name) || child(node.body); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 197 /* ImportDeclaration */: - return children(node.modifiers) || child(node.name) || child(node.moduleReference); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 198 /* ExportAssignment */: - return children(node.modifiers) || child(node.exportName); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportName); case 165 /* TemplateExpression */: - return child(node.head) || children(node.templateSpans); - case 168 /* TemplateSpan */: - return child(node.expression) || child(node.literal); + return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); + case 169 /* TemplateSpan */: + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 122 /* ComputedPropertyName */: - return child(node.expression); + return visitNode(cbNode, node.expression); case 202 /* HeritageClause */: - return children(node.types); + return visitNodes(cbNodes, node.types); case 199 /* ExternalModuleReference */: - return child(node.expression); + return visitNode(cbNode, node.expression); } } ts.forEachChild = forEachChild; - function createCompilerHost(options) { - var currentDirectory; - var existingDirectories = {}; - function getCanonicalFileName(fileName) { - return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); - } - var unsupportedFileEncodingErrorCode = -2147024809; - function getSourceFile(filename, languageVersion, onError) { - try { - var text = ts.sys.readFile(filename, options.charset); - } - catch (e) { - if (onError) { - onError(e.number === unsupportedFileEncodingErrorCode ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText : e.message); - } - text = ""; - } - return text !== undefined ? createSourceFile(filename, text, languageVersion) : undefined; - } - function writeFile(fileName, data, writeByteOrderMark, onError) { - function directoryExists(directoryPath) { - if (ts.hasProperty(existingDirectories, directoryPath)) { - return true; - } - if (ts.sys.directoryExists(directoryPath)) { - existingDirectories[directoryPath] = true; - return true; - } - return false; - } - function ensureDirectoriesExist(directoryPath) { - if (directoryPath.length > ts.getRootLength(directoryPath) && !directoryExists(directoryPath)) { - var parentDirectory = ts.getDirectoryPath(directoryPath); - ensureDirectoriesExist(parentDirectory); - ts.sys.createDirectory(directoryPath); - } - } - try { - ensureDirectoriesExist(ts.getDirectoryPath(ts.normalizePath(fileName))); - ts.sys.writeFile(fileName, data, writeByteOrderMark); - } - catch (e) { - if (onError) { - onError(e.message); - } - } - } - return { - getSourceFile: getSourceFile, - getDefaultLibFilename: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"); }, - writeFile: writeFile, - getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, - useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, - getCanonicalFileName: getCanonicalFileName, - getNewLine: function () { return ts.sys.newLine; } - }; - } - ts.createCompilerHost = createCompilerHost; function parsingContextErrors(context) { switch (context) { case 0 /* SourceElements */: return ts.Diagnostics.Declaration_or_statement_expected; @@ -3298,45 +3428,265 @@ var ts; var nodeText = ts.getSourceTextOfNodeFromSourceFile(sourceFile, node.expression); return nodeText === '"use strict"' || nodeText === "'use strict'"; } + function createSyntaxCursor(sourceFile) { + var currentArray = sourceFile.statements; + var currentArrayIndex = 0; + ts.Debug.assert(currentArrayIndex < currentArray.length); + var current = currentArray[currentArrayIndex]; + var lastQueriedPosition = -1 /* Value */; + return { + currentNode: function (position) { + if (position !== lastQueriedPosition) { + if (current && current.end === position && currentArrayIndex < currentArray.length) { + currentArrayIndex++; + current = currentArray[currentArrayIndex]; + } + if (!current || current.pos !== position) { + findHighestListElementThatStartsAtPosition(position); + } + } + lastQueriedPosition = position; + ts.Debug.assert(!current || current.pos === position); + return current; + } + }; + function findHighestListElementThatStartsAtPosition(position) { + currentArray = undefined; + currentArrayIndex = -1 /* Value */; + current = undefined; + forEachChild(sourceFile, visitNode, visitArray); + function visitNode(node) { + if (position >= node.pos && position < node.end) { + forEachChild(node, visitNode, visitArray); + return true; + } + return false; + } + function visitArray(array) { + if (position >= array.pos && position < array.end) { + for (var i = 0, n = array.length; i < n; i++) { + var child = array[i]; + if (child) { + if (child.pos === position) { + currentArray = array; + currentArrayIndex = i; + current = child; + return true; + } + else { + if (child.pos < position && position < child.end) { + forEachChild(child, visitNode, visitArray); + return true; + } + } + } + } + } + return false; + } + } + } function createSourceFile(filename, sourceText, languageVersion, setParentNodes) { if (setParentNodes === void 0) { setParentNodes = false; } var parsingContext; - var identifiers = {}; + var identifiers; var identifierCount = 0; var nodeCount = 0; var lineStarts; - var contextFlags = 0; - var parseErrorBeforeNextFinishedNode = false; - var sourceFile = createNode(207 /* SourceFile */, 0); - if (ts.fileExtensionIs(filename, ".d.ts")) { - sourceFile.flags = 1024 /* DeclarationFile */; + var syntacticDiagnostics; + var scanner; + var token; + var syntaxCursor; + var contextFlags; + var parseErrorBeforeNextFinishedNode; + var sourceFile; + return parseSourceFile(sourceText, setParentNodes); + function parseSourceFile(text, setParentNodes) { + sourceText = text; + parsingContext = 0; + identifiers = {}; + lineStarts = undefined; + syntacticDiagnostics = undefined; + contextFlags = 0; + parseErrorBeforeNextFinishedNode = false; + sourceFile = createNode(207 /* SourceFile */, 0); + sourceFile.referenceDiagnostics = []; + sourceFile.parseDiagnostics = []; + sourceFile.semanticDiagnostics = []; + scanner = ts.createScanner(languageVersion, true, sourceText, scanError); + token = nextToken(); + sourceFile.flags = ts.fileExtensionIs(filename, ".d.ts") ? 1024 /* DeclarationFile */ : 0; + sourceFile.end = sourceText.length; + sourceFile.filename = ts.normalizePath(filename); + sourceFile.text = sourceText; + sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition; + sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter; + sourceFile.getLineStarts = getLineStarts; + sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics; + sourceFile.update = update; + processReferenceComments(sourceFile); + sourceFile.statements = parseList(0 /* SourceElements */, true, parseSourceElement); + ts.Debug.assert(token === 1 /* EndOfFileToken */); + sourceFile.endOfFileToken = parseTokenNode(); + setExternalModuleIndicator(sourceFile); + sourceFile.nodeCount = nodeCount; + sourceFile.identifierCount = identifierCount; + sourceFile.languageVersion = languageVersion; + sourceFile.identifiers = identifiers; + if (setParentNodes) { + fixupParentReferences(sourceFile); + } + return sourceFile; } - sourceFile.end = sourceText.length; - sourceFile.filename = ts.normalizePath(filename); - sourceFile.text = sourceText; - sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition; - sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter; - sourceFile.getLineStarts = getLineStarts; - sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics; - sourceFile.referenceDiagnostics = []; - sourceFile.parseDiagnostics = []; - sourceFile.grammarDiagnostics = []; - sourceFile.semanticDiagnostics = []; - processReferenceComments(); - var scanner = ts.createScanner(languageVersion, true, sourceText, scanError); - var token = nextToken(); - sourceFile.statements = parseList(0 /* SourceElements */, true, parseSourceElement); - ts.Debug.assert(token === 1 /* EndOfFileToken */); - sourceFile.endOfFileToken = parseTokenNode(); - sourceFile.externalModuleIndicator = getExternalModuleIndicator(); - sourceFile.nodeCount = nodeCount; - sourceFile.identifierCount = identifierCount; - sourceFile.languageVersion = languageVersion; - sourceFile.identifiers = identifiers; - if (setParentNodes) { - fixupParentReferences(sourceFile); + function update(newText, textChangeRange) { + if (ts.textChangeRangeIsUnchanged(textChangeRange)) { + return sourceFile; + } + if (sourceFile.statements.length === 0) { + return parseSourceFile(newText, true); + } + syntaxCursor = createSyntaxCursor(sourceFile); + var changeRange = extendToAffectedRange(textChangeRange); + var delta = ts.textChangeRangeNewSpan(changeRange).length - changeRange.span.length; + updateTokenPositionsAndMarkElements(sourceFile, changeRange.span.start, ts.textSpanEnd(changeRange.span), ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)), delta); + var result = parseSourceFile(newText, true); + syntaxCursor = undefined; + return result; + } + function updateTokenPositionsAndMarkElements(node, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta) { + visitNode(node); + function visitNode(child) { + if (child.pos > changeRangeOldEnd) { + moveElementEntirelyPastChangeRange(child, delta); + return; + } + var fullEnd = child.end; + if (fullEnd >= changeStart) { + child.intersectsChange = true; + adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); + forEachChild(child, visitNode, visitArray); + return; + } + } + function visitArray(array) { + if (array.pos > changeRangeOldEnd) { + moveElementEntirelyPastChangeRange(array, delta); + } + else { + var fullEnd = array.end; + if (fullEnd >= changeStart) { + array.intersectsChange = true; + adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); + for (var i = 0, n = array.length; i < n; i++) { + visitNode(array[i]); + } + } + } + } + } + function adjustIntersectingElement(element, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta) { + ts.Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range"); + ts.Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range"); + element.pos = Math.min(element.pos, changeRangeNewEnd); + if (element.end >= changeRangeOldEnd) { + element.end += delta; + } + else { + element.end = Math.min(element.end, changeRangeNewEnd); + } + ts.Debug.assert(element.pos <= element.end); + if (element.parent) { + ts.Debug.assert(element.pos >= element.parent.pos); + ts.Debug.assert(element.end <= element.parent.end); + } + } + function moveElementEntirelyPastChangeRange(element, delta) { + if (element.length) { + visitArray(element); + } + else { + visitNode(element); + } + function visitNode(node) { + node._children = undefined; + node.pos += delta; + node.end += delta; + forEachChild(node, visitNode, visitArray); + } + function visitArray(array) { + array.pos += delta; + array.end += delta; + for (var i = 0, n = array.length; i < n; i++) { + visitNode(array[i]); + } + } + } + function extendToAffectedRange(changeRange) { + var maxLookahead = 1; + var start = changeRange.span.start; + for (var i = 0; start > 0 && i <= maxLookahead; i++) { + var nearestNode = findNearestNodeStartingBeforeOrAtPosition(start); + var position = nearestNode.pos; + start = Math.max(0, position - 1); + } + var finalSpan = ts.createTextSpanFromBounds(start, ts.textSpanEnd(changeRange.span)); + var finalLength = changeRange.newLength + (changeRange.span.start - start); + return ts.createTextChangeRange(finalSpan, finalLength); + } + function findNearestNodeStartingBeforeOrAtPosition(position) { + var bestResult = sourceFile; + var lastNodeEntirelyBeforePosition; + forEachChild(sourceFile, visit); + if (lastNodeEntirelyBeforePosition) { + var lastChildOfLastEntireNodeBeforePosition = getLastChild(lastNodeEntirelyBeforePosition); + if (lastChildOfLastEntireNodeBeforePosition.pos > bestResult.pos) { + bestResult = lastChildOfLastEntireNodeBeforePosition; + } + } + return bestResult; + function getLastChild(node) { + while (true) { + var lastChild = getLastChildWorker(node); + if (lastChild) { + node = lastChild; + } + else { + return node; + } + } + } + function getLastChildWorker(node) { + var last = undefined; + forEachChild(node, function (child) { + if (ts.nodeIsPresent(child)) { + last = child; + } + }); + return last; + } + function visit(child) { + if (ts.nodeIsMissing(child)) { + return; + } + if (child.pos <= position) { + if (child.pos >= bestResult.pos) { + bestResult = child; + } + if (position < child.end) { + forEachChild(child, visit); + return true; + } + else { + ts.Debug.assert(child.end <= position); + lastNodeEntirelyBeforePosition = child; + } + } + else { + ts.Debug.assert(child.pos > position); + return true; + } + } } - return sourceFile; function setContextFlag(val, flag) { if (val) { contextFlags |= flag; @@ -3426,9 +3776,9 @@ var ts; } parseErrorBeforeNextFinishedNode = true; } - function scanError(message) { + function scanError(message, length) { var pos = scanner.getTextPos(); - parseErrorAtPosition(pos, 0, message); + parseErrorAtPosition(pos, length || 0, message); } function getNodePos() { return scanner.getStartPos(); @@ -3480,13 +3830,13 @@ var ts; } return inStrictModeContext() ? token > 109 /* LastFutureReservedWord */ : token > 100 /* LastReservedWord */; } - function parseExpected(kind, diagnosticMessage, arg0) { + function parseExpected(kind, diagnosticMessage) { if (token === kind) { nextToken(); return true; } if (diagnosticMessage) { - parseErrorAtCurrentToken(diagnosticMessage, arg0); + parseErrorAtCurrentToken(diagnosticMessage); } else { parseErrorAtCurrentToken(ts.Diagnostics._0_expected, ts.tokenToString(kind)); @@ -3514,7 +3864,7 @@ var ts; } return token === 15 /* CloseBraceToken */ || token === 1 /* EndOfFileToken */ || scanner.hasPrecedingLineBreak(); } - function parseSemicolon(diagnosticMessage) { + function parseSemicolon() { if (canParseSemicolon()) { if (token === 22 /* SemicolonToken */) { nextToken(); @@ -3522,7 +3872,7 @@ var ts; return true; } else { - return parseExpected(22 /* SemicolonToken */, diagnosticMessage); + return parseExpected(22 /* SemicolonToken */); } } function createNode(kind, pos) { @@ -3623,14 +3973,18 @@ var ts; function canFollowModifier() { return token === 18 /* OpenBracketToken */ || token === 35 /* AsteriskToken */ || isLiteralPropertyName(); } - function isListElement(kind, inErrorRecovery) { - switch (kind) { + function isListElement(parsingContext, inErrorRecovery) { + var node = currentNode(parsingContext); + if (node) { + return true; + } + switch (parsingContext) { case 0 /* SourceElements */: case 1 /* ModuleElements */: return isSourceElement(inErrorRecovery); case 2 /* BlockStatements */: case 4 /* SwitchClauseStatements */: - return isStatement(inErrorRecovery); + return isStartOfStatement(inErrorRecovery); case 3 /* SwitchClauses */: return token === 66 /* CaseKeyword */ || token === 72 /* DefaultKeyword */; case 5 /* TypeMembers */: @@ -3648,13 +4002,13 @@ var ts; case 9 /* VariableDeclarations */: return isIdentifierOrPattern(); case 11 /* ArrayBindingElements */: - return token === 23 /* CommaToken */ || isIdentifierOrPattern(); + return token === 23 /* CommaToken */ || token === 21 /* DotDotDotToken */ || isIdentifierOrPattern(); case 16 /* TypeParameters */: return isIdentifier(); case 12 /* ArgumentExpressions */: return token === 23 /* CommaToken */ || isStartOfExpression(); case 14 /* ArrayLiteralMembers */: - return token === 23 /* CommaToken */ || isStartOfExpression(); + return token === 23 /* CommaToken */ || token === 21 /* DotDotDotToken */ || isStartOfExpression(); case 15 /* Parameters */: return isStartOfParameter(); case 17 /* TypeArguments */: @@ -3741,7 +4095,7 @@ var ts; var savedStrictModeContext = inStrictModeContext(); while (!isListTerminator(kind)) { if (isListElement(kind, false)) { - var element = parseElement(); + var element = parseListElement(kind, parseElement); result.push(element); if (checkForStrictMode && !inStrictModeContext()) { if (ts.isPrologueDirective(element)) { @@ -3765,6 +4119,183 @@ var ts; parsingContext = saveParsingContext; return result; } + function parseListElement(kind, parseElement) { + var node = currentNode(kind); + if (node) { + return consumeNode(node); + } + return parseElement(); + } + function currentNode(parsingContext) { + if (parseErrorBeforeNextFinishedNode) { + return undefined; + } + if (!syntaxCursor) { + return undefined; + } + var node = syntaxCursor.currentNode(scanner.getStartPos()); + if (ts.nodeIsMissing(node)) { + return undefined; + } + if (node.intersectsChange) { + return undefined; + } + if (ts.containsParseError(node)) { + return undefined; + } + var nodeContextFlags = node.parserContextFlags & 31 /* ParserGeneratedFlags */; + if (nodeContextFlags !== contextFlags) { + return undefined; + } + if (!canReuseNode(node, parsingContext)) { + return undefined; + } + return node; + } + function consumeNode(node) { + scanner.setTextPos(node.end); + nextToken(); + return node; + } + function canReuseNode(node, parsingContext) { + switch (parsingContext) { + case 1 /* ModuleElements */: + return isReusableModuleElement(node); + case 6 /* ClassMembers */: + return isReusableClassMember(node); + case 3 /* SwitchClauses */: + return isReusableSwitchClause(node); + case 2 /* BlockStatements */: + case 4 /* SwitchClauseStatements */: + return isReusableStatement(node); + case 7 /* EnumMembers */: + return isReusableEnumMember(node); + case 5 /* TypeMembers */: + return isReusableTypeMember(node); + case 9 /* VariableDeclarations */: + return isReusableVariableDeclaration(node); + case 15 /* Parameters */: + return isReusableParameter(node); + case 19 /* HeritageClauses */: + case 8 /* TypeReferences */: + case 16 /* TypeParameters */: + case 18 /* TupleElementTypes */: + case 17 /* TypeArguments */: + case 12 /* ArgumentExpressions */: + case 13 /* ObjectLiteralMembers */: + } + return false; + } + function isReusableModuleElement(node) { + if (node) { + switch (node.kind) { + case 197 /* ImportDeclaration */: + case 198 /* ExportAssignment */: + case 191 /* ClassDeclaration */: + case 192 /* InterfaceDeclaration */: + case 195 /* ModuleDeclaration */: + case 194 /* EnumDeclaration */: + case 190 /* FunctionDeclaration */: + case 171 /* VariableStatement */: + case 170 /* Block */: + case 174 /* IfStatement */: + case 173 /* ExpressionStatement */: + case 185 /* ThrowStatement */: + case 181 /* ReturnStatement */: + case 183 /* SwitchStatement */: + case 180 /* BreakStatement */: + case 179 /* ContinueStatement */: + case 178 /* ForInStatement */: + case 177 /* ForStatement */: + case 176 /* WhileStatement */: + case 182 /* WithStatement */: + case 172 /* EmptyStatement */: + case 186 /* TryStatement */: + case 184 /* LabeledStatement */: + case 175 /* DoStatement */: + case 187 /* DebuggerStatement */: + return true; + } + } + return false; + } + function isReusableClassMember(node) { + if (node) { + switch (node.kind) { + case 129 /* Constructor */: + case 134 /* IndexSignature */: + case 128 /* MethodDeclaration */: + case 130 /* GetAccessor */: + case 131 /* SetAccessor */: + case 126 /* PropertyDeclaration */: + return true; + } + } + return false; + } + function isReusableSwitchClause(node) { + if (node) { + switch (node.kind) { + case 200 /* CaseClause */: + case 201 /* DefaultClause */: + return true; + } + } + return false; + } + function isReusableStatement(node) { + if (node) { + switch (node.kind) { + case 190 /* FunctionDeclaration */: + case 171 /* VariableStatement */: + case 170 /* Block */: + case 174 /* IfStatement */: + case 173 /* ExpressionStatement */: + case 185 /* ThrowStatement */: + case 181 /* ReturnStatement */: + case 183 /* SwitchStatement */: + case 180 /* BreakStatement */: + case 179 /* ContinueStatement */: + case 178 /* ForInStatement */: + case 177 /* ForStatement */: + case 176 /* WhileStatement */: + case 182 /* WithStatement */: + case 172 /* EmptyStatement */: + case 186 /* TryStatement */: + case 184 /* LabeledStatement */: + case 175 /* DoStatement */: + case 187 /* DebuggerStatement */: + return true; + } + } + return false; + } + function isReusableEnumMember(node) { + return node.kind === 206 /* EnumMember */; + } + function isReusableTypeMember(node) { + if (node) { + switch (node.kind) { + case 133 /* ConstructSignature */: + case 127 /* MethodSignature */: + case 134 /* IndexSignature */: + case 125 /* PropertySignature */: + case 132 /* CallSignature */: + return true; + } + } + return false; + } + function isReusableVariableDeclaration(node) { + if (node.kind !== 188 /* VariableDeclaration */) { + return false; + } + var variableDeclarator = node; + return variableDeclarator.initializer === undefined; + } + function isReusableParameter(node) { + return node.kind === 124 /* Parameter */; + } function abortParsingListOrMoveToNextToken(kind) { parseErrorAtCurrentToken(parsingContextErrors(kind)); if (isInSomeParsingContext()) { @@ -3781,7 +4312,7 @@ var ts; var commaStart = -1; while (true) { if (isListElement(kind, false)) { - result.push(parseElement()); + result.push(parseListElement(kind, parseElement)); commaStart = scanner.getTokenPos(); if (parseOptional(23 /* CommaToken */)) { continue; @@ -3860,7 +4391,7 @@ var ts; return finishNode(template); } function parseTemplateSpan() { - var span = createNode(168 /* TemplateSpan */); + var span = createNode(169 /* TemplateSpan */); span.expression = allowInAnd(parseExpression); var literal; if (token === 15 /* CloseBraceToken */) { @@ -4026,7 +4557,8 @@ var ts; nextToken(); return token === 51 /* ColonToken */ || token === 23 /* CommaToken */ || token === 19 /* CloseBracketToken */; } - function parseIndexSignatureDeclaration(fullStart, modifiers) { + function parseIndexSignatureDeclaration(modifiers) { + var fullStart = modifiers ? modifiers.pos : scanner.getStartPos(); var node = createNode(134 /* IndexSignature */, fullStart); setModifiers(node, modifiers); node.parameters = parseBracketedList(15 /* Parameters */, parseParameter, 18 /* OpenBracketToken */, 19 /* CloseBracketToken */); @@ -4062,9 +4594,21 @@ var ts; case 18 /* OpenBracketToken */: return true; default: + if (ts.isModifier(token)) { + var result = lookAhead(isStartOfIndexSignatureDeclaration); + if (result) { + return result; + } + } return isLiteralPropertyName() && lookAhead(isTypeMemberWithLiteralPropertyName); } } + function isStartOfIndexSignatureDeclaration() { + while (ts.isModifier(token)) { + nextToken(); + } + return isIndexSignature(); + } function isTypeMemberWithLiteralPropertyName() { nextToken(); return token === 16 /* OpenParenToken */ || token === 24 /* LessThanToken */ || token === 50 /* QuestionToken */ || token === 51 /* ColonToken */ || canParseSemicolon(); @@ -4075,7 +4619,7 @@ var ts; case 24 /* LessThanToken */: return parseSignatureMember(132 /* CallSignature */); case 18 /* OpenBracketToken */: - return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), undefined) : parsePropertyOrMethodSignature(); + return isIndexSignature() ? parseIndexSignatureDeclaration(undefined) : parsePropertyOrMethodSignature(); case 87 /* NewKeyword */: if (lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(133 /* ConstructSignature */); @@ -4084,11 +4628,21 @@ var ts; case 7 /* NumericLiteral */: return parsePropertyOrMethodSignature(); default: + if (ts.isModifier(token)) { + var result = tryParse(parseIndexSignatureWithModifiers); + if (result) { + return result; + } + } if (isIdentifierOrKeyword()) { return parsePropertyOrMethodSignature(); } } } + function parseIndexSignatureWithModifiers() { + var modifiers = parseModifiers(); + return isIndexSignature() ? parseIndexSignatureDeclaration(modifiers) : undefined; + } function isStartOfConstructSignature() { nextToken(); return token === 16 /* OpenParenToken */ || token === 24 /* LessThanToken */; @@ -4445,7 +4999,7 @@ var ts; if (token === 14 /* OpenBraceToken */) { return parseFunctionBlock(false, false); } - if (isStatement(true) && !isStartOfExpressionStatement() && token !== 82 /* FunctionKeyword */) { + if (isStartOfStatement(true) && !isStartOfExpressionStatement() && token !== 82 /* FunctionKeyword */) { return parseFunctionBlock(false, true); } return parseAssignmentExpressionOrHigher(); @@ -4720,16 +5274,16 @@ var ts; } function parsePrimaryExpression() { switch (token) { + case 7 /* NumericLiteral */: + case 8 /* StringLiteral */: + case 10 /* NoSubstitutionTemplateLiteral */: + return parseLiteralNode(); case 92 /* ThisKeyword */: case 90 /* SuperKeyword */: case 88 /* NullKeyword */: case 94 /* TrueKeyword */: case 79 /* FalseKeyword */: return parseTokenNode(); - case 7 /* NumericLiteral */: - case 8 /* StringLiteral */: - case 10 /* NoSubstitutionTemplateLiteral */: - return parseLiteralNode(); case 16 /* OpenParenToken */: return parseParenthesizedExpression(); case 18 /* OpenBracketToken */: @@ -4759,10 +5313,16 @@ var ts; return finishNode(node); } function parseAssignmentExpressionOrOmittedExpression() { - return token === 23 /* CommaToken */ ? createNode(167 /* OmittedExpression */) : parseAssignmentExpressionOrHigher(); + return token === 23 /* CommaToken */ ? createNode(168 /* OmittedExpression */) : parseAssignmentExpressionOrHigher(); + } + function parseSpreadElement() { + var node = createNode(167 /* SpreadElementExpression */); + parseExpected(21 /* DotDotDotToken */); + node.expression = parseAssignmentExpressionOrHigher(); + return finishNode(node); } function parseArrayLiteralElement() { - return parseAssignmentExpressionOrOmittedExpression(); + return token === 21 /* DotDotDotToken */ ? parseSpreadElement() : parseAssignmentExpressionOrOmittedExpression(); } function parseArgumentExpression() { return allowInAnd(parseAssignmentExpressionOrOmittedExpression); @@ -4776,21 +5336,30 @@ var ts; parseExpected(19 /* CloseBracketToken */); return finishNode(node); } + function tryParseAccessorDeclaration(fullStart, modifiers) { + if (parseContextualModifier(114 /* GetKeyword */)) { + return parseAccessorDeclaration(130 /* GetAccessor */, fullStart, modifiers); + } + else if (parseContextualModifier(118 /* SetKeyword */)) { + return parseAccessorDeclaration(131 /* SetAccessor */, fullStart, modifiers); + } + return undefined; + } function parseObjectLiteralElement() { var fullStart = scanner.getStartPos(); - var initialToken = token; - if (parseContextualModifier(114 /* GetKeyword */) || parseContextualModifier(118 /* SetKeyword */)) { - var kind = initialToken === 114 /* GetKeyword */ ? 130 /* GetAccessor */ : 131 /* SetAccessor */; - return parseAccessorDeclaration(kind, fullStart, undefined); + var modifiers = parseModifiers(); + var accessor = tryParseAccessorDeclaration(fullStart, modifiers); + if (accessor) { + return accessor; } var asteriskToken = parseOptionalToken(35 /* AsteriskToken */); var tokenIsIdentifier = isIdentifier(); var nameToken = token; var propertyName = parsePropertyName(); - if (asteriskToken || token === 16 /* OpenParenToken */ || token === 24 /* LessThanToken */) { - return parseMethodDeclaration(fullStart, undefined, asteriskToken, propertyName, undefined, true); - } var questionToken = parseOptionalToken(50 /* QuestionToken */); + if (asteriskToken || token === 16 /* OpenParenToken */ || token === 24 /* LessThanToken */) { + return parseMethodDeclaration(fullStart, modifiers, asteriskToken, propertyName, questionToken); + } if ((token === 23 /* CommaToken */ || token === 15 /* CloseBraceToken */) && tokenIsIdentifier) { var shorthandDeclaration = createNode(205 /* ShorthandPropertyAssignment */, fullStart); shorthandDeclaration.name = propertyName; @@ -4838,9 +5407,9 @@ var ts; } return finishNode(node); } - function parseBlock(kind, ignoreMissingOpenBrace, checkForStrictMode) { - var node = createNode(kind); - if (parseExpected(14 /* OpenBraceToken */) || ignoreMissingOpenBrace) { + function parseBlock(ignoreMissingOpenBrace, checkForStrictMode, diagnosticMessage) { + var node = createNode(170 /* Block */); + if (parseExpected(14 /* OpenBraceToken */, diagnosticMessage) || ignoreMissingOpenBrace) { node.statements = parseList(2 /* BlockStatements */, checkForStrictMode, parseStatement); parseExpected(15 /* CloseBraceToken */); } @@ -4849,20 +5418,20 @@ var ts; } return finishNode(node); } - function parseFunctionBlock(allowYield, ignoreMissingOpenBrace) { + function parseFunctionBlock(allowYield, ignoreMissingOpenBrace, diagnosticMessage) { var savedYieldContext = inYieldContext(); setYieldContext(allowYield); - var block = parseBlock(169 /* Block */, ignoreMissingOpenBrace, true); + var block = parseBlock(ignoreMissingOpenBrace, true, diagnosticMessage); setYieldContext(savedYieldContext); return block; } function parseEmptyStatement() { - var node = createNode(171 /* EmptyStatement */); + var node = createNode(172 /* EmptyStatement */); parseExpected(22 /* SemicolonToken */); return finishNode(node); } function parseIfStatement() { - var node = createNode(173 /* IfStatement */); + var node = createNode(174 /* IfStatement */); parseExpected(83 /* IfKeyword */); parseExpected(16 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); @@ -4872,7 +5441,7 @@ var ts; return finishNode(node); } function parseDoStatement() { - var node = createNode(174 /* DoStatement */); + var node = createNode(175 /* DoStatement */); parseExpected(74 /* DoKeyword */); node.statement = parseStatement(); parseExpected(99 /* WhileKeyword */); @@ -4883,7 +5452,7 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(175 /* WhileStatement */); + var node = createNode(176 /* WhileStatement */); parseExpected(99 /* WhileKeyword */); parseExpected(16 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); @@ -4895,41 +5464,26 @@ var ts; var pos = getNodePos(); parseExpected(81 /* ForKeyword */); parseExpected(16 /* OpenParenToken */); + var initializer = undefined; if (token !== 22 /* SemicolonToken */) { - if (parseOptional(97 /* VarKeyword */)) { - var declarations = disallowInAnd(parseVariableDeclarationList); - } - else if (parseOptional(103 /* LetKeyword */)) { - var declarations = setFlag(disallowInAnd(parseVariableDeclarationList), 2048 /* Let */); - } - else if (parseOptional(69 /* ConstKeyword */)) { - var declarations = setFlag(disallowInAnd(parseVariableDeclarationList), 4096 /* Const */); + if (token === 97 /* VarKeyword */ || token === 103 /* LetKeyword */ || token === 69 /* ConstKeyword */) { + initializer = parseVariableDeclarationList(true); } else { - var varOrInit = disallowInAnd(parseExpression); + initializer = disallowInAnd(parseExpression); } } var forOrForInStatement; if (parseOptional(85 /* InKeyword */)) { - var forInStatement = createNode(177 /* ForInStatement */, pos); - if (declarations) { - forInStatement.declarations = declarations; - } - else { - forInStatement.variable = varOrInit; - } + var forInStatement = createNode(178 /* ForInStatement */, pos); + forInStatement.initializer = initializer; forInStatement.expression = allowInAnd(parseExpression); parseExpected(17 /* CloseParenToken */); forOrForInStatement = forInStatement; } else { - var forStatement = createNode(176 /* ForStatement */, pos); - if (declarations) { - forStatement.declarations = declarations; - } - if (varOrInit) { - forStatement.initializer = varOrInit; - } + var forStatement = createNode(177 /* ForStatement */, pos); + forStatement.initializer = initializer; parseExpected(22 /* SemicolonToken */); if (token !== 22 /* SemicolonToken */ && token !== 17 /* CloseParenToken */) { forStatement.condition = allowInAnd(parseExpression); @@ -4946,7 +5500,7 @@ var ts; } function parseBreakOrContinueStatement(kind) { var node = createNode(kind); - parseExpected(kind === 179 /* BreakStatement */ ? 65 /* BreakKeyword */ : 70 /* ContinueKeyword */); + parseExpected(kind === 180 /* BreakStatement */ ? 65 /* BreakKeyword */ : 70 /* ContinueKeyword */); if (!canParseSemicolon()) { node.label = parseIdentifier(); } @@ -4954,7 +5508,7 @@ var ts; return finishNode(node); } function parseReturnStatement() { - var node = createNode(180 /* ReturnStatement */); + var node = createNode(181 /* ReturnStatement */); parseExpected(89 /* ReturnKeyword */); if (!canParseSemicolon()) { node.expression = allowInAnd(parseExpression); @@ -4963,7 +5517,7 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(181 /* WithStatement */); + var node = createNode(182 /* WithStatement */); parseExpected(100 /* WithKeyword */); parseExpected(16 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); @@ -4990,7 +5544,7 @@ var ts; return token === 66 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(182 /* SwitchStatement */); + var node = createNode(183 /* SwitchStatement */); parseExpected(91 /* SwitchKeyword */); parseExpected(16 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); @@ -5001,26 +5555,23 @@ var ts; return finishNode(node); } function parseThrowStatement() { - var node = createNode(184 /* ThrowStatement */); + var node = createNode(185 /* ThrowStatement */); parseExpected(93 /* ThrowKeyword */); node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression); parseSemicolon(); return finishNode(node); } function parseTryStatement() { - var node = createNode(185 /* TryStatement */); - node.tryBlock = parseTokenAndBlock(95 /* TryKeyword */); + var node = createNode(186 /* TryStatement */); + parseExpected(95 /* TryKeyword */); + node.tryBlock = parseBlock(false, false); node.catchClause = token === 67 /* CatchKeyword */ ? parseCatchClause() : undefined; - node.finallyBlock = !node.catchClause || token === 80 /* FinallyKeyword */ ? parseTokenAndBlock(80 /* FinallyKeyword */) : undefined; + if (!node.catchClause || token === 80 /* FinallyKeyword */) { + parseExpected(80 /* FinallyKeyword */); + node.finallyBlock = parseBlock(false, false); + } return finishNode(node); } - function parseTokenAndBlock(token) { - var pos = getNodePos(); - parseExpected(token); - var result = parseBlock(token === 95 /* TryKeyword */ ? 186 /* TryBlock */ : 187 /* FinallyBlock */, false, false); - result.pos = pos; - return result; - } function parseCatchClause() { var result = createNode(203 /* CatchClause */); parseExpected(67 /* CatchKeyword */); @@ -5028,11 +5579,11 @@ var ts; result.name = parseIdentifier(); result.type = parseTypeAnnotation(); parseExpected(17 /* CloseParenToken */); - result.block = parseBlock(169 /* Block */, false, false); + result.block = parseBlock(false, false); return finishNode(result); } function parseDebuggerStatement() { - var node = createNode(188 /* DebuggerStatement */); + var node = createNode(187 /* DebuggerStatement */); parseExpected(71 /* DebuggerKeyword */); parseSemicolon(); return finishNode(node); @@ -5041,19 +5592,25 @@ var ts; var fullStart = scanner.getStartPos(); var expression = allowInAnd(parseExpression); if (expression.kind === 64 /* Identifier */ && parseOptional(51 /* ColonToken */)) { - var labeledStatement = createNode(183 /* LabeledStatement */, fullStart); + var labeledStatement = createNode(184 /* LabeledStatement */, fullStart); labeledStatement.label = expression; labeledStatement.statement = parseStatement(); return finishNode(labeledStatement); } else { - var expressionStatement = createNode(172 /* ExpressionStatement */, fullStart); + var expressionStatement = createNode(173 /* ExpressionStatement */, fullStart); expressionStatement.expression = expression; parseSemicolon(); return finishNode(expressionStatement); } } - function isStatement(inErrorRecovery) { + function isStartOfStatement(inErrorRecovery) { + if (ts.isModifier(token)) { + var result = lookAhead(parseVariableStatementOrFunctionDeclarationWithModifiers); + if (result) { + return true; + } + } switch (token) { case 22 /* SemicolonToken */: return !inErrorRecovery; @@ -5109,7 +5666,7 @@ var ts; function parseStatement() { switch (token) { case 14 /* OpenBraceToken */: - return parseBlock(169 /* Block */, false, false); + return parseBlock(false, false); case 97 /* VarKeyword */: case 69 /* ConstKeyword */: return parseVariableStatement(scanner.getStartPos(), undefined); @@ -5126,9 +5683,9 @@ var ts; case 81 /* ForKeyword */: return parseForOrForInStatement(); case 70 /* ContinueKeyword */: - return parseBreakOrContinueStatement(178 /* ContinueStatement */); + return parseBreakOrContinueStatement(179 /* ContinueStatement */); case 65 /* BreakKeyword */: - return parseBreakOrContinueStatement(179 /* BreakStatement */); + return parseBreakOrContinueStatement(180 /* BreakStatement */); case 89 /* ReturnKeyword */: return parseReturnStatement(); case 100 /* WithKeyword */: @@ -5148,21 +5705,50 @@ var ts; return parseVariableStatement(scanner.getStartPos(), undefined); } default: + if (ts.isModifier(token)) { + var result = tryParse(parseVariableStatementOrFunctionDeclarationWithModifiers); + if (result) { + return result; + } + } return parseExpressionOrLabeledStatement(); } } - function parseFunctionBlockOrSemicolon(isGenerator) { - if (token === 14 /* OpenBraceToken */) { - return parseFunctionBlock(isGenerator, false); + function parseVariableStatementOrFunctionDeclarationWithModifiers() { + var start = scanner.getStartPos(); + var modifiers = parseModifiers(); + switch (token) { + case 69 /* ConstKeyword */: + var nextTokenIsEnum = lookAhead(nextTokenIsEnumKeyword); + if (nextTokenIsEnum) { + return undefined; + } + return parseVariableStatement(start, modifiers); + case 103 /* LetKeyword */: + if (!isLetDeclaration()) { + return undefined; + } + return parseVariableStatement(start, modifiers); + case 97 /* VarKeyword */: + return parseVariableStatement(start, modifiers); + case 82 /* FunctionKeyword */: + return parseFunctionDeclaration(start, modifiers); } - parseSemicolon(ts.Diagnostics.or_expected); return undefined; } + function parseFunctionBlockOrSemicolon(isGenerator, diagnosticMessage) { + if (token !== 14 /* OpenBraceToken */ && canParseSemicolon()) { + parseSemicolon(); + return; + } + return parseFunctionBlock(isGenerator, false, diagnosticMessage); + } function parseArrayBindingElement() { if (token === 23 /* CommaToken */) { - return createNode(167 /* OmittedExpression */); + return createNode(168 /* OmittedExpression */); } var node = createNode(146 /* BindingElement */); + node.dotDotDotToken = parseOptionalToken(21 /* DotDotDotToken */); node.name = parseIdentifierOrPattern(); node.initializer = parseInitializer(false); return finishNode(node); @@ -5208,40 +5794,37 @@ var ts; return parseIdentifier(); } function parseVariableDeclaration() { - var node = createNode(189 /* VariableDeclaration */); + var node = createNode(188 /* VariableDeclaration */); node.name = parseIdentifierOrPattern(); node.type = parseTypeAnnotation(); node.initializer = parseInitializer(false); return finishNode(node); } - function setFlag(nodes, flag) { - for (var i = 0; i < nodes.length; i++) { - var node = nodes[i]; - node.flags |= flag; - if (node.name && ts.isBindingPattern(node.name)) { - setFlag(node.name.elements, flag); - } - } - return nodes; - } - function parseVariableDeclarationList() { - return parseDelimitedList(9 /* VariableDeclarations */, parseVariableDeclaration); - } - function parseVariableStatement(fullStart, modifiers) { - var node = createNode(170 /* VariableStatement */, fullStart); - setModifiers(node, modifiers); - if (token === 103 /* LetKeyword */) { - node.flags |= 2048 /* Let */; - } - else if (token === 69 /* ConstKeyword */) { - node.flags |= 4096 /* Const */; - } - else { - ts.Debug.assert(token === 97 /* VarKeyword */); + function parseVariableDeclarationList(disallowIn) { + var node = createNode(189 /* VariableDeclarationList */); + switch (token) { + case 97 /* VarKeyword */: + break; + case 103 /* LetKeyword */: + node.flags |= 2048 /* Let */; + break; + case 69 /* ConstKeyword */: + node.flags |= 4096 /* Const */; + break; + default: + ts.Debug.fail(); } nextToken(); - node.declarations = allowInAnd(parseVariableDeclarationList); - setFlag(node.declarations, node.flags); + var savedDisallowIn = inDisallowInContext(); + setDisallowInContext(disallowIn); + node.declarations = parseDelimitedList(9 /* VariableDeclarations */, parseVariableDeclaration); + setDisallowInContext(savedDisallowIn); + return finishNode(node); + } + function parseVariableStatement(fullStart, modifiers) { + var node = createNode(171 /* VariableStatement */, fullStart); + setModifiers(node, modifiers); + node.declarationList = parseVariableDeclarationList(false); parseSemicolon(); return finishNode(node); } @@ -5252,7 +5835,7 @@ var ts; node.asteriskToken = parseOptionalToken(35 /* AsteriskToken */); node.name = parseIdentifier(); fillSignature(51 /* ColonToken */, !!node.asteriskToken, false, node); - node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken); + node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, ts.Diagnostics.or_expected); return finishNode(node); } function parseConstructorDeclaration(pos, modifiers) { @@ -5260,17 +5843,17 @@ var ts; setModifiers(node, modifiers); parseExpected(112 /* ConstructorKeyword */); fillSignature(51 /* ColonToken */, false, false, node); - node.body = parseFunctionBlockOrSemicolon(false); + node.body = parseFunctionBlockOrSemicolon(false, ts.Diagnostics.or_expected); return finishNode(node); } - function parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, requireBlock) { + function parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, diagnosticMessage) { var method = createNode(128 /* MethodDeclaration */, fullStart); setModifiers(method, modifiers); method.asteriskToken = asteriskToken; method.name = name; method.questionToken = questionToken; fillSignature(51 /* ColonToken */, !!asteriskToken, false, method); - method.body = requireBlock ? parseFunctionBlock(!!asteriskToken, false) : parseFunctionBlockOrSemicolon(!!asteriskToken); + method.body = parseFunctionBlockOrSemicolon(!!asteriskToken, diagnosticMessage); return finishNode(method); } function parsePropertyOrMethodDeclaration(fullStart, modifiers) { @@ -5278,7 +5861,7 @@ var ts; var name = parsePropertyName(); var questionToken = parseOptionalToken(50 /* QuestionToken */); if (asteriskToken || token === 16 /* OpenParenToken */ || token === 24 /* LessThanToken */) { - return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, false); + return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected); } else { var property = createNode(126 /* PropertyDeclaration */, fullStart); @@ -5360,17 +5943,15 @@ var ts; function parseClassElement() { var fullStart = getNodePos(); var modifiers = parseModifiers(); - if (parseContextualModifier(114 /* GetKeyword */)) { - return parseAccessorDeclaration(130 /* GetAccessor */, fullStart, modifiers); - } - if (parseContextualModifier(118 /* SetKeyword */)) { - return parseAccessorDeclaration(131 /* SetAccessor */, fullStart, modifiers); + var accessor = tryParseAccessorDeclaration(fullStart, modifiers); + if (accessor) { + return accessor; } if (token === 112 /* ConstructorKeyword */) { return parseConstructorDeclaration(fullStart, modifiers); } if (isIndexSignature()) { - return parseIndexSignatureDeclaration(fullStart, modifiers); + return parseIndexSignatureDeclaration(modifiers); } if (isIdentifierOrKeyword() || token === 8 /* StringLiteral */ || token === 7 /* NumericLiteral */ || token === 35 /* AsteriskToken */ || token === 18 /* OpenBracketToken */) { return parsePropertyOrMethodDeclaration(fullStart, modifiers); @@ -5606,7 +6187,7 @@ var ts; } } function isSourceElement(inErrorRecovery) { - return isDeclarationStart() || isStatement(inErrorRecovery); + return isDeclarationStart() || isStartOfStatement(inErrorRecovery); } function parseSourceElement() { return parseSourceElementOrModuleElement(); @@ -5617,7 +6198,7 @@ var ts; function parseSourceElementOrModuleElement() { return isDeclarationStart() ? parseDeclaration() : parseStatement(); } - function processReferenceComments() { + function processReferenceComments(sourceFile) { var triviaScanner = ts.createScanner(languageVersion, false, sourceText); var referencedFiles = []; var amdDependencies = []; @@ -5664,10 +6245,9 @@ var ts; sourceFile.amdDependencies = amdDependencies; sourceFile.amdModuleName = amdModuleName; } - function getExternalModuleIndicator() { - return ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 197 /* ImportDeclaration */ && node.moduleReference.kind === 199 /* ExternalModuleReference */ || node.kind === 198 /* ExportAssignment */ ? node : undefined; }); + function setExternalModuleIndicator(sourceFile) { + sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 197 /* ImportDeclaration */ && node.moduleReference.kind === 199 /* ExternalModuleReference */ || node.kind === 198 /* ExportAssignment */ ? node : undefined; }); } - var syntacticDiagnostics; function getSyntacticDiagnostics() { if (syntacticDiagnostics === undefined) { syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics); @@ -5710,225 +6290,6 @@ var ts; return token >= 52 /* FirstAssignment */ && token <= 63 /* LastAssignment */; } ts.isAssignmentOperator = isAssignmentOperator; - function createProgram(rootNames, options, host) { - var program; - var files = []; - var filesByName = {}; - var errors = []; - var seenNoDefaultLib = options.noLib; - var commonSourceDirectory; - ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); - if (!seenNoDefaultLib) { - processRootFile(host.getDefaultLibFilename(options), true); - } - verifyCompilerOptions(); - errors.sort(ts.compareDiagnostics); - program = { - getSourceFile: getSourceFile, - getSourceFiles: function () { return files; }, - getCompilerOptions: function () { return options; }, - getCompilerHost: function () { return host; }, - getDiagnostics: getDiagnostics, - getGlobalDiagnostics: getGlobalDiagnostics, - getTypeChecker: function (fullTypeCheckMode) { return ts.createTypeChecker(program, fullTypeCheckMode); }, - getCommonSourceDirectory: function () { return commonSourceDirectory; } - }; - return program; - function getSourceFile(filename) { - filename = host.getCanonicalFileName(filename); - return ts.hasProperty(filesByName, filename) ? filesByName[filename] : undefined; - } - function getDiagnostics(sourceFile) { - return sourceFile ? ts.filter(errors, function (e) { return e.file === sourceFile; }) : errors; - } - function getGlobalDiagnostics() { - return ts.filter(errors, function (e) { return !e.file; }); - } - function hasExtension(filename) { - return ts.getBaseFilename(filename).indexOf(".") >= 0; - } - function processRootFile(filename, isDefaultLib) { - processSourceFile(ts.normalizePath(filename), isDefaultLib); - } - function processSourceFile(filename, isDefaultLib, refFile, refPos, refEnd) { - if (refEnd !== undefined && refPos !== undefined) { - var start = refPos; - var length = refEnd - refPos; - } - var diagnostic; - if (hasExtension(filename)) { - if (!options.allowNonTsExtensions && !ts.fileExtensionIs(filename, ".ts")) { - diagnostic = ts.Diagnostics.File_0_must_have_extension_ts_or_d_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))) { - diagnostic = ts.Diagnostics.File_0_not_found; - filename += ".ts"; - } - } - if (diagnostic) { - if (refFile) { - errors.push(ts.createFileDiagnostic(refFile, start, length, diagnostic, filename)); - } - else { - errors.push(ts.createCompilerDiagnostic(diagnostic, filename)); - } - } - } - function findSourceFile(filename, isDefaultLib, refFile, refStart, refLength) { - var canonicalName = host.getCanonicalFileName(filename); - if (ts.hasProperty(filesByName, canonicalName)) { - return getSourceFileFromCache(filename, canonicalName, false); - } - else { - var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(filename, host.getCurrentDirectory()); - var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (ts.hasProperty(filesByName, canonicalAbsolutePath)) { - return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); - } - var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, function (hostErrorMessage) { - if (refFile) { - errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); - } - else { - errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); - } - }); - if (file) { - seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; - filesByName[canonicalAbsolutePath] = file; - if (!options.noResolve) { - var basePath = ts.getDirectoryPath(filename); - processReferencedFiles(file, basePath); - processImportedModules(file, basePath); - } - if (isDefaultLib) { - files.unshift(file); - } - else { - files.push(file); - } - ts.forEach(file.getSyntacticDiagnostics(), function (e) { - errors.push(e); - }); - } - } - return file; - function getSourceFileFromCache(filename, canonicalName, useAbsolutePath) { - var file = filesByName[canonicalName]; - if (file && host.useCaseSensitiveFileNames()) { - var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.filename, host.getCurrentDirectory()) : file.filename; - if (canonicalName !== sourceFileName) { - errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, sourceFileName)); - } - } - return file; - } - } - function processReferencedFiles(file, basePath) { - ts.forEach(file.referencedFiles, function (ref) { - 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 (ts.isExternalModuleImportDeclaration(node) && ts.getExternalModuleImportDeclarationExpression(node).kind === 8 /* StringLiteral */) { - var nameLiteral = ts.getExternalModuleImportDeclarationExpression(node); - var moduleName = nameLiteral.text; - if (moduleName) { - var searchPath = basePath; - while (true) { - var searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleName)); - if (findModuleSourceFile(searchName + ".ts", nameLiteral) || findModuleSourceFile(searchName + ".d.ts", nameLiteral)) { - break; - } - var parentPath = ts.getDirectoryPath(searchPath); - if (parentPath === searchPath) { - break; - } - searchPath = parentPath; - } - } - } - else if (node.kind === 195 /* ModuleDeclaration */ && node.name.kind === 8 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || ts.isDeclarationFile(file))) { - forEachChild(node.body, function (node) { - if (ts.isExternalModuleImportDeclaration(node) && ts.getExternalModuleImportDeclarationExpression(node).kind === 8 /* StringLiteral */) { - var nameLiteral = ts.getExternalModuleImportDeclarationExpression(node); - var moduleName = nameLiteral.text; - if (moduleName) { - var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName)); - var tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral); - if (!tsFile) { - findModuleSourceFile(searchName + ".d.ts", nameLiteral); - } - } - } - }); - } - }); - function findModuleSourceFile(filename, nameLiteral) { - return findSourceFile(filename, false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos); - } - } - function verifyCompilerOptions() { - if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { - if (options.mapRoot) { - errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option)); - } - if (options.sourceRoot) { - errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option)); - } - return; - } - var firstExternalModule = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (firstExternalModule && options.module === 0 /* None */) { - var externalModuleErrorSpan = ts.getErrorSpanForNode(firstExternalModule.externalModuleIndicator); - var errorStart = ts.skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos); - var errorLength = externalModuleErrorSpan.end - errorStart; - errors.push(ts.createFileDiagnostic(firstExternalModule, errorStart, errorLength, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); - } - if (options.outDir || options.sourceRoot || (options.mapRoot && (!options.out || firstExternalModule !== undefined))) { - var commonPathComponents; - ts.forEach(files, function (sourceFile) { - if (!(sourceFile.flags & 1024 /* DeclarationFile */) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { - var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory()); - sourcePathComponents.pop(); - if (commonPathComponents) { - for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) { - if (commonPathComponents[i] !== sourcePathComponents[i]) { - if (i === 0) { - errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); - return; - } - commonPathComponents.length = i; - break; - } - } - if (sourcePathComponents.length < commonPathComponents.length) { - commonPathComponents.length = sourcePathComponents.length; - } - } - else { - commonPathComponents = sourcePathComponents; - } - } - }); - commonSourceDirectory = ts.getNormalizedPathFromPathComponents(commonPathComponents); - if (commonSourceDirectory) { - commonSourceDirectory += ts.directorySeparator; - } - } - } - } - ts.createProgram = createProgram; })(ts || (ts = {})); var ts; (function (ts) { @@ -6080,7 +6441,7 @@ var ts; if (symbolKind & 1536 /* Namespace */) { exportKind |= 4194304 /* ExportNamespace */; } - if (node.flags & 1 /* Export */ || (node.kind !== 197 /* ImportDeclaration */ && isAmbientContext(container))) { + if (ts.getCombinedNodeFlags(node) & 1 /* Export */ || (node.kind !== 197 /* 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); @@ -6104,9 +6465,7 @@ var ts; parent = node; if (symbolKind & 262128 /* IsContainer */) { container = node; - ts.Debug.assert(container.nextContainer === undefined); if (lastContainer) { - ts.Debug.assert(lastContainer.nextContainer === undefined); lastContainer.nextContainer = container; } lastContainer = container; @@ -6234,12 +6593,12 @@ var ts; case 124 /* Parameter */: bindParameter(node); break; - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: if (ts.isBindingPattern(node.name)) { bindChildren(node, 0, false); } - else if (node.flags & 6144 /* BlockScoped */) { + else if (ts.getCombinedNodeFlags(node) & 6144 /* BlockScoped */) { bindBlockScopedVariableDeclaration(node); } else { @@ -6323,13 +6682,11 @@ var ts; bindAnonymousDeclaration(node, 512 /* ValueModule */, '"' + ts.removeFileExtension(node.filename) + '"', true); break; } - case 169 /* Block */: - case 186 /* TryBlock */: + case 170 /* Block */: case 203 /* CatchClause */: - case 187 /* FinallyBlock */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 182 /* SwitchStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 183 /* SwitchStatement */: bindChildren(node, 0, true); break; default: @@ -6355,3434 +6712,27 @@ var ts; ts.bindSourceFile = bindSourceFile; })(ts || (ts = {})); var ts; -(function (ts) { - var indentStrings = ["", " "]; - function getIndentString(level) { - if (indentStrings[level] === undefined) { - indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; - } - return indentStrings[level]; - } - ts.getIndentString = getIndentString; - function getIndentSize() { - return indentStrings[1].length; - } - function shouldEmitToOwnFile(sourceFile, compilerOptions) { - if (!ts.isDeclarationFile(sourceFile)) { - if ((ts.isExternalModule(sourceFile) || !compilerOptions.out) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { - return true; - } - return false; - } - return false; - } - ts.shouldEmitToOwnFile = shouldEmitToOwnFile; - function isExternalModuleOrDeclarationFile(sourceFile) { - return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); - } - ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; - function createTextWriter(newLine) { - var output = ""; - var indent = 0; - var lineStart = true; - var lineCount = 0; - var linePos = 0; - function write(s) { - if (s && s.length) { - if (lineStart) { - output += getIndentString(indent); - lineStart = false; - } - output += s; - } - } - function rawWrite(s) { - if (s !== undefined) { - if (lineStart) { - lineStart = false; - } - output += s; - } - } - function writeLiteral(s) { - if (s && s.length) { - write(s); - var lineStartsOfS = ts.computeLineStarts(s); - if (lineStartsOfS.length > 1) { - lineCount = lineCount + lineStartsOfS.length - 1; - linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; - } - } - } - function writeLine() { - if (!lineStart) { - output += newLine; - lineCount++; - linePos = output.length; - lineStart = true; - } - } - function writeTextOfNode(sourceFile, node) { - write(ts.getSourceTextOfNodeFromSourceFile(sourceFile, node)); - } - return { - write: write, - rawWrite: rawWrite, - writeTextOfNode: writeTextOfNode, - writeLiteral: writeLiteral, - writeLine: writeLine, - increaseIndent: function () { return indent++; }, - decreaseIndent: function () { return indent--; }, - getIndent: function () { return indent; }, - getTextPos: function () { return output.length; }, - getLine: function () { return lineCount + 1; }, - getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; }, - getText: function () { return output; } - }; - } - function getLineOfLocalPosition(currentSourceFile, pos) { - return currentSourceFile.getLineAndCharacterFromPosition(pos).line; - } - function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) { - if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) { - writer.writeLine(); - } - } - function emitComments(currentSourceFile, writer, comments, trailingSeparator, newLine, writeComment) { - var emitLeadingSpace = !trailingSeparator; - ts.forEach(comments, function (comment) { - if (emitLeadingSpace) { - writer.write(" "); - emitLeadingSpace = false; - } - writeComment(currentSourceFile, writer, comment, newLine); - if (comment.hasTrailingNewLine) { - writer.writeLine(); - } - else if (trailingSeparator) { - writer.write(" "); - } - else { - emitLeadingSpace = true; - } - }); - } - function writeCommentRange(currentSourceFile, writer, comment, newLine) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) { - var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos); - var firstCommentLineIndent; - for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1); - if (pos !== comment.pos) { - if (firstCommentLineIndent === undefined) { - firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, 1), comment.pos); - } - var currentWriterIndentSpacing = writer.getIndent() * getIndentSize(); - var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart); - if (spacesToEmit > 0) { - var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize(); - var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize()); - writer.rawWrite(indentSizeSpaceString); - while (numberOfSingleSpacesToEmit) { - writer.rawWrite(" "); - numberOfSingleSpacesToEmit--; - } - } - else { - writer.rawWrite(""); - } - } - writeTrimmedCurrentLine(pos, nextLineStart); - pos = nextLineStart; - } - } - else { - writer.write(currentSourceFile.text.substring(comment.pos, comment.end)); - } - function writeTrimmedCurrentLine(pos, nextLineStart) { - var end = Math.min(comment.end, nextLineStart - 1); - var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ''); - if (currentLineText) { - writer.write(currentLineText); - if (end !== comment.end) { - writer.writeLine(); - } - } - else { - writer.writeLiteral(newLine); - } - } - function calculateIndent(pos, end) { - var currentLineIndent = 0; - for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { - if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) { - currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); - } - else { - currentLineIndent++; - } - } - return currentLineIndent; - } - } - function getFirstConstructorWithBody(node) { - return ts.forEach(node.members, function (member) { - if (member.kind === 129 /* Constructor */ && member.body) { - return member; - } - }); - } - function getAllAccessorDeclarations(node, accessor) { - var firstAccessor; - var getAccessor; - var setAccessor; - if (accessor.name.kind === 122 /* ComputedPropertyName */) { - firstAccessor = accessor; - if (accessor.kind === 130 /* GetAccessor */) { - getAccessor = accessor; - } - else if (accessor.kind === 131 /* SetAccessor */) { - setAccessor = accessor; - } - else { - ts.Debug.fail("Accessor has wrong kind"); - } - } - else { - ts.forEach(node.members, function (member) { - if ((member.kind === 130 /* GetAccessor */ || member.kind === 131 /* SetAccessor */) && member.name.text === accessor.name.text && (member.flags & 128 /* Static */) === (accessor.flags & 128 /* Static */)) { - if (!firstAccessor) { - firstAccessor = member; - } - if (member.kind === 130 /* GetAccessor */ && !getAccessor) { - getAccessor = member; - } - if (member.kind === 131 /* SetAccessor */ && !setAccessor) { - setAccessor = member; - } - } - }); - } - return { - firstAccessor: firstAccessor, - getAccessor: getAccessor, - setAccessor: setAccessor - }; - } - function getSourceFilePathInNewDir(sourceFile, program, newDirPath) { - var compilerHost = program.getCompilerHost(); - var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.filename, compilerHost.getCurrentDirectory()); - sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), ""); - return ts.combinePaths(newDirPath, sourceFilePath); - } - function getOwnEmitOutputFilePath(sourceFile, program, extension) { - var compilerOptions = program.getCompilerOptions(); - if (compilerOptions.outDir) { - var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, program, compilerOptions.outDir)); - } - else { - var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename); - } - return emitOutputFilePathWithoutExtension + extension; - } - function writeFile(compilerHost, diagnostics, filename, data, writeByteOrderMark) { - compilerHost.writeFile(filename, data, writeByteOrderMark, function (hostErrorMessage) { - diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage)); - }); - } - function emitDeclarations(program, resolver, diagnostics, jsFilePath, root) { - var newLine = program.getCompilerHost().getNewLine(); - var compilerOptions = program.getCompilerOptions(); - var compilerHost = program.getCompilerHost(); - var write; - var writeLine; - var increaseIndent; - var decreaseIndent; - var writeTextOfNode; - var writer = createAndSetNewTextWriterWithSymbolWriter(); - var enclosingDeclaration; - var currentSourceFile; - var reportedDeclarationError = false; - var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { - } : writeJsDocComments; - var aliasDeclarationEmitInfo = []; - function createAndSetNewTextWriterWithSymbolWriter() { - var writer = createTextWriter(newLine); - 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; - setWriter(writer); - return writer; - } - function setWriter(newWriter) { - writer = newWriter; - write = newWriter.write; - writeTextOfNode = newWriter.writeTextOfNode; - writeLine = newWriter.writeLine; - increaseIndent = newWriter.increaseIndent; - decreaseIndent = newWriter.decreaseIndent; - } - function writeAsychronousImportDeclarations(importDeclarations) { - var oldWriter = writer; - ts.forEach(importDeclarations, function (aliasToWrite) { - var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; }); - if (aliasEmitInfo) { - createAndSetNewTextWriterWithSymbolWriter(); - for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { - increaseIndent(); - } - writeImportDeclaration(aliasToWrite); - aliasEmitInfo.asynchronousOutput = writer.getText(); - } - }); - setWriter(oldWriter); - } - function handleSymbolAccessibilityError(symbolAccesibilityResult) { - if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) { - if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { - writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); - } - } - else { - reportedDeclarationError = true; - var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult); - if (errorInfo) { - if (errorInfo.typeName) { - diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName)); - } - else { - diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName)); - } - } - } - } - function trackSymbol(symbol, enclosingDeclaration, meaning) { - handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); - } - function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - write(": "); - if (type) { - emitType(type); - } - else { - resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); - } - } - function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - write(": "); - if (signature.type) { - emitType(signature.type); - } - else { - resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); - } - } - function emitLines(nodes) { - for (var i = 0, n = nodes.length; i < n; i++) { - emitNode(nodes[i]); - } - } - function emitSeparatedList(nodes, separator, eachNodeEmitFn) { - var currentWriterPos = writer.getTextPos(); - for (var i = 0, n = nodes.length; i < n; i++) { - if (currentWriterPos !== writer.getTextPos()) { - write(separator); - } - currentWriterPos = writer.getTextPos(); - eachNodeEmitFn(nodes[i]); - } - } - function emitCommaList(nodes, eachNodeEmitFn) { - emitSeparatedList(nodes, ", ", eachNodeEmitFn); - } - function writeJsDocComments(declaration) { - if (declaration) { - var jsDocComments = ts.getJsDocComments(declaration, currentSourceFile); - emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments); - emitComments(currentSourceFile, writer, jsDocComments, true, newLine, writeCommentRange); - } - } - function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type, getSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - emitType(type); - } - function emitType(type) { - switch (type.kind) { - case 110 /* AnyKeyword */: - case 119 /* StringKeyword */: - case 117 /* NumberKeyword */: - case 111 /* BooleanKeyword */: - case 98 /* VoidKeyword */: - case 8 /* StringLiteral */: - return writeTextOfNode(currentSourceFile, type); - case 135 /* TypeReference */: - return emitTypeReference(type); - case 138 /* TypeQuery */: - return emitTypeQuery(type); - case 140 /* ArrayType */: - return emitArrayType(type); - case 141 /* TupleType */: - return emitTupleType(type); - case 142 /* UnionType */: - return emitUnionType(type); - case 143 /* ParenthesizedType */: - return emitParenType(type); - case 136 /* FunctionType */: - case 137 /* ConstructorType */: - return emitSignatureDeclarationWithJsDocComments(type); - case 139 /* TypeLiteral */: - return emitTypeLiteral(type); - case 64 /* Identifier */: - return emitEntityName(type); - case 121 /* QualifiedName */: - return emitEntityName(type); - default: - ts.Debug.fail("Unknown type annotation: " + type.kind); - } - function emitEntityName(entityName) { - var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 197 /* ImportDeclaration */ ? entityName.parent : enclosingDeclaration); - handleSymbolAccessibilityError(visibilityResult); - writeEntityName(entityName); - function writeEntityName(entityName) { - if (entityName.kind === 64 /* Identifier */) { - writeTextOfNode(currentSourceFile, entityName); - } - else { - var qualifiedName = entityName; - writeEntityName(qualifiedName.left); - write("."); - writeTextOfNode(currentSourceFile, qualifiedName.right); - } - } - } - function emitTypeReference(type) { - emitEntityName(type.typeName); - if (type.typeArguments) { - write("<"); - emitCommaList(type.typeArguments, emitType); - write(">"); - } - } - function emitTypeQuery(type) { - write("typeof "); - emitEntityName(type.exprName); - } - function emitArrayType(type) { - emitType(type.elementType); - write("[]"); - } - function emitTupleType(type) { - write("["); - emitCommaList(type.elementTypes, emitType); - write("]"); - } - function emitUnionType(type) { - emitSeparatedList(type.types, " | ", emitType); - } - function emitParenType(type) { - write("("); - emitType(type.type); - write(")"); - } - function emitTypeLiteral(type) { - write("{"); - if (type.members.length) { - writeLine(); - increaseIndent(); - emitLines(type.members); - decreaseIndent(); - } - write("}"); - } - } - function emitSourceFile(node) { - currentSourceFile = node; - enclosingDeclaration = node; - emitLines(node.statements); - } - function emitExportAssignment(node) { - write("export = "); - writeTextOfNode(currentSourceFile, node.exportName); - write(";"); - writeLine(); - } - function emitModuleElementDeclarationFlags(node) { - if (node.parent === currentSourceFile) { - if (node.flags & 1 /* Export */) { - write("export "); - } - if (node.kind !== 192 /* InterfaceDeclaration */) { - write("declare "); - } - } - } - function emitClassMemberDeclarationFlags(node) { - if (node.flags & 32 /* Private */) { - write("private "); - } - else if (node.flags & 64 /* Protected */) { - write("protected "); - } - if (node.flags & 128 /* Static */) { - write("static "); - } - } - function emitImportDeclaration(node) { - var nodeEmitInfo = { - declaration: node, - outputPos: writer.getTextPos(), - indent: writer.getIndent(), - hasWritten: resolver.isDeclarationVisible(node) - }; - aliasDeclarationEmitInfo.push(nodeEmitInfo); - if (nodeEmitInfo.hasWritten) { - writeImportDeclaration(node); - } - } - function writeImportDeclaration(node) { - emitJsDocComments(node); - if (node.flags & 1 /* Export */) { - write("export "); - } - write("import "); - writeTextOfNode(currentSourceFile, node.name); - write(" = "); - if (ts.isInternalModuleImportDeclaration(node)) { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError); - write(";"); - } - else { - write("require("); - writeTextOfNode(currentSourceFile, ts.getExternalModuleImportDeclarationExpression(node)); - write(");"); - } - writer.writeLine(); - function getImportEntityNameVisibilityError(symbolAccesibilityResult) { - return { - diagnosticMessage: ts.Diagnostics.Import_declaration_0_is_using_private_name_1, - errorNode: node, - typeName: node.name - }; - } - } - function emitModuleDeclaration(node) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("module "); - writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== 196 /* ModuleBlock */) { - node = node.body; - write("."); - writeTextOfNode(currentSourceFile, node.name); - } - var prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.body.statements); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - function emitTypeAliasDeclaration(node) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("type "); - writeTextOfNode(currentSourceFile, node.name); - write(" = "); - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); - write(";"); - writeLine(); - } - function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) { - return { - diagnosticMessage: ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, - errorNode: node.type, - typeName: node.name - }; - } - } - function emitEnumDeclaration(node) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (ts.isConst(node)) { - write("const "); - } - write("enum "); - writeTextOfNode(currentSourceFile, node.name); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - } - } - function emitEnumMemberDeclaration(node) { - emitJsDocComments(node); - writeTextOfNode(currentSourceFile, node.name); - var enumMemberValue = resolver.getEnumMemberValue(node); - if (enumMemberValue !== undefined) { - write(" = "); - write(enumMemberValue.toString()); - } - write(","); - writeLine(); - } - function isPrivateMethodTypeParameter(node) { - return node.parent.kind === 128 /* MethodDeclaration */ && (node.parent.flags & 32 /* Private */); - } - function emitTypeParameters(typeParameters) { - function emitTypeParameter(node) { - increaseIndent(); - emitJsDocComments(node); - decreaseIndent(); - writeTextOfNode(currentSourceFile, node.name); - if (node.constraint && !isPrivateMethodTypeParameter(node)) { - write(" extends "); - if (node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || (node.parent.parent && node.parent.parent.kind === 139 /* TypeLiteral */)) { - ts.Debug.assert(node.parent.kind === 128 /* MethodDeclaration */ || node.parent.kind === 127 /* MethodSignature */ || node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || node.parent.kind === 132 /* CallSignature */ || node.parent.kind === 133 /* ConstructSignature */); - emitType(node.constraint); - } - else { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError); - } - } - function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - switch (node.parent.kind) { - case 191 /* ClassDeclaration */: - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; - break; - case 192 /* InterfaceDeclaration */: - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; - break; - case 133 /* ConstructSignature */: - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - case 132 /* CallSignature */: - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - if (node.parent.flags & 128 /* Static */) { - diagnosticMessage = 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 === 191 /* ClassDeclaration */) { - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; - } - else { - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; - } - break; - case 190 /* FunctionDeclaration */: - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; - break; - default: - ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind); - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: node, - typeName: node.name - }; - } - } - if (typeParameters) { - write("<"); - emitCommaList(typeParameters, emitTypeParameter); - write(">"); - } - } - function emitHeritageClause(typeReferences, isImplementsList) { - if (typeReferences) { - write(isImplementsList ? " implements " : " extends "); - emitCommaList(typeReferences, emitTypeOfTypeReference); - } - function emitTypeOfTypeReference(node) { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); - function getHeritageClauseVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - if (node.parent.parent.kind === 191 /* ClassDeclaration */) { - diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; - } - else { - diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: node, - typeName: node.parent.parent.name - }; - } - } - } - function emitClassDeclaration(node) { - function emitParameterProperties(constructorDeclaration) { - if (constructorDeclaration) { - ts.forEach(constructorDeclaration.parameters, function (param) { - if (param.flags & 112 /* AccessibilityModifier */) { - emitPropertyDeclaration(param); - } - }); - } - } - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("class "); - writeTextOfNode(currentSourceFile, node.name); - var prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - var baseTypeNode = ts.getClassBaseTypeNode(node); - if (baseTypeNode) { - emitHeritageClause([baseTypeNode], false); - } - emitHeritageClause(ts.getClassImplementedTypeNodes(node), true); - write(" {"); - writeLine(); - increaseIndent(); - emitParameterProperties(getFirstConstructorWithBody(node)); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - function emitInterfaceDeclaration(node) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("interface "); - writeTextOfNode(currentSourceFile, node.name); - var prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - emitHeritageClause(ts.getInterfaceBaseTypeNodes(node), false); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - function emitPropertyDeclaration(node) { - emitJsDocComments(node); - emitClassMemberDeclarationFlags(node); - emitVariableDeclaration(node); - write(";"); - writeLine(); - } - function emitVariableDeclaration(node) { - if (node.kind !== 189 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { - writeTextOfNode(currentSourceFile, node.name); - if ((node.kind === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) && ts.hasQuestionToken(node)) { - write("?"); - } - if ((node.kind === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) && node.parent.kind === 139 /* TypeLiteral */) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); - } - else if (!(node.flags & 32 /* Private */)) { - writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); - } - } - function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - if (node.kind === 189 /* 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 === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) { - 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 === 191 /* 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 { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; - } - } - return diagnosticMessage !== undefined ? { - diagnosticMessage: diagnosticMessage, - errorNode: node, - typeName: node.name - } : undefined; - } - } - function emitTypeOfVariableDeclarationFromTypeLiteral(node) { - if (node.type) { - write(": "); - emitType(node.type); - } - } - function emitVariableStatement(node) { - var hasDeclarationWithEmit = ts.forEach(node.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); }); - if (hasDeclarationWithEmit) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (ts.isLet(node)) { - write("let "); - } - else if (ts.isConst(node)) { - write("const "); - } - else { - write("var "); - } - emitCommaList(node.declarations, emitVariableDeclaration); - write(";"); - writeLine(); - } - } - function emitAccessorDeclaration(node) { - var accessors = getAllAccessorDeclarations(node.parent, node); - if (node === accessors.firstAccessor) { - emitJsDocComments(accessors.getAccessor); - emitJsDocComments(accessors.setAccessor); - emitClassMemberDeclarationFlags(node); - writeTextOfNode(currentSourceFile, node.name); - if (!(node.flags & 32 /* Private */)) { - var accessorWithTypeAnnotation = node; - var type = getTypeAnnotationFromAccessor(node); - if (!type) { - var anotherAccessor = node.kind === 130 /* GetAccessor */ ? accessors.setAccessor : accessors.getAccessor; - type = getTypeAnnotationFromAccessor(anotherAccessor); - if (type) { - accessorWithTypeAnnotation = anotherAccessor; - } - } - writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError); - } - write(";"); - writeLine(); - } - function getTypeAnnotationFromAccessor(accessor) { - if (accessor) { - return accessor.kind === 130 /* GetAccessor */ ? accessor.type : accessor.parameters[0].type; - } - } - function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - if (accessorWithTypeAnnotation.kind === 131 /* SetAccessor */) { - if (accessorWithTypeAnnotation.parent.flags & 128 /* Static */) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; - } - else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: accessorWithTypeAnnotation.parameters[0], - typeName: accessorWithTypeAnnotation.name - }; - } - else { - if (accessorWithTypeAnnotation.flags & 128 /* Static */) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; - } - else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: accessorWithTypeAnnotation.name, - typeName: undefined - }; - } - } - } - function emitFunctionDeclaration(node) { - if ((node.kind !== 190 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { - emitJsDocComments(node); - if (node.kind === 190 /* FunctionDeclaration */) { - emitModuleElementDeclarationFlags(node); - } - else if (node.kind === 128 /* MethodDeclaration */) { - emitClassMemberDeclarationFlags(node); - } - if (node.kind === 190 /* FunctionDeclaration */) { - write("function "); - writeTextOfNode(currentSourceFile, node.name); - } - else if (node.kind === 129 /* Constructor */) { - write("constructor"); - } - else { - writeTextOfNode(currentSourceFile, node.name); - if (ts.hasQuestionToken(node)) { - write("?"); - } - } - emitSignatureDeclaration(node); - } - } - function emitSignatureDeclarationWithJsDocComments(node) { - emitJsDocComments(node); - emitSignatureDeclaration(node); - } - function emitSignatureDeclaration(node) { - if (node.kind === 133 /* ConstructSignature */ || node.kind === 137 /* ConstructorType */) { - write("new "); - } - emitTypeParameters(node.typeParameters); - if (node.kind === 134 /* IndexSignature */) { - write("["); - } - else { - write("("); - } - var prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitCommaList(node.parameters, emitParameterDeclaration); - if (node.kind === 134 /* IndexSignature */) { - write("]"); - } - else { - write(")"); - } - var isFunctionTypeOrConstructorType = node.kind === 136 /* FunctionType */ || node.kind === 137 /* ConstructorType */; - if (isFunctionTypeOrConstructorType || node.parent.kind === 139 /* TypeLiteral */) { - if (node.type) { - write(isFunctionTypeOrConstructorType ? " => " : ": "); - emitType(node.type); - } - } - else if (node.kind !== 129 /* Constructor */ && !(node.flags & 32 /* Private */)) { - writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); - } - enclosingDeclaration = prevEnclosingDeclaration; - if (!isFunctionTypeOrConstructorType) { - write(";"); - writeLine(); - } - function getReturnTypeVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - switch (node.kind) { - case 133 /* ConstructSignature */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - case 132 /* CallSignature */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - case 134 /* IndexSignature */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - 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 === 191 /* 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 190 /* 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: - ts.Debug.fail("This is unknown kind for signature: " + node.kind); - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: node.name || node - }; - } - } - function emitParameterDeclaration(node) { - increaseIndent(); - emitJsDocComments(node); - if (node.dotDotDotToken) { - write("..."); - } - if (ts.isBindingPattern(node.name)) { - write("_" + ts.indexOf(node.parent.parameters, node)); - } - else { - writeTextOfNode(currentSourceFile, node.name); - } - if (node.initializer || ts.hasQuestionToken(node)) { - write("?"); - } - decreaseIndent(); - if (node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || node.parent.parent.kind === 139 /* TypeLiteral */) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); - } - else if (!(node.parent.flags & 32 /* Private */)) { - writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError); - } - function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - switch (node.parent.kind) { - case 129 /* Constructor */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; - break; - case 133 /* ConstructSignature */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - case 132 /* CallSignature */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - 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 === 191 /* 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 190 /* 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: - ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind); - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: node, - typeName: node.name - }; - } - } - function emitNode(node) { - switch (node.kind) { - case 129 /* Constructor */: - case 190 /* FunctionDeclaration */: - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - return emitFunctionDeclaration(node); - case 133 /* ConstructSignature */: - case 132 /* CallSignature */: - case 134 /* IndexSignature */: - return emitSignatureDeclarationWithJsDocComments(node); - case 130 /* GetAccessor */: - case 131 /* SetAccessor */: - return emitAccessorDeclaration(node); - case 170 /* VariableStatement */: - return emitVariableStatement(node); - case 126 /* PropertyDeclaration */: - case 125 /* PropertySignature */: - return emitPropertyDeclaration(node); - case 192 /* InterfaceDeclaration */: - return emitInterfaceDeclaration(node); - case 191 /* ClassDeclaration */: - return emitClassDeclaration(node); - case 193 /* TypeAliasDeclaration */: - return emitTypeAliasDeclaration(node); - case 206 /* EnumMember */: - return emitEnumMemberDeclaration(node); - case 194 /* EnumDeclaration */: - return emitEnumDeclaration(node); - case 195 /* ModuleDeclaration */: - return emitModuleDeclaration(node); - case 197 /* ImportDeclaration */: - return emitImportDeclaration(node); - case 198 /* ExportAssignment */: - return emitExportAssignment(node); - case 207 /* SourceFile */: - return emitSourceFile(node); - } - } - var referencePathsOutput = ""; - function writeReferencePath(referencedFile) { - var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, program, ".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 = ts.tryResolveScriptReference(program, root, fileReference); - if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { - writeReferencePath(referencedFile); - if (!isExternalModuleOrDeclarationFile(referencedFile)) { - addedGlobalFileReference = true; - } - } - }); - } - emitNode(root); - } - else { - var emittedReferencedFiles = []; - ts.forEach(program.getSourceFiles(), function (sourceFile) { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - if (!compilerOptions.noResolve) { - ts.forEach(sourceFile.referencedFiles, function (fileReference) { - var referencedFile = ts.tryResolveScriptReference(program, sourceFile, fileReference); - if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) { - writeReferencePath(referencedFile); - emittedReferencedFiles.push(referencedFile); - } - }); - } - emitNode(sourceFile); - } - }); - } - return { - reportedDeclarationError: reportedDeclarationError, - aliasDeclarationEmitInfo: aliasDeclarationEmitInfo, - synchronousDeclarationOutput: writer.getText(), - referencePathsOutput: referencePathsOutput - }; - } - function getDeclarationDiagnostics(program, resolver, targetSourceFile) { - var diagnostics = []; - var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, program, ".js"); - emitDeclarations(program, resolver, diagnostics, jsFilePath, targetSourceFile); - return diagnostics; - } - ts.getDeclarationDiagnostics = getDeclarationDiagnostics; - function emitFiles(resolver, targetSourceFile) { - var program = resolver.getProgram(); - var compilerHost = program.getCompilerHost(); - var compilerOptions = program.getCompilerOptions(); - var sourceMapDataList = compilerOptions.sourceMap ? [] : undefined; - var diagnostics = []; - var newLine = program.getCompilerHost().getNewLine(); - function emitJavaScript(jsFilePath, root) { - var writer = createTextWriter(newLine); - var write = writer.write; - var writeTextOfNode = writer.writeTextOfNode; - var writeLine = writer.writeLine; - var increaseIndent = writer.increaseIndent; - var decreaseIndent = writer.decreaseIndent; - var currentSourceFile; - var extendsEmitted = false; - var tempCount = 0; - var tempVariables; - var tempParameters; - var writeEmittedFiles = writeJavaScriptFile; - var emitLeadingComments = compilerOptions.removeComments ? function (node) { - } : emitLeadingDeclarationComments; - var emitTrailingComments = compilerOptions.removeComments ? function (node) { - } : emitTrailingDeclarationComments; - var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { - } : emitLeadingCommentsOfLocalPosition; - var detachedCommentsInfo; - var emitDetachedComments = compilerOptions.removeComments ? function (node) { - } : emitDetachedCommentsAtPosition; - var emitPinnedOrTripleSlashComments = compilerOptions.removeComments ? function (node) { - } : emitPinnedOrTripleSlashCommentsOfNode; - var writeComment = writeCommentRange; - var emit = emitNode; - var emitStart = function (node) { - }; - var emitEnd = function (node) { - }; - var emitToken = emitTokenText; - var scopeEmitStart = function (scopeDeclaration, scopeName) { - }; - var scopeEmitEnd = function () { - }; - var sourceMapData; - function initializeEmitterWithSourceMaps() { - var sourceMapDir; - var sourceMapSourceIndex = -1; - var sourceMapNameIndexMap = {}; - var sourceMapNameIndices = []; - function getSourceMapNameIndex() { - return sourceMapNameIndices.length ? sourceMapNameIndices[sourceMapNameIndices.length - 1] : -1; - } - var lastRecordedSourceMapSpan; - var lastEncodedSourceMapSpan = { - emittedLine: 1, - emittedColumn: 1, - sourceLine: 1, - sourceColumn: 1, - sourceIndex: 0 - }; - var lastEncodedNameIndex = 0; - function encodeLastRecordedSourceMapSpan() { - if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { - return; - } - var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; - if (lastEncodedSourceMapSpan.emittedLine == lastRecordedSourceMapSpan.emittedLine) { - if (sourceMapData.sourceMapMappings) { - sourceMapData.sourceMapMappings += ","; - } - } - else { - for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { - sourceMapData.sourceMapMappings += ";"; - } - prevEncodedEmittedColumn = 1; - } - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); - if (lastRecordedSourceMapSpan.nameIndex >= 0) { - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); - lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; - } - lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; - sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); - function base64VLQFormatEncode(inValue) { - function base64FormatEncode(inValue) { - if (inValue < 64) { - return 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.charAt(inValue); - } - throw TypeError(inValue + ": not a 64 based value"); - } - if (inValue < 0) { - inValue = ((-inValue) << 1) + 1; - } - else { - inValue = inValue << 1; - } - var encodedStr = ""; - do { - var currentDigit = inValue & 31; - inValue = inValue >> 5; - if (inValue > 0) { - currentDigit = currentDigit | 32; - } - encodedStr = encodedStr + base64FormatEncode(currentDigit); - } while (inValue > 0); - return encodedStr; - } - } - function recordSourceMapSpan(pos) { - var sourceLinePos = currentSourceFile.getLineAndCharacterFromPosition(pos); - var emittedLine = writer.getLine(); - var emittedColumn = writer.getColumn(); - if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan.emittedLine != emittedLine || lastRecordedSourceMapSpan.emittedColumn != emittedColumn || (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { - encodeLastRecordedSourceMapSpan(); - lastRecordedSourceMapSpan = { - emittedLine: emittedLine, - emittedColumn: emittedColumn, - sourceLine: sourceLinePos.line, - sourceColumn: sourceLinePos.character, - nameIndex: getSourceMapNameIndex(), - sourceIndex: sourceMapSourceIndex - }; - } - else { - lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; - lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; - lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; - } - } - function recordEmitNodeStartSpan(node) { - recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); - } - function recordEmitNodeEndSpan(node) { - recordSourceMapSpan(node.end); - } - function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { - var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); - recordSourceMapSpan(tokenStartPos); - var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); - recordSourceMapSpan(tokenEndPos); - return tokenEndPos; - } - function recordNewSourceFileStart(node) { - var sourcesDirectoryPath = compilerOptions.sourceRoot ? program.getCommonSourceDirectory() : sourceMapDir; - sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, true)); - sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; - sourceMapData.inputSourceFileNames.push(node.filename); - } - function recordScopeNameOfNode(node, scopeName) { - function recordScopeNameIndex(scopeNameIndex) { - sourceMapNameIndices.push(scopeNameIndex); - } - function recordScopeNameStart(scopeName) { - var scopeNameIndex = -1; - if (scopeName) { - var parentIndex = getSourceMapNameIndex(); - if (parentIndex !== -1) { - scopeName = sourceMapData.sourceMapNames[parentIndex] + "." + scopeName; - } - scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); - if (scopeNameIndex === undefined) { - scopeNameIndex = sourceMapData.sourceMapNames.length; - sourceMapData.sourceMapNames.push(scopeName); - sourceMapNameIndexMap[scopeName] = scopeNameIndex; - } - } - recordScopeNameIndex(scopeNameIndex); - } - if (scopeName) { - recordScopeNameStart(scopeName); - } - else if (node.kind === 190 /* FunctionDeclaration */ || node.kind === 156 /* FunctionExpression */ || node.kind === 128 /* MethodDeclaration */ || node.kind === 127 /* MethodSignature */ || node.kind === 130 /* GetAccessor */ || node.kind === 131 /* SetAccessor */ || node.kind === 195 /* ModuleDeclaration */ || node.kind === 191 /* ClassDeclaration */ || node.kind === 194 /* EnumDeclaration */) { - if (node.name) { - scopeName = node.name.text; - } - recordScopeNameStart(scopeName); - } - else { - recordScopeNameIndex(getSourceMapNameIndex()); - } - } - function recordScopeNameEnd() { - sourceMapNameIndices.pop(); - } - ; - function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { - recordSourceMapSpan(comment.pos); - writeCommentRange(currentSourceFile, writer, comment, newLine); - recordSourceMapSpan(comment.end); - } - function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings) { - if (typeof JSON !== "undefined") { - return JSON.stringify({ - version: version, - file: file, - sourceRoot: sourceRoot, - sources: sources, - names: names, - mappings: mappings - }); - } - 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 += "\"" + ts.escapeString(list[i]) + "\""; - } - return output; - } - } - function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { - encodeLastRecordedSourceMapSpan(); - writeFile(compilerHost, diagnostics, sourceMapData.sourceMapFilePath, serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings), false); - sourceMapDataList.push(sourceMapData); - writeJavaScriptFile(emitOutput + "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL, writeByteOrderMark); - } - var sourceMapJsFile = ts.getBaseFilename(ts.normalizeSlashes(jsFilePath)); - sourceMapData = { - sourceMapFilePath: jsFilePath + ".map", - jsSourceMappingURL: sourceMapJsFile + ".map", - sourceMapFile: sourceMapJsFile, - sourceMapSourceRoot: compilerOptions.sourceRoot || "", - sourceMapSources: [], - inputSourceFileNames: [], - sourceMapNames: [], - sourceMapMappings: "", - sourceMapDecodedMappings: [] - }; - sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); - if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47 /* slash */) { - sourceMapData.sourceMapSourceRoot += ts.directorySeparator; - } - if (compilerOptions.mapRoot) { - sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); - if (root) { - sourceMapDir = ts.getDirectoryPath(getSourceFilePathInNewDir(root, program, sourceMapDir)); - } - 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(), compilerHost.getCanonicalFileName, true); - } - else { - sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); - } - } - else { - sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); - } - function emitNodeWithMap(node) { - if (node) { - if (node.kind != 207 /* SourceFile */) { - recordEmitNodeStartSpan(node); - emitNode(node); - recordEmitNodeEndSpan(node); - } - else { - recordNewSourceFileStart(node); - emitNode(node); - } - } - } - writeEmittedFiles = writeJavaScriptAndSourceMapFile; - emit = emitNodeWithMap; - emitStart = recordEmitNodeStartSpan; - emitEnd = recordEmitNodeEndSpan; - emitToken = writeTextWithSpanRecord; - scopeEmitStart = recordScopeNameOfNode; - scopeEmitEnd = recordScopeNameEnd; - writeComment = writeCommentRangeWithMap; - } - function writeJavaScriptFile(emitOutput, writeByteOrderMark) { - writeFile(compilerHost, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); - } - function createTempVariable(location, forLoopVariable) { - var name = forLoopVariable ? "_i" : undefined; - while (true) { - if (name && resolver.isUnknownIdentifier(location, name)) { - break; - } - name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + 97 /* a */) : tempCount - 25); - tempCount++; - } - var result = ts.createNode(64 /* Identifier */); - result.text = name; - return result; - } - function recordTempDeclaration(name) { - if (!tempVariables) { - tempVariables = []; - } - tempVariables.push(name); - } - function emitTempDeclarations(newLine) { - if (tempVariables) { - if (newLine) { - writeLine(); - } - else { - write(" "); - } - write("var "); - emitCommaList(tempVariables); - write(";"); - } - } - function emitTokenText(tokenKind, startPos, emitFn) { - var tokenString = ts.tokenToString(tokenKind); - if (emitFn) { - emitFn(); - } - else { - write(tokenString); - } - return startPos + tokenString.length; - } - function emitOptional(prefix, node) { - if (node) { - write(prefix); - emit(node); - } - } - function emitTrailingCommaIfPresent(nodeList) { - if (nodeList.hasTrailingComma) { - write(","); - } - } - 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 emitMultiLineList(nodes) { - if (nodes) { - for (var i = 0; i < nodes.length; i++) { - if (i) { - write(","); - } - writeLine(); - emit(nodes[i]); - } - } - } - function emitLines(nodes) { - emitLinesStartingAt(nodes, 0); - } - function emitLinesStartingAt(nodes, startIndex) { - for (var i = startIndex; i < nodes.length; i++) { - writeLine(); - emit(nodes[i]); - } - } - function isBinaryOrOctalIntegerLiteral(text) { - if (text.length <= 0) { - return false; - } - if (text.charCodeAt(1) === 66 /* B */ || text.charCodeAt(1) === 98 /* b */ || text.charCodeAt(1) === 79 /* O */ || text.charCodeAt(1) === 111 /* o */) { - return true; - } - return false; - } - function emitLiteral(node) { - var text = compilerOptions.target < 2 /* ES6 */ && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; - if (compilerOptions.sourceMap && (node.kind === 8 /* StringLiteral */ || ts.isTemplateLiteralKind(node.kind))) { - writer.writeLiteral(text); - } - else if (compilerOptions.target < 2 /* ES6 */ && node.kind === 7 /* NumericLiteral */ && isBinaryOrOctalIntegerLiteral(text)) { - write(node.text); - } - else { - write(text); - } - } - function getTemplateLiteralAsStringLiteral(node) { - return '"' + ts.escapeString(node.text) + '"'; - } - function emitTemplateExpression(node) { - if (compilerOptions.target >= 2 /* ES6 */) { - ts.forEachChild(node, emit); - return; - } - ts.Debug.assert(node.parent.kind !== 153 /* TaggedTemplateExpression */); - var emitOuterParens = ts.isExpression(node.parent) && templateNeedsParens(node, node.parent); - if (emitOuterParens) { - write("("); - } - emitLiteral(node.head); - ts.forEach(node.templateSpans, function (templateSpan) { - var needsParens = templateSpan.expression.kind !== 155 /* ParenthesizedExpression */ && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1 /* GreaterThan */; - write(" + "); - if (needsParens) { - write("("); - } - emit(templateSpan.expression); - if (needsParens) { - write(")"); - } - if (templateSpan.literal.text.length !== 0) { - write(" + "); - emitLiteral(templateSpan.literal); - } - }); - if (emitOuterParens) { - write(")"); - } - function templateNeedsParens(template, parent) { - switch (parent.kind) { - case 151 /* CallExpression */: - case 152 /* NewExpression */: - return parent.expression === template; - case 155 /* ParenthesizedExpression */: - return false; - case 153 /* TaggedTemplateExpression */: - ts.Debug.fail("Path should be unreachable; tagged templates not supported pre-ES6."); - default: - return comparePrecedenceToBinaryPlus(parent) !== -1 /* LessThan */; - } - } - function comparePrecedenceToBinaryPlus(expression) { - ts.Debug.assert(compilerOptions.target <= 1 /* ES5 */); - switch (expression.kind) { - case 163 /* BinaryExpression */: - switch (expression.operator) { - case 35 /* AsteriskToken */: - case 36 /* SlashToken */: - case 37 /* PercentToken */: - return 1 /* GreaterThan */; - case 33 /* PlusToken */: - return 0 /* EqualTo */; - default: - return -1 /* LessThan */; - } - case 164 /* ConditionalExpression */: - return -1 /* LessThan */; - default: - return 1 /* GreaterThan */; - } - } - } - function emitTemplateSpan(span) { - emit(span.expression); - emit(span.literal); - } - function emitExpressionForPropertyName(node) { - if (node.kind === 8 /* StringLiteral */) { - emitLiteral(node); - } - else if (node.kind === 122 /* ComputedPropertyName */) { - emit(node.expression); - } - else { - write("\""); - if (node.kind === 7 /* NumericLiteral */) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - write("\""); - } - } - function isNotExpressionIdentifier(node) { - var parent = node.parent; - switch (parent.kind) { - case 124 /* Parameter */: - case 189 /* VariableDeclaration */: - case 146 /* BindingElement */: - case 126 /* PropertyDeclaration */: - case 125 /* PropertySignature */: - case 204 /* PropertyAssignment */: - case 205 /* ShorthandPropertyAssignment */: - case 206 /* EnumMember */: - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - case 190 /* FunctionDeclaration */: - case 130 /* GetAccessor */: - case 131 /* SetAccessor */: - case 156 /* FunctionExpression */: - case 191 /* ClassDeclaration */: - case 192 /* InterfaceDeclaration */: - case 194 /* EnumDeclaration */: - case 195 /* ModuleDeclaration */: - case 197 /* ImportDeclaration */: - return parent.name === node; - case 179 /* BreakStatement */: - case 178 /* ContinueStatement */: - case 198 /* ExportAssignment */: - return false; - case 183 /* LabeledStatement */: - return node.parent.label === node; - case 203 /* CatchClause */: - return node.parent.name === node; - } - } - function emitExpressionIdentifier(node) { - var prefix = resolver.getExpressionNamePrefix(node); - if (prefix) { - write(prefix); - write("."); - } - writeTextOfNode(currentSourceFile, node); - } - function emitIdentifier(node) { - if (!node.parent) { - write(node.text); - } - else if (!isNotExpressionIdentifier(node)) { - emitExpressionIdentifier(node); - } - else { - writeTextOfNode(currentSourceFile, node); - } - } - function emitThis(node) { - if (resolver.getNodeCheckFlags(node) & 2 /* LexicalThis */) { - write("_this"); - } - else { - write("this"); - } - } - function emitSuper(node) { - var flags = resolver.getNodeCheckFlags(node); - if (flags & 16 /* SuperInstance */) { - write("_super.prototype"); - } - else if (flags & 32 /* SuperStatic */) { - write("_super"); - } - else { - write("super"); - } - } - function emitObjectBindingPattern(node) { - write("{ "); - emitCommaList(node.elements); - emitTrailingCommaIfPresent(node.elements); - write(" }"); - } - function emitArrayBindingPattern(node) { - write("["); - emitCommaList(node.elements); - emitTrailingCommaIfPresent(node.elements); - write("]"); - } - function emitArrayLiteral(node) { - if (node.flags & 256 /* MultiLine */) { - write("["); - increaseIndent(); - emitMultiLineList(node.elements); - emitTrailingCommaIfPresent(node.elements); - decreaseIndent(); - writeLine(); - write("]"); - } - else { - write("["); - emitCommaList(node.elements); - emitTrailingCommaIfPresent(node.elements); - write("]"); - } - } - function emitObjectLiteral(node) { - if (!node.properties.length) { - write("{}"); - } - else if (node.flags & 256 /* MultiLine */) { - write("{"); - increaseIndent(); - emitMultiLineList(node.properties); - if (compilerOptions.target >= 1 /* ES5 */) { - emitTrailingCommaIfPresent(node.properties); - } - decreaseIndent(); - writeLine(); - write("}"); - } - else { - write("{ "); - emitCommaList(node.properties); - if (compilerOptions.target >= 1 /* ES5 */) { - emitTrailingCommaIfPresent(node.properties); - } - write(" }"); - } - } - function emitComputedPropertyName(node) { - write("["); - emit(node.expression); - write("]"); - } - function emitMethod(node) { - if (!ts.isObjectLiteralMethod(node)) { - return; - } - emitLeadingComments(node); - emit(node.name); - if (compilerOptions.target < 2 /* ES6 */) { - write(": function "); - } - emitSignatureAndBody(node); - emitTrailingComments(node); - } - function emitPropertyAssignment(node) { - emitLeadingComments(node); - emit(node.name); - write(": "); - emit(node.initializer); - emitTrailingComments(node); - } - function emitShorthandPropertyAssignment(node) { - emitLeadingComments(node); - emit(node.name); - if (compilerOptions.target < 2 /* ES6 */ || resolver.getExpressionNamePrefix(node.name)) { - write(": "); - emitExpressionIdentifier(node.name); - } - emitTrailingComments(node); - } - function tryEmitConstantValue(node) { - var constantValue = resolver.getConstantValue(node); - if (constantValue !== undefined) { - var propertyName = node.kind === 149 /* PropertyAccessExpression */ ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); - write(constantValue.toString() + " /* " + propertyName + " */"); - return true; - } - return false; - } - function emitPropertyAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - write("."); - emit(node.name); - } - function emitQualifiedName(node) { - emit(node.left); - write("."); - emit(node.right); - } - function emitIndexedAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - write("["); - emit(node.argumentExpression); - write("]"); - } - function emitCallExpression(node) { - var superCall = false; - if (node.expression.kind === 90 /* SuperKeyword */) { - write("_super"); - superCall = true; - } - else { - emit(node.expression); - superCall = node.expression.kind === 149 /* PropertyAccessExpression */ && node.expression.expression.kind === 90 /* SuperKeyword */; - } - if (superCall) { - write(".call("); - emitThis(node.expression); - if (node.arguments.length) { - write(", "); - emitCommaList(node.arguments); - } - write(")"); - } - else { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - function emitNewExpression(node) { - write("new "); - emit(node.expression); - if (node.arguments) { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - function emitTaggedTemplateExpression(node) { - ts.Debug.assert(compilerOptions.target >= 2 /* ES6 */, "Trying to emit a tagged template in pre-ES6 mode."); - emit(node.tag); - write(" "); - emit(node.template); - } - function emitParenExpression(node) { - if (node.expression.kind === 154 /* TypeAssertionExpression */) { - var operand = node.expression.expression; - while (operand.kind == 154 /* TypeAssertionExpression */) { - operand = operand.expression; - } - if (operand.kind !== 161 /* PrefixUnaryExpression */ && operand.kind !== 160 /* VoidExpression */ && operand.kind !== 159 /* TypeOfExpression */ && operand.kind !== 158 /* DeleteExpression */ && operand.kind !== 162 /* PostfixUnaryExpression */ && operand.kind !== 152 /* NewExpression */ && !(operand.kind === 151 /* CallExpression */ && node.parent.kind === 152 /* NewExpression */) && !(operand.kind === 156 /* FunctionExpression */ && node.parent.kind === 151 /* CallExpression */)) { - emit(operand); - return; - } - } - write("("); - emit(node.expression); - write(")"); - } - function emitDeleteExpression(node) { - write(ts.tokenToString(73 /* DeleteKeyword */)); - write(" "); - emit(node.expression); - } - function emitVoidExpression(node) { - write(ts.tokenToString(98 /* VoidKeyword */)); - write(" "); - emit(node.expression); - } - function emitTypeOfExpression(node) { - write(ts.tokenToString(96 /* TypeOfKeyword */)); - write(" "); - emit(node.expression); - } - function emitPrefixUnaryExpression(node) { - write(ts.tokenToString(node.operator)); - if (node.operand.kind === 161 /* PrefixUnaryExpression */) { - var operand = node.operand; - if (node.operator === 33 /* PlusToken */ && (operand.operator === 33 /* PlusToken */ || operand.operator === 38 /* PlusPlusToken */)) { - write(" "); - } - else if (node.operator === 34 /* MinusToken */ && (operand.operator === 34 /* MinusToken */ || operand.operator === 39 /* MinusMinusToken */)) { - write(" "); - } - } - emit(node.operand); - } - function emitPostfixUnaryExpression(node) { - emit(node.operand); - write(ts.tokenToString(node.operator)); - } - function emitBinaryExpression(node) { - if (node.operator === 52 /* EqualsToken */ && (node.left.kind === 148 /* ObjectLiteralExpression */ || node.left.kind === 147 /* ArrayLiteralExpression */)) { - emitDestructuring(node); - } - else { - emit(node.left); - if (node.operator !== 23 /* CommaToken */) - write(" "); - write(ts.tokenToString(node.operator)); - write(" "); - emit(node.right); - } - } - function emitConditionalExpression(node) { - emit(node.condition); - write(" ? "); - emit(node.whenTrue); - write(" : "); - emit(node.whenFalse); - } - function emitBlock(node) { - emitToken(14 /* OpenBraceToken */, node.pos); - increaseIndent(); - scopeEmitStart(node.parent); - if (node.kind === 196 /* ModuleBlock */) { - ts.Debug.assert(node.parent.kind === 195 /* ModuleDeclaration */); - emitCaptureThisForNodeIfNecessary(node.parent); - } - emitLines(node.statements); - if (node.kind === 196 /* ModuleBlock */) { - emitTempDeclarations(true); - } - decreaseIndent(); - writeLine(); - emitToken(15 /* CloseBraceToken */, node.statements.end); - scopeEmitEnd(); - } - function emitEmbeddedStatement(node) { - if (node.kind === 169 /* Block */) { - write(" "); - emit(node); - } - else { - increaseIndent(); - writeLine(); - emit(node); - decreaseIndent(); - } - } - function emitExpressionStatement(node) { - var isArrowExpression = node.expression.kind === 157 /* ArrowFunction */; - emitLeadingComments(node); - if (isArrowExpression) - write("("); - emit(node.expression); - if (isArrowExpression) - write(")"); - write(";"); - emitTrailingComments(node); - } - function emitIfStatement(node) { - emitLeadingComments(node); - var endPos = emitToken(83 /* IfKeyword */, node.pos); - write(" "); - endPos = emitToken(16 /* OpenParenToken */, endPos); - emit(node.expression); - emitToken(17 /* CloseParenToken */, node.expression.end); - emitEmbeddedStatement(node.thenStatement); - if (node.elseStatement) { - writeLine(); - emitToken(75 /* ElseKeyword */, node.thenStatement.end); - if (node.elseStatement.kind === 173 /* IfStatement */) { - write(" "); - emit(node.elseStatement); - } - else { - emitEmbeddedStatement(node.elseStatement); - } - } - emitTrailingComments(node); - } - function emitDoStatement(node) { - write("do"); - emitEmbeddedStatement(node.statement); - if (node.statement.kind === 169 /* Block */) { - write(" "); - } - else { - writeLine(); - } - write("while ("); - emit(node.expression); - write(");"); - } - function emitWhileStatement(node) { - write("while ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitForStatement(node) { - var endPos = emitToken(81 /* ForKeyword */, node.pos); - write(" "); - endPos = emitToken(16 /* OpenParenToken */, endPos); - if (node.declarations) { - if (node.declarations[0] && ts.isLet(node.declarations[0])) { - emitToken(103 /* LetKeyword */, endPos); - } - else if (node.declarations[0] && ts.isConst(node.declarations[0])) { - emitToken(69 /* ConstKeyword */, endPos); - } - else { - emitToken(97 /* VarKeyword */, endPos); - } - write(" "); - emitCommaList(node.declarations); - } - if (node.initializer) { - emit(node.initializer); - } - write(";"); - emitOptional(" ", node.condition); - write(";"); - emitOptional(" ", node.iterator); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitForInStatement(node) { - var endPos = emitToken(81 /* ForKeyword */, node.pos); - write(" "); - endPos = emitToken(16 /* OpenParenToken */, endPos); - if (node.declarations) { - if (node.declarations.length >= 1) { - var decl = node.declarations[0]; - if (ts.isLet(decl)) { - emitToken(103 /* LetKeyword */, endPos); - } - else { - emitToken(97 /* VarKeyword */, endPos); - } - write(" "); - emit(decl); - } - } - else { - emit(node.variable); - } - write(" in "); - emit(node.expression); - emitToken(17 /* CloseParenToken */, node.expression.end); - emitEmbeddedStatement(node.statement); - } - function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 179 /* BreakStatement */ ? 65 /* BreakKeyword */ : 70 /* ContinueKeyword */, node.pos); - emitOptional(" ", node.label); - write(";"); - } - function emitReturnStatement(node) { - emitLeadingComments(node); - emitToken(89 /* ReturnKeyword */, node.pos); - emitOptional(" ", node.expression); - write(";"); - emitTrailingComments(node); - } - function emitWithStatement(node) { - write("with ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitSwitchStatement(node) { - var endPos = emitToken(91 /* SwitchKeyword */, node.pos); - write(" "); - emitToken(16 /* OpenParenToken */, endPos); - emit(node.expression); - endPos = emitToken(17 /* CloseParenToken */, node.expression.end); - write(" "); - emitToken(14 /* OpenBraceToken */, endPos); - increaseIndent(); - emitLines(node.clauses); - decreaseIndent(); - writeLine(); - emitToken(15 /* CloseBraceToken */, node.clauses.end); - } - function isOnSameLine(node1, node2) { - return getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); - } - function emitCaseOrDefaultClause(node) { - if (node.kind === 200 /* CaseClause */) { - write("case "); - emit(node.expression); - write(":"); - } - else { - write("default:"); - } - if (node.statements.length === 1 && isOnSameLine(node, node.statements[0])) { - write(" "); - emit(node.statements[0]); - } - else { - increaseIndent(); - emitLines(node.statements); - decreaseIndent(); - } - } - function emitThrowStatement(node) { - write("throw "); - emit(node.expression); - write(";"); - } - function emitTryStatement(node) { - write("try "); - emit(node.tryBlock); - emit(node.catchClause); - if (node.finallyBlock) { - writeLine(); - write("finally "); - emit(node.finallyBlock); - } - } - function emitCatchClause(node) { - writeLine(); - var endPos = emitToken(67 /* CatchKeyword */, node.pos); - write(" "); - emitToken(16 /* OpenParenToken */, endPos); - emit(node.name); - emitToken(17 /* CloseParenToken */, node.name.end); - write(" "); - emitBlock(node.block); - } - function emitDebuggerStatement(node) { - emitToken(71 /* DebuggerKeyword */, node.pos); - write(";"); - } - function emitLabelledStatement(node) { - emit(node.label); - write(": "); - emit(node.statement); - } - function getContainingModule(node) { - do { - node = node.parent; - } while (node && node.kind !== 195 /* ModuleDeclaration */); - return node; - } - function emitModuleMemberName(node) { - emitStart(node.name); - if (node.flags & 1 /* Export */) { - var container = getContainingModule(node); - write(container ? resolver.getLocalNameOfContainer(container) : "exports"); - write("."); - } - emitNode(node.name); - emitEnd(node.name); - } - function emitDestructuring(root, value) { - var emitCount = 0; - var isDeclaration = (root.kind === 189 /* VariableDeclaration */ && !(root.flags & 1 /* Export */)) || root.kind === 124 /* Parameter */; - if (root.kind === 163 /* BinaryExpression */) { - emitAssignmentExpression(root); - } - else { - emitBindingElement(root, value); - } - function emitAssignment(name, value) { - if (emitCount++) { - write(", "); - } - if (name.parent && (name.parent.kind === 189 /* VariableDeclaration */ || name.parent.kind === 146 /* BindingElement */)) { - emitModuleMemberName(name.parent); - } - else { - emit(name); - } - write(" = "); - emit(value); - } - function ensureIdentifier(expr) { - if (expr.kind !== 64 /* Identifier */) { - var identifier = createTempVariable(root); - if (!isDeclaration) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - expr = identifier; - } - return expr; - } - function createVoidZero() { - var zero = ts.createNode(7 /* NumericLiteral */); - zero.text = "0"; - var result = ts.createNode(160 /* VoidExpression */); - result.expression = zero; - return result; - } - function createDefaultValueCheck(value, defaultValue) { - value = ensureIdentifier(value); - var equals = ts.createNode(163 /* BinaryExpression */); - equals.left = value; - equals.operator = 30 /* EqualsEqualsEqualsToken */; - equals.right = createVoidZero(); - var cond = ts.createNode(164 /* ConditionalExpression */); - cond.condition = equals; - cond.whenTrue = defaultValue; - cond.whenFalse = value; - return cond; - } - function createNumericLiteral(value) { - var node = ts.createNode(7 /* NumericLiteral */); - node.text = "" + value; - return node; - } - function parenthesizeForAccess(expr) { - if (expr.kind === 64 /* Identifier */ || expr.kind === 149 /* PropertyAccessExpression */ || expr.kind === 150 /* ElementAccessExpression */) { - return expr; - } - var node = ts.createNode(155 /* ParenthesizedExpression */); - node.expression = expr; - return node; - } - function createPropertyAccess(object, propName) { - if (propName.kind !== 64 /* Identifier */) { - return createElementAccess(object, propName); - } - var node = ts.createNode(149 /* PropertyAccessExpression */); - node.expression = parenthesizeForAccess(object); - node.name = propName; - return node; - } - function createElementAccess(object, index) { - var node = ts.createNode(150 /* ElementAccessExpression */); - node.expression = parenthesizeForAccess(object); - node.argumentExpression = index; - return node; - } - function emitObjectLiteralAssignment(target, value) { - var properties = target.properties; - if (properties.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < properties.length; i++) { - var p = properties[i]; - if (p.kind === 204 /* PropertyAssignment */ || p.kind === 205 /* ShorthandPropertyAssignment */) { - var propName = (p.name); - emitDestructuringAssignment(p.initializer || propName, createPropertyAccess(value, propName)); - } - } - } - function emitArrayLiteralAssignment(target, value) { - var elements = target.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < elements.length; i++) { - var e = elements[i]; - if (e.kind !== 167 /* OmittedExpression */) { - emitDestructuringAssignment(e, createElementAccess(value, createNumericLiteral(i))); - } - } - } - function emitDestructuringAssignment(target, value) { - if (target.kind === 163 /* BinaryExpression */ && target.operator === 52 /* EqualsToken */) { - value = createDefaultValueCheck(value, target.right); - target = target.left; - } - if (target.kind === 148 /* ObjectLiteralExpression */) { - emitObjectLiteralAssignment(target, value); - } - else if (target.kind === 147 /* ArrayLiteralExpression */) { - emitArrayLiteralAssignment(target, value); - } - else { - emitAssignment(target, value); - } - } - function emitAssignmentExpression(root) { - var target = root.left; - var value = root.right; - if (root.parent.kind === 172 /* ExpressionStatement */) { - emitDestructuringAssignment(target, value); - } - else { - if (root.parent.kind !== 155 /* ParenthesizedExpression */) { - write("("); - } - value = ensureIdentifier(value); - emitDestructuringAssignment(target, value); - write(", "); - emit(value); - if (root.parent.kind !== 155 /* ParenthesizedExpression */) { - write(")"); - } - } - } - function emitBindingElement(target, value) { - if (target.initializer) { - value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; - } - else if (!value) { - value = createVoidZero(); - } - if (ts.isBindingPattern(target.name)) { - var pattern = target.name; - var elements = pattern.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < elements.length; i++) { - var element = elements[i]; - if (pattern.kind === 144 /* ObjectBindingPattern */) { - var propName = element.propertyName || element.name; - emitBindingElement(element, createPropertyAccess(value, propName)); - } - else if (element.kind !== 167 /* OmittedExpression */) { - emitBindingElement(element, createElementAccess(value, createNumericLiteral(i))); - } - } - } - else { - emitAssignment(target.name, value); - } - } - } - function emitVariableDeclaration(node) { - emitLeadingComments(node); - if (ts.isBindingPattern(node.name)) { - emitDestructuring(node); - } - else { - emitModuleMemberName(node); - emitOptional(" = ", node.initializer); - } - emitTrailingComments(node); - } - function emitVariableStatement(node) { - emitLeadingComments(node); - if (!(node.flags & 1 /* Export */)) { - if (ts.isLet(node)) { - write("let "); - } - else if (ts.isConst(node)) { - write("const "); - } - else { - write("var "); - } - } - emitCommaList(node.declarations); - write(";"); - emitTrailingComments(node); - } - function emitParameter(node) { - emitLeadingComments(node); - if (ts.isBindingPattern(node.name)) { - var name = createTempVariable(node); - if (!tempParameters) { - tempParameters = []; - } - tempParameters.push(name); - emit(name); - } - else { - emit(node.name); - } - emitTrailingComments(node); - } - function emitDefaultValueAssignments(node) { - var tempIndex = 0; - ts.forEach(node.parameters, function (p) { - if (ts.isBindingPattern(p.name)) { - writeLine(); - write("var "); - emitDestructuring(p, tempParameters[tempIndex]); - write(";"); - tempIndex++; - } - else if (p.initializer) { - writeLine(); - emitStart(p); - write("if ("); - emitNode(p.name); - write(" === void 0)"); - emitEnd(p); - write(" { "); - emitStart(p); - emitNode(p.name); - write(" = "); - emitNode(p.initializer); - emitEnd(p); - write("; }"); - } - }); - } - function emitRestParameter(node) { - if (ts.hasRestParameters(node)) { - var restIndex = node.parameters.length - 1; - var restParam = node.parameters[restIndex]; - var tempName = createTempVariable(node, true).text; - writeLine(); - emitLeadingComments(restParam); - emitStart(restParam); - write("var "); - emitNode(restParam.name); - write(" = [];"); - emitEnd(restParam); - emitTrailingComments(restParam); - writeLine(); - write("for ("); - emitStart(restParam); - write("var " + tempName + " = " + restIndex + ";"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + " < arguments.length;"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + "++"); - emitEnd(restParam); - write(") {"); - increaseIndent(); - writeLine(); - emitStart(restParam); - emitNode(restParam.name); - write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); - emitEnd(restParam); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function emitAccessor(node) { - emitLeadingComments(node); - write(node.kind === 130 /* GetAccessor */ ? "get " : "set "); - emit(node.name); - emitSignatureAndBody(node); - emitTrailingComments(node); - } - function emitFunctionDeclaration(node) { - if (!node.body) { - return emitPinnedOrTripleSlashComments(node); - } - if (node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { - emitLeadingComments(node); - } - write("function "); - if (node.kind === 190 /* FunctionDeclaration */ || (node.kind === 156 /* FunctionExpression */ && node.name)) { - emit(node.name); - } - emitSignatureAndBody(node); - if (node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { - emitTrailingComments(node); - } - } - function emitCaptureThisForNodeIfNecessary(node) { - if (resolver.getNodeCheckFlags(node) & 4 /* CaptureThis */) { - writeLine(); - emitStart(node); - write("var _this = this;"); - emitEnd(node); - } - } - function emitSignatureParameters(node) { - increaseIndent(); - write("("); - if (node) { - emitCommaList(node.parameters, node.parameters.length - (ts.hasRestParameters(node) ? 1 : 0)); - } - write(")"); - decreaseIndent(); - } - function emitSignatureAndBody(node) { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; - tempParameters = undefined; - emitSignatureParameters(node); - write(" {"); - scopeEmitStart(node); - increaseIndent(); - emitDetachedComments(node.body.kind === 169 /* Block */ ? node.body.statements : node.body); - var startIndex = 0; - if (node.body.kind === 169 /* Block */) { - startIndex = emitDirectivePrologues(node.body.statements, true); - } - var outPos = writer.getTextPos(); - emitCaptureThisForNodeIfNecessary(node); - emitDefaultValueAssignments(node); - emitRestParameter(node); - if (node.body.kind !== 169 /* Block */ && outPos === writer.getTextPos()) { - decreaseIndent(); - write(" "); - emitStart(node.body); - write("return "); - emitNode(node.body); - emitEnd(node.body); - write(";"); - emitTempDeclarations(false); - write(" "); - emitStart(node.body); - write("}"); - emitEnd(node.body); - } - else { - if (node.body.kind === 169 /* Block */) { - emitLinesStartingAt(node.body.statements, startIndex); - } - else { - writeLine(); - emitLeadingComments(node.body); - write("return "); - emit(node.body); - write(";"); - emitTrailingComments(node.body); - } - emitTempDeclarations(true); - writeLine(); - if (node.body.kind === 169 /* Block */) { - emitLeadingCommentsOfPosition(node.body.statements.end); - decreaseIndent(); - emitToken(15 /* CloseBraceToken */, node.body.statements.end); - } - else { - decreaseIndent(); - emitStart(node.body); - write("}"); - emitEnd(node.body); - } - } - scopeEmitEnd(); - if (node.flags & 1 /* Export */) { - writeLine(); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emit(node.name); - emitEnd(node); - write(";"); - } - tempCount = saveTempCount; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - function findInitialSuperCall(ctor) { - if (ctor.body) { - var statement = ctor.body.statements[0]; - if (statement && statement.kind === 172 /* ExpressionStatement */) { - var expr = statement.expression; - if (expr && expr.kind === 151 /* CallExpression */) { - var func = expr.expression; - if (func && func.kind === 90 /* SuperKeyword */) { - return statement; - } - } - } - } - } - function emitParameterPropertyAssignments(node) { - ts.forEach(node.parameters, function (param) { - if (param.flags & 112 /* AccessibilityModifier */) { - writeLine(); - emitStart(param); - emitStart(param.name); - write("this."); - emitNode(param.name); - emitEnd(param.name); - write(" = "); - emit(param.name); - write(";"); - emitEnd(param); - } - }); - } - function emitMemberAccessForPropertyName(memberName) { - if (memberName.kind === 8 /* StringLiteral */ || memberName.kind === 7 /* NumericLiteral */) { - write("["); - emitNode(memberName); - write("]"); - } - else if (memberName.kind === 122 /* ComputedPropertyName */) { - emitComputedPropertyName(memberName); - } - else { - write("."); - emitNode(memberName); - } - } - function emitMemberAssignments(node, staticFlag) { - ts.forEach(node.members, function (member) { - if (member.kind === 126 /* PropertyDeclaration */ && (member.flags & 128 /* Static */) === staticFlag && member.initializer) { - writeLine(); - emitLeadingComments(member); - emitStart(member); - emitStart(member.name); - if (staticFlag) { - emitNode(node.name); - } - else { - write("this"); - } - emitMemberAccessForPropertyName(member.name); - emitEnd(member.name); - write(" = "); - emit(member.initializer); - write(";"); - emitEnd(member); - emitTrailingComments(member); - } - }); - } - function emitMemberFunctions(node) { - ts.forEach(node.members, function (member) { - if (member.kind === 128 /* MethodDeclaration */ || node.kind === 127 /* MethodSignature */) { - if (!member.body) { - return emitPinnedOrTripleSlashComments(member); - } - writeLine(); - emitLeadingComments(member); - emitStart(member); - emitStart(member.name); - emitNode(node.name); - if (!(member.flags & 128 /* Static */)) { - write(".prototype"); - } - emitMemberAccessForPropertyName(member.name); - emitEnd(member.name); - write(" = "); - emitStart(member); - emitFunctionDeclaration(member); - emitEnd(member); - emitEnd(member); - write(";"); - emitTrailingComments(member); - } - else if (member.kind === 130 /* GetAccessor */ || member.kind === 131 /* SetAccessor */) { - var accessors = getAllAccessorDeclarations(node, member); - if (member === accessors.firstAccessor) { - writeLine(); - emitStart(member); - write("Object.defineProperty("); - emitStart(member.name); - emitNode(node.name); - if (!(member.flags & 128 /* Static */)) { - write(".prototype"); - } - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write(", {"); - increaseIndent(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - write("get: "); - emitStart(accessors.getAccessor); - write("function "); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - write(","); - } - if (accessors.setAccessor) { - writeLine(); - emitLeadingComments(accessors.setAccessor); - write("set: "); - emitStart(accessors.setAccessor); - write("function "); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor); - write(","); - } - writeLine(); - write("enumerable: true,"); - writeLine(); - write("configurable: true"); - decreaseIndent(); - writeLine(); - write("});"); - emitEnd(member); - } - } - }); - } - function emitClassDeclaration(node) { - emitLeadingComments(node); - write("var "); - emit(node.name); - write(" = (function ("); - var baseTypeNode = ts.getClassBaseTypeNode(node); - if (baseTypeNode) { - write("_super"); - } - write(") {"); - increaseIndent(); - scopeEmitStart(node); - if (baseTypeNode) { - writeLine(); - emitStart(baseTypeNode); - write("__extends("); - emit(node.name); - write(", _super);"); - emitEnd(baseTypeNode); - } - writeLine(); - emitConstructorOfClass(); - emitMemberFunctions(node); - emitMemberAssignments(node, 128 /* Static */); - writeLine(); - function emitClassReturnStatement() { - write("return "); - emitNode(node.name); - } - emitToken(15 /* CloseBraceToken */, node.members.end, emitClassReturnStatement); - write(";"); - decreaseIndent(); - writeLine(); - emitToken(15 /* CloseBraceToken */, node.members.end); - scopeEmitEnd(); - emitStart(node); - write(")("); - if (baseTypeNode) { - emit(baseTypeNode.typeName); - } - write(");"); - emitEnd(node); - if (node.flags & 1 /* Export */) { - writeLine(); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emit(node.name); - emitEnd(node); - write(";"); - } - emitTrailingComments(node); - function emitConstructorOfClass() { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; - tempParameters = undefined; - ts.forEach(node.members, function (member) { - if (member.kind === 129 /* Constructor */ && !member.body) { - emitPinnedOrTripleSlashComments(member); - } - }); - var ctor = getFirstConstructorWithBody(node); - if (ctor) { - emitLeadingComments(ctor); - } - emitStart(ctor || node); - write("function "); - emit(node.name); - emitSignatureParameters(ctor); - write(" {"); - scopeEmitStart(node, "constructor"); - increaseIndent(); - if (ctor) { - emitDetachedComments(ctor.body.statements); - } - emitCaptureThisForNodeIfNecessary(node); - if (ctor) { - emitDefaultValueAssignments(ctor); - emitRestParameter(ctor); - if (baseTypeNode) { - var superCall = findInitialSuperCall(ctor); - if (superCall) { - writeLine(); - emit(superCall); - } - } - emitParameterPropertyAssignments(ctor); - } - else { - if (baseTypeNode) { - writeLine(); - emitStart(baseTypeNode); - write("_super.apply(this, arguments);"); - emitEnd(baseTypeNode); - } - } - emitMemberAssignments(node, 0); - if (ctor) { - var statements = ctor.body.statements; - if (superCall) - statements = statements.slice(1); - emitLines(statements); - } - emitTempDeclarations(true); - writeLine(); - if (ctor) { - emitLeadingCommentsOfPosition(ctor.body.statements.end); - } - decreaseIndent(); - emitToken(15 /* CloseBraceToken */, ctor ? ctor.body.statements.end : node.members.end); - scopeEmitEnd(); - emitEnd(ctor || node); - if (ctor) { - emitTrailingComments(ctor); - } - tempCount = saveTempCount; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - } - function emitInterfaceDeclaration(node) { - emitPinnedOrTripleSlashComments(node); - } - function emitEnumDeclaration(node) { - var isConstEnum = ts.isConst(node); - if (isConstEnum && !compilerOptions.preserveConstEnums) { - return; - } - emitLeadingComments(node); - if (!(node.flags & 1 /* Export */)) { - emitStart(node); - write("var "); - emit(node.name); - emitEnd(node); - write(";"); - } - writeLine(); - emitStart(node); - write("(function ("); - emitStart(node.name); - write(resolver.getLocalNameOfContainer(node)); - emitEnd(node.name); - write(") {"); - increaseIndent(); - scopeEmitStart(node); - emitEnumMemberDeclarations(isConstEnum); - decreaseIndent(); - writeLine(); - emitToken(15 /* CloseBraceToken */, node.members.end); - scopeEmitEnd(); - write(")("); - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - if (node.flags & 1 /* Export */) { - writeLine(); - emitStart(node); - write("var "); - emit(node.name); - write(" = "); - emitModuleMemberName(node); - emitEnd(node); - write(";"); - } - emitTrailingComments(node); - function emitEnumMemberDeclarations(isConstEnum) { - ts.forEach(node.members, function (member) { - writeLine(); - emitLeadingComments(member); - emitStart(member); - write(resolver.getLocalNameOfContainer(node)); - write("["); - write(resolver.getLocalNameOfContainer(node)); - write("["); - emitExpressionForPropertyName(member.name); - write("] = "); - if (member.initializer && !isConstEnum) { - emit(member.initializer); - } - else { - write(resolver.getEnumMemberValue(member).toString()); - } - write("] = "); - emitExpressionForPropertyName(member.name); - emitEnd(member); - write(";"); - emitTrailingComments(member); - }); - } - } - function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 195 /* ModuleDeclaration */) { - var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); - return recursiveInnerModule || moduleDeclaration.body; - } - } - function emitModuleDeclaration(node) { - var shouldEmit = ts.getModuleInstanceState(node) === 1 /* Instantiated */ || (ts.getModuleInstanceState(node) === 2 /* ConstEnumOnly */ && compilerOptions.preserveConstEnums); - if (!shouldEmit) { - return emitPinnedOrTripleSlashComments(node); - } - emitLeadingComments(node); - emitStart(node); - write("var "); - emit(node.name); - write(";"); - emitEnd(node); - writeLine(); - emitStart(node); - write("(function ("); - emitStart(node.name); - write(resolver.getLocalNameOfContainer(node)); - emitEnd(node.name); - write(") "); - if (node.body.kind === 196 /* ModuleBlock */) { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - tempCount = 0; - tempVariables = undefined; - emit(node.body); - tempCount = saveTempCount; - tempVariables = saveTempVariables; - } - else { - write("{"); - increaseIndent(); - scopeEmitStart(node); - emitCaptureThisForNodeIfNecessary(node); - writeLine(); - emit(node.body); - decreaseIndent(); - writeLine(); - var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; - emitToken(15 /* CloseBraceToken */, moduleBlock.statements.end); - scopeEmitEnd(); - } - write(")("); - if (node.flags & 1 /* Export */) { - emit(node.name); - write(" = "); - } - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - emitTrailingComments(node); - } - function emitImportDeclaration(node) { - var emitImportDeclaration = resolver.isReferencedImportDeclaration(node); - if (!emitImportDeclaration) { - emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportWithEntityName(node); - } - if (emitImportDeclaration) { - if (ts.isExternalModuleImportDeclaration(node) && node.parent.kind === 207 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { - if (node.flags & 1 /* Export */) { - writeLine(); - emitLeadingComments(node); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emit(node.name); - write(";"); - emitEnd(node); - emitTrailingComments(node); - } - } - else { - writeLine(); - emitLeadingComments(node); - emitStart(node); - if (!(node.flags & 1 /* Export */)) - write("var "); - emitModuleMemberName(node); - write(" = "); - if (ts.isInternalModuleImportDeclaration(node)) { - emit(node.moduleReference); - } - else { - var literal = ts.getExternalModuleImportDeclarationExpression(node); - write("require("); - emitStart(literal); - emitLiteral(literal); - emitEnd(literal); - emitToken(17 /* CloseParenToken */, literal.end); - } - write(";"); - emitEnd(node); - emitTrailingComments(node); - } - } - } - function getExternalImportDeclarations(node) { - var result = []; - ts.forEach(node.statements, function (statement) { - if (ts.isExternalModuleImportDeclaration(statement) && resolver.isReferencedImportDeclaration(statement)) { - result.push(statement); - } - }); - return result; - } - function getFirstExportAssignment(sourceFile) { - return ts.forEach(sourceFile.statements, function (node) { - if (node.kind === 198 /* ExportAssignment */) { - return node; - } - }); - } - function emitAMDModule(node, startIndex) { - var imports = getExternalImportDeclarations(node); - writeLine(); - write("define("); - if (node.amdModuleName) { - write("\"" + node.amdModuleName + "\", "); - } - write("[\"require\", \"exports\""); - ts.forEach(imports, function (imp) { - write(", "); - emitLiteral(ts.getExternalModuleImportDeclarationExpression(imp)); - }); - ts.forEach(node.amdDependencies, function (amdDependency) { - var text = "\"" + amdDependency + "\""; - write(", "); - write(text); - }); - write("], function (require, exports"); - ts.forEach(imports, function (imp) { - write(", "); - emit(imp.name); - }); - write(") {"); - increaseIndent(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { - writeLine(); - var exportAssignement = getFirstExportAssignment(node); - emitStart(exportAssignement); - write("return "); - emitStart(exportAssignement.exportName); - write(exportName); - emitEnd(exportAssignement.exportName); - write(";"); - emitEnd(exportAssignement); - } - decreaseIndent(); - writeLine(); - write("});"); - } - function emitCommonJSModule(node, startIndex) { - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { - writeLine(); - var exportAssignement = getFirstExportAssignment(node); - emitStart(exportAssignement); - write("module.exports = "); - emitStart(exportAssignement.exportName); - write(exportName); - emitEnd(exportAssignement.exportName); - write(";"); - emitEnd(exportAssignement); - } - } - function emitDirectivePrologues(statements, startWithNewLine) { - for (var i = 0; i < statements.length; ++i) { - if (ts.isPrologueDirective(statements[i])) { - if (startWithNewLine || i > 0) { - writeLine(); - } - emit(statements[i]); - } - else { - return i; - } - } - return statements.length; - } - function emitSourceFile(node) { - currentSourceFile = node; - writeLine(); - emitDetachedComments(node); - var startIndex = emitDirectivePrologues(node.statements, false); - if (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8 /* EmitExtends */) { - writeLine(); - write("var __extends = this.__extends || function (d, b) {"); - increaseIndent(); - writeLine(); - write("for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];"); - writeLine(); - write("function __() { this.constructor = d; }"); - writeLine(); - write("__.prototype = b.prototype;"); - writeLine(); - write("d.prototype = new __();"); - decreaseIndent(); - writeLine(); - write("};"); - extendsEmitted = true; - } - if (ts.isExternalModule(node)) { - if (compilerOptions.module === 2 /* AMD */) { - emitAMDModule(node, startIndex); - } - else { - emitCommonJSModule(node, startIndex); - } - } - else { - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - } - emitLeadingComments(node.endOfFileToken); - } - function emitNode(node) { - if (!node) { - return; - } - if (node.flags & 2 /* Ambient */) { - return emitPinnedOrTripleSlashComments(node); - } - switch (node.kind) { - case 64 /* Identifier */: - return emitIdentifier(node); - case 124 /* Parameter */: - return emitParameter(node); - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - return emitMethod(node); - case 130 /* GetAccessor */: - case 131 /* SetAccessor */: - return emitAccessor(node); - case 92 /* ThisKeyword */: - return emitThis(node); - case 90 /* SuperKeyword */: - return emitSuper(node); - case 88 /* NullKeyword */: - return write("null"); - case 94 /* TrueKeyword */: - return write("true"); - case 79 /* FalseKeyword */: - return write("false"); - case 7 /* NumericLiteral */: - case 8 /* StringLiteral */: - case 9 /* RegularExpressionLiteral */: - case 10 /* NoSubstitutionTemplateLiteral */: - case 11 /* TemplateHead */: - case 12 /* TemplateMiddle */: - case 13 /* TemplateTail */: - return emitLiteral(node); - case 165 /* TemplateExpression */: - return emitTemplateExpression(node); - case 168 /* TemplateSpan */: - return emitTemplateSpan(node); - case 121 /* QualifiedName */: - return emitQualifiedName(node); - case 144 /* ObjectBindingPattern */: - return emitObjectBindingPattern(node); - case 145 /* ArrayBindingPattern */: - return emitArrayBindingPattern(node); - case 147 /* ArrayLiteralExpression */: - return emitArrayLiteral(node); - case 148 /* ObjectLiteralExpression */: - return emitObjectLiteral(node); - case 204 /* PropertyAssignment */: - return emitPropertyAssignment(node); - case 205 /* ShorthandPropertyAssignment */: - return emitShorthandPropertyAssignment(node); - case 122 /* ComputedPropertyName */: - return emitComputedPropertyName(node); - case 149 /* PropertyAccessExpression */: - return emitPropertyAccess(node); - case 150 /* ElementAccessExpression */: - return emitIndexedAccess(node); - case 151 /* CallExpression */: - return emitCallExpression(node); - case 152 /* NewExpression */: - return emitNewExpression(node); - case 153 /* TaggedTemplateExpression */: - return emitTaggedTemplateExpression(node); - case 154 /* TypeAssertionExpression */: - return emit(node.expression); - case 155 /* ParenthesizedExpression */: - return emitParenExpression(node); - case 190 /* FunctionDeclaration */: - case 156 /* FunctionExpression */: - case 157 /* ArrowFunction */: - return emitFunctionDeclaration(node); - case 158 /* DeleteExpression */: - return emitDeleteExpression(node); - case 159 /* TypeOfExpression */: - return emitTypeOfExpression(node); - case 160 /* VoidExpression */: - return emitVoidExpression(node); - case 161 /* PrefixUnaryExpression */: - return emitPrefixUnaryExpression(node); - case 162 /* PostfixUnaryExpression */: - return emitPostfixUnaryExpression(node); - case 163 /* BinaryExpression */: - return emitBinaryExpression(node); - case 164 /* ConditionalExpression */: - return emitConditionalExpression(node); - case 167 /* OmittedExpression */: - return; - case 169 /* Block */: - case 186 /* TryBlock */: - case 187 /* FinallyBlock */: - case 196 /* ModuleBlock */: - return emitBlock(node); - case 170 /* VariableStatement */: - return emitVariableStatement(node); - case 171 /* EmptyStatement */: - return write(";"); - case 172 /* ExpressionStatement */: - return emitExpressionStatement(node); - case 173 /* IfStatement */: - return emitIfStatement(node); - case 174 /* DoStatement */: - return emitDoStatement(node); - case 175 /* WhileStatement */: - return emitWhileStatement(node); - case 176 /* ForStatement */: - return emitForStatement(node); - case 177 /* ForInStatement */: - return emitForInStatement(node); - case 178 /* ContinueStatement */: - case 179 /* BreakStatement */: - return emitBreakOrContinueStatement(node); - case 180 /* ReturnStatement */: - return emitReturnStatement(node); - case 181 /* WithStatement */: - return emitWithStatement(node); - case 182 /* SwitchStatement */: - return emitSwitchStatement(node); - case 200 /* CaseClause */: - case 201 /* DefaultClause */: - return emitCaseOrDefaultClause(node); - case 183 /* LabeledStatement */: - return emitLabelledStatement(node); - case 184 /* ThrowStatement */: - return emitThrowStatement(node); - case 185 /* TryStatement */: - return emitTryStatement(node); - case 203 /* CatchClause */: - return emitCatchClause(node); - case 188 /* DebuggerStatement */: - return emitDebuggerStatement(node); - case 189 /* VariableDeclaration */: - return emitVariableDeclaration(node); - case 191 /* ClassDeclaration */: - return emitClassDeclaration(node); - case 192 /* InterfaceDeclaration */: - return emitInterfaceDeclaration(node); - case 194 /* EnumDeclaration */: - return emitEnumDeclaration(node); - case 195 /* ModuleDeclaration */: - return emitModuleDeclaration(node); - case 197 /* ImportDeclaration */: - return emitImportDeclaration(node); - case 207 /* SourceFile */: - return emitSourceFile(node); - } - } - function hasDetachedComments(pos) { - return detachedCommentsInfo !== undefined && detachedCommentsInfo[detachedCommentsInfo.length - 1].nodePos === pos; - } - function getLeadingCommentsWithoutDetachedComments() { - var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); - if (detachedCommentsInfo.length - 1) { - detachedCommentsInfo.pop(); - } - else { - detachedCommentsInfo = undefined; - } - return leadingComments; - } - function getLeadingCommentsToEmit(node) { - if (node.parent.kind === 207 /* SourceFile */ || node.pos !== node.parent.pos) { - var leadingComments; - if (hasDetachedComments(node.pos)) { - leadingComments = getLeadingCommentsWithoutDetachedComments(); - } - else { - leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); - } - return leadingComments; - } - } - function emitLeadingDeclarationComments(node) { - var leadingComments = getLeadingCommentsToEmit(node); - emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); - } - function emitTrailingDeclarationComments(node) { - if (node.parent.kind === 207 /* SourceFile */ || node.end !== node.parent.end) { - var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); - emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); - } - } - function emitLeadingCommentsOfLocalPosition(pos) { - var leadingComments; - if (hasDetachedComments(pos)) { - leadingComments = getLeadingCommentsWithoutDetachedComments(); - } - else { - leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); - } - emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); - emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); - } - function emitDetachedCommentsAtPosition(node) { - var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); - if (leadingComments) { - var detachedComments = []; - var lastComment; - ts.forEach(leadingComments, function (comment) { - if (lastComment) { - var lastCommentLine = getLineOfLocalPosition(currentSourceFile, lastComment.end); - var commentLine = getLineOfLocalPosition(currentSourceFile, comment.pos); - if (commentLine >= lastCommentLine + 2) { - return detachedComments; - } - } - detachedComments.push(comment); - lastComment = comment; - }); - if (detachedComments.length) { - var lastCommentLine = getLineOfLocalPosition(currentSourceFile, detachedComments[detachedComments.length - 1].end); - var astLine = getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); - if (astLine >= lastCommentLine + 2) { - emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment); - var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: detachedComments[detachedComments.length - 1].end }; - if (detachedCommentsInfo) { - detachedCommentsInfo.push(currentDetachedCommentInfo); - } - else { - detachedCommentsInfo = [currentDetachedCommentInfo]; - } - } - } - } - } - function emitPinnedOrTripleSlashCommentsOfNode(node) { - var pinnedComments = ts.filter(getLeadingCommentsToEmit(node), isPinnedOrTripleSlashComment); - function isPinnedOrTripleSlashComment(comment) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) { - return currentSourceFile.text.charCodeAt(comment.pos + 2) === 33 /* exclamation */; - } - else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 /* slash */ && comment.pos + 2 < comment.end && currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 /* slash */ && currentSourceFile.text.substring(comment.pos, comment.end).match(ts.fullTripleSlashReferencePathRegEx)) { - return true; - } - } - emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, pinnedComments); - emitComments(currentSourceFile, writer, pinnedComments, true, newLine, writeComment); - } - if (compilerOptions.sourceMap) { - initializeEmitterWithSourceMaps(); - } - if (root) { - emit(root); - } - else { - ts.forEach(program.getSourceFiles(), function (sourceFile) { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - emit(sourceFile); - } - }); - } - writeLine(); - writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); - } - function writeDeclarationFile(jsFilePath, sourceFile) { - var emitDeclarationResult = emitDeclarations(program, resolver, diagnostics, jsFilePath, sourceFile); - if (!emitDeclarationResult.reportedDeclarationError) { - var declarationOutput = emitDeclarationResult.referencePathsOutput; - var appliedSyncOutputPos = 0; - ts.forEach(emitDeclarationResult.aliasDeclarationEmitInfo, function (aliasEmitInfo) { - if (aliasEmitInfo.asynchronousOutput) { - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); - declarationOutput += aliasEmitInfo.asynchronousOutput; - appliedSyncOutputPos = aliasEmitInfo.outputPos; - } - }); - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos); - writeFile(compilerHost, diagnostics, ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); - } - } - var hasSemanticErrors = false; - var isEmitBlocked = false; - if (targetSourceFile === undefined) { - hasSemanticErrors = resolver.hasSemanticErrors(); - isEmitBlocked = resolver.isEmitBlocked(); - ts.forEach(program.getSourceFiles(), function (sourceFile) { - if (shouldEmitToOwnFile(sourceFile, compilerOptions)) { - var jsFilePath = getOwnEmitOutputFilePath(sourceFile, program, ".js"); - emitFile(jsFilePath, sourceFile); - } - }); - if (compilerOptions.out) { - emitFile(compilerOptions.out); - } - } - else { - if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { - hasSemanticErrors = resolver.hasSemanticErrors(targetSourceFile); - isEmitBlocked = resolver.isEmitBlocked(targetSourceFile); - var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, program, ".js"); - emitFile(jsFilePath, targetSourceFile); - } - else if (!ts.isDeclarationFile(targetSourceFile) && compilerOptions.out) { - ts.forEach(program.getSourceFiles(), function (sourceFile) { - if (!shouldEmitToOwnFile(sourceFile, compilerOptions)) { - hasSemanticErrors = hasSemanticErrors || resolver.hasSemanticErrors(sourceFile); - isEmitBlocked = isEmitBlocked || resolver.isEmitBlocked(sourceFile); - } - }); - emitFile(compilerOptions.out); - } - } - function emitFile(jsFilePath, sourceFile) { - if (!isEmitBlocked) { - emitJavaScript(jsFilePath, sourceFile); - if (!hasSemanticErrors && compilerOptions.declaration) { - writeDeclarationFile(jsFilePath, sourceFile); - } - } - } - diagnostics.sort(ts.compareDiagnostics); - diagnostics = ts.deduplicateSortedDiagnostics(diagnostics); - var hasEmitterError = ts.forEach(diagnostics, function (diagnostic) { return diagnostic.category === 1 /* Error */; }); - var emitResultStatus; - if (isEmitBlocked) { - emitResultStatus = 1 /* AllOutputGenerationSkipped */; - } - else if (hasEmitterError) { - emitResultStatus = 4 /* EmitErrorsEncountered */; - } - else if (hasSemanticErrors && compilerOptions.declaration) { - emitResultStatus = 3 /* DeclarationGenerationSkipped */; - } - else if (hasSemanticErrors && !compilerOptions.declaration) { - emitResultStatus = 2 /* JSGeneratedWithSemanticErrors */; - } - else { - emitResultStatus = 0 /* Succeeded */; - } - return { - emitResultStatus: emitResultStatus, - diagnostics: diagnostics, - sourceMaps: sourceMapDataList - }; - } - ts.emitFiles = emitFiles; -})(ts || (ts = {})); -var ts; (function (ts) { var nextSymbolId = 1; var nextNodeId = 1; var nextMergeId = 1; - function createTypeChecker(program, fullTypeCheck) { + function createTypeChecker(host, produceDiagnostics) { var Symbol = ts.objectAllocator.getSymbolConstructor(); var Type = ts.objectAllocator.getTypeConstructor(); var Signature = ts.objectAllocator.getSignatureConstructor(); var typeCount = 0; var emptyArray = []; var emptySymbols = {}; - var compilerOptions = program.getCompilerOptions(); + var compilerOptions = host.getCompilerOptions(); + var emitResolver = createResolver(); var checker = { - getProgram: function () { return program; }, - getNodeCount: function () { return ts.sum(program.getSourceFiles(), "nodeCount"); }, - getIdentifierCount: function () { return ts.sum(program.getSourceFiles(), "identifierCount"); }, - getSymbolCount: function () { return ts.sum(program.getSourceFiles(), "symbolCount"); }, + getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); }, + getIdentifierCount: function () { return ts.sum(host.getSourceFiles(), "identifierCount"); }, + getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount"); }, getTypeCount: function () { return typeCount; }, isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; }, isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; }, - emitFiles: invokeEmitter, getDiagnostics: getDiagnostics, - getDeclarationDiagnostics: getDeclarationDiagnostics, getGlobalDiagnostics: getGlobalDiagnostics, getTypeOfSymbolAtLocation: getTypeOfSymbolAtLocation, getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol, @@ -9808,8 +6758,7 @@ var ts; getSignatureFromDeclaration: getSignatureFromDeclaration, isImplementationOfOverload: isImplementationOfOverload, getAliasedSymbol: resolveImport, - hasEarlyErrors: hasEarlyErrors, - isEmitBlocked: isEmitBlocked + getEmitResolver: function () { return emitResolver; } }; var undefinedSymbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "undefined"); var argumentsSymbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "arguments"); @@ -10018,7 +6967,7 @@ var ts; if (!compilerOptions.out) { return true; } - var sourceFiles = program.getSourceFiles(); + var sourceFiles = host.getSourceFiles(); return sourceFiles.indexOf(file1) <= sourceFiles.indexOf(file2); } function resolveName(location, name, meaning, nameNotFoundMessage, nameArg) { @@ -10117,7 +7066,7 @@ var ts; return undefined; } if (result.flags & 2 /* BlockScopedVariable */) { - var declaration = ts.forEach(result.declarations, function (d) { return d.flags & 6144 /* BlockScoped */ ? d : undefined; }); + var declaration = ts.forEach(result.declarations, function (d) { return ts.getCombinedNodeFlags(d) & 6144 /* BlockScoped */ ? d : undefined; }); ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); if (!isDefinedBefore(declaration, errorLocation)) { error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name)); @@ -10213,7 +7162,7 @@ var ts; } while (true) { var filename = ts.normalizePath(ts.combinePaths(searchPath, moduleName)); - var sourceFile = program.getSourceFile(filename + ".ts") || program.getSourceFile(filename + ".d.ts"); + var sourceFile = host.getSourceFile(filename + ".ts") || host.getSourceFile(filename + ".d.ts"); if (sourceFile || isRelative) break; var parentPath = ts.getDirectoryPath(searchPath); @@ -10315,7 +7264,7 @@ var ts; var members = node.members; for (var i = 0; i < members.length; i++) { var member = members[i]; - if (member.kind === 129 /* Constructor */ && member.body) { + if (member.kind === 129 /* Constructor */ && ts.nodeIsPresent(member.body)) { return member; } } @@ -10410,7 +7359,7 @@ var ts; } function isAccessible(symbolFromSymbolTable, resolvedAliasSymbol) { if (symbol === (resolvedAliasSymbol || symbolFromSymbolTable)) { - return !ts.forEach(symbolFromSymbolTable.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); }) && canQualifySymbol(symbolFromSymbolTable, meaning); + return !ts.forEach(symbolFromSymbolTable.declarations, hasExternalModuleSymbol) && canQualifySymbol(symbolFromSymbolTable, meaning); } } if (isAccessible(ts.lookUp(symbols, symbol.name))) { @@ -10474,7 +7423,7 @@ var ts; meaningToLook = getQualifiedLeftMeaning(meaning); symbol = getParentOfSymbol(symbol); } - var symbolExternalModule = ts.forEach(initialSymbol.declarations, function (declaration) { return getExternalModuleContainer(declaration); }); + var symbolExternalModule = ts.forEach(initialSymbol.declarations, getExternalModuleContainer); if (symbolExternalModule) { var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration); if (symbolExternalModule !== enclosingExternalModule) { @@ -10627,7 +7576,7 @@ var ts; } } else { - if (!parentSymbol && ts.forEach(symbol.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); })) { + if (!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) { return; } if (symbol.flags & 2048 /* TypeLiteral */ || symbol.flags & 4096 /* ObjectLiteral */) { @@ -11016,7 +7965,7 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: case 195 /* ModuleDeclaration */: case 191 /* ClassDeclaration */: @@ -11026,7 +7975,7 @@ var ts; case 194 /* EnumDeclaration */: case 197 /* ImportDeclaration */: var parent = getDeclarationContainer(node); - if (!(node.flags & 1 /* Export */) && !(node.kind !== 197 /* ImportDeclaration */ && parent.kind !== 207 /* SourceFile */ && ts.isInAmbientContext(parent))) { + if (!(ts.getCombinedNodeFlags(node) & 1 /* Export */) && !(node.kind !== 197 /* ImportDeclaration */ && parent.kind !== 207 /* SourceFile */ && ts.isInAmbientContext(parent))) { return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); } return isDeclarationVisible(parent); @@ -11045,7 +7994,6 @@ var ts; case 134 /* IndexSignature */: case 124 /* Parameter */: case 196 /* ModuleBlock */: - case 123 /* TypeParameter */: case 136 /* FunctionType */: case 137 /* ConstructorType */: case 139 /* TypeLiteral */: @@ -11055,6 +8003,7 @@ var ts; case 142 /* UnionType */: case 143 /* ParenthesizedType */: return isDeclarationVisible(node.parent); + case 123 /* TypeParameter */: case 207 /* SourceFile */: return true; default: @@ -11077,7 +8026,7 @@ var ts; } function getDeclarationContainer(node) { node = getRootDeclaration(node); - return node.kind === 189 /* VariableDeclaration */ ? node.parent.parent : node.parent; + return node.kind === 188 /* VariableDeclaration */ ? node.parent.parent.parent : node.parent; } function getTypeOfPrototypeProperty(prototype) { var classType = getDeclaredTypeOfSymbol(prototype.parent); @@ -11106,22 +8055,28 @@ var ts; error(name, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name)); return unknownType; } - return type; } - if (!isTypeAssignableTo(parentType, anyArrayType)) { - error(pattern, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(parentType)); - return unknownType; - } - var propName = "" + ts.indexOf(pattern.elements, declaration); - var type = isTupleLikeType(parentType) ? getTypeOfPropertyOfType(parentType, propName) : getIndexTypeOfType(parentType, 1 /* Number */); - if (!type) { - error(declaration, ts.Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName); - return unknownType; + else { + if (!isTypeAssignableTo(parentType, anyArrayType)) { + error(pattern, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(parentType)); + return unknownType; + } + if (!declaration.dotDotDotToken) { + var propName = "" + ts.indexOf(pattern.elements, declaration); + var type = isTupleLikeType(parentType) ? getTypeOfPropertyOfType(parentType, propName) : getIndexTypeOfType(parentType, 1 /* Number */); + if (!type) { + error(declaration, ts.Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName); + return unknownType; + } + } + else { + var type = createArrayType(getIndexTypeOfType(parentType, 1 /* Number */)); + } } return type; } function getTypeForVariableLikeDeclaration(declaration) { - if (declaration.parent.kind === 177 /* ForInStatement */) { + if (declaration.parent.parent.kind === 178 /* ForInStatement */) { return anyType; } if (ts.isBindingPattern(declaration.parent)) { @@ -11160,10 +8115,7 @@ var ts; } return anyType; } - function getTypeFromBindingPattern(pattern) { - if (pattern.kind === 145 /* ArrayBindingPattern */) { - return createTupleType(ts.map(pattern.elements, function (e) { return e.kind === 167 /* OmittedExpression */ ? anyType : getTypeFromBindingElement(e); })); - } + function getTypeFromObjectBindingPattern(pattern) { var members = {}; ts.forEach(pattern.elements, function (e) { var flags = 4 /* Property */ | 67108864 /* Transient */ | (e.initializer ? 536870912 /* Optional */ : 0); @@ -11174,6 +8126,20 @@ var ts; }); return createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined); } + function getTypeFromArrayBindingPattern(pattern) { + var hasSpreadElement = false; + var elementTypes = []; + ts.forEach(pattern.elements, function (e) { + elementTypes.push(e.kind === 168 /* OmittedExpression */ || e.dotDotDotToken ? anyType : getTypeFromBindingElement(e)); + if (e.dotDotDotToken) { + hasSpreadElement = true; + } + }); + return !elementTypes.length ? anyArrayType : hasSpreadElement ? createArrayType(getUnionType(elementTypes)) : createTupleType(elementTypes); + } + function getTypeFromBindingPattern(pattern) { + return pattern.kind === 144 /* ObjectBindingPattern */ ? getTypeFromObjectBindingPattern(pattern) : getTypeFromArrayBindingPattern(pattern); + } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { var type = getTypeForVariableLikeDeclaration(declaration); if (type) { @@ -11906,7 +8872,7 @@ var ts; var setter = ts.getDeclarationOfKind(declaration.symbol, 131 /* SetAccessor */); returnType = getAnnotatedAccessorType(setter); } - if (!returnType && !declaration.body) { + if (!returnType && ts.nodeIsMissing(declaration.body)) { returnType = anyType; } } @@ -12519,7 +9485,7 @@ var ts; return false; } function isContextSensitiveFunctionLikeDeclaration(node) { - return !node.typeParameters && !ts.forEach(node.parameters, function (p) { return p.type; }); + return !node.typeParameters && node.parameters.length && !ts.forEach(node.parameters, function (p) { return p.type; }); } function getTypeWithoutConstructors(type) { if (type.flags & 48128 /* ObjectType */) { @@ -12578,7 +9544,7 @@ var ts; if (containingMessageChain) { errorInfo = ts.concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); } - addDiagnostic(ts.createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, program.getCompilerHost().getNewLine())); + addDiagnostic(ts.createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, host.getCompilerHost().getNewLine())); } return result !== 0 /* False */; function reportError(message, arg0, arg1, arg2) { @@ -12793,9 +9759,7 @@ var ts; if (result) { var maybeCache = maybeStack[depth]; var destinationCache = result === -1 /* True */ || depth === 0 ? relation : maybeStack[depth - 1]; - for (var p in maybeCache) { - destinationCache[p] = maybeCache[p]; - } + ts.copyMap(maybeCache, destinationCache); } else { relation[id] = false; @@ -13118,7 +10082,7 @@ var ts; result &= related; } } - else if (source.typeParameters || source.typeParameters) { + else if (source.typeParameters || target.typeParameters) { return 0 /* False */; } source = getErasedSignature(source); @@ -13209,7 +10173,7 @@ var ts; return anyType; } if (type.flags & 16384 /* Union */) { - return getUnionType(ts.map(type.types, function (t) { return getWidenedType(t); })); + return getUnionType(ts.map(type.types, getWidenedType)); } if (isTypeOfObjectLiteral(type)) { return getWidenedTypeOfObjectLiteral(type); @@ -13277,7 +10241,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (fullTypeCheck && compilerOptions.noImplicitAny && type.flags & 131072 /* Unwidened */) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 131072 /* Unwidened */) { if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); } @@ -13547,7 +10511,7 @@ var ts; switch (node.kind) { case 163 /* BinaryExpression */: return isAssignedInBinaryExpression(node); - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: return isAssignedInVariableDeclaration(node); case 144 /* ObjectBindingPattern */: @@ -13566,25 +10530,24 @@ var ts; case 160 /* VoidExpression */: case 162 /* PostfixUnaryExpression */: case 164 /* ConditionalExpression */: - case 169 /* Block */: - case 170 /* VariableStatement */: - case 172 /* ExpressionStatement */: - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 180 /* ReturnStatement */: - case 181 /* WithStatement */: - case 182 /* SwitchStatement */: + case 167 /* SpreadElementExpression */: + case 170 /* Block */: + case 171 /* VariableStatement */: + case 173 /* ExpressionStatement */: + case 174 /* IfStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 181 /* ReturnStatement */: + case 182 /* WithStatement */: + case 183 /* SwitchStatement */: case 200 /* CaseClause */: case 201 /* DefaultClause */: - case 183 /* LabeledStatement */: - case 184 /* ThrowStatement */: - case 185 /* TryStatement */: - case 186 /* TryBlock */: + case 184 /* LabeledStatement */: + case 185 /* ThrowStatement */: + case 186 /* TryStatement */: case 203 /* CatchClause */: - case 187 /* FinallyBlock */: return ts.forEachChild(node, isAssignedIn); } return false; @@ -13615,13 +10578,13 @@ var ts; } function getNarrowedTypeOfSymbol(symbol, node) { var type = getTypeOfSymbol(symbol); - if (node && symbol.flags & 3 /* Variable */ && type.flags & (48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { + if (node && symbol.flags & 3 /* Variable */ && type.flags & (1 /* Any */ | 48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { loop: while (node.parent) { var child = node; node = node.parent; var narrowedType = type; switch (node.kind) { - case 173 /* IfStatement */: + case 174 /* IfStatement */: if (child !== node.expression) { narrowedType = narrowType(type, node.expression, child === node.thenStatement); } @@ -13704,7 +10667,7 @@ var ts; } } function narrowTypeByInstanceof(type, expr, assumeTrue) { - if (!assumeTrue || expr.left.kind !== 64 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + if (type.flags & 1 /* Any */ || !assumeTrue || expr.left.kind !== 64 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { return type; } var rightType = checkExpression(expr.right); @@ -13965,15 +10928,21 @@ var ts; } return undefined; } - function getContextualTypeForArgument(node) { - var callExpression = node.parent; - var argIndex = ts.indexOf(callExpression.arguments, node); + function getContextualTypeForArgument(callTarget, arg) { + var args = getEffectiveCallArguments(callTarget); + var argIndex = ts.indexOf(args, arg); if (argIndex >= 0) { - var signature = getResolvedSignature(callExpression); + var signature = getResolvedSignature(callTarget); return getTypeAtPosition(signature, argIndex); } return undefined; } + function getContextualTypeForSubstitutionExpression(template, substitutionExpression) { + if (template.parent.kind === 153 /* TaggedTemplateExpression */) { + return getContextualTypeForArgument(template.parent, substitutionExpression); + } + return undefined; + } function getContextualTypeForBinaryOperand(node) { var binaryExpression = node.parent; var operator = binaryExpression.operator; @@ -14024,7 +10993,7 @@ var ts; return applyToContextualType(type, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }); } function contextualTypeIsTupleLikeType(type) { - return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return isTupleLikeType(t); }) : isTupleLikeType(type)); + return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, isTupleLikeType) : isTupleLikeType(type)); } function contextualTypeHasIndexSignature(type, kind) { return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }) : getIndexTypeOfObjectOrUnionType(type, kind)); @@ -14067,18 +11036,18 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 124 /* Parameter */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: case 146 /* BindingElement */: return getContextualTypeForInitializerExpression(node); case 157 /* ArrowFunction */: - case 180 /* ReturnStatement */: + case 181 /* ReturnStatement */: return getContextualTypeForReturnExpression(node); case 151 /* CallExpression */: case 152 /* NewExpression */: - return getContextualTypeForArgument(node); + return getContextualTypeForArgument(parent, node); case 154 /* TypeAssertionExpression */: return getTypeFromTypeNode(parent.type); case 163 /* BinaryExpression */: @@ -14089,6 +11058,9 @@ var ts; return getContextualTypeForElementExpression(node); case 164 /* ConditionalExpression */: return getContextualTypeForConditionalOperand(node); + case 169 /* TemplateSpan */: + ts.Debug.assert(parent.parent.kind === 165 /* TemplateExpression */); + return getContextualTypeForSubstitutionExpression(parent.parent, node); } return undefined; } @@ -14159,15 +11131,36 @@ var ts; } return false; } + function checkSpreadElementExpression(node, contextualMapper) { + var type = checkExpressionCached(node.expression, contextualMapper); + if (!isTypeAssignableTo(type, anyArrayType)) { + error(node.expression, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(type)); + return unknownType; + } + return type; + } function checkArrayLiteral(node, contextualMapper) { var elements = node.elements; if (!elements.length) { return createArrayType(undefinedType); } - var elementTypes = ts.map(elements, function (e) { return checkExpression(e, contextualMapper); }); - var contextualType = getContextualType(node); - if ((contextualType && contextualTypeIsTupleLikeType(contextualType)) || isAssignmentTarget(node)) { - return createTupleType(elementTypes); + var hasSpreadElement = false; + var elementTypes = []; + ts.forEach(elements, function (e) { + var type = checkExpression(e, contextualMapper); + if (e.kind === 167 /* SpreadElementExpression */) { + elementTypes.push(getIndexTypeOfType(type, 1 /* Number */) || anyType); + hasSpreadElement = true; + } + else { + elementTypes.push(type); + } + }); + if (!hasSpreadElement) { + var contextualType = getContextualType(node); + if (contextualType && contextualTypeIsTupleLikeType(contextualType) || isAssignmentTarget(node)) { + return createTupleType(elementTypes); + } } return createArrayType(getUnionType(elementTypes)); } @@ -14246,7 +11239,7 @@ var ts; return s.valueDeclaration ? s.valueDeclaration.kind : 126 /* PropertyDeclaration */; } function getDeclarationFlagsFromSymbol(s) { - return s.valueDeclaration ? s.valueDeclaration.flags : s.flags & 134217728 /* Prototype */ ? 16 /* Public */ | 128 /* Static */ : 0; + return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 /* Prototype */ ? 16 /* Public */ | 128 /* Static */ : 0; } function checkClassPropertyAccess(node, left, type, prop) { var flags = getDeclarationFlagsFromSymbol(prop); @@ -14461,7 +11454,7 @@ var ts; var context = createInferenceContext(typeParameters, false); var mapper = createInferenceMapper(context); for (var i = 0; i < args.length; i++) { - if (args[i].kind === 167 /* OmittedExpression */) { + if (args[i].kind === 168 /* OmittedExpression */) { continue; } if (!excludeArgument || excludeArgument[i] === undefined) { @@ -14475,7 +11468,7 @@ var ts; } if (excludeArgument) { for (var i = 0; i < args.length; i++) { - if (args[i].kind === 167 /* OmittedExpression */) { + if (args[i].kind === 168 /* OmittedExpression */) { continue; } if (excludeArgument[i] === false) { @@ -14513,7 +11506,7 @@ var ts; for (var i = 0; i < args.length; i++) { var arg = args[i]; var argType; - if (arg.kind === 167 /* OmittedExpression */) { + if (arg.kind === 168 /* OmittedExpression */) { continue; } var paramType = getTypeAtPosition(signature, i); @@ -14600,7 +11593,7 @@ var ts; else { error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); } - if (!fullTypeCheck) { + if (!produceDiagnostics) { for (var i = 0, n = candidates.length; i < n; i++) { if (hasCorrectArity(node, args, candidates[i])) { return candidates[i]; @@ -14814,7 +11807,7 @@ var ts; function checkTypeAssertion(node) { var exprType = checkExpression(node.expression); var targetType = getTypeFromTypeNode(node.type); - if (fullTypeCheck && targetType !== unknownType) { + if (produceDiagnostics && targetType !== unknownType) { var widenedType = getWidenedType(exprType); if (!(isTypeAssignableTo(targetType, widenedType))) { checkTypeAssignableTo(exprType, targetType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); @@ -14840,7 +11833,7 @@ var ts; } function getReturnTypeFromBody(func, contextualMapper) { var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func); - if (func.body.kind !== 169 /* Block */) { + if (func.body.kind !== 170 /* Block */) { var type = checkExpressionCached(func.body, contextualMapper); } else { @@ -14878,16 +11871,16 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 184 /* ThrowStatement */); + return (body.statements.length === 1) && (body.statements[0].kind === 185 /* ThrowStatement */); } function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) { - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } if (returnType === voidType || returnType === anyType) { return; } - if (!func.body || func.body.kind !== 169 /* Block */) { + if (ts.nodeIsMissing(func.body) || func.body.kind !== 170 /* Block */) { return; } var bodyBlock = func.body; @@ -14930,7 +11923,7 @@ var ts; checkSignatureDeclaration(node); } } - if (fullTypeCheck && node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { + if (produceDiagnostics && node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); } @@ -14942,7 +11935,7 @@ var ts; checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } if (node.body) { - if (node.body.kind === 169 /* Block */) { + if (node.body.kind === 170 /* Block */) { checkSourceElement(node.body); } else { @@ -15117,14 +12110,24 @@ var ts; var elements = node.elements; for (var i = 0; i < elements.length; i++) { var e = elements[i]; - if (e.kind !== 167 /* OmittedExpression */) { - var propName = "" + i; - var type = sourceType.flags & 1 /* Any */ ? sourceType : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : getIndexTypeOfType(sourceType, 1 /* Number */); - if (type) { - checkDestructuringAssignment(e, type, contextualMapper); + if (e.kind !== 168 /* OmittedExpression */) { + if (e.kind !== 167 /* SpreadElementExpression */) { + var propName = "" + i; + var type = sourceType.flags & 1 /* Any */ ? sourceType : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : getIndexTypeOfType(sourceType, 1 /* Number */); + if (type) { + checkDestructuringAssignment(e, type, contextualMapper); + } + else { + error(e, ts.Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName); + } } else { - error(e, ts.Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName); + if (i === elements.length - 1) { + checkReferenceAssignment(e.expression, sourceType, contextualMapper); + } + else { + error(e, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); + } } } } @@ -15141,6 +12144,9 @@ var ts; if (target.kind === 147 /* ArrayLiteralExpression */) { return checkArrayLiteralAssignment(target, sourceType, contextualMapper); } + return checkReferenceAssignment(target, sourceType, contextualMapper); + } + function checkReferenceAssignment(target, sourceType, contextualMapper) { var targetType = checkExpression(target, contextualMapper); if (checkReferenceExpression(target, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant)) { checkTypeAssignableTo(sourceType, targetType, target, undefined); @@ -15260,7 +12266,7 @@ var ts; } } function checkAssignmentOperator(valueType) { - if (fullTypeCheck && operator >= 52 /* FirstAssignment */ && operator <= 63 /* LastAssignment */) { + if (produceDiagnostics && operator >= 52 /* FirstAssignment */ && operator <= 63 /* LastAssignment */) { var ok = checkReferenceExpression(node.left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); if (ok) { checkTypeAssignableTo(valueType, leftType, node.left, undefined); @@ -15405,7 +12411,9 @@ var ts; return checkBinaryExpression(node, contextualMapper); case 164 /* ConditionalExpression */: return checkConditionalExpression(node, contextualMapper); - case 167 /* OmittedExpression */: + case 167 /* SpreadElementExpression */: + return checkSpreadElementExpression(node, contextualMapper); + case 168 /* OmittedExpression */: return undefinedType; case 166 /* YieldExpression */: checkYieldExpression(node); @@ -15418,7 +12426,7 @@ var ts; grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected); } checkSourceElement(node.constraint); - if (fullTypeCheck) { + if (produceDiagnostics) { checkTypeParameterHasIllegalReferencesInConstraint(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0); } @@ -15429,7 +12437,7 @@ var ts; var func = ts.getContainingFunction(node); if (node.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */)) { func = ts.getContainingFunction(node); - if (!(func.kind === 129 /* Constructor */ && func.body)) { + if (!(func.kind === 129 /* Constructor */ && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } @@ -15451,7 +12459,7 @@ var ts; if (node.type) { checkSourceElement(node.type); } - if (fullTypeCheck) { + if (produceDiagnostics) { checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { @@ -15519,10 +12527,10 @@ var ts; if (node === firstDeclaration) { checkFunctionOrConstructorSymbol(symbol); } - if (!node.body) { + if (ts.nodeIsMissing(node.body)) { return; } - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } function isSuperCallExpression(n) { @@ -15556,7 +12564,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 !== 172 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) { + if (!statements.length || statements[0].kind !== 173 /* 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 { @@ -15570,10 +12578,10 @@ var ts; } } function checkAccessorDeclaration(node) { - checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); - if (fullTypeCheck) { + if (produceDiagnostics) { + checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); if (node.kind === 130 /* GetAccessor */) { - if (!ts.isInAmbientContext(node) && node.body && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { + if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement); } } @@ -15605,7 +12613,7 @@ var ts; for (var i = 0; i < len; i++) { checkSourceElement(node.typeArguments[i]); var constraint = getConstraintOfTypeParameter(type.target.typeParameters[i]); - if (fullTypeCheck && constraint) { + if (produceDiagnostics && constraint) { var typeArgument = type.typeArguments[i]; checkTypeAssignableTo(typeArgument, constraint, node, ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1); } @@ -15617,7 +12625,7 @@ var ts; } function checkTypeLiteral(node) { ts.forEach(node.members, checkSourceElement); - if (fullTypeCheck) { + if (produceDiagnostics) { var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); @@ -15640,14 +12648,14 @@ var ts; return (node.flags & 32 /* Private */) && ts.isInAmbientContext(node); } function checkSpecializedSignatureDeclaration(signatureDeclarationNode) { - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } var signature = getSignatureFromDeclaration(signatureDeclarationNode); if (!signature.hasStringLiterals) { return; } - if (signatureDeclarationNode.body) { + if (ts.nodeIsPresent(signatureDeclarationNode.body)) { error(signatureDeclarationNode, ts.Diagnostics.A_signature_with_an_implementation_cannot_use_a_string_literal_type); return; } @@ -15671,7 +12679,7 @@ var ts; error(signatureDeclarationNode, ts.Diagnostics.Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature); } function getEffectiveDeclarationFlags(n, flagsToCheck) { - var flags = n.flags; + var flags = ts.getCombinedNodeFlags(n); if (n.parent.kind !== 192 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { if (!(flags & 2 /* Ambient */)) { flags |= 1 /* Export */; @@ -15681,7 +12689,7 @@ var ts; return flags & flagsToCheck; } function checkFunctionOrConstructorSymbol(symbol) { - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } function getCanonicalOverload(overloads, implementation) { @@ -15751,7 +12759,7 @@ var ts; error(errorNode, diagnostic); return; } - else if (subsequentNode.body) { + else if (ts.nodeIsPresent(subsequentNode.body)) { error(errorNode, ts.Diagnostics.Function_implementation_name_must_be_0, ts.declarationNameToString(node.name)); return; } @@ -15781,7 +12789,7 @@ var ts; allNodeFlags &= currentNodeFlags; someHaveQuestionToken = someHaveQuestionToken || ts.hasQuestionToken(node); allHaveQuestionToken = allHaveQuestionToken && ts.hasQuestionToken(node); - if (node.body && bodyDeclaration) { + if (ts.nodeIsPresent(node.body) && bodyDeclaration) { if (isConstructor) { multipleConstructorImplementation = true; } @@ -15792,7 +12800,7 @@ var ts; else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) { reportImplementationExpectedError(previousDeclaration); } - if (node.body) { + if (ts.nodeIsPresent(node.body)) { if (!bodyDeclaration) { bodyDeclaration = node; } @@ -15837,7 +12845,7 @@ var ts; } } function checkExportsOnMergedDeclarations(node) { - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } var symbol; @@ -15892,9 +12900,8 @@ var ts; } } function checkFunctionDeclaration(node) { - checkFunctionLikeDeclaration(node); - checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); - if (fullTypeCheck) { + if (produceDiagnostics) { + checkFunctionLikeDeclaration(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -15919,12 +12926,12 @@ var ts; if (node.type && !isAccessor(node.kind)) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (compilerOptions.noImplicitAny && !node.body && !node.type && !isPrivateWithinAmbient(node)) { + if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) { reportImplicitAnyError(node, anyType); } } function checkBlock(node) { - if (node.kind === 169 /* Block */) { + if (node.kind === 170 /* Block */) { checkGrammarForStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); @@ -15933,7 +12940,7 @@ var ts; } } function checkCollisionWithArgumentsInGeneratedCode(node) { - if (!ts.hasRestParameters(node) || ts.isInAmbientContext(node) || !node.body) { + if (!ts.hasRestParameters(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { return; } ts.forEach(node.parameters, function (p) { @@ -15953,7 +12960,7 @@ var ts; return false; } var root = getRootDeclaration(node); - if (root.kind === 124 /* Parameter */ && !root.parent.body) { + if (root.kind === 124 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) { return false; } return true; @@ -16010,7 +13017,7 @@ var ts; } } function checkCollisionWithConstDeclarations(node) { - if (node.initializer && (node.flags & 6144 /* BlockScoped */) === 0) { + if (node.initializer && (ts.getCombinedNodeFlags(node) & 6144 /* BlockScoped */) === 0) { var symbol = getSymbolOfNode(node); if (symbol.flags & 1 /* FunctionScopedVariable */) { var localDeclarationSymbol = resolveName(node, node.name.text, 3 /* Variable */, undefined, undefined); @@ -16055,12 +13062,6 @@ var ts; } } function checkVariableLikeDeclaration(node) { - if (node.kind === 146 /* BindingElement */) { - checkGrammarEvalOrArgumentsInStrictMode(node, node.name); - } - else if (node.kind === 189 /* VariableDeclaration */) { - checkGrammarVariableDeclaration(node); - } checkSourceElement(node.type); if (ts.hasComputedNameButNotSymbol(node)) { if (node.initializer) { @@ -16071,7 +13072,7 @@ var ts; if (ts.isBindingPattern(node.name)) { ts.forEach(node.name.elements, checkSourceElement); } - if (node.initializer && getRootDeclaration(node).kind === 124 /* Parameter */ && !ts.getContainingFunction(node).body) { + if (node.initializer && getRootDeclaration(node).kind === 124 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } @@ -16107,9 +13108,32 @@ var ts; checkCollisionWithRequireExportsInGeneratedCode(node, node.name); } } + function checkVariableDeclaration(node) { + checkGrammarVariableDeclaration(node); + return checkVariableLikeDeclaration(node); + } + function checkBindingElement(node) { + checkGrammarBindingElement(node); + return checkVariableLikeDeclaration(node); + } function checkVariableStatement(node) { - checkGrammarModifiers(node) || checkGrammarVariableDeclarations(node, node.declarations) || checkGrammarForDisallowedLetOrConstStatement(node); - ts.forEach(node.declarations, checkSourceElement); + checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); + ts.forEach(node.declarationList.declarations, checkSourceElement); + } + function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) { + if (node.modifiers) { + if (inBlockOrObjectLiteralExpression(node)) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + } + } + function inBlockOrObjectLiteralExpression(node) { + while (node) { + if (node.kind === 170 /* Block */ || node.kind === 148 /* ObjectLiteralExpression */) { + return true; + } + node = node.parent; + } } function checkExpressionStatement(node) { checkGrammarForStatementInAmbientContext(node); @@ -16132,11 +13156,19 @@ var ts; checkSourceElement(node.statement); } function checkForStatement(node) { - checkGrammarForStatementInAmbientContext(node) || checkGrammarVariableDeclarations(node, node.declarations); - if (node.declarations) - ts.forEach(node.declarations, checkVariableLikeDeclaration); - if (node.initializer) - checkExpression(node.initializer); + if (!checkGrammarForStatementInAmbientContext(node)) { + if (node.initializer && node.initializer.kind == 189 /* VariableDeclarationList */) { + checkGrammarVariableDeclarationList(node.initializer); + } + } + if (node.initializer) { + if (node.initializer.kind === 189 /* VariableDeclarationList */) { + ts.forEach(node.initializer.declarations, checkVariableDeclaration); + } + else { + checkExpression(node.initializer); + } + } if (node.condition) checkExpression(node.condition); if (node.iterator) @@ -16145,29 +13177,33 @@ var ts; } function checkForInStatement(node) { if (!checkGrammarForStatementInAmbientContext(node)) { - var declarations = node.declarations; - if (!checkGrammarVariableDeclarations(node, declarations)) { - if (declarations && declarations.length > 1) { - grammarErrorOnFirstToken(declarations[1], ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); + if (node.initializer.kind === 189 /* VariableDeclarationList */) { + var variableList = node.initializer; + if (!checkGrammarVariableDeclarationList(variableList)) { + if (variableList.declarations.length > 1) { + grammarErrorOnFirstToken(variableList.declarations[1], ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); + } } } } - if (node.declarations) { - if (node.declarations.length >= 1) { - var decl = node.declarations[0]; - checkVariableLikeDeclaration(decl); + if (node.initializer.kind === 189 /* VariableDeclarationList */) { + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length >= 1) { + var decl = variableDeclarationList.declarations[0]; + checkVariableDeclaration(decl); if (decl.type) { error(decl, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation); } } } - if (node.variable) { - var exprType = checkExpression(node.variable); + else { + var varExpr = node.initializer; + var exprType = checkExpression(varExpr); if (exprType !== anyType && exprType !== stringType) { - error(node.variable, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); + error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { - checkReferenceExpression(node.variable, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); } } var exprType = checkExpression(node.expression); @@ -16237,7 +13273,7 @@ var ts; hasDuplicateDefaultClause = true; } } - if (fullTypeCheck && clause.kind === 200 /* CaseClause */) { + if (produceDiagnostics && clause.kind === 200 /* CaseClause */) { var caseClause = clause; var caseType = checkExpression(caseClause.expression); if (!isTypeAssignableTo(expressionType, caseType)) { @@ -16254,7 +13290,7 @@ var ts; if (ts.isAnyFunction(current)) { break; } - if (current.kind === 183 /* LabeledStatement */ && current.label.text === node.label.text) { + if (current.kind === 184 /* LabeledStatement */ && current.label.text === node.label.text) { var sourceFile = ts.getSourceFileOfNode(node); grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label)); break; @@ -16352,7 +13388,7 @@ var ts; for (var i = 0; i < typeParameterDeclarations.length; i++) { var node = typeParameterDeclarations[i]; checkTypeParameter(node); - if (fullTypeCheck) { + if (produceDiagnostics) { for (var j = 0; j < i; j++) { if (typeParameterDeclarations[j].symbol === node.symbol) { error(node.name, ts.Diagnostics.Duplicate_identifier_0, ts.declarationNameToString(node.name)); @@ -16378,7 +13414,7 @@ var ts; checkTypeReference(baseTypeNode); } if (type.baseTypes.length) { - if (fullTypeCheck) { + if (produceDiagnostics) { var baseType = type.baseTypes[0]; checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); var staticBaseType = getTypeOfSymbol(baseType.symbol); @@ -16394,7 +13430,7 @@ var ts; if (implementedTypeNodes) { ts.forEach(implementedTypeNodes, function (typeRefNode) { checkTypeReference(typeRefNode); - if (fullTypeCheck) { + if (produceDiagnostics) { var t = getTypeFromTypeReferenceNode(typeRefNode); if (t !== unknownType) { var declaredType = (t.flags & 4096 /* Reference */) ? t.target : t; @@ -16409,7 +13445,7 @@ var ts; }); } ts.forEach(node.members, checkSourceElement); - if (fullTypeCheck) { + if (produceDiagnostics) { checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); } @@ -16514,7 +13550,7 @@ var ts; var typeName2 = typeToString(base); var errorInfo = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.Named_properties_0_of_types_1_and_2_are_not_identical, prop.name, typeName1, typeName2); errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2); - addDiagnostic(ts.createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, program.getCompilerHost().getNewLine())); + addDiagnostic(ts.createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, host.getCompilerHost().getNewLine())); } } } @@ -16524,7 +13560,7 @@ var ts; function checkInterfaceDeclaration(node) { checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); - if (fullTypeCheck) { + if (produceDiagnostics) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); @@ -16546,7 +13582,7 @@ var ts; } ts.forEach(ts.getInterfaceBaseTypeNodes(node), checkTypeReference); ts.forEach(node.members, checkSourceElement); - if (fullTypeCheck) { + if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); } } @@ -16691,10 +13727,10 @@ var ts; } } function checkEnumDeclaration(node) { - checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } + checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -16736,36 +13772,36 @@ var ts; var declarations = symbol.declarations; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; - if ((declaration.kind === 191 /* ClassDeclaration */ || (declaration.kind === 190 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) { + if ((declaration.kind === 191 /* ClassDeclaration */ || (declaration.kind === 190 /* FunctionDeclaration */ && ts.nodeIsPresent(declaration.body))) && !ts.isInAmbientContext(declaration)) { return declaration; } } return undefined; } function checkModuleDeclaration(node) { - if (!checkGrammarModifiers(node)) { - if (!ts.isInAmbientContext(node) && node.name.kind === 8 /* StringLiteral */) { - grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); - } - else if (node.name.kind === 64 /* Identifier */ && node.body.kind === 196 /* ModuleBlock */) { - var statements = node.body.statements; - for (var i = 0, n = statements.length; i < n; i++) { - var statement = statements[i]; - if (statement.kind === 198 /* ExportAssignment */) { - grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); - } - else if (ts.isExternalModuleImportDeclaration(statement)) { - grammarErrorOnNode(ts.getExternalModuleImportDeclarationExpression(statement), ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + if (produceDiagnostics) { + if (!checkGrammarModifiers(node)) { + if (!ts.isInAmbientContext(node) && node.name.kind === 8 /* StringLiteral */) { + grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); + } + else if (node.name.kind === 64 /* Identifier */ && node.body.kind === 196 /* ModuleBlock */) { + var statements = node.body.statements; + for (var i = 0, n = statements.length; i < n; i++) { + var statement = statements[i]; + if (statement.kind === 198 /* ExportAssignment */) { + grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + } + else if (ts.isExternalModuleImportDeclaration(statement)) { + grammarErrorOnNode(ts.getExternalModuleImportDeclarationExpression(statement), ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + } } } } - } - if (fullTypeCheck) { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - if (symbol.flags & 512 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node)) { + if (symbol.flags & 512 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node) && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums)) { var classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (classOrFunc) { if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(classOrFunc)) { @@ -16897,41 +13933,42 @@ var ts; return checkSourceElement(node.type); case 190 /* FunctionDeclaration */: return checkFunctionDeclaration(node); - case 169 /* Block */: + case 170 /* Block */: case 196 /* ModuleBlock */: return checkBlock(node); - case 170 /* VariableStatement */: + case 171 /* VariableStatement */: return checkVariableStatement(node); - case 172 /* ExpressionStatement */: + case 173 /* ExpressionStatement */: return checkExpressionStatement(node); - case 173 /* IfStatement */: + case 174 /* IfStatement */: return checkIfStatement(node); - case 174 /* DoStatement */: + case 175 /* DoStatement */: return checkDoStatement(node); - case 175 /* WhileStatement */: + case 176 /* WhileStatement */: return checkWhileStatement(node); - case 176 /* ForStatement */: + case 177 /* ForStatement */: return checkForStatement(node); - case 177 /* ForInStatement */: + case 178 /* ForInStatement */: return checkForInStatement(node); - case 178 /* ContinueStatement */: - case 179 /* BreakStatement */: + case 179 /* ContinueStatement */: + case 180 /* BreakStatement */: return checkBreakOrContinueStatement(node); - case 180 /* ReturnStatement */: + case 181 /* ReturnStatement */: return checkReturnStatement(node); - case 181 /* WithStatement */: + case 182 /* WithStatement */: return checkWithStatement(node); - case 182 /* SwitchStatement */: + case 183 /* SwitchStatement */: return checkSwitchStatement(node); - case 183 /* LabeledStatement */: + case 184 /* LabeledStatement */: return checkLabeledStatement(node); - case 184 /* ThrowStatement */: + case 185 /* ThrowStatement */: return checkThrowStatement(node); - case 185 /* TryStatement */: + case 186 /* TryStatement */: return checkTryStatement(node); - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: + return checkVariableDeclaration(node); case 146 /* BindingElement */: - return checkVariableLikeDeclaration(node); + return checkBindingElement(node); case 191 /* ClassDeclaration */: return checkClassDeclaration(node); case 192 /* InterfaceDeclaration */: @@ -16946,10 +13983,10 @@ var ts; return checkImportDeclaration(node); case 198 /* ExportAssignment */: return checkExportAssignment(node); - case 171 /* EmptyStatement */: + case 172 /* EmptyStatement */: checkGrammarForStatementInAmbientContext(node); return; - case 188 /* DebuggerStatement */: + case 187 /* DebuggerStatement */: checkGrammarForStatementInAmbientContext(node); return; } @@ -16974,7 +14011,7 @@ var ts; case 190 /* FunctionDeclaration */: ts.forEach(node.parameters, checkFunctionExpressionBodies); break; - case 181 /* WithStatement */: + case 182 /* WithStatement */: checkFunctionExpressionBodies(node.expression); break; case 124 /* Parameter */: @@ -16991,6 +14028,8 @@ var ts; case 151 /* CallExpression */: case 152 /* NewExpression */: case 153 /* TaggedTemplateExpression */: + case 165 /* TemplateExpression */: + case 169 /* TemplateSpan */: case 154 /* TypeAssertionExpression */: case 155 /* ParenthesizedExpression */: case 159 /* TypeOfExpression */: @@ -17000,28 +14039,28 @@ var ts; case 162 /* PostfixUnaryExpression */: case 163 /* BinaryExpression */: case 164 /* ConditionalExpression */: - case 169 /* Block */: + case 167 /* SpreadElementExpression */: + case 170 /* Block */: case 196 /* ModuleBlock */: - case 170 /* VariableStatement */: - case 172 /* ExpressionStatement */: - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 178 /* ContinueStatement */: - case 179 /* BreakStatement */: - case 180 /* ReturnStatement */: - case 182 /* SwitchStatement */: + case 171 /* VariableStatement */: + case 173 /* ExpressionStatement */: + case 174 /* IfStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 179 /* ContinueStatement */: + case 180 /* BreakStatement */: + case 181 /* ReturnStatement */: + case 183 /* SwitchStatement */: case 200 /* CaseClause */: case 201 /* DefaultClause */: - case 183 /* LabeledStatement */: - case 184 /* ThrowStatement */: - case 185 /* TryStatement */: - case 186 /* TryBlock */: + case 184 /* LabeledStatement */: + case 185 /* ThrowStatement */: + case 186 /* TryStatement */: case 203 /* CatchClause */: - case 187 /* FinallyBlock */: - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: + case 189 /* VariableDeclarationList */: case 191 /* ClassDeclaration */: case 194 /* EnumDeclaration */: case 206 /* EnumMember */: @@ -17056,7 +14095,7 @@ var ts; } } function getSortedDiagnostics() { - ts.Debug.assert(fullTypeCheck, "diagnostics are available only in the full typecheck mode"); + ts.Debug.assert(produceDiagnostics, "diagnostics are available only in the full typecheck mode"); if (diagnosticsModified) { diagnostics.sort(ts.compareDiagnostics); diagnostics = ts.deduplicateSortedDiagnostics(diagnostics); @@ -17065,25 +14104,27 @@ var ts; return diagnostics; } function getDiagnostics(sourceFile) { + throwIfNonDiagnosticsProducing(); if (sourceFile) { checkSourceFile(sourceFile); return ts.filter(getSortedDiagnostics(), function (d) { return d.file === sourceFile; }); } - ts.forEach(program.getSourceFiles(), checkSourceFile); + ts.forEach(host.getSourceFiles(), checkSourceFile); return getSortedDiagnostics(); } - function getDeclarationDiagnostics(targetSourceFile) { - var resolver = createResolver(); - checkSourceFile(targetSourceFile); - return ts.getDeclarationDiagnostics(program, resolver, targetSourceFile); - } function getGlobalDiagnostics() { + throwIfNonDiagnosticsProducing(); return ts.filter(getSortedDiagnostics(), function (d) { return !d.file; }); } + function throwIfNonDiagnosticsProducing() { + if (!produceDiagnostics) { + throw new Error("Trying to get diagnostics from a type checker that does not produce them."); + } + } function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 181 /* WithStatement */ && node.parent.statement === node) { + if (node.parent.kind === 182 /* WithStatement */ && node.parent.statement === node) { return true; } node = node.parent; @@ -17203,7 +14244,7 @@ var ts; case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: case 124 /* Parameter */: - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: return node === parent.type; case 190 /* FunctionDeclaration */: case 156 /* FunctionExpression */: @@ -17424,8 +14465,17 @@ var ts; } function isUniqueLocalName(name, container) { for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { - if (node.locals && ts.hasProperty(node.locals, name) && node.locals[name].flags & (107455 /* Value */ | 1048576 /* ExportValue */)) { - return false; + if (node.locals && ts.hasProperty(node.locals, name)) { + var symbolWithRelevantName = node.locals[name]; + if (symbolWithRelevantName.flags & (107455 /* Value */ | 1048576 /* ExportValue */)) { + return false; + } + if (symbolWithRelevantName.flags & 8388608 /* Import */) { + var importDeclarationWithRelevantName = ts.getDeclarationOfKind(symbolWithRelevantName, 197 /* ImportDeclaration */); + if (isReferencedImportDeclaration(importDeclarationWithRelevantName)) { + return false; + } + } } } return true; @@ -17477,12 +14527,6 @@ var ts; function hasSemanticErrors(sourceFile) { return getDiagnostics(sourceFile).length > 0 || getGlobalDiagnostics().length > 0; } - function isEmitBlocked(sourceFile) { - return program.getDiagnostics(sourceFile).length !== 0 || hasEarlyErrors(sourceFile) || (compilerOptions.noEmitOnError && getDiagnostics(sourceFile).length !== 0); - } - function hasEarlyErrors(sourceFile) { - return ts.forEach(getDiagnostics(sourceFile), function (d) { return d.isEarly; }); - } function isImportResolvedToValue(symbol) { var target = resolveImport(symbol); return target !== unknownSymbol && target.flags & 107455 /* Value */ && !isConstEnumOrConstEnumOnlyModule(target); @@ -17501,7 +14545,7 @@ var ts; return false; } function isImplementationOfOverload(node) { - if (node.body) { + if (ts.nodeIsPresent(node.body)) { var symbol = getSymbolOfNode(node); var signaturesOfSymbol = getSignaturesOfSymbol(symbol); return signaturesOfSymbol.length > 1 || (signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node); @@ -17540,7 +14584,6 @@ var ts; } function createResolver() { return { - getProgram: function () { return program; }, getLocalNameOfContainer: getLocalNameOfContainer, getExpressionNamePrefix: getExpressionNamePrefix, getExportAssignmentName: getExportAssignmentName, @@ -17549,7 +14592,6 @@ var ts; getEnumMemberValue: getEnumMemberValue, isTopLevelValueImportWithEntityName: isTopLevelValueImportWithEntityName, hasSemanticErrors: hasSemanticErrors, - isEmitBlocked: isEmitBlocked, isDeclarationVisible: isDeclarationVisible, isImplementationOfOverload: isImplementationOfOverload, writeTypeOfDeclaration: writeTypeOfDeclaration, @@ -17560,16 +14602,12 @@ var ts; isUnknownIdentifier: isUnknownIdentifier }; } - function invokeEmitter(targetSourceFile) { - var resolver = createResolver(); - return ts.emitFiles(resolver, targetSourceFile); - } function initializeTypeChecker() { - ts.forEach(program.getSourceFiles(), function (file) { + ts.forEach(host.getSourceFiles(), function (file) { ts.bindSourceFile(file); ts.forEach(file.semanticDiagnostics, addDiagnostic); }); - ts.forEach(program.getSourceFiles(), function (file) { + ts.forEach(host.getSourceFiles(), function (file) { if (!ts.isExternalModule(file)) { extendSymbolTable(globals, file.locals); } @@ -17604,7 +14642,7 @@ var ts; case 195 /* ModuleDeclaration */: case 194 /* EnumDeclaration */: case 198 /* ExportAssignment */: - case 170 /* VariableStatement */: + case 171 /* VariableStatement */: case 190 /* FunctionDeclaration */: case 193 /* TypeAliasDeclaration */: case 197 /* ImportDeclaration */: @@ -17821,7 +14859,7 @@ var ts; var sourceFile = ts.getSourceFileOfNode(node); for (var i = 0, n = arguments.length; i < n; i++) { var arg = arguments[i]; - if (arg.kind === 167 /* OmittedExpression */) { + if (arg.kind === 168 /* OmittedExpression */) { return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected); } } @@ -17929,7 +14967,7 @@ var ts; for (var i = 0, n = node.properties.length; i < n; i++) { var prop = node.properties[i]; var name = prop.name; - if (prop.kind === 167 /* OmittedExpression */ || name.kind === 122 /* ComputedPropertyName */) { + if (prop.kind === 168 /* OmittedExpression */ || name.kind === 122 /* ComputedPropertyName */) { checkGrammarComputedPropertyName(name); continue; } @@ -18024,9 +15062,17 @@ var ts; } } function checkGrammarMethod(node) { - if (checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { + if (checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { return true; } + if (node.parent.kind === 148 /* ObjectLiteralExpression */) { + if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { + return true; + } + else if (node.body === undefined) { + return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); + } + } if (node.parent.kind === 191 /* ClassDeclaration */) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; @@ -18047,12 +15093,12 @@ var ts; } function isIterationStatement(node, lookInLabeledStatements) { switch (node.kind) { - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: return true; - case 183 /* LabeledStatement */: + case 184 /* LabeledStatement */: return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); } return false; @@ -18064,17 +15110,17 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { - case 183 /* LabeledStatement */: + case 184 /* LabeledStatement */: if (node.label && current.label.text === node.label.text) { - var isMisplacedContinueLabel = node.kind === 178 /* ContinueStatement */ && !isIterationStatement(current.statement, true); + var isMisplacedContinueLabel = node.kind === 179 /* ContinueStatement */ && !isIterationStatement(current.statement, true); if (isMisplacedContinueLabel) { return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); } return false; } break; - case 182 /* SwitchStatement */: - if (node.kind === 179 /* BreakStatement */ && !node.label) { + case 183 /* SwitchStatement */: + if (node.kind === 180 /* BreakStatement */ && !node.label) { return false; } break; @@ -18087,14 +15133,26 @@ var ts; current = current.parent; } if (node.label) { - var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; + var message = node.kind === 180 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } else { - var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; + var message = node.kind === 180 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } } + function checkGrammarBindingElement(node) { + if (node.dotDotDotToken) { + var elements = node.parent.elements; + if (node !== elements[elements.length - 1]) { + return grammarErrorOnNode(node, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); + } + if (node.initializer) { + return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.A_rest_element_cannot_have_an_initializer); + } + } + return checkGrammarEvalOrArgumentsInStrictMode(node, node.name); + } function checkGrammarVariableDeclaration(node) { if (ts.isInAmbientContext(node)) { if (ts.isBindingPattern(node.name)) { @@ -18116,45 +15174,43 @@ var ts; } return checkGrammarEvalOrArgumentsInStrictMode(node, node.name); } - function checkGrammarVariableDeclarations(container, declarations) { - if (declarations) { - if (checkGrammarForDisallowedTrailingComma(declarations)) { - return true; + function checkGrammarVariableDeclarationList(declarationList) { + var declarations = declarationList.declarations; + if (checkGrammarForDisallowedTrailingComma(declarationList.declarations)) { + return true; + } + if (!declarationList.declarations.length) { + return grammarErrorAtPos(ts.getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); + } + if (compilerOptions.target < 2 /* ES6 */) { + if (ts.isLet(declarationList)) { + return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } - if (!declarations.length) { - return grammarErrorAtPos(ts.getSourceFileOfNode(container), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); - } - var decl = declarations[0]; - if (compilerOptions.target < 2 /* ES6 */) { - if (ts.isLet(decl)) { - return grammarErrorOnFirstToken(decl, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (ts.isConst(decl)) { - return grammarErrorOnFirstToken(decl, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } + else if (ts.isConst(declarationList)) { + return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } } } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 181 /* WithStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: + case 174 /* IfStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: + case 182 /* WithStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: return false; - case 183 /* LabeledStatement */: + case 184 /* LabeledStatement */: return allowLetAndConstDeclarations(parent.parent); } return true; } function checkGrammarForDisallowedLetOrConstStatement(node) { if (!allowLetAndConstDeclarations(node.parent)) { - if (ts.isLet(node)) { + if (ts.isLet(node.declarationList)) { return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block); } - else if (ts.isConst(node)) { + else if (ts.isConst(node.declarationList)) { return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block); } } @@ -18275,7 +15331,7 @@ var ts; function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) { for (var i = 0, n = file.statements.length; i < n; i++) { var decl = file.statements[i]; - if (ts.isDeclaration(decl) || decl.kind === 170 /* VariableStatement */) { + if (ts.isDeclaration(decl) || decl.kind === 171 /* VariableStatement */) { if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) { return true; } @@ -18294,7 +15350,7 @@ var ts; if (!links.hasReportedStatementInAmbientContext && ts.isAnyFunction(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); } - if (node.parent.kind === 169 /* Block */ || node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { + if (node.parent.kind === 170 /* Block */ || node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { var links = getNodeLinks(node.parent); if (!links.hasReportedStatementInAmbientContext) { return links.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts); @@ -18329,6 +15385,3852 @@ var ts; ts.createTypeChecker = createTypeChecker; })(ts || (ts = {})); var ts; +(function (ts) { + var indentStrings = ["", " "]; + function getIndentString(level) { + if (indentStrings[level] === undefined) { + indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; + } + return indentStrings[level]; + } + ts.getIndentString = getIndentString; + function getIndentSize() { + return indentStrings[1].length; + } + function shouldEmitToOwnFile(sourceFile, compilerOptions) { + if (!ts.isDeclarationFile(sourceFile)) { + if ((ts.isExternalModule(sourceFile) || !compilerOptions.out) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { + return true; + } + return false; + } + return false; + } + ts.shouldEmitToOwnFile = shouldEmitToOwnFile; + function isExternalModuleOrDeclarationFile(sourceFile) { + return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); + } + ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; + function createTextWriter(newLine) { + var output = ""; + var indent = 0; + var lineStart = true; + var lineCount = 0; + var linePos = 0; + function write(s) { + if (s && s.length) { + if (lineStart) { + output += getIndentString(indent); + lineStart = false; + } + output += s; + } + } + function rawWrite(s) { + if (s !== undefined) { + if (lineStart) { + lineStart = false; + } + output += s; + } + } + function writeLiteral(s) { + if (s && s.length) { + write(s); + var lineStartsOfS = ts.computeLineStarts(s); + if (lineStartsOfS.length > 1) { + lineCount = lineCount + lineStartsOfS.length - 1; + linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; + } + } + } + function writeLine() { + if (!lineStart) { + output += newLine; + lineCount++; + linePos = output.length; + lineStart = true; + } + } + function writeTextOfNode(sourceFile, node) { + write(ts.getSourceTextOfNodeFromSourceFile(sourceFile, node)); + } + return { + write: write, + rawWrite: rawWrite, + writeTextOfNode: writeTextOfNode, + writeLiteral: writeLiteral, + writeLine: writeLine, + increaseIndent: function () { return indent++; }, + decreaseIndent: function () { return indent--; }, + getIndent: function () { return indent; }, + getTextPos: function () { return output.length; }, + getLine: function () { return lineCount + 1; }, + getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; }, + getText: function () { return output; } + }; + } + function getLineOfLocalPosition(currentSourceFile, pos) { + return currentSourceFile.getLineAndCharacterFromPosition(pos).line; + } + function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) { + if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) { + writer.writeLine(); + } + } + function emitComments(currentSourceFile, writer, comments, trailingSeparator, newLine, writeComment) { + var emitLeadingSpace = !trailingSeparator; + ts.forEach(comments, function (comment) { + if (emitLeadingSpace) { + writer.write(" "); + emitLeadingSpace = false; + } + writeComment(currentSourceFile, writer, comment, newLine); + if (comment.hasTrailingNewLine) { + writer.writeLine(); + } + else if (trailingSeparator) { + writer.write(" "); + } + else { + emitLeadingSpace = true; + } + }); + } + function writeCommentRange(currentSourceFile, writer, comment, newLine) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) { + var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos); + var firstCommentLineIndent; + for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { + var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1); + if (pos !== comment.pos) { + if (firstCommentLineIndent === undefined) { + firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, 1), comment.pos); + } + var currentWriterIndentSpacing = writer.getIndent() * getIndentSize(); + var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart); + if (spacesToEmit > 0) { + var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize(); + var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize()); + writer.rawWrite(indentSizeSpaceString); + while (numberOfSingleSpacesToEmit) { + writer.rawWrite(" "); + numberOfSingleSpacesToEmit--; + } + } + else { + writer.rawWrite(""); + } + } + writeTrimmedCurrentLine(pos, nextLineStart); + pos = nextLineStart; + } + } + else { + writer.write(currentSourceFile.text.substring(comment.pos, comment.end)); + } + function writeTrimmedCurrentLine(pos, nextLineStart) { + var end = Math.min(comment.end, nextLineStart - 1); + var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ''); + if (currentLineText) { + writer.write(currentLineText); + if (end !== comment.end) { + writer.writeLine(); + } + } + else { + writer.writeLiteral(newLine); + } + } + function calculateIndent(pos, end) { + var currentLineIndent = 0; + for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { + if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) { + currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); + } + else { + currentLineIndent++; + } + } + return currentLineIndent; + } + } + function getFirstConstructorWithBody(node) { + return ts.forEach(node.members, function (member) { + if (member.kind === 129 /* Constructor */ && ts.nodeIsPresent(member.body)) { + return member; + } + }); + } + function getAllAccessorDeclarations(node, accessor) { + var firstAccessor; + var getAccessor; + var setAccessor; + if (accessor.name.kind === 122 /* ComputedPropertyName */) { + firstAccessor = accessor; + if (accessor.kind === 130 /* GetAccessor */) { + getAccessor = accessor; + } + else if (accessor.kind === 131 /* SetAccessor */) { + setAccessor = accessor; + } + else { + ts.Debug.fail("Accessor has wrong kind"); + } + } + else { + ts.forEach(node.members, function (member) { + if ((member.kind === 130 /* GetAccessor */ || member.kind === 131 /* SetAccessor */) && member.name.text === accessor.name.text && (member.flags & 128 /* Static */) === (accessor.flags & 128 /* Static */)) { + if (!firstAccessor) { + firstAccessor = member; + } + if (member.kind === 130 /* GetAccessor */ && !getAccessor) { + getAccessor = member; + } + if (member.kind === 131 /* SetAccessor */ && !setAccessor) { + setAccessor = member; + } + } + }); + } + return { + firstAccessor: firstAccessor, + getAccessor: getAccessor, + setAccessor: setAccessor + }; + } + function getSourceFilePathInNewDir(sourceFile, host, newDirPath) { + var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.filename, host.getCurrentDirectory()); + sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), ""); + return ts.combinePaths(newDirPath, sourceFilePath); + } + function getOwnEmitOutputFilePath(sourceFile, host, extension) { + var compilerOptions = host.getCompilerOptions(); + if (compilerOptions.outDir) { + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); + } + else { + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename); + } + return emitOutputFilePathWithoutExtension + extension; + } + function writeFile(host, diagnostics, filename, data, writeByteOrderMark) { + host.writeFile(filename, data, writeByteOrderMark, function (hostErrorMessage) { + diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage)); + }); + } + function emitDeclarations(host, resolver, diagnostics, jsFilePath, root) { + var newLine = host.getNewLine(); + var compilerOptions = host.getCompilerOptions(); + var write; + var writeLine; + var increaseIndent; + var decreaseIndent; + var writeTextOfNode; + var writer = createAndSetNewTextWriterWithSymbolWriter(); + var enclosingDeclaration; + var currentSourceFile; + var reportedDeclarationError = false; + var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { + } : writeJsDocComments; + var aliasDeclarationEmitInfo = []; + function createAndSetNewTextWriterWithSymbolWriter() { + var writer = createTextWriter(newLine); + 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; + setWriter(writer); + return writer; + } + function setWriter(newWriter) { + writer = newWriter; + write = newWriter.write; + writeTextOfNode = newWriter.writeTextOfNode; + writeLine = newWriter.writeLine; + increaseIndent = newWriter.increaseIndent; + decreaseIndent = newWriter.decreaseIndent; + } + function writeAsychronousImportDeclarations(importDeclarations) { + var oldWriter = writer; + ts.forEach(importDeclarations, function (aliasToWrite) { + var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; }); + if (aliasEmitInfo) { + createAndSetNewTextWriterWithSymbolWriter(); + for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { + increaseIndent(); + } + writeImportDeclaration(aliasToWrite); + aliasEmitInfo.asynchronousOutput = writer.getText(); + } + }); + setWriter(oldWriter); + } + function handleSymbolAccessibilityError(symbolAccesibilityResult) { + if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) { + if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { + writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); + } + } + else { + reportedDeclarationError = true; + var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult); + if (errorInfo) { + if (errorInfo.typeName) { + diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName)); + } + else { + diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName)); + } + } + } + } + function trackSymbol(symbol, enclosingDeclaration, meaning) { + handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); + } + function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + write(": "); + if (type) { + emitType(type); + } + else { + resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); + } + } + function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + write(": "); + if (signature.type) { + emitType(signature.type); + } + else { + resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); + } + } + function emitLines(nodes) { + for (var i = 0, n = nodes.length; i < n; i++) { + emitNode(nodes[i]); + } + } + function emitSeparatedList(nodes, separator, eachNodeEmitFn) { + var currentWriterPos = writer.getTextPos(); + for (var i = 0, n = nodes.length; i < n; i++) { + if (currentWriterPos !== writer.getTextPos()) { + write(separator); + } + currentWriterPos = writer.getTextPos(); + eachNodeEmitFn(nodes[i]); + } + } + function emitCommaList(nodes, eachNodeEmitFn) { + emitSeparatedList(nodes, ", ", eachNodeEmitFn); + } + function writeJsDocComments(declaration) { + if (declaration) { + var jsDocComments = ts.getJsDocComments(declaration, currentSourceFile); + emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments); + emitComments(currentSourceFile, writer, jsDocComments, true, newLine, writeCommentRange); + } + } + function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type, getSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + emitType(type); + } + function emitType(type) { + switch (type.kind) { + case 110 /* AnyKeyword */: + case 119 /* StringKeyword */: + case 117 /* NumberKeyword */: + case 111 /* BooleanKeyword */: + case 98 /* VoidKeyword */: + case 8 /* StringLiteral */: + return writeTextOfNode(currentSourceFile, type); + case 135 /* TypeReference */: + return emitTypeReference(type); + case 138 /* TypeQuery */: + return emitTypeQuery(type); + case 140 /* ArrayType */: + return emitArrayType(type); + case 141 /* TupleType */: + return emitTupleType(type); + case 142 /* UnionType */: + return emitUnionType(type); + case 143 /* ParenthesizedType */: + return emitParenType(type); + case 136 /* FunctionType */: + case 137 /* ConstructorType */: + return emitSignatureDeclarationWithJsDocComments(type); + case 139 /* TypeLiteral */: + return emitTypeLiteral(type); + case 64 /* Identifier */: + return emitEntityName(type); + case 121 /* QualifiedName */: + return emitEntityName(type); + default: + ts.Debug.fail("Unknown type annotation: " + type.kind); + } + function emitEntityName(entityName) { + var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 197 /* ImportDeclaration */ ? entityName.parent : enclosingDeclaration); + handleSymbolAccessibilityError(visibilityResult); + writeEntityName(entityName); + function writeEntityName(entityName) { + if (entityName.kind === 64 /* Identifier */) { + writeTextOfNode(currentSourceFile, entityName); + } + else { + var qualifiedName = entityName; + writeEntityName(qualifiedName.left); + write("."); + writeTextOfNode(currentSourceFile, qualifiedName.right); + } + } + } + function emitTypeReference(type) { + emitEntityName(type.typeName); + if (type.typeArguments) { + write("<"); + emitCommaList(type.typeArguments, emitType); + write(">"); + } + } + function emitTypeQuery(type) { + write("typeof "); + emitEntityName(type.exprName); + } + function emitArrayType(type) { + emitType(type.elementType); + write("[]"); + } + function emitTupleType(type) { + write("["); + emitCommaList(type.elementTypes, emitType); + write("]"); + } + function emitUnionType(type) { + emitSeparatedList(type.types, " | ", emitType); + } + function emitParenType(type) { + write("("); + emitType(type.type); + write(")"); + } + function emitTypeLiteral(type) { + write("{"); + if (type.members.length) { + writeLine(); + increaseIndent(); + emitLines(type.members); + decreaseIndent(); + } + write("}"); + } + } + function emitSourceFile(node) { + currentSourceFile = node; + enclosingDeclaration = node; + emitLines(node.statements); + } + function emitExportAssignment(node) { + write("export = "); + writeTextOfNode(currentSourceFile, node.exportName); + write(";"); + writeLine(); + } + function emitModuleElementDeclarationFlags(node) { + if (node.parent === currentSourceFile) { + if (node.flags & 1 /* Export */) { + write("export "); + } + if (node.kind !== 192 /* InterfaceDeclaration */) { + write("declare "); + } + } + } + function emitClassMemberDeclarationFlags(node) { + if (node.flags & 32 /* Private */) { + write("private "); + } + else if (node.flags & 64 /* Protected */) { + write("protected "); + } + if (node.flags & 128 /* Static */) { + write("static "); + } + } + function emitImportDeclaration(node) { + var nodeEmitInfo = { + declaration: node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + hasWritten: resolver.isDeclarationVisible(node) + }; + aliasDeclarationEmitInfo.push(nodeEmitInfo); + if (nodeEmitInfo.hasWritten) { + writeImportDeclaration(node); + } + } + function writeImportDeclaration(node) { + emitJsDocComments(node); + if (node.flags & 1 /* Export */) { + write("export "); + } + write("import "); + writeTextOfNode(currentSourceFile, node.name); + write(" = "); + if (ts.isInternalModuleImportDeclaration(node)) { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError); + write(";"); + } + else { + write("require("); + writeTextOfNode(currentSourceFile, ts.getExternalModuleImportDeclarationExpression(node)); + write(");"); + } + writer.writeLine(); + function getImportEntityNameVisibilityError(symbolAccesibilityResult) { + return { + diagnosticMessage: ts.Diagnostics.Import_declaration_0_is_using_private_name_1, + errorNode: node, + typeName: node.name + }; + } + } + function emitModuleDeclaration(node) { + if (resolver.isDeclarationVisible(node)) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("module "); + writeTextOfNode(currentSourceFile, node.name); + while (node.body.kind !== 196 /* ModuleBlock */) { + node = node.body; + write("."); + writeTextOfNode(currentSourceFile, node.name); + } + var prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.body.statements); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + } + function emitTypeAliasDeclaration(node) { + if (resolver.isDeclarationVisible(node)) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("type "); + writeTextOfNode(currentSourceFile, node.name); + write(" = "); + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); + write(";"); + writeLine(); + } + function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) { + return { + diagnosticMessage: ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, + errorNode: node.type, + typeName: node.name + }; + } + } + function emitEnumDeclaration(node) { + if (resolver.isDeclarationVisible(node)) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (ts.isConst(node)) { + write("const "); + } + write("enum "); + writeTextOfNode(currentSourceFile, node.name); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + } + } + function emitEnumMemberDeclaration(node) { + emitJsDocComments(node); + writeTextOfNode(currentSourceFile, node.name); + var enumMemberValue = resolver.getEnumMemberValue(node); + if (enumMemberValue !== undefined) { + write(" = "); + write(enumMemberValue.toString()); + } + write(","); + writeLine(); + } + function isPrivateMethodTypeParameter(node) { + return node.parent.kind === 128 /* MethodDeclaration */ && (node.parent.flags & 32 /* Private */); + } + function emitTypeParameters(typeParameters) { + function emitTypeParameter(node) { + increaseIndent(); + emitJsDocComments(node); + decreaseIndent(); + writeTextOfNode(currentSourceFile, node.name); + if (node.constraint && !isPrivateMethodTypeParameter(node)) { + write(" extends "); + if (node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || (node.parent.parent && node.parent.parent.kind === 139 /* TypeLiteral */)) { + ts.Debug.assert(node.parent.kind === 128 /* MethodDeclaration */ || node.parent.kind === 127 /* MethodSignature */ || node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || node.parent.kind === 132 /* CallSignature */ || node.parent.kind === 133 /* ConstructSignature */); + emitType(node.constraint); + } + else { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError); + } + } + function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + switch (node.parent.kind) { + case 191 /* ClassDeclaration */: + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; + break; + case 192 /* InterfaceDeclaration */: + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; + break; + case 133 /* ConstructSignature */: + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + case 132 /* CallSignature */: + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + if (node.parent.flags & 128 /* Static */) { + diagnosticMessage = 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 === 191 /* ClassDeclaration */) { + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; + } + break; + case 190 /* FunctionDeclaration */: + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; + break; + default: + ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind); + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: node, + typeName: node.name + }; + } + } + if (typeParameters) { + write("<"); + emitCommaList(typeParameters, emitTypeParameter); + write(">"); + } + } + function emitHeritageClause(typeReferences, isImplementsList) { + if (typeReferences) { + write(isImplementsList ? " implements " : " extends "); + emitCommaList(typeReferences, emitTypeOfTypeReference); + } + function emitTypeOfTypeReference(node) { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); + function getHeritageClauseVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + if (node.parent.parent.kind === 191 /* ClassDeclaration */) { + diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: node, + typeName: node.parent.parent.name + }; + } + } + } + function emitClassDeclaration(node) { + function emitParameterProperties(constructorDeclaration) { + if (constructorDeclaration) { + ts.forEach(constructorDeclaration.parameters, function (param) { + if (param.flags & 112 /* AccessibilityModifier */) { + emitPropertyDeclaration(param); + } + }); + } + } + if (resolver.isDeclarationVisible(node)) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("class "); + writeTextOfNode(currentSourceFile, node.name); + var prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + var baseTypeNode = ts.getClassBaseTypeNode(node); + if (baseTypeNode) { + emitHeritageClause([baseTypeNode], false); + } + emitHeritageClause(ts.getClassImplementedTypeNodes(node), true); + write(" {"); + writeLine(); + increaseIndent(); + emitParameterProperties(getFirstConstructorWithBody(node)); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + } + function emitInterfaceDeclaration(node) { + if (resolver.isDeclarationVisible(node)) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("interface "); + writeTextOfNode(currentSourceFile, node.name); + var prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + emitHeritageClause(ts.getInterfaceBaseTypeNodes(node), false); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + } + function emitPropertyDeclaration(node) { + emitJsDocComments(node); + emitClassMemberDeclarationFlags(node); + emitVariableDeclaration(node); + write(";"); + writeLine(); + } + function emitVariableDeclaration(node) { + if (node.kind !== 188 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { + writeTextOfNode(currentSourceFile, node.name); + if ((node.kind === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) && ts.hasQuestionToken(node)) { + write("?"); + } + if ((node.kind === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) && node.parent.kind === 139 /* TypeLiteral */) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.flags & 32 /* Private */)) { + writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); + } + } + function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + if (node.kind === 188 /* 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 === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) { + 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 === 191 /* 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 { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + } + } + return diagnosticMessage !== undefined ? { + diagnosticMessage: diagnosticMessage, + errorNode: node, + typeName: node.name + } : undefined; + } + } + function emitTypeOfVariableDeclarationFromTypeLiteral(node) { + if (node.type) { + write(": "); + emitType(node.type); + } + } + function emitVariableStatement(node) { + var hasDeclarationWithEmit = ts.forEach(node.declarationList.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); }); + if (hasDeclarationWithEmit) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (ts.isLet(node.declarationList)) { + write("let "); + } + else if (ts.isConst(node.declarationList)) { + write("const "); + } + else { + write("var "); + } + emitCommaList(node.declarationList.declarations, emitVariableDeclaration); + write(";"); + writeLine(); + } + } + function emitAccessorDeclaration(node) { + var accessors = getAllAccessorDeclarations(node.parent, node); + if (node === accessors.firstAccessor) { + emitJsDocComments(accessors.getAccessor); + emitJsDocComments(accessors.setAccessor); + emitClassMemberDeclarationFlags(node); + writeTextOfNode(currentSourceFile, node.name); + if (!(node.flags & 32 /* Private */)) { + var accessorWithTypeAnnotation = node; + var type = getTypeAnnotationFromAccessor(node); + if (!type) { + var anotherAccessor = node.kind === 130 /* GetAccessor */ ? accessors.setAccessor : accessors.getAccessor; + type = getTypeAnnotationFromAccessor(anotherAccessor); + if (type) { + accessorWithTypeAnnotation = anotherAccessor; + } + } + writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError); + } + write(";"); + writeLine(); + } + function getTypeAnnotationFromAccessor(accessor) { + if (accessor) { + return accessor.kind === 130 /* GetAccessor */ ? accessor.type : accessor.parameters[0].type; + } + } + function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + if (accessorWithTypeAnnotation.kind === 131 /* SetAccessor */) { + if (accessorWithTypeAnnotation.parent.flags & 128 /* Static */) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: accessorWithTypeAnnotation.parameters[0], + typeName: accessorWithTypeAnnotation.name + }; + } + else { + if (accessorWithTypeAnnotation.flags & 128 /* Static */) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; + } + else { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: accessorWithTypeAnnotation.name, + typeName: undefined + }; + } + } + } + function emitFunctionDeclaration(node) { + if ((node.kind !== 190 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { + emitJsDocComments(node); + if (node.kind === 190 /* FunctionDeclaration */) { + emitModuleElementDeclarationFlags(node); + } + else if (node.kind === 128 /* MethodDeclaration */) { + emitClassMemberDeclarationFlags(node); + } + if (node.kind === 190 /* FunctionDeclaration */) { + write("function "); + writeTextOfNode(currentSourceFile, node.name); + } + else if (node.kind === 129 /* Constructor */) { + write("constructor"); + } + else { + writeTextOfNode(currentSourceFile, node.name); + if (ts.hasQuestionToken(node)) { + write("?"); + } + } + emitSignatureDeclaration(node); + } + } + function emitSignatureDeclarationWithJsDocComments(node) { + emitJsDocComments(node); + emitSignatureDeclaration(node); + } + function emitSignatureDeclaration(node) { + if (node.kind === 133 /* ConstructSignature */ || node.kind === 137 /* ConstructorType */) { + write("new "); + } + emitTypeParameters(node.typeParameters); + if (node.kind === 134 /* IndexSignature */) { + write("["); + } + else { + write("("); + } + var prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitCommaList(node.parameters, emitParameterDeclaration); + if (node.kind === 134 /* IndexSignature */) { + write("]"); + } + else { + write(")"); + } + var isFunctionTypeOrConstructorType = node.kind === 136 /* FunctionType */ || node.kind === 137 /* ConstructorType */; + if (isFunctionTypeOrConstructorType || node.parent.kind === 139 /* TypeLiteral */) { + if (node.type) { + write(isFunctionTypeOrConstructorType ? " => " : ": "); + emitType(node.type); + } + } + else if (node.kind !== 129 /* Constructor */ && !(node.flags & 32 /* Private */)) { + writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); + } + enclosingDeclaration = prevEnclosingDeclaration; + if (!isFunctionTypeOrConstructorType) { + write(";"); + writeLine(); + } + function getReturnTypeVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + switch (node.kind) { + case 133 /* ConstructSignature */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + case 132 /* CallSignature */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + case 134 /* IndexSignature */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + 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 === 191 /* 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 190 /* 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: + ts.Debug.fail("This is unknown kind for signature: " + node.kind); + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: node.name || node + }; + } + } + function emitParameterDeclaration(node) { + increaseIndent(); + emitJsDocComments(node); + if (node.dotDotDotToken) { + write("..."); + } + if (ts.isBindingPattern(node.name)) { + write("_" + ts.indexOf(node.parent.parameters, node)); + } + else { + writeTextOfNode(currentSourceFile, node.name); + } + if (node.initializer || ts.hasQuestionToken(node)) { + write("?"); + } + decreaseIndent(); + if (node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || node.parent.parent.kind === 139 /* TypeLiteral */) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.parent.flags & 32 /* Private */)) { + writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError); + } + function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + switch (node.parent.kind) { + case 129 /* Constructor */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; + break; + case 133 /* ConstructSignature */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + case 132 /* CallSignature */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + 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 === 191 /* 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 190 /* 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: + ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind); + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: node, + typeName: node.name + }; + } + } + function emitNode(node) { + switch (node.kind) { + case 129 /* Constructor */: + case 190 /* FunctionDeclaration */: + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + return emitFunctionDeclaration(node); + case 133 /* ConstructSignature */: + case 132 /* CallSignature */: + case 134 /* IndexSignature */: + return emitSignatureDeclarationWithJsDocComments(node); + case 130 /* GetAccessor */: + case 131 /* SetAccessor */: + return emitAccessorDeclaration(node); + case 171 /* VariableStatement */: + return emitVariableStatement(node); + case 126 /* PropertyDeclaration */: + case 125 /* PropertySignature */: + return emitPropertyDeclaration(node); + case 192 /* InterfaceDeclaration */: + return emitInterfaceDeclaration(node); + case 191 /* ClassDeclaration */: + return emitClassDeclaration(node); + case 193 /* TypeAliasDeclaration */: + return emitTypeAliasDeclaration(node); + case 206 /* EnumMember */: + return emitEnumMemberDeclaration(node); + case 194 /* EnumDeclaration */: + return emitEnumDeclaration(node); + case 195 /* ModuleDeclaration */: + return emitModuleDeclaration(node); + case 197 /* ImportDeclaration */: + return emitImportDeclaration(node); + case 198 /* ExportAssignment */: + return emitExportAssignment(node); + case 207 /* SourceFile */: + return emitSourceFile(node); + } + } + var referencePathsOutput = ""; + function writeReferencePath(referencedFile) { + var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; + declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, host.getCurrentDirectory(), host.getCanonicalFileName, false); + referencePathsOutput += "/// " + newLine; + } + if (root) { + if (!compilerOptions.noResolve) { + var addedGlobalFileReference = false; + ts.forEach(root.referencedFiles, function (fileReference) { + var referencedFile = ts.tryResolveScriptReference(host, root, fileReference); + if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { + writeReferencePath(referencedFile); + if (!isExternalModuleOrDeclarationFile(referencedFile)) { + addedGlobalFileReference = true; + } + } + }); + } + emitNode(root); + } + else { + var emittedReferencedFiles = []; + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + if (!compilerOptions.noResolve) { + ts.forEach(sourceFile.referencedFiles, function (fileReference) { + var referencedFile = ts.tryResolveScriptReference(host, sourceFile, fileReference); + if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) { + writeReferencePath(referencedFile); + emittedReferencedFiles.push(referencedFile); + } + }); + } + emitNode(sourceFile); + } + }); + } + return { + reportedDeclarationError: reportedDeclarationError, + aliasDeclarationEmitInfo: aliasDeclarationEmitInfo, + synchronousDeclarationOutput: writer.getText(), + referencePathsOutput: referencePathsOutput + }; + } + function getDeclarationDiagnostics(host, resolver, targetSourceFile) { + var diagnostics = []; + var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); + emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile); + return diagnostics; + } + ts.getDeclarationDiagnostics = getDeclarationDiagnostics; + function emitFiles(resolver, host, targetSourceFile) { + var compilerOptions = host.getCompilerOptions(); + var sourceMapDataList = compilerOptions.sourceMap ? [] : undefined; + var diagnostics = []; + var newLine = host.getNewLine(); + function emitJavaScript(jsFilePath, root) { + var writer = createTextWriter(newLine); + var write = writer.write; + var writeTextOfNode = writer.writeTextOfNode; + var writeLine = writer.writeLine; + var increaseIndent = writer.increaseIndent; + var decreaseIndent = writer.decreaseIndent; + var currentSourceFile; + var extendsEmitted = false; + var tempCount = 0; + var tempVariables; + var tempParameters; + var writeEmittedFiles = writeJavaScriptFile; + var emitLeadingComments = compilerOptions.removeComments ? function (node) { + } : emitLeadingDeclarationComments; + var emitTrailingComments = compilerOptions.removeComments ? function (node) { + } : emitTrailingDeclarationComments; + var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { + } : emitLeadingCommentsOfLocalPosition; + var detachedCommentsInfo; + var emitDetachedComments = compilerOptions.removeComments ? function (node) { + } : emitDetachedCommentsAtPosition; + var emitPinnedOrTripleSlashComments = compilerOptions.removeComments ? function (node) { + } : emitPinnedOrTripleSlashCommentsOfNode; + var writeComment = writeCommentRange; + var emit = emitNode; + var emitStart = function (node) { + }; + var emitEnd = function (node) { + }; + var emitToken = emitTokenText; + var scopeEmitStart = function (scopeDeclaration, scopeName) { + }; + var scopeEmitEnd = function () { + }; + var sourceMapData; + function initializeEmitterWithSourceMaps() { + var sourceMapDir; + var sourceMapSourceIndex = -1; + var sourceMapNameIndexMap = {}; + var sourceMapNameIndices = []; + function getSourceMapNameIndex() { + return sourceMapNameIndices.length ? sourceMapNameIndices[sourceMapNameIndices.length - 1] : -1; + } + var lastRecordedSourceMapSpan; + var lastEncodedSourceMapSpan = { + emittedLine: 1, + emittedColumn: 1, + sourceLine: 1, + sourceColumn: 1, + sourceIndex: 0 + }; + var lastEncodedNameIndex = 0; + function encodeLastRecordedSourceMapSpan() { + if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { + return; + } + var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; + if (lastEncodedSourceMapSpan.emittedLine == lastRecordedSourceMapSpan.emittedLine) { + if (sourceMapData.sourceMapMappings) { + sourceMapData.sourceMapMappings += ","; + } + } + else { + for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { + sourceMapData.sourceMapMappings += ";"; + } + prevEncodedEmittedColumn = 1; + } + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); + if (lastRecordedSourceMapSpan.nameIndex >= 0) { + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); + lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; + } + lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; + sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); + function base64VLQFormatEncode(inValue) { + function base64FormatEncode(inValue) { + if (inValue < 64) { + return 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.charAt(inValue); + } + throw TypeError(inValue + ": not a 64 based value"); + } + if (inValue < 0) { + inValue = ((-inValue) << 1) + 1; + } + else { + inValue = inValue << 1; + } + var encodedStr = ""; + do { + var currentDigit = inValue & 31; + inValue = inValue >> 5; + if (inValue > 0) { + currentDigit = currentDigit | 32; + } + encodedStr = encodedStr + base64FormatEncode(currentDigit); + } while (inValue > 0); + return encodedStr; + } + } + function recordSourceMapSpan(pos) { + var sourceLinePos = currentSourceFile.getLineAndCharacterFromPosition(pos); + var emittedLine = writer.getLine(); + var emittedColumn = writer.getColumn(); + if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan.emittedLine != emittedLine || lastRecordedSourceMapSpan.emittedColumn != emittedColumn || (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { + encodeLastRecordedSourceMapSpan(); + lastRecordedSourceMapSpan = { + emittedLine: emittedLine, + emittedColumn: emittedColumn, + sourceLine: sourceLinePos.line, + sourceColumn: sourceLinePos.character, + nameIndex: getSourceMapNameIndex(), + sourceIndex: sourceMapSourceIndex + }; + } + else { + lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; + lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; + lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; + } + } + function recordEmitNodeStartSpan(node) { + recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); + } + function recordEmitNodeEndSpan(node) { + recordSourceMapSpan(node.end); + } + function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { + var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); + recordSourceMapSpan(tokenStartPos); + var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); + recordSourceMapSpan(tokenEndPos); + return tokenEndPos; + } + function recordNewSourceFileStart(node) { + var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; + sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, host.getCurrentDirectory(), host.getCanonicalFileName, true)); + sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; + sourceMapData.inputSourceFileNames.push(node.filename); + } + function recordScopeNameOfNode(node, scopeName) { + function recordScopeNameIndex(scopeNameIndex) { + sourceMapNameIndices.push(scopeNameIndex); + } + function recordScopeNameStart(scopeName) { + var scopeNameIndex = -1; + if (scopeName) { + var parentIndex = getSourceMapNameIndex(); + if (parentIndex !== -1) { + scopeName = sourceMapData.sourceMapNames[parentIndex] + "." + scopeName; + } + scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); + if (scopeNameIndex === undefined) { + scopeNameIndex = sourceMapData.sourceMapNames.length; + sourceMapData.sourceMapNames.push(scopeName); + sourceMapNameIndexMap[scopeName] = scopeNameIndex; + } + } + recordScopeNameIndex(scopeNameIndex); + } + if (scopeName) { + recordScopeNameStart(scopeName); + } + else if (node.kind === 190 /* FunctionDeclaration */ || node.kind === 156 /* FunctionExpression */ || node.kind === 128 /* MethodDeclaration */ || node.kind === 127 /* MethodSignature */ || node.kind === 130 /* GetAccessor */ || node.kind === 131 /* SetAccessor */ || node.kind === 195 /* ModuleDeclaration */ || node.kind === 191 /* ClassDeclaration */ || node.kind === 194 /* EnumDeclaration */) { + if (node.name) { + scopeName = node.name.text; + } + recordScopeNameStart(scopeName); + } + else { + recordScopeNameIndex(getSourceMapNameIndex()); + } + } + function recordScopeNameEnd() { + sourceMapNameIndices.pop(); + } + ; + function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { + recordSourceMapSpan(comment.pos); + writeCommentRange(currentSourceFile, writer, comment, newLine); + recordSourceMapSpan(comment.end); + } + function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings) { + if (typeof JSON !== "undefined") { + return JSON.stringify({ + version: version, + file: file, + sourceRoot: sourceRoot, + sources: sources, + names: names, + mappings: mappings + }); + } + 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 += "\"" + ts.escapeString(list[i]) + "\""; + } + return output; + } + } + function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { + encodeLastRecordedSourceMapSpan(); + writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings), false); + sourceMapDataList.push(sourceMapData); + writeJavaScriptFile(emitOutput + "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL, writeByteOrderMark); + } + var sourceMapJsFile = ts.getBaseFilename(ts.normalizeSlashes(jsFilePath)); + sourceMapData = { + sourceMapFilePath: jsFilePath + ".map", + jsSourceMappingURL: sourceMapJsFile + ".map", + sourceMapFile: sourceMapJsFile, + sourceMapSourceRoot: compilerOptions.sourceRoot || "", + sourceMapSources: [], + inputSourceFileNames: [], + sourceMapNames: [], + sourceMapMappings: "", + sourceMapDecodedMappings: [] + }; + sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); + if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47 /* slash */) { + sourceMapData.sourceMapSourceRoot += ts.directorySeparator; + } + if (compilerOptions.mapRoot) { + sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); + if (root) { + sourceMapDir = ts.getDirectoryPath(getSourceFilePathInNewDir(root, host, sourceMapDir)); + } + if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { + sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir); + sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), host.getCurrentDirectory(), host.getCanonicalFileName, true); + } + else { + sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); + } + } + else { + sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); + } + function emitNodeWithMap(node) { + if (node) { + if (node.kind != 207 /* SourceFile */) { + recordEmitNodeStartSpan(node); + emitNode(node); + recordEmitNodeEndSpan(node); + } + else { + recordNewSourceFileStart(node); + emitNode(node); + } + } + } + writeEmittedFiles = writeJavaScriptAndSourceMapFile; + emit = emitNodeWithMap; + emitStart = recordEmitNodeStartSpan; + emitEnd = recordEmitNodeEndSpan; + emitToken = writeTextWithSpanRecord; + scopeEmitStart = recordScopeNameOfNode; + scopeEmitEnd = recordScopeNameEnd; + writeComment = writeCommentRangeWithMap; + } + function writeJavaScriptFile(emitOutput, writeByteOrderMark) { + writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); + } + function createTempVariable(location, forLoopVariable) { + var name = forLoopVariable ? "_i" : undefined; + while (true) { + if (name && resolver.isUnknownIdentifier(location, name)) { + break; + } + name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + 97 /* a */) : tempCount - 25); + tempCount++; + } + var result = ts.createNode(64 /* Identifier */); + result.text = name; + return result; + } + function recordTempDeclaration(name) { + if (!tempVariables) { + tempVariables = []; + } + tempVariables.push(name); + } + function emitTempDeclarations(newLine) { + if (tempVariables) { + if (newLine) { + writeLine(); + } + else { + write(" "); + } + write("var "); + emitCommaList(tempVariables); + write(";"); + } + } + function emitTokenText(tokenKind, startPos, emitFn) { + var tokenString = ts.tokenToString(tokenKind); + if (emitFn) { + emitFn(); + } + else { + write(tokenString); + } + return startPos + tokenString.length; + } + function emitOptional(prefix, node) { + if (node) { + write(prefix); + emit(node); + } + } + function emitParenthesized(node, parenthesized) { + if (parenthesized) { + write("("); + } + emit(node); + if (parenthesized) { + write(")"); + } + } + function emitTrailingCommaIfPresent(nodeList) { + if (nodeList.hasTrailingComma) { + write(","); + } + } + function emitList(nodes, start, count, multiLine, trailingComma) { + if (multiLine) { + increaseIndent(); + } + for (var i = 0; i < count; i++) { + if (multiLine) { + if (i) { + write(","); + } + writeLine(); + } + else { + if (i) { + write(", "); + } + } + emit(nodes[start + i]); + } + if (trailingComma) { + write(","); + } + if (multiLine) { + decreaseIndent(); + writeLine(); + } + } + function emitCommaList(nodes) { + if (nodes) { + emitList(nodes, 0, nodes.length, false, false); + } + } + function emitMultiLineList(nodes) { + if (nodes) { + emitList(nodes, 0, nodes.length, true, false); + } + } + function emitLines(nodes) { + emitLinesStartingAt(nodes, 0); + } + function emitLinesStartingAt(nodes, startIndex) { + for (var i = startIndex; i < nodes.length; i++) { + writeLine(); + emit(nodes[i]); + } + } + function isBinaryOrOctalIntegerLiteral(text) { + if (text.length <= 0) { + return false; + } + if (text.charCodeAt(1) === 66 /* B */ || text.charCodeAt(1) === 98 /* b */ || text.charCodeAt(1) === 79 /* O */ || text.charCodeAt(1) === 111 /* o */) { + return true; + } + return false; + } + function emitLiteral(node) { + var text = compilerOptions.target < 2 /* ES6 */ && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; + if (compilerOptions.sourceMap && (node.kind === 8 /* StringLiteral */ || ts.isTemplateLiteralKind(node.kind))) { + writer.writeLiteral(text); + } + else if (compilerOptions.target < 2 /* ES6 */ && node.kind === 7 /* NumericLiteral */ && isBinaryOrOctalIntegerLiteral(text)) { + write(node.text); + } + else { + write(text); + } + } + function getTemplateLiteralAsStringLiteral(node) { + return '"' + ts.escapeString(node.text) + '"'; + } + function emitTemplateExpression(node) { + if (compilerOptions.target >= 2 /* ES6 */) { + ts.forEachChild(node, emit); + return; + } + ts.Debug.assert(node.parent.kind !== 153 /* TaggedTemplateExpression */); + var emitOuterParens = ts.isExpression(node.parent) && templateNeedsParens(node, node.parent); + if (emitOuterParens) { + write("("); + } + var headEmitted = false; + if (shouldEmitTemplateHead()) { + emitLiteral(node.head); + headEmitted = true; + } + for (var i = 0; i < node.templateSpans.length; i++) { + var templateSpan = node.templateSpans[i]; + var needsParens = templateSpan.expression.kind !== 155 /* ParenthesizedExpression */ && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1 /* GreaterThan */; + if (i > 0 || headEmitted) { + write(" + "); + } + emitParenthesized(templateSpan.expression, needsParens); + if (templateSpan.literal.text.length !== 0) { + write(" + "); + emitLiteral(templateSpan.literal); + } + } + if (emitOuterParens) { + write(")"); + } + function shouldEmitTemplateHead() { + ts.Debug.assert(node.templateSpans.length !== 0); + return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; + } + function templateNeedsParens(template, parent) { + switch (parent.kind) { + case 151 /* CallExpression */: + case 152 /* NewExpression */: + return parent.expression === template; + case 155 /* ParenthesizedExpression */: + return false; + case 153 /* TaggedTemplateExpression */: + ts.Debug.fail("Path should be unreachable; tagged templates not supported pre-ES6."); + default: + return comparePrecedenceToBinaryPlus(parent) !== -1 /* LessThan */; + } + } + function comparePrecedenceToBinaryPlus(expression) { + ts.Debug.assert(compilerOptions.target <= 1 /* ES5 */); + switch (expression.kind) { + case 163 /* BinaryExpression */: + switch (expression.operator) { + case 35 /* AsteriskToken */: + case 36 /* SlashToken */: + case 37 /* PercentToken */: + return 1 /* GreaterThan */; + case 33 /* PlusToken */: + case 34 /* MinusToken */: + return 0 /* EqualTo */; + default: + return -1 /* LessThan */; + } + case 164 /* ConditionalExpression */: + return -1 /* LessThan */; + default: + return 1 /* GreaterThan */; + } + } + } + function emitTemplateSpan(span) { + emit(span.expression); + emit(span.literal); + } + function emitExpressionForPropertyName(node) { + if (node.kind === 8 /* StringLiteral */) { + emitLiteral(node); + } + else if (node.kind === 122 /* ComputedPropertyName */) { + emit(node.expression); + } + else { + write("\""); + if (node.kind === 7 /* NumericLiteral */) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + write("\""); + } + } + function isNotExpressionIdentifier(node) { + var parent = node.parent; + switch (parent.kind) { + case 124 /* Parameter */: + case 188 /* VariableDeclaration */: + case 146 /* BindingElement */: + case 126 /* PropertyDeclaration */: + case 125 /* PropertySignature */: + case 204 /* PropertyAssignment */: + case 205 /* ShorthandPropertyAssignment */: + case 206 /* EnumMember */: + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + case 190 /* FunctionDeclaration */: + case 130 /* GetAccessor */: + case 131 /* SetAccessor */: + case 156 /* FunctionExpression */: + case 191 /* ClassDeclaration */: + case 192 /* InterfaceDeclaration */: + case 194 /* EnumDeclaration */: + case 195 /* ModuleDeclaration */: + case 197 /* ImportDeclaration */: + return parent.name === node; + case 180 /* BreakStatement */: + case 179 /* ContinueStatement */: + case 198 /* ExportAssignment */: + return false; + case 184 /* LabeledStatement */: + return node.parent.label === node; + case 203 /* CatchClause */: + return node.parent.name === node; + } + } + function emitExpressionIdentifier(node) { + var prefix = resolver.getExpressionNamePrefix(node); + if (prefix) { + write(prefix); + write("."); + } + writeTextOfNode(currentSourceFile, node); + } + function emitIdentifier(node) { + if (!node.parent) { + write(node.text); + } + else if (!isNotExpressionIdentifier(node)) { + emitExpressionIdentifier(node); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } + function emitThis(node) { + if (resolver.getNodeCheckFlags(node) & 2 /* LexicalThis */) { + write("_this"); + } + else { + write("this"); + } + } + function emitSuper(node) { + var flags = resolver.getNodeCheckFlags(node); + if (flags & 16 /* SuperInstance */) { + write("_super.prototype"); + } + else if (flags & 32 /* SuperStatic */) { + write("_super"); + } + else { + write("super"); + } + } + function emitObjectBindingPattern(node) { + write("{ "); + var elements = node.elements; + emitList(elements, 0, elements.length, false, elements.hasTrailingComma); + write(" }"); + } + function emitArrayBindingPattern(node) { + write("["); + var elements = node.elements; + emitList(elements, 0, elements.length, false, elements.hasTrailingComma); + write("]"); + } + function emitBindingElement(node) { + if (node.propertyName) { + emit(node.propertyName); + write(": "); + } + if (node.dotDotDotToken) { + write("..."); + } + if (ts.isBindingPattern(node.name)) { + emit(node.name); + } + else { + emitModuleMemberName(node); + } + emitOptional(" = ", node.initializer); + } + function emitSpreadElementExpression(node) { + write("..."); + emit(node.expression); + } + function needsParenthesisForPropertyAccess(node) { + switch (node.kind) { + case 64 /* Identifier */: + case 147 /* ArrayLiteralExpression */: + case 149 /* PropertyAccessExpression */: + case 150 /* ElementAccessExpression */: + case 151 /* CallExpression */: + case 155 /* ParenthesizedExpression */: + return false; + } + return true; + } + function emitArrayLiteral(node) { + var elements = node.elements; + var length = elements.length; + if (length === 0) { + write("[]"); + return; + } + if (compilerOptions.target >= 2 /* ES6 */) { + write("["); + emitList(elements, 0, elements.length, (node.flags & 256 /* MultiLine */) !== 0, elements.hasTrailingComma); + write("]"); + return; + } + var pos = 0; + var group = 0; + while (pos < length) { + if (group === 1) { + write(".concat("); + } + else if (group > 1) { + write(", "); + } + var e = elements[pos]; + if (e.kind === 167 /* SpreadElementExpression */) { + e = e.expression; + emitParenthesized(e, group === 0 && needsParenthesisForPropertyAccess(e)); + pos++; + } + else { + var i = pos; + while (i < length && elements[i].kind !== 167 /* SpreadElementExpression */) { + i++; + } + write("["); + emitList(elements, pos, i - pos, (node.flags & 256 /* MultiLine */) !== 0, elements.hasTrailingComma); + write("]"); + pos = i; + } + group++; + } + if (group > 1) { + write(")"); + } + } + function emitObjectLiteral(node) { + write("{"); + var properties = node.properties; + if (properties.length) { + var multiLine = (node.flags & 256 /* MultiLine */) !== 0; + if (!multiLine) { + write(" "); + } + emitList(properties, 0, properties.length, multiLine, properties.hasTrailingComma && compilerOptions.target >= 1 /* ES5 */); + if (!multiLine) { + write(" "); + } + } + write("}"); + } + function emitComputedPropertyName(node) { + write("["); + emit(node.expression); + write("]"); + } + function emitMethod(node) { + if (!ts.isObjectLiteralMethod(node)) { + return; + } + emitLeadingComments(node); + emit(node.name); + if (compilerOptions.target < 2 /* ES6 */) { + write(": function "); + } + emitSignatureAndBody(node); + emitTrailingComments(node); + } + function emitPropertyAssignment(node) { + emitLeadingComments(node); + emit(node.name); + write(": "); + emit(node.initializer); + emitTrailingComments(node); + } + function emitShorthandPropertyAssignment(node) { + emitLeadingComments(node); + emit(node.name); + if (compilerOptions.target < 2 /* ES6 */ || resolver.getExpressionNamePrefix(node.name)) { + write(": "); + emitExpressionIdentifier(node.name); + } + emitTrailingComments(node); + } + function tryEmitConstantValue(node) { + var constantValue = resolver.getConstantValue(node); + if (constantValue !== undefined) { + var propertyName = node.kind === 149 /* PropertyAccessExpression */ ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); + write(constantValue.toString() + " /* " + propertyName + " */"); + return true; + } + return false; + } + function emitPropertyAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + write("."); + emit(node.name); + } + function emitQualifiedName(node) { + emit(node.left); + write("."); + emit(node.right); + } + function emitIndexedAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + write("["); + emit(node.argumentExpression); + write("]"); + } + function emitCallExpression(node) { + var superCall = false; + if (node.expression.kind === 90 /* SuperKeyword */) { + write("_super"); + superCall = true; + } + else { + emit(node.expression); + superCall = node.expression.kind === 149 /* PropertyAccessExpression */ && node.expression.expression.kind === 90 /* SuperKeyword */; + } + if (superCall) { + write(".call("); + emitThis(node.expression); + if (node.arguments.length) { + write(", "); + emitCommaList(node.arguments); + } + write(")"); + } + else { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + function emitNewExpression(node) { + write("new "); + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + function emitTaggedTemplateExpression(node) { + ts.Debug.assert(compilerOptions.target >= 2 /* ES6 */, "Trying to emit a tagged template in pre-ES6 mode."); + emit(node.tag); + write(" "); + emit(node.template); + } + function emitParenExpression(node) { + if (node.expression.kind === 154 /* TypeAssertionExpression */) { + var operand = node.expression.expression; + while (operand.kind == 154 /* TypeAssertionExpression */) { + operand = operand.expression; + } + if (operand.kind !== 161 /* PrefixUnaryExpression */ && operand.kind !== 160 /* VoidExpression */ && operand.kind !== 159 /* TypeOfExpression */ && operand.kind !== 158 /* DeleteExpression */ && operand.kind !== 162 /* PostfixUnaryExpression */ && operand.kind !== 152 /* NewExpression */ && !(operand.kind === 151 /* CallExpression */ && node.parent.kind === 152 /* NewExpression */) && !(operand.kind === 156 /* FunctionExpression */ && node.parent.kind === 151 /* CallExpression */)) { + emit(operand); + return; + } + } + write("("); + emit(node.expression); + write(")"); + } + function emitDeleteExpression(node) { + write(ts.tokenToString(73 /* DeleteKeyword */)); + write(" "); + emit(node.expression); + } + function emitVoidExpression(node) { + write(ts.tokenToString(98 /* VoidKeyword */)); + write(" "); + emit(node.expression); + } + function emitTypeOfExpression(node) { + write(ts.tokenToString(96 /* TypeOfKeyword */)); + write(" "); + emit(node.expression); + } + function emitPrefixUnaryExpression(node) { + write(ts.tokenToString(node.operator)); + if (node.operand.kind === 161 /* PrefixUnaryExpression */) { + var operand = node.operand; + if (node.operator === 33 /* PlusToken */ && (operand.operator === 33 /* PlusToken */ || operand.operator === 38 /* PlusPlusToken */)) { + write(" "); + } + else if (node.operator === 34 /* MinusToken */ && (operand.operator === 34 /* MinusToken */ || operand.operator === 39 /* MinusMinusToken */)) { + write(" "); + } + } + emit(node.operand); + } + function emitPostfixUnaryExpression(node) { + emit(node.operand); + write(ts.tokenToString(node.operator)); + } + function emitBinaryExpression(node) { + if (compilerOptions.target < 2 /* ES6 */ && node.operator === 52 /* EqualsToken */ && (node.left.kind === 148 /* ObjectLiteralExpression */ || node.left.kind === 147 /* ArrayLiteralExpression */)) { + emitDestructuring(node); + } + else { + emit(node.left); + if (node.operator !== 23 /* CommaToken */) + write(" "); + write(ts.tokenToString(node.operator)); + write(" "); + emit(node.right); + } + } + function emitConditionalExpression(node) { + emit(node.condition); + write(" ? "); + emit(node.whenTrue); + write(" : "); + emit(node.whenFalse); + } + function emitBlock(node) { + emitToken(14 /* OpenBraceToken */, node.pos); + increaseIndent(); + scopeEmitStart(node.parent); + if (node.kind === 196 /* ModuleBlock */) { + ts.Debug.assert(node.parent.kind === 195 /* ModuleDeclaration */); + emitCaptureThisForNodeIfNecessary(node.parent); + } + emitLines(node.statements); + if (node.kind === 196 /* ModuleBlock */) { + emitTempDeclarations(true); + } + decreaseIndent(); + writeLine(); + emitToken(15 /* CloseBraceToken */, node.statements.end); + scopeEmitEnd(); + } + function emitEmbeddedStatement(node) { + if (node.kind === 170 /* Block */) { + write(" "); + emit(node); + } + else { + increaseIndent(); + writeLine(); + emit(node); + decreaseIndent(); + } + } + function emitExpressionStatement(node) { + emitLeadingComments(node); + emitParenthesized(node.expression, node.expression.kind === 157 /* ArrowFunction */); + write(";"); + emitTrailingComments(node); + } + function emitIfStatement(node) { + emitLeadingComments(node); + var endPos = emitToken(83 /* IfKeyword */, node.pos); + write(" "); + endPos = emitToken(16 /* OpenParenToken */, endPos); + emit(node.expression); + emitToken(17 /* CloseParenToken */, node.expression.end); + emitEmbeddedStatement(node.thenStatement); + if (node.elseStatement) { + writeLine(); + emitToken(75 /* ElseKeyword */, node.thenStatement.end); + if (node.elseStatement.kind === 174 /* IfStatement */) { + write(" "); + emit(node.elseStatement); + } + else { + emitEmbeddedStatement(node.elseStatement); + } + } + emitTrailingComments(node); + } + function emitDoStatement(node) { + write("do"); + emitEmbeddedStatement(node.statement); + if (node.statement.kind === 170 /* Block */) { + write(" "); + } + else { + writeLine(); + } + write("while ("); + emit(node.expression); + write(");"); + } + function emitWhileStatement(node) { + write("while ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitForStatement(node) { + var endPos = emitToken(81 /* ForKeyword */, node.pos); + write(" "); + endPos = emitToken(16 /* OpenParenToken */, endPos); + if (node.initializer && node.initializer.kind === 189 /* VariableDeclarationList */) { + var variableDeclarationList = node.initializer; + var declarations = variableDeclarationList.declarations; + if (declarations[0] && ts.isLet(declarations[0])) { + emitToken(103 /* LetKeyword */, endPos); + } + else if (declarations[0] && ts.isConst(declarations[0])) { + emitToken(69 /* ConstKeyword */, endPos); + } + else { + emitToken(97 /* VarKeyword */, endPos); + } + write(" "); + emitCommaList(variableDeclarationList.declarations); + } + else if (node.initializer) { + emit(node.initializer); + } + write(";"); + emitOptional(" ", node.condition); + write(";"); + emitOptional(" ", node.iterator); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitForInStatement(node) { + var endPos = emitToken(81 /* ForKeyword */, node.pos); + write(" "); + endPos = emitToken(16 /* OpenParenToken */, endPos); + if (node.initializer.kind === 189 /* VariableDeclarationList */) { + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length >= 1) { + var decl = variableDeclarationList.declarations[0]; + if (ts.isLet(decl)) { + emitToken(103 /* LetKeyword */, endPos); + } + else { + emitToken(97 /* VarKeyword */, endPos); + } + write(" "); + emit(decl); + } + } + else { + emit(node.initializer); + } + write(" in "); + emit(node.expression); + emitToken(17 /* CloseParenToken */, node.expression.end); + emitEmbeddedStatement(node.statement); + } + function emitBreakOrContinueStatement(node) { + emitToken(node.kind === 180 /* BreakStatement */ ? 65 /* BreakKeyword */ : 70 /* ContinueKeyword */, node.pos); + emitOptional(" ", node.label); + write(";"); + } + function emitReturnStatement(node) { + emitLeadingComments(node); + emitToken(89 /* ReturnKeyword */, node.pos); + emitOptional(" ", node.expression); + write(";"); + emitTrailingComments(node); + } + function emitWithStatement(node) { + write("with ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitSwitchStatement(node) { + var endPos = emitToken(91 /* SwitchKeyword */, node.pos); + write(" "); + emitToken(16 /* OpenParenToken */, endPos); + emit(node.expression); + endPos = emitToken(17 /* CloseParenToken */, node.expression.end); + write(" "); + emitToken(14 /* OpenBraceToken */, endPos); + increaseIndent(); + emitLines(node.clauses); + decreaseIndent(); + writeLine(); + emitToken(15 /* CloseBraceToken */, node.clauses.end); + } + function isOnSameLine(node1, node2) { + return getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); + } + function emitCaseOrDefaultClause(node) { + if (node.kind === 200 /* CaseClause */) { + write("case "); + emit(node.expression); + write(":"); + } + else { + write("default:"); + } + if (node.statements.length === 1 && isOnSameLine(node, node.statements[0])) { + write(" "); + emit(node.statements[0]); + } + else { + increaseIndent(); + emitLines(node.statements); + decreaseIndent(); + } + } + function emitThrowStatement(node) { + write("throw "); + emit(node.expression); + write(";"); + } + function emitTryStatement(node) { + write("try "); + emit(node.tryBlock); + emit(node.catchClause); + if (node.finallyBlock) { + writeLine(); + write("finally "); + emit(node.finallyBlock); + } + } + function emitCatchClause(node) { + writeLine(); + var endPos = emitToken(67 /* CatchKeyword */, node.pos); + write(" "); + emitToken(16 /* OpenParenToken */, endPos); + emit(node.name); + emitToken(17 /* CloseParenToken */, node.name.end); + write(" "); + emitBlock(node.block); + } + function emitDebuggerStatement(node) { + emitToken(71 /* DebuggerKeyword */, node.pos); + write(";"); + } + function emitLabelledStatement(node) { + emit(node.label); + write(": "); + emit(node.statement); + } + function getContainingModule(node) { + do { + node = node.parent; + } while (node && node.kind !== 195 /* ModuleDeclaration */); + return node; + } + function emitModuleMemberName(node) { + emitStart(node.name); + if (ts.getCombinedNodeFlags(node) & 1 /* Export */) { + var container = getContainingModule(node); + write(container ? resolver.getLocalNameOfContainer(container) : "exports"); + write("."); + } + emitNode(node.name); + emitEnd(node.name); + } + function emitDestructuring(root, value) { + var emitCount = 0; + var isDeclaration = (root.kind === 188 /* VariableDeclaration */ && !(ts.getCombinedNodeFlags(root) & 1 /* Export */)) || root.kind === 124 /* Parameter */; + if (root.kind === 163 /* BinaryExpression */) { + emitAssignmentExpression(root); + } + else { + emitBindingElement(root, value); + } + function emitAssignment(name, value) { + if (emitCount++) { + write(", "); + } + if (name.parent && (name.parent.kind === 188 /* VariableDeclaration */ || name.parent.kind === 146 /* BindingElement */)) { + emitModuleMemberName(name.parent); + } + else { + emit(name); + } + write(" = "); + emit(value); + } + function ensureIdentifier(expr) { + if (expr.kind !== 64 /* Identifier */) { + var identifier = createTempVariable(root); + if (!isDeclaration) { + recordTempDeclaration(identifier); + } + emitAssignment(identifier, expr); + expr = identifier; + } + return expr; + } + function createVoidZero() { + var zero = ts.createNode(7 /* NumericLiteral */); + zero.text = "0"; + var result = ts.createNode(160 /* VoidExpression */); + result.expression = zero; + return result; + } + function createDefaultValueCheck(value, defaultValue) { + value = ensureIdentifier(value); + var equals = ts.createNode(163 /* BinaryExpression */); + equals.left = value; + equals.operator = 30 /* EqualsEqualsEqualsToken */; + equals.right = createVoidZero(); + var cond = ts.createNode(164 /* ConditionalExpression */); + cond.condition = equals; + cond.whenTrue = defaultValue; + cond.whenFalse = value; + return cond; + } + function createNumericLiteral(value) { + var node = ts.createNode(7 /* NumericLiteral */); + node.text = "" + value; + return node; + } + function parenthesizeForAccess(expr) { + if (expr.kind === 64 /* Identifier */ || expr.kind === 149 /* PropertyAccessExpression */ || expr.kind === 150 /* ElementAccessExpression */) { + return expr; + } + var node = ts.createNode(155 /* ParenthesizedExpression */); + node.expression = expr; + return node; + } + function createPropertyAccess(object, propName) { + if (propName.kind !== 64 /* Identifier */) { + return createElementAccess(object, propName); + } + var node = ts.createNode(149 /* PropertyAccessExpression */); + node.expression = parenthesizeForAccess(object); + node.name = propName; + return node; + } + function createElementAccess(object, index) { + var node = ts.createNode(150 /* ElementAccessExpression */); + node.expression = parenthesizeForAccess(object); + node.argumentExpression = index; + return node; + } + function emitObjectLiteralAssignment(target, value) { + var properties = target.properties; + if (properties.length !== 1) { + value = ensureIdentifier(value); + } + for (var i = 0; i < properties.length; i++) { + var p = properties[i]; + if (p.kind === 204 /* PropertyAssignment */ || p.kind === 205 /* ShorthandPropertyAssignment */) { + var propName = (p.name); + emitDestructuringAssignment(p.initializer || propName, createPropertyAccess(value, propName)); + } + } + } + function emitArrayLiteralAssignment(target, value) { + var elements = target.elements; + if (elements.length !== 1) { + value = ensureIdentifier(value); + } + for (var i = 0; i < elements.length; i++) { + var e = elements[i]; + if (e.kind !== 168 /* OmittedExpression */) { + if (e.kind !== 167 /* SpreadElementExpression */) { + emitDestructuringAssignment(e, createElementAccess(value, createNumericLiteral(i))); + } + else { + if (i === elements.length - 1) { + value = ensureIdentifier(value); + emitAssignment(e.expression, value); + write(".slice(" + i + ")"); + } + } + } + } + } + function emitDestructuringAssignment(target, value) { + if (target.kind === 163 /* BinaryExpression */ && target.operator === 52 /* EqualsToken */) { + value = createDefaultValueCheck(value, target.right); + target = target.left; + } + if (target.kind === 148 /* ObjectLiteralExpression */) { + emitObjectLiteralAssignment(target, value); + } + else if (target.kind === 147 /* ArrayLiteralExpression */) { + emitArrayLiteralAssignment(target, value); + } + else { + emitAssignment(target, value); + } + } + function emitAssignmentExpression(root) { + var target = root.left; + var value = root.right; + if (root.parent.kind === 173 /* ExpressionStatement */) { + emitDestructuringAssignment(target, value); + } + else { + if (root.parent.kind !== 155 /* ParenthesizedExpression */) { + write("("); + } + value = ensureIdentifier(value); + emitDestructuringAssignment(target, value); + write(", "); + emit(value); + if (root.parent.kind !== 155 /* ParenthesizedExpression */) { + write(")"); + } + } + } + function emitBindingElement(target, value) { + if (target.initializer) { + value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; + } + else if (!value) { + value = createVoidZero(); + } + if (ts.isBindingPattern(target.name)) { + var pattern = target.name; + var elements = pattern.elements; + if (elements.length !== 1) { + value = ensureIdentifier(value); + } + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + if (pattern.kind === 144 /* ObjectBindingPattern */) { + var propName = element.propertyName || element.name; + emitBindingElement(element, createPropertyAccess(value, propName)); + } + else if (element.kind !== 168 /* OmittedExpression */) { + if (!element.dotDotDotToken) { + emitBindingElement(element, createElementAccess(value, createNumericLiteral(i))); + } + else { + if (i === elements.length - 1) { + value = ensureIdentifier(value); + emitAssignment(element.name, value); + write(".slice(" + i + ")"); + } + } + } + } + } + else { + emitAssignment(target.name, value); + } + } + } + function emitVariableDeclaration(node) { + emitLeadingComments(node); + if (ts.isBindingPattern(node.name)) { + if (compilerOptions.target < 2 /* ES6 */) { + emitDestructuring(node); + } + else { + emit(node.name); + emitOptional(" = ", node.initializer); + } + } + else { + emitModuleMemberName(node); + emitOptional(" = ", node.initializer); + } + emitTrailingComments(node); + } + function emitVariableStatement(node) { + emitLeadingComments(node); + if (!(node.flags & 1 /* Export */)) { + if (ts.isLet(node.declarationList)) { + write("let "); + } + else if (ts.isConst(node.declarationList)) { + write("const "); + } + else { + write("var "); + } + } + emitCommaList(node.declarationList.declarations); + write(";"); + emitTrailingComments(node); + } + function emitParameter(node) { + emitLeadingComments(node); + if (compilerOptions.target < 2 /* ES6 */) { + if (ts.isBindingPattern(node.name)) { + var name = createTempVariable(node); + if (!tempParameters) { + tempParameters = []; + } + tempParameters.push(name); + emit(name); + } + else { + emit(node.name); + } + } + else { + if (node.dotDotDotToken) { + write("..."); + } + emit(node.name); + emitOptional(" = ", node.initializer); + } + emitTrailingComments(node); + } + function emitDefaultValueAssignments(node) { + if (compilerOptions.target < 2 /* ES6 */) { + var tempIndex = 0; + ts.forEach(node.parameters, function (p) { + if (ts.isBindingPattern(p.name)) { + writeLine(); + write("var "); + emitDestructuring(p, tempParameters[tempIndex]); + write(";"); + tempIndex++; + } + else if (p.initializer) { + writeLine(); + emitStart(p); + write("if ("); + emitNode(p.name); + write(" === void 0)"); + emitEnd(p); + write(" { "); + emitStart(p); + emitNode(p.name); + write(" = "); + emitNode(p.initializer); + emitEnd(p); + write("; }"); + } + }); + } + } + function emitRestParameter(node) { + if (compilerOptions.target < 2 /* ES6 */ && ts.hasRestParameters(node)) { + var restIndex = node.parameters.length - 1; + var restParam = node.parameters[restIndex]; + var tempName = createTempVariable(node, true).text; + writeLine(); + emitLeadingComments(restParam); + emitStart(restParam); + write("var "); + emitNode(restParam.name); + write(" = [];"); + emitEnd(restParam); + emitTrailingComments(restParam); + writeLine(); + write("for ("); + emitStart(restParam); + write("var " + tempName + " = " + restIndex + ";"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + " < arguments.length;"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + "++"); + emitEnd(restParam); + write(") {"); + increaseIndent(); + writeLine(); + emitStart(restParam); + emitNode(restParam.name); + write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); + emitEnd(restParam); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function emitAccessor(node) { + emitLeadingComments(node); + write(node.kind === 130 /* GetAccessor */ ? "get " : "set "); + emit(node.name); + emitSignatureAndBody(node); + emitTrailingComments(node); + } + function emitFunctionDeclaration(node) { + if (ts.nodeIsMissing(node.body)) { + return emitPinnedOrTripleSlashComments(node); + } + if (node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { + emitLeadingComments(node); + } + write("function "); + if (node.kind === 190 /* FunctionDeclaration */ || (node.kind === 156 /* FunctionExpression */ && node.name)) { + emit(node.name); + } + emitSignatureAndBody(node); + if (node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { + emitTrailingComments(node); + } + } + function emitCaptureThisForNodeIfNecessary(node) { + if (resolver.getNodeCheckFlags(node) & 4 /* CaptureThis */) { + writeLine(); + emitStart(node); + write("var _this = this;"); + emitEnd(node); + } + } + function emitSignatureParameters(node) { + increaseIndent(); + write("("); + if (node) { + var parameters = node.parameters; + var omitCount = compilerOptions.target < 2 /* ES6 */ && ts.hasRestParameters(node) ? 1 : 0; + emitList(parameters, 0, parameters.length - omitCount, false, false); + } + write(")"); + decreaseIndent(); + } + function emitSignatureAndBody(node) { + var saveTempCount = tempCount; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; + emitSignatureParameters(node); + write(" {"); + scopeEmitStart(node); + increaseIndent(); + emitDetachedComments(node.body.kind === 170 /* Block */ ? node.body.statements : node.body); + var startIndex = 0; + if (node.body.kind === 170 /* Block */) { + startIndex = emitDirectivePrologues(node.body.statements, true); + } + var outPos = writer.getTextPos(); + emitCaptureThisForNodeIfNecessary(node); + emitDefaultValueAssignments(node); + emitRestParameter(node); + if (node.body.kind !== 170 /* Block */ && outPos === writer.getTextPos()) { + decreaseIndent(); + write(" "); + emitStart(node.body); + write("return "); + emitNode(node.body); + emitEnd(node.body); + write(";"); + emitTempDeclarations(false); + write(" "); + emitStart(node.body); + write("}"); + emitEnd(node.body); + } + else { + if (node.body.kind === 170 /* Block */) { + emitLinesStartingAt(node.body.statements, startIndex); + } + else { + writeLine(); + emitLeadingComments(node.body); + write("return "); + emit(node.body); + write(";"); + emitTrailingComments(node.body); + } + emitTempDeclarations(true); + writeLine(); + if (node.body.kind === 170 /* Block */) { + emitLeadingCommentsOfPosition(node.body.statements.end); + decreaseIndent(); + emitToken(15 /* CloseBraceToken */, node.body.statements.end); + } + else { + decreaseIndent(); + emitStart(node.body); + write("}"); + emitEnd(node.body); + } + } + scopeEmitEnd(); + if (node.flags & 1 /* Export */) { + writeLine(); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emit(node.name); + emitEnd(node); + write(";"); + } + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + function findInitialSuperCall(ctor) { + if (ctor.body) { + var statement = ctor.body.statements[0]; + if (statement && statement.kind === 173 /* ExpressionStatement */) { + var expr = statement.expression; + if (expr && expr.kind === 151 /* CallExpression */) { + var func = expr.expression; + if (func && func.kind === 90 /* SuperKeyword */) { + return statement; + } + } + } + } + } + function emitParameterPropertyAssignments(node) { + ts.forEach(node.parameters, function (param) { + if (param.flags & 112 /* AccessibilityModifier */) { + writeLine(); + emitStart(param); + emitStart(param.name); + write("this."); + emitNode(param.name); + emitEnd(param.name); + write(" = "); + emit(param.name); + write(";"); + emitEnd(param); + } + }); + } + function emitMemberAccessForPropertyName(memberName) { + if (memberName.kind === 8 /* StringLiteral */ || memberName.kind === 7 /* NumericLiteral */) { + write("["); + emitNode(memberName); + write("]"); + } + else if (memberName.kind === 122 /* ComputedPropertyName */) { + emitComputedPropertyName(memberName); + } + else { + write("."); + emitNode(memberName); + } + } + function emitMemberAssignments(node, staticFlag) { + ts.forEach(node.members, function (member) { + if (member.kind === 126 /* PropertyDeclaration */ && (member.flags & 128 /* Static */) === staticFlag && member.initializer) { + writeLine(); + emitLeadingComments(member); + emitStart(member); + emitStart(member.name); + if (staticFlag) { + emitNode(node.name); + } + else { + write("this"); + } + emitMemberAccessForPropertyName(member.name); + emitEnd(member.name); + write(" = "); + emit(member.initializer); + write(";"); + emitEnd(member); + emitTrailingComments(member); + } + }); + } + function emitMemberFunctions(node) { + ts.forEach(node.members, function (member) { + if (member.kind === 128 /* MethodDeclaration */ || node.kind === 127 /* MethodSignature */) { + if (!member.body) { + return emitPinnedOrTripleSlashComments(member); + } + writeLine(); + emitLeadingComments(member); + emitStart(member); + emitStart(member.name); + emitNode(node.name); + if (!(member.flags & 128 /* Static */)) { + write(".prototype"); + } + emitMemberAccessForPropertyName(member.name); + emitEnd(member.name); + write(" = "); + emitStart(member); + emitFunctionDeclaration(member); + emitEnd(member); + emitEnd(member); + write(";"); + emitTrailingComments(member); + } + else if (member.kind === 130 /* GetAccessor */ || member.kind === 131 /* SetAccessor */) { + var accessors = getAllAccessorDeclarations(node, member); + if (member === accessors.firstAccessor) { + writeLine(); + emitStart(member); + write("Object.defineProperty("); + emitStart(member.name); + emitNode(node.name); + if (!(member.flags & 128 /* Static */)) { + write(".prototype"); + } + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + write(", {"); + increaseIndent(); + if (accessors.getAccessor) { + writeLine(); + emitLeadingComments(accessors.getAccessor); + write("get: "); + emitStart(accessors.getAccessor); + write("function "); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + write(","); + } + if (accessors.setAccessor) { + writeLine(); + emitLeadingComments(accessors.setAccessor); + write("set: "); + emitStart(accessors.setAccessor); + write("function "); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor); + write(","); + } + writeLine(); + write("enumerable: true,"); + writeLine(); + write("configurable: true"); + decreaseIndent(); + writeLine(); + write("});"); + emitEnd(member); + } + } + }); + } + function emitClassDeclaration(node) { + emitLeadingComments(node); + write("var "); + emit(node.name); + write(" = (function ("); + var baseTypeNode = ts.getClassBaseTypeNode(node); + if (baseTypeNode) { + write("_super"); + } + write(") {"); + increaseIndent(); + scopeEmitStart(node); + if (baseTypeNode) { + writeLine(); + emitStart(baseTypeNode); + write("__extends("); + emit(node.name); + write(", _super);"); + emitEnd(baseTypeNode); + } + writeLine(); + emitConstructorOfClass(); + emitMemberFunctions(node); + emitMemberAssignments(node, 128 /* Static */); + writeLine(); + function emitClassReturnStatement() { + write("return "); + emitNode(node.name); + } + emitToken(15 /* CloseBraceToken */, node.members.end, emitClassReturnStatement); + write(";"); + decreaseIndent(); + writeLine(); + emitToken(15 /* CloseBraceToken */, node.members.end); + scopeEmitEnd(); + emitStart(node); + write(")("); + if (baseTypeNode) { + emit(baseTypeNode.typeName); + } + write(");"); + emitEnd(node); + if (node.flags & 1 /* Export */) { + writeLine(); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emit(node.name); + emitEnd(node); + write(";"); + } + emitTrailingComments(node); + function emitConstructorOfClass() { + var saveTempCount = tempCount; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; + ts.forEach(node.members, function (member) { + if (member.kind === 129 /* Constructor */ && !member.body) { + emitPinnedOrTripleSlashComments(member); + } + }); + var ctor = getFirstConstructorWithBody(node); + if (ctor) { + emitLeadingComments(ctor); + } + emitStart(ctor || node); + write("function "); + emit(node.name); + emitSignatureParameters(ctor); + write(" {"); + scopeEmitStart(node, "constructor"); + increaseIndent(); + if (ctor) { + emitDetachedComments(ctor.body.statements); + } + emitCaptureThisForNodeIfNecessary(node); + if (ctor) { + emitDefaultValueAssignments(ctor); + emitRestParameter(ctor); + if (baseTypeNode) { + var superCall = findInitialSuperCall(ctor); + if (superCall) { + writeLine(); + emit(superCall); + } + } + emitParameterPropertyAssignments(ctor); + } + else { + if (baseTypeNode) { + writeLine(); + emitStart(baseTypeNode); + write("_super.apply(this, arguments);"); + emitEnd(baseTypeNode); + } + } + emitMemberAssignments(node, 0); + if (ctor) { + var statements = ctor.body.statements; + if (superCall) + statements = statements.slice(1); + emitLines(statements); + } + emitTempDeclarations(true); + writeLine(); + if (ctor) { + emitLeadingCommentsOfPosition(ctor.body.statements.end); + } + decreaseIndent(); + emitToken(15 /* CloseBraceToken */, ctor ? ctor.body.statements.end : node.members.end); + scopeEmitEnd(); + emitEnd(ctor || node); + if (ctor) { + emitTrailingComments(ctor); + } + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + } + function emitInterfaceDeclaration(node) { + emitPinnedOrTripleSlashComments(node); + } + function emitEnumDeclaration(node) { + var isConstEnum = ts.isConst(node); + if (isConstEnum && !compilerOptions.preserveConstEnums) { + return; + } + emitLeadingComments(node); + if (!(node.flags & 1 /* Export */)) { + emitStart(node); + write("var "); + emit(node.name); + emitEnd(node); + write(";"); + } + writeLine(); + emitStart(node); + write("(function ("); + emitStart(node.name); + write(resolver.getLocalNameOfContainer(node)); + emitEnd(node.name); + write(") {"); + increaseIndent(); + scopeEmitStart(node); + emitEnumMemberDeclarations(isConstEnum); + decreaseIndent(); + writeLine(); + emitToken(15 /* CloseBraceToken */, node.members.end); + scopeEmitEnd(); + write(")("); + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + if (node.flags & 1 /* Export */) { + writeLine(); + emitStart(node); + write("var "); + emit(node.name); + write(" = "); + emitModuleMemberName(node); + emitEnd(node); + write(";"); + } + emitTrailingComments(node); + function emitEnumMemberDeclarations(isConstEnum) { + ts.forEach(node.members, function (member) { + writeLine(); + emitLeadingComments(member); + emitStart(member); + write(resolver.getLocalNameOfContainer(node)); + write("["); + write(resolver.getLocalNameOfContainer(node)); + write("["); + emitExpressionForPropertyName(member.name); + write("] = "); + if (member.initializer && !isConstEnum) { + emit(member.initializer); + } + else { + write(resolver.getEnumMemberValue(member).toString()); + } + write("] = "); + emitExpressionForPropertyName(member.name); + emitEnd(member); + write(";"); + emitTrailingComments(member); + }); + } + } + function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { + if (moduleDeclaration.body.kind === 195 /* ModuleDeclaration */) { + var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); + return recursiveInnerModule || moduleDeclaration.body; + } + } + function emitModuleDeclaration(node) { + var shouldEmit = ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums); + if (!shouldEmit) { + return emitPinnedOrTripleSlashComments(node); + } + emitLeadingComments(node); + emitStart(node); + write("var "); + emit(node.name); + write(";"); + emitEnd(node); + writeLine(); + emitStart(node); + write("(function ("); + emitStart(node.name); + write(resolver.getLocalNameOfContainer(node)); + emitEnd(node.name); + write(") "); + if (node.body.kind === 196 /* ModuleBlock */) { + var saveTempCount = tempCount; + var saveTempVariables = tempVariables; + tempCount = 0; + tempVariables = undefined; + emit(node.body); + tempCount = saveTempCount; + tempVariables = saveTempVariables; + } + else { + write("{"); + increaseIndent(); + scopeEmitStart(node); + emitCaptureThisForNodeIfNecessary(node); + writeLine(); + emit(node.body); + decreaseIndent(); + writeLine(); + var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; + emitToken(15 /* CloseBraceToken */, moduleBlock.statements.end); + scopeEmitEnd(); + } + write(")("); + if (node.flags & 1 /* Export */) { + emit(node.name); + write(" = "); + } + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + emitTrailingComments(node); + } + function emitImportDeclaration(node) { + var emitImportDeclaration = resolver.isReferencedImportDeclaration(node); + if (!emitImportDeclaration) { + emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportWithEntityName(node); + } + if (emitImportDeclaration) { + if (ts.isExternalModuleImportDeclaration(node) && node.parent.kind === 207 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { + if (node.flags & 1 /* Export */) { + writeLine(); + emitLeadingComments(node); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emit(node.name); + write(";"); + emitEnd(node); + emitTrailingComments(node); + } + } + else { + writeLine(); + emitLeadingComments(node); + emitStart(node); + if (!(node.flags & 1 /* Export */)) + write("var "); + emitModuleMemberName(node); + write(" = "); + if (ts.isInternalModuleImportDeclaration(node)) { + emit(node.moduleReference); + } + else { + var literal = ts.getExternalModuleImportDeclarationExpression(node); + write("require("); + emitStart(literal); + emitLiteral(literal); + emitEnd(literal); + emitToken(17 /* CloseParenToken */, literal.end); + } + write(";"); + emitEnd(node); + emitTrailingComments(node); + } + } + } + function getExternalImportDeclarations(node) { + var result = []; + ts.forEach(node.statements, function (statement) { + if (ts.isExternalModuleImportDeclaration(statement) && resolver.isReferencedImportDeclaration(statement)) { + result.push(statement); + } + }); + return result; + } + function getFirstExportAssignment(sourceFile) { + return ts.forEach(sourceFile.statements, function (node) { + if (node.kind === 198 /* ExportAssignment */) { + return node; + } + }); + } + function emitAMDModule(node, startIndex) { + var imports = getExternalImportDeclarations(node); + writeLine(); + write("define("); + if (node.amdModuleName) { + write("\"" + node.amdModuleName + "\", "); + } + write("[\"require\", \"exports\""); + ts.forEach(imports, function (imp) { + write(", "); + emitLiteral(ts.getExternalModuleImportDeclarationExpression(imp)); + }); + ts.forEach(node.amdDependencies, function (amdDependency) { + var text = "\"" + amdDependency + "\""; + write(", "); + write(text); + }); + write("], function (require, exports"); + ts.forEach(imports, function (imp) { + write(", "); + emit(imp.name); + }); + write(") {"); + increaseIndent(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + var exportName = resolver.getExportAssignmentName(node); + if (exportName) { + writeLine(); + var exportAssignment = getFirstExportAssignment(node); + emitStart(exportAssignment); + write("return "); + emitStart(exportAssignment.exportName); + write(exportName); + emitEnd(exportAssignment.exportName); + write(";"); + emitEnd(exportAssignment); + } + decreaseIndent(); + writeLine(); + write("});"); + } + function emitCommonJSModule(node, startIndex) { + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + var exportName = resolver.getExportAssignmentName(node); + if (exportName) { + writeLine(); + var exportAssignment = getFirstExportAssignment(node); + emitStart(exportAssignment); + write("module.exports = "); + emitStart(exportAssignment.exportName); + write(exportName); + emitEnd(exportAssignment.exportName); + write(";"); + emitEnd(exportAssignment); + } + } + function emitDirectivePrologues(statements, startWithNewLine) { + for (var i = 0; i < statements.length; ++i) { + if (ts.isPrologueDirective(statements[i])) { + if (startWithNewLine || i > 0) { + writeLine(); + } + emit(statements[i]); + } + else { + return i; + } + } + return statements.length; + } + function emitSourceFile(node) { + currentSourceFile = node; + writeLine(); + emitDetachedComments(node); + var startIndex = emitDirectivePrologues(node.statements, false); + if (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8 /* EmitExtends */) { + writeLine(); + write("var __extends = this.__extends || function (d, b) {"); + increaseIndent(); + writeLine(); + write("for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];"); + writeLine(); + write("function __() { this.constructor = d; }"); + writeLine(); + write("__.prototype = b.prototype;"); + writeLine(); + write("d.prototype = new __();"); + decreaseIndent(); + writeLine(); + write("};"); + extendsEmitted = true; + } + if (ts.isExternalModule(node)) { + if (compilerOptions.module === 2 /* AMD */) { + emitAMDModule(node, startIndex); + } + else { + emitCommonJSModule(node, startIndex); + } + } + else { + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + } + emitLeadingComments(node.endOfFileToken); + } + function emitNode(node) { + if (!node) { + return; + } + if (node.flags & 2 /* Ambient */) { + return emitPinnedOrTripleSlashComments(node); + } + switch (node.kind) { + case 64 /* Identifier */: + return emitIdentifier(node); + case 124 /* Parameter */: + return emitParameter(node); + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + return emitMethod(node); + case 130 /* GetAccessor */: + case 131 /* SetAccessor */: + return emitAccessor(node); + case 92 /* ThisKeyword */: + return emitThis(node); + case 90 /* SuperKeyword */: + return emitSuper(node); + case 88 /* NullKeyword */: + return write("null"); + case 94 /* TrueKeyword */: + return write("true"); + case 79 /* FalseKeyword */: + return write("false"); + case 7 /* NumericLiteral */: + case 8 /* StringLiteral */: + case 9 /* RegularExpressionLiteral */: + case 10 /* NoSubstitutionTemplateLiteral */: + case 11 /* TemplateHead */: + case 12 /* TemplateMiddle */: + case 13 /* TemplateTail */: + return emitLiteral(node); + case 165 /* TemplateExpression */: + return emitTemplateExpression(node); + case 169 /* TemplateSpan */: + return emitTemplateSpan(node); + case 121 /* QualifiedName */: + return emitQualifiedName(node); + case 144 /* ObjectBindingPattern */: + return emitObjectBindingPattern(node); + case 145 /* ArrayBindingPattern */: + return emitArrayBindingPattern(node); + case 146 /* BindingElement */: + return emitBindingElement(node); + case 147 /* ArrayLiteralExpression */: + return emitArrayLiteral(node); + case 148 /* ObjectLiteralExpression */: + return emitObjectLiteral(node); + case 204 /* PropertyAssignment */: + return emitPropertyAssignment(node); + case 205 /* ShorthandPropertyAssignment */: + return emitShorthandPropertyAssignment(node); + case 122 /* ComputedPropertyName */: + return emitComputedPropertyName(node); + case 149 /* PropertyAccessExpression */: + return emitPropertyAccess(node); + case 150 /* ElementAccessExpression */: + return emitIndexedAccess(node); + case 151 /* CallExpression */: + return emitCallExpression(node); + case 152 /* NewExpression */: + return emitNewExpression(node); + case 153 /* TaggedTemplateExpression */: + return emitTaggedTemplateExpression(node); + case 154 /* TypeAssertionExpression */: + return emit(node.expression); + case 155 /* ParenthesizedExpression */: + return emitParenExpression(node); + case 190 /* FunctionDeclaration */: + case 156 /* FunctionExpression */: + case 157 /* ArrowFunction */: + return emitFunctionDeclaration(node); + case 158 /* DeleteExpression */: + return emitDeleteExpression(node); + case 159 /* TypeOfExpression */: + return emitTypeOfExpression(node); + case 160 /* VoidExpression */: + return emitVoidExpression(node); + case 161 /* PrefixUnaryExpression */: + return emitPrefixUnaryExpression(node); + case 162 /* PostfixUnaryExpression */: + return emitPostfixUnaryExpression(node); + case 163 /* BinaryExpression */: + return emitBinaryExpression(node); + case 164 /* ConditionalExpression */: + return emitConditionalExpression(node); + case 167 /* SpreadElementExpression */: + return emitSpreadElementExpression(node); + case 168 /* OmittedExpression */: + return; + case 170 /* Block */: + case 196 /* ModuleBlock */: + return emitBlock(node); + case 171 /* VariableStatement */: + return emitVariableStatement(node); + case 172 /* EmptyStatement */: + return write(";"); + case 173 /* ExpressionStatement */: + return emitExpressionStatement(node); + case 174 /* IfStatement */: + return emitIfStatement(node); + case 175 /* DoStatement */: + return emitDoStatement(node); + case 176 /* WhileStatement */: + return emitWhileStatement(node); + case 177 /* ForStatement */: + return emitForStatement(node); + case 178 /* ForInStatement */: + return emitForInStatement(node); + case 179 /* ContinueStatement */: + case 180 /* BreakStatement */: + return emitBreakOrContinueStatement(node); + case 181 /* ReturnStatement */: + return emitReturnStatement(node); + case 182 /* WithStatement */: + return emitWithStatement(node); + case 183 /* SwitchStatement */: + return emitSwitchStatement(node); + case 200 /* CaseClause */: + case 201 /* DefaultClause */: + return emitCaseOrDefaultClause(node); + case 184 /* LabeledStatement */: + return emitLabelledStatement(node); + case 185 /* ThrowStatement */: + return emitThrowStatement(node); + case 186 /* TryStatement */: + return emitTryStatement(node); + case 203 /* CatchClause */: + return emitCatchClause(node); + case 187 /* DebuggerStatement */: + return emitDebuggerStatement(node); + case 188 /* VariableDeclaration */: + return emitVariableDeclaration(node); + case 191 /* ClassDeclaration */: + return emitClassDeclaration(node); + case 192 /* InterfaceDeclaration */: + return emitInterfaceDeclaration(node); + case 194 /* EnumDeclaration */: + return emitEnumDeclaration(node); + case 195 /* ModuleDeclaration */: + return emitModuleDeclaration(node); + case 197 /* ImportDeclaration */: + return emitImportDeclaration(node); + case 207 /* SourceFile */: + return emitSourceFile(node); + } + } + function hasDetachedComments(pos) { + return detachedCommentsInfo !== undefined && detachedCommentsInfo[detachedCommentsInfo.length - 1].nodePos === pos; + } + function getLeadingCommentsWithoutDetachedComments() { + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); + if (detachedCommentsInfo.length - 1) { + detachedCommentsInfo.pop(); + } + else { + detachedCommentsInfo = undefined; + } + return leadingComments; + } + function getLeadingCommentsToEmit(node) { + if (node.parent.kind === 207 /* SourceFile */ || node.pos !== node.parent.pos) { + var leadingComments; + if (hasDetachedComments(node.pos)) { + leadingComments = getLeadingCommentsWithoutDetachedComments(); + } + else { + leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); + } + return leadingComments; + } + } + function emitLeadingDeclarationComments(node) { + var leadingComments = getLeadingCommentsToEmit(node); + emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); + } + function emitTrailingDeclarationComments(node) { + if (node.parent.kind === 207 /* SourceFile */ || node.end !== node.parent.end) { + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); + emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); + } + } + function emitLeadingCommentsOfLocalPosition(pos) { + var leadingComments; + if (hasDetachedComments(pos)) { + leadingComments = getLeadingCommentsWithoutDetachedComments(); + } + else { + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); + } + emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); + emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); + } + function emitDetachedCommentsAtPosition(node) { + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); + if (leadingComments) { + var detachedComments = []; + var lastComment; + ts.forEach(leadingComments, function (comment) { + if (lastComment) { + var lastCommentLine = getLineOfLocalPosition(currentSourceFile, lastComment.end); + var commentLine = getLineOfLocalPosition(currentSourceFile, comment.pos); + if (commentLine >= lastCommentLine + 2) { + return detachedComments; + } + } + detachedComments.push(comment); + lastComment = comment; + }); + if (detachedComments.length) { + var lastCommentLine = getLineOfLocalPosition(currentSourceFile, detachedComments[detachedComments.length - 1].end); + var astLine = getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); + if (astLine >= lastCommentLine + 2) { + emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment); + var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: detachedComments[detachedComments.length - 1].end }; + if (detachedCommentsInfo) { + detachedCommentsInfo.push(currentDetachedCommentInfo); + } + else { + detachedCommentsInfo = [currentDetachedCommentInfo]; + } + } + } + } + } + function emitPinnedOrTripleSlashCommentsOfNode(node) { + var pinnedComments = ts.filter(getLeadingCommentsToEmit(node), isPinnedOrTripleSlashComment); + function isPinnedOrTripleSlashComment(comment) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) { + return currentSourceFile.text.charCodeAt(comment.pos + 2) === 33 /* exclamation */; + } + else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 /* slash */ && comment.pos + 2 < comment.end && currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 /* slash */ && currentSourceFile.text.substring(comment.pos, comment.end).match(ts.fullTripleSlashReferencePathRegEx)) { + return true; + } + } + emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, pinnedComments); + emitComments(currentSourceFile, writer, pinnedComments, true, newLine, writeComment); + } + if (compilerOptions.sourceMap) { + initializeEmitterWithSourceMaps(); + } + if (root) { + emit(root); + } + else { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + emit(sourceFile); + } + }); + } + writeLine(); + writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); + } + function writeDeclarationFile(jsFilePath, sourceFile) { + var emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile); + if (!emitDeclarationResult.reportedDeclarationError) { + var declarationOutput = emitDeclarationResult.referencePathsOutput; + var appliedSyncOutputPos = 0; + ts.forEach(emitDeclarationResult.aliasDeclarationEmitInfo, function (aliasEmitInfo) { + if (aliasEmitInfo.asynchronousOutput) { + declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); + declarationOutput += aliasEmitInfo.asynchronousOutput; + appliedSyncOutputPos = aliasEmitInfo.outputPos; + } + }); + declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos); + writeFile(host, diagnostics, ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); + } + } + var hasSemanticErrors = false; + var isEmitBlocked = false; + if (targetSourceFile === undefined) { + hasSemanticErrors = resolver.hasSemanticErrors(); + isEmitBlocked = host.isEmitBlocked(); + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (shouldEmitToOwnFile(sourceFile, compilerOptions)) { + var jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, ".js"); + emitFile(jsFilePath, sourceFile); + } + }); + if (compilerOptions.out) { + emitFile(compilerOptions.out); + } + } + else { + if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { + hasSemanticErrors = resolver.hasSemanticErrors(targetSourceFile); + isEmitBlocked = host.isEmitBlocked(targetSourceFile); + var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); + emitFile(jsFilePath, targetSourceFile); + } + else if (!ts.isDeclarationFile(targetSourceFile) && compilerOptions.out) { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (!shouldEmitToOwnFile(sourceFile, compilerOptions)) { + hasSemanticErrors = hasSemanticErrors || resolver.hasSemanticErrors(sourceFile); + isEmitBlocked = isEmitBlocked || host.isEmitBlocked(sourceFile); + } + }); + emitFile(compilerOptions.out); + } + } + function emitFile(jsFilePath, sourceFile) { + if (!isEmitBlocked) { + emitJavaScript(jsFilePath, sourceFile); + if (!hasSemanticErrors && compilerOptions.declaration) { + writeDeclarationFile(jsFilePath, sourceFile); + } + } + } + diagnostics.sort(ts.compareDiagnostics); + diagnostics = ts.deduplicateSortedDiagnostics(diagnostics); + var hasEmitterError = ts.forEach(diagnostics, function (diagnostic) { return diagnostic.category === 1 /* Error */; }); + var emitResultStatus; + if (isEmitBlocked) { + emitResultStatus = 1 /* AllOutputGenerationSkipped */; + } + else if (hasEmitterError) { + emitResultStatus = 4 /* EmitErrorsEncountered */; + } + else if (hasSemanticErrors && compilerOptions.declaration) { + emitResultStatus = 3 /* DeclarationGenerationSkipped */; + } + else if (hasSemanticErrors && !compilerOptions.declaration) { + emitResultStatus = 2 /* JSGeneratedWithSemanticErrors */; + } + else { + emitResultStatus = 0 /* Succeeded */; + } + return { + emitResultStatus: emitResultStatus, + diagnostics: diagnostics, + sourceMaps: sourceMapDataList + }; + } + ts.emitFiles = emitFiles; +})(ts || (ts = {})); +var ts; +(function (ts) { + function createCompilerHost(options) { + var currentDirectory; + var existingDirectories = {}; + function getCanonicalFileName(fileName) { + return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); + } + var unsupportedFileEncodingErrorCode = -2147024809; + function getSourceFile(filename, languageVersion, onError) { + try { + var text = ts.sys.readFile(filename, options.charset); + } + catch (e) { + if (onError) { + onError(e.number === unsupportedFileEncodingErrorCode ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText : e.message); + } + text = ""; + } + return text !== undefined ? ts.createSourceFile(filename, text, languageVersion) : undefined; + } + function writeFile(fileName, data, writeByteOrderMark, onError) { + function directoryExists(directoryPath) { + if (ts.hasProperty(existingDirectories, directoryPath)) { + return true; + } + if (ts.sys.directoryExists(directoryPath)) { + existingDirectories[directoryPath] = true; + return true; + } + return false; + } + function ensureDirectoriesExist(directoryPath) { + if (directoryPath.length > ts.getRootLength(directoryPath) && !directoryExists(directoryPath)) { + var parentDirectory = ts.getDirectoryPath(directoryPath); + ensureDirectoriesExist(parentDirectory); + ts.sys.createDirectory(directoryPath); + } + } + try { + ensureDirectoriesExist(ts.getDirectoryPath(ts.normalizePath(fileName))); + ts.sys.writeFile(fileName, data, writeByteOrderMark); + } + catch (e) { + if (onError) { + onError(e.message); + } + } + } + return { + getSourceFile: getSourceFile, + getDefaultLibFilename: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"); }, + writeFile: writeFile, + getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, + useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, + getCanonicalFileName: getCanonicalFileName, + getNewLine: function () { return ts.sys.newLine; } + }; + } + ts.createCompilerHost = createCompilerHost; + function createProgram(rootNames, options, host) { + var program; + var files = []; + var filesByName = {}; + var errors = []; + var seenNoDefaultLib = options.noLib; + var commonSourceDirectory; + ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); + if (!seenNoDefaultLib) { + processRootFile(host.getDefaultLibFilename(options), true); + } + verifyCompilerOptions(); + errors.sort(ts.compareDiagnostics); + var diagnosticsProducingTypeChecker; + var noDiagnosticsTypeChecker; + var emitHost; + program = { + getSourceFile: getSourceFile, + getSourceFiles: function () { return files; }, + getCompilerOptions: function () { return options; }, + getCompilerHost: function () { return host; }, + getDiagnostics: getDiagnostics, + getGlobalDiagnostics: getGlobalDiagnostics, + getDeclarationDiagnostics: getDeclarationDiagnostics, + getTypeChecker: getTypeChecker, + getCommonSourceDirectory: function () { return commonSourceDirectory; }, + emitFiles: invokeEmitter, + isEmitBlocked: isEmitBlocked, + getCurrentDirectory: host.getCurrentDirectory + }; + return program; + function getEmitHost() { + return emitHost || (emitHost = ts.createEmitHostFromProgram(program)); + } + function hasEarlyErrors(sourceFile) { + return ts.forEach(getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile), function (d) { return d.isEarly; }); + } + function isEmitBlocked(sourceFile) { + return getDiagnostics(sourceFile).length !== 0 || hasEarlyErrors(sourceFile) || (options.noEmitOnError && getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile).length !== 0); + } + function getDiagnosticsProducingTypeChecker() { + return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, true)); + } + function getTypeChecker(produceDiagnostics) { + if (produceDiagnostics) { + return getDiagnosticsProducingTypeChecker(); + } + else { + return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = ts.createTypeChecker(program, produceDiagnostics)); + } + } + function getDeclarationDiagnostics(targetSourceFile) { + var typeChecker = getDiagnosticsProducingTypeChecker(); + typeChecker.getDiagnostics(targetSourceFile); + var resolver = typeChecker.getEmitResolver(); + return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile); + } + function invokeEmitter(targetSourceFile) { + var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(); + return ts.emitFiles(resolver, getEmitHost(), targetSourceFile); + } + function getSourceFile(filename) { + filename = host.getCanonicalFileName(filename); + return ts.hasProperty(filesByName, filename) ? filesByName[filename] : undefined; + } + function getDiagnostics(sourceFile) { + return sourceFile ? ts.filter(errors, function (e) { return e.file === sourceFile; }) : errors; + } + function getGlobalDiagnostics() { + return ts.filter(errors, function (e) { return !e.file; }); + } + function hasExtension(filename) { + return ts.getBaseFilename(filename).indexOf(".") >= 0; + } + function processRootFile(filename, isDefaultLib) { + processSourceFile(ts.normalizePath(filename), isDefaultLib); + } + function processSourceFile(filename, isDefaultLib, refFile, refPos, refEnd) { + if (refEnd !== undefined && refPos !== undefined) { + var start = refPos; + var length = refEnd - refPos; + } + var diagnostic; + if (hasExtension(filename)) { + if (!options.allowNonTsExtensions && !ts.fileExtensionIs(filename, ".ts")) { + diagnostic = ts.Diagnostics.File_0_must_have_extension_ts_or_d_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 (options.allowNonTsExtensions && !findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) { + diagnostic = ts.Diagnostics.File_0_not_found; + } + else if (!findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) { + diagnostic = ts.Diagnostics.File_0_not_found; + filename += ".ts"; + } + } + if (diagnostic) { + if (refFile) { + errors.push(ts.createFileDiagnostic(refFile, start, length, diagnostic, filename)); + } + else { + errors.push(ts.createCompilerDiagnostic(diagnostic, filename)); + } + } + } + function findSourceFile(filename, isDefaultLib, refFile, refStart, refLength) { + var canonicalName = host.getCanonicalFileName(filename); + if (ts.hasProperty(filesByName, canonicalName)) { + return getSourceFileFromCache(filename, canonicalName, false); + } + else { + var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(filename, host.getCurrentDirectory()); + var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); + if (ts.hasProperty(filesByName, canonicalAbsolutePath)) { + return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); + } + var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, function (hostErrorMessage) { + if (refFile) { + errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); + } + else { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); + } + }); + if (file) { + seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; + filesByName[canonicalAbsolutePath] = file; + if (!options.noResolve) { + var basePath = ts.getDirectoryPath(filename); + processReferencedFiles(file, basePath); + processImportedModules(file, basePath); + } + if (isDefaultLib) { + files.unshift(file); + } + else { + files.push(file); + } + ts.forEach(file.getSyntacticDiagnostics(), function (e) { + errors.push(e); + }); + } + } + return file; + function getSourceFileFromCache(filename, canonicalName, useAbsolutePath) { + var file = filesByName[canonicalName]; + if (file && host.useCaseSensitiveFileNames()) { + var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.filename, host.getCurrentDirectory()) : file.filename; + if (canonicalName !== sourceFileName) { + errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, sourceFileName)); + } + } + return file; + } + } + function processReferencedFiles(file, basePath) { + ts.forEach(file.referencedFiles, function (ref) { + 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 (ts.isExternalModuleImportDeclaration(node) && ts.getExternalModuleImportDeclarationExpression(node).kind === 8 /* StringLiteral */) { + var nameLiteral = ts.getExternalModuleImportDeclarationExpression(node); + var moduleName = nameLiteral.text; + if (moduleName) { + var searchPath = basePath; + while (true) { + var searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleName)); + if (findModuleSourceFile(searchName + ".ts", nameLiteral) || findModuleSourceFile(searchName + ".d.ts", nameLiteral)) { + break; + } + var parentPath = ts.getDirectoryPath(searchPath); + if (parentPath === searchPath) { + break; + } + searchPath = parentPath; + } + } + } + else if (node.kind === 195 /* ModuleDeclaration */ && node.name.kind === 8 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || ts.isDeclarationFile(file))) { + ts.forEachChild(node.body, function (node) { + if (ts.isExternalModuleImportDeclaration(node) && ts.getExternalModuleImportDeclarationExpression(node).kind === 8 /* StringLiteral */) { + var nameLiteral = ts.getExternalModuleImportDeclarationExpression(node); + var moduleName = nameLiteral.text; + if (moduleName) { + var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName)); + var tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral); + if (!tsFile) { + findModuleSourceFile(searchName + ".d.ts", nameLiteral); + } + } + } + }); + } + }); + function findModuleSourceFile(filename, nameLiteral) { + return findSourceFile(filename, false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos); + } + } + function verifyCompilerOptions() { + if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { + if (options.mapRoot) { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option)); + } + if (options.sourceRoot) { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option)); + } + return; + } + var firstExternalModule = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); + if (firstExternalModule && options.module === 0 /* None */) { + var externalModuleErrorSpan = ts.getErrorSpanForNode(firstExternalModule.externalModuleIndicator); + var errorStart = ts.skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos); + var errorLength = externalModuleErrorSpan.end - errorStart; + errors.push(ts.createFileDiagnostic(firstExternalModule, errorStart, errorLength, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + } + if (options.outDir || options.sourceRoot || (options.mapRoot && (!options.out || firstExternalModule !== undefined))) { + var commonPathComponents; + ts.forEach(files, function (sourceFile) { + if (!(sourceFile.flags & 1024 /* DeclarationFile */) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { + var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory()); + sourcePathComponents.pop(); + if (commonPathComponents) { + for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) { + if (commonPathComponents[i] !== sourcePathComponents[i]) { + if (i === 0) { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + return; + } + commonPathComponents.length = i; + break; + } + } + if (sourcePathComponents.length < commonPathComponents.length) { + commonPathComponents.length = sourcePathComponents.length; + } + } + else { + commonPathComponents = sourcePathComponents; + } + } + }); + commonSourceDirectory = ts.getNormalizedPathFromPathComponents(commonPathComponents); + if (commonSourceDirectory) { + commonSourceDirectory += ts.directorySeparator; + } + } + if (options.noEmit) { + if (options.out || options.outDir) { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmit_cannot_be_specified_with_option_out_or_outDir)); + } + if (options.declaration) { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration)); + } + } + } + } + ts.createProgram = createProgram; +})(ts || (ts = {})); +var ts; (function (ts) { ts.optionDeclarations = [ { @@ -18380,6 +19282,11 @@ var ts; paramType: ts.Diagnostics.KIND, error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd }, + { + name: "noEmit", + type: "boolean", + description: ts.Diagnostics.Do_not_emit_outputs + }, { name: "noEmitOnError", type: "boolean", @@ -18388,7 +19295,7 @@ var ts; { name: "noImplicitAny", type: "boolean", - description: ts.Diagnostics.Warn_on_expressions_and_declarations_with_an_implied_any_type + description: ts.Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type }, { name: "noLib", @@ -18774,12 +19681,15 @@ var ts; var checker = program.getTypeChecker(true); var checkStart = new Date().getTime(); errors = checker.getDiagnostics(); - if (checker.isEmitBlocked()) { + if (program.isEmitBlocked()) { exitStatus = 1 /* AllOutputGenerationSkipped */; } + else if (compilerOptions.noEmit) { + exitStatus = 0 /* Succeeded */; + } else { var emitStart = new Date().getTime(); - var emitOutput = checker.emitFiles(); + var emitOutput = program.emitFiles(); var emitErrors = emitOutput.diagnostics; exitStatus = emitOutput.emitResultStatus; var reportStart = new Date().getTime(); diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 0cb7ac8775c..592b73ba8d9 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -189,29 +189,29 @@ declare module "typescript" { ConditionalExpression = 164, TemplateExpression = 165, YieldExpression = 166, - OmittedExpression = 167, - TemplateSpan = 168, - Block = 169, - VariableStatement = 170, - EmptyStatement = 171, - ExpressionStatement = 172, - IfStatement = 173, - DoStatement = 174, - WhileStatement = 175, - ForStatement = 176, - ForInStatement = 177, - ContinueStatement = 178, - BreakStatement = 179, - ReturnStatement = 180, - WithStatement = 181, - SwitchStatement = 182, - LabeledStatement = 183, - ThrowStatement = 184, - TryStatement = 185, - TryBlock = 186, - FinallyBlock = 187, - DebuggerStatement = 188, - VariableDeclaration = 189, + SpreadElementExpression = 167, + OmittedExpression = 168, + TemplateSpan = 169, + Block = 170, + VariableStatement = 171, + EmptyStatement = 172, + ExpressionStatement = 173, + IfStatement = 174, + DoStatement = 175, + WhileStatement = 176, + ForStatement = 177, + ForInStatement = 178, + ContinueStatement = 179, + BreakStatement = 180, + ReturnStatement = 181, + WithStatement = 182, + SwitchStatement = 183, + LabeledStatement = 184, + ThrowStatement = 185, + TryStatement = 186, + DebuggerStatement = 187, + VariableDeclaration = 188, + VariableDeclarationList = 189, FunctionDeclaration = 190, ClassDeclaration = 191, InterfaceDeclaration = 192, @@ -230,9 +230,8 @@ declare module "typescript" { ShorthandPropertyAssignment = 205, EnumMember = 206, SourceFile = 207, - Program = 208, - SyntaxList = 209, - Count = 210, + SyntaxList = 208, + Count = 209, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, @@ -253,8 +252,6 @@ declare module "typescript" { LastLiteralToken = 10, FirstTemplateToken = 10, LastTemplateToken = 13, - FirstOperator = 22, - LastOperator = 63, FirstBinaryOperator = 24, LastBinaryOperator = 63, FirstNode = 121, @@ -331,10 +328,14 @@ declare module "typescript" { type?: TypeNode; } interface VariableDeclaration extends Declaration { + parent?: VariableDeclarationList; name: Identifier | BindingPattern; type?: TypeNode; initializer?: Expression; } + interface VariableDeclarationList extends Node { + declarations: NodeArray; + } interface ParameterDeclaration extends Declaration { dotDotDotToken?: Node; name: Identifier | BindingPattern; @@ -514,6 +515,9 @@ declare module "typescript" { interface ArrayLiteralExpression extends PrimaryExpression { elements: NodeArray; } + interface SpreadElementExpression extends Expression { + expression: Expression; + } interface ObjectLiteralExpression extends PrimaryExpression, Declaration { properties: NodeArray; } @@ -548,7 +552,7 @@ declare module "typescript" { statements: NodeArray; } interface VariableStatement extends Statement { - declarations: NodeArray; + declarationList: VariableDeclarationList; } interface ExpressionStatement extends Statement { expression: Expression; @@ -568,14 +572,12 @@ declare module "typescript" { expression: Expression; } interface ForStatement extends IterationStatement { - declarations?: NodeArray; - initializer?: Expression; + initializer?: VariableDeclarationList | Expression; condition?: Expression; iterator?: Expression; } interface ForInStatement extends IterationStatement { - declarations?: NodeArray; - variable?: Expression; + initializer: VariableDeclarationList | Expression; expression: Expression; } interface BreakOrContinueStatement extends Statement { @@ -682,12 +684,12 @@ declare module "typescript" { getLineAndCharacterFromPosition(position: number): LineAndCharacter; getPositionFromLineAndCharacter(line: number, character: number): number; getLineStarts(): number[]; + update(newText: string, textChangeRange: TextChangeRange): SourceFile; amdDependencies: string[]; amdModuleName: string; referencedFiles: FileReference[]; referenceDiagnostics: Diagnostic[]; parseDiagnostics: Diagnostic[]; - grammarDiagnostics: Diagnostic[]; getSyntacticDiagnostics(): Diagnostic[]; semanticDiagnostics: Diagnostic[]; hasNoDefaultLib: boolean; @@ -698,15 +700,21 @@ declare module "typescript" { languageVersion: ScriptTarget; identifiers: Map; } - interface Program { - getSourceFile(filename: string): SourceFile; - getSourceFiles(): SourceFile[]; + interface ScriptReferenceHost { getCompilerOptions(): CompilerOptions; + getSourceFile(filename: string): SourceFile; + getCurrentDirectory(): string; + } + interface Program extends ScriptReferenceHost { + getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getTypeChecker(fullTypeCheckMode: boolean): TypeChecker; + getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getTypeChecker(produceDiagnostics: boolean): TypeChecker; getCommonSourceDirectory(): string; + emitFiles(targetSourceFile?: SourceFile): EmitResult; + isEmitBlocked(sourceFile?: SourceFile): boolean; } interface SourceMapSpan { emittedLine: number; @@ -740,16 +748,20 @@ declare module "typescript" { diagnostics: Diagnostic[]; sourceMaps: SourceMapData[]; } + interface TypeCheckerHost { + getCompilerOptions(): CompilerOptions; + getCompilerHost(): CompilerHost; + getSourceFiles(): SourceFile[]; + getSourceFile(filename: string): SourceFile; + } interface TypeChecker { - getProgram(): Program; + getEmitResolver(): EmitResolver; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; getNodeCount(): number; getIdentifierCount(): number; getSymbolCount(): number; getTypeCount(): number; - emitFiles(targetSourceFile?: SourceFile): EmitResult; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; @@ -773,7 +785,6 @@ declare module "typescript" { isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; isUndefinedSymbol(symbol: Symbol): boolean; isArgumentsSymbol(symbol: Symbol): boolean; - isEmitBlocked(sourceFile?: SourceFile): boolean; getEnumMemberValue(node: EnumMember): number; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean; getAliasedSymbol(symbol: Symbol): Symbol; @@ -833,7 +844,6 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getProgram(): Program; getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; getExpressionNamePrefix(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; @@ -849,7 +859,6 @@ declare module "typescript" { isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number; - isEmitBlocked(sourceFile?: SourceFile): boolean; isUnknownIdentifier(location: Node, name: string): boolean; } const enum SymbolFlags { @@ -1019,8 +1028,6 @@ declare module "typescript" { } interface GenericType extends InterfaceType, TypeReference { instantiations: Map; - openReferenceTargets: GenericType[]; - openReferenceChecks: Map; } interface TupleType extends ObjectType { elementTypes: Type[]; @@ -1119,6 +1126,7 @@ declare module "typescript" { locale?: string; mapRoot?: string; module?: ModuleKind; + noEmit?: boolean; noEmitOnError?: boolean; noErrorTruncation?: boolean; noImplicitAny?: boolean; @@ -1303,13 +1311,18 @@ declare module "typescript" { useCaseSensitiveFileNames(): boolean; getNewLine(): string; } + interface TextSpan { + start: number; + length: number; + } + interface TextChangeRange { + span: TextSpan; + newLength: number; + } } declare module "typescript" { interface ErrorCallback { - (message: DiagnosticMessage): void; - } - interface CommentCallback { - (pos: number, end: number): void; + (message: DiagnosticMessage, length: number): void; } interface Scanner { getStartPos(): number; @@ -1355,17 +1368,19 @@ declare module "typescript" { declare module "typescript" { function getNodeConstructor(kind: SyntaxKind): new () => Node; function createNode(kind: SyntaxKind): Node; - function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodes?: (nodes: Node[]) => T): T; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T; function modifierToFlag(token: SyntaxKind): NodeFlags; function isEvalOrArgumentsIdentifier(node: Node): boolean; function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile; function isLeftHandSideExpression(expr: Expression): boolean; function isAssignmentOperator(token: SyntaxKind): boolean; - function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program; } declare module "typescript" { - function createTypeChecker(program: Program, fullTypeCheck: boolean): TypeChecker; + function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker; +} +declare module "typescript" { + function createCompilerHost(options: CompilerOptions): CompilerHost; + function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program; } declare module "typescript" { var servicesVersion: string; @@ -1412,9 +1427,8 @@ declare module "typescript" { interface SourceFile { isOpen: boolean; version: string; - getScriptSnapshot(): IScriptSnapshot; + scriptSnapshot: IScriptSnapshot; getNamedDeclarations(): Declaration[]; - update(scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TextChangeRange): SourceFile; } /** * Represents an immutable snapshot of a script at a specified time.Once acquired, the @@ -1496,96 +1510,6 @@ declare module "typescript" { getSourceFile(filename: string): SourceFile; dispose(): void; } - class TextSpan { - private _start; - private _length; - /** - * Creates a TextSpan instance beginning with the position Start and having the Length - * specified with length. - */ - constructor(start: number, length: number); - toJSON(key: any): any; - start(): number; - length(): number; - end(): number; - isEmpty(): boolean; - /** - * Determines whether the position lies within the span. Returns true if the position is greater than or equal to Start and strictly less - * than End, otherwise false. - * @param position The position to check. - */ - containsPosition(position: number): boolean; - /** - * Determines whether span falls completely within this span. Returns true if the specified span falls completely within this span, otherwise false. - * @param span The span to check. - */ - containsTextSpan(span: TextSpan): boolean; - /** - * Determines whether the given span overlaps this span. Two spans are considered to overlap - * if they have positions in common and neither is empty. Empty spans do not overlap with any - * other span. Returns true if the spans overlap, false otherwise. - * @param span The span to check. - */ - overlapsWith(span: TextSpan): boolean; - /** - * Returns the overlap with the given span, or undefined if there is no overlap. - * @param span The span to check. - */ - overlap(span: TextSpan): TextSpan; - /** - * Determines whether span intersects this span. Two spans are considered to - * intersect if they have positions in common or the end of one span - * coincides with the start of the other span. Returns true if the spans intersect, false otherwise. - * @param The span to check. - */ - intersectsWithTextSpan(span: TextSpan): boolean; - intersectsWith(start: number, length: number): boolean; - /** - * Determines whether the given position intersects this span. - * A position is considered to intersect if it is between the start and - * end positions (inclusive) of this span. Returns true if the position intersects, false otherwise. - * @param position The position to check. - */ - intersectsWithPosition(position: number): boolean; - /** - * Returns the intersection with the given span, or undefined if there is no intersection. - * @param span The span to check. - */ - intersection(span: TextSpan): TextSpan; - /** - * Creates a new TextSpan from the given start and end positions - * as opposed to a position and length. - */ - static fromBounds(start: number, end: number): TextSpan; - } - class TextChangeRange { - static unchanged: TextChangeRange; - private _span; - private _newLength; - /** - * Initializes a new instance of TextChangeRange. - */ - constructor(span: TextSpan, newLength: number); - /** - * The span of text before the edit which is being changed - */ - span(): TextSpan; - /** - * Width of the span after the edit. A 0 here would represent a delete - */ - newLength(): number; - newSpan(): TextSpan; - isUnchanged(): boolean; - /** - * Called to merge all the changes that occurred across several versions of a script snapshot - * into a single change. i.e. if a user keeps making successive edits to a script we will - * have a text change from V1 to V2, V2 to V3, ..., Vn. - * - * This function will then merge those changes into a single change range valid between V1 and - * Vn. - */ - static collapseChangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; - } interface ClassifiedSpan { textSpan: TextSpan; classificationType: string; @@ -1877,6 +1801,8 @@ declare module "typescript" { throwIfCancellationRequested(): void; } function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, isOpen: boolean, setNodeParents: boolean): SourceFile; + var disableIncrementalParsing: boolean; + function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TextChangeRange): SourceFile; function createDocumentRegistry(): DocumentRegistry; function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo; function createLanguageService(host: LanguageServiceHost, documentRegistry: DocumentRegistry): LanguageService; diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index 24ea4aebd31..6fd1cda359a 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -189,29 +189,29 @@ declare module ts { ConditionalExpression = 164, TemplateExpression = 165, YieldExpression = 166, - OmittedExpression = 167, - TemplateSpan = 168, - Block = 169, - VariableStatement = 170, - EmptyStatement = 171, - ExpressionStatement = 172, - IfStatement = 173, - DoStatement = 174, - WhileStatement = 175, - ForStatement = 176, - ForInStatement = 177, - ContinueStatement = 178, - BreakStatement = 179, - ReturnStatement = 180, - WithStatement = 181, - SwitchStatement = 182, - LabeledStatement = 183, - ThrowStatement = 184, - TryStatement = 185, - TryBlock = 186, - FinallyBlock = 187, - DebuggerStatement = 188, - VariableDeclaration = 189, + SpreadElementExpression = 167, + OmittedExpression = 168, + TemplateSpan = 169, + Block = 170, + VariableStatement = 171, + EmptyStatement = 172, + ExpressionStatement = 173, + IfStatement = 174, + DoStatement = 175, + WhileStatement = 176, + ForStatement = 177, + ForInStatement = 178, + ContinueStatement = 179, + BreakStatement = 180, + ReturnStatement = 181, + WithStatement = 182, + SwitchStatement = 183, + LabeledStatement = 184, + ThrowStatement = 185, + TryStatement = 186, + DebuggerStatement = 187, + VariableDeclaration = 188, + VariableDeclarationList = 189, FunctionDeclaration = 190, ClassDeclaration = 191, InterfaceDeclaration = 192, @@ -230,9 +230,8 @@ declare module ts { ShorthandPropertyAssignment = 205, EnumMember = 206, SourceFile = 207, - Program = 208, - SyntaxList = 209, - Count = 210, + SyntaxList = 208, + Count = 209, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, @@ -253,8 +252,6 @@ declare module ts { LastLiteralToken = 10, FirstTemplateToken = 10, LastTemplateToken = 13, - FirstOperator = 22, - LastOperator = 63, FirstBinaryOperator = 24, LastBinaryOperator = 63, FirstNode = 121, @@ -331,10 +328,14 @@ declare module ts { type?: TypeNode; } interface VariableDeclaration extends Declaration { + parent?: VariableDeclarationList; name: Identifier | BindingPattern; type?: TypeNode; initializer?: Expression; } + interface VariableDeclarationList extends Node { + declarations: NodeArray; + } interface ParameterDeclaration extends Declaration { dotDotDotToken?: Node; name: Identifier | BindingPattern; @@ -514,6 +515,9 @@ declare module ts { interface ArrayLiteralExpression extends PrimaryExpression { elements: NodeArray; } + interface SpreadElementExpression extends Expression { + expression: Expression; + } interface ObjectLiteralExpression extends PrimaryExpression, Declaration { properties: NodeArray; } @@ -548,7 +552,7 @@ declare module ts { statements: NodeArray; } interface VariableStatement extends Statement { - declarations: NodeArray; + declarationList: VariableDeclarationList; } interface ExpressionStatement extends Statement { expression: Expression; @@ -568,14 +572,12 @@ declare module ts { expression: Expression; } interface ForStatement extends IterationStatement { - declarations?: NodeArray; - initializer?: Expression; + initializer?: VariableDeclarationList | Expression; condition?: Expression; iterator?: Expression; } interface ForInStatement extends IterationStatement { - declarations?: NodeArray; - variable?: Expression; + initializer: VariableDeclarationList | Expression; expression: Expression; } interface BreakOrContinueStatement extends Statement { @@ -682,12 +684,12 @@ declare module ts { getLineAndCharacterFromPosition(position: number): LineAndCharacter; getPositionFromLineAndCharacter(line: number, character: number): number; getLineStarts(): number[]; + update(newText: string, textChangeRange: TextChangeRange): SourceFile; amdDependencies: string[]; amdModuleName: string; referencedFiles: FileReference[]; referenceDiagnostics: Diagnostic[]; parseDiagnostics: Diagnostic[]; - grammarDiagnostics: Diagnostic[]; getSyntacticDiagnostics(): Diagnostic[]; semanticDiagnostics: Diagnostic[]; hasNoDefaultLib: boolean; @@ -698,15 +700,21 @@ declare module ts { languageVersion: ScriptTarget; identifiers: Map; } - interface Program { - getSourceFile(filename: string): SourceFile; - getSourceFiles(): SourceFile[]; + interface ScriptReferenceHost { getCompilerOptions(): CompilerOptions; + getSourceFile(filename: string): SourceFile; + getCurrentDirectory(): string; + } + interface Program extends ScriptReferenceHost { + getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getTypeChecker(fullTypeCheckMode: boolean): TypeChecker; + getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getTypeChecker(produceDiagnostics: boolean): TypeChecker; getCommonSourceDirectory(): string; + emitFiles(targetSourceFile?: SourceFile): EmitResult; + isEmitBlocked(sourceFile?: SourceFile): boolean; } interface SourceMapSpan { emittedLine: number; @@ -740,16 +748,20 @@ declare module ts { diagnostics: Diagnostic[]; sourceMaps: SourceMapData[]; } + interface TypeCheckerHost { + getCompilerOptions(): CompilerOptions; + getCompilerHost(): CompilerHost; + getSourceFiles(): SourceFile[]; + getSourceFile(filename: string): SourceFile; + } interface TypeChecker { - getProgram(): Program; + getEmitResolver(): EmitResolver; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; getNodeCount(): number; getIdentifierCount(): number; getSymbolCount(): number; getTypeCount(): number; - emitFiles(targetSourceFile?: SourceFile): EmitResult; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; @@ -773,7 +785,6 @@ declare module ts { isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; isUndefinedSymbol(symbol: Symbol): boolean; isArgumentsSymbol(symbol: Symbol): boolean; - isEmitBlocked(sourceFile?: SourceFile): boolean; getEnumMemberValue(node: EnumMember): number; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean; getAliasedSymbol(symbol: Symbol): Symbol; @@ -833,7 +844,6 @@ declare module ts { errorModuleName?: string; } interface EmitResolver { - getProgram(): Program; getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; getExpressionNamePrefix(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; @@ -849,7 +859,6 @@ declare module ts { isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number; - isEmitBlocked(sourceFile?: SourceFile): boolean; isUnknownIdentifier(location: Node, name: string): boolean; } const enum SymbolFlags { @@ -1019,8 +1028,6 @@ declare module ts { } interface GenericType extends InterfaceType, TypeReference { instantiations: Map; - openReferenceTargets: GenericType[]; - openReferenceChecks: Map; } interface TupleType extends ObjectType { elementTypes: Type[]; @@ -1119,6 +1126,7 @@ declare module ts { locale?: string; mapRoot?: string; module?: ModuleKind; + noEmit?: boolean; noEmitOnError?: boolean; noErrorTruncation?: boolean; noImplicitAny?: boolean; @@ -1303,13 +1311,18 @@ declare module ts { useCaseSensitiveFileNames(): boolean; getNewLine(): string; } + interface TextSpan { + start: number; + length: number; + } + interface TextChangeRange { + span: TextSpan; + newLength: number; + } } declare module ts { interface ErrorCallback { - (message: DiagnosticMessage): void; - } - interface CommentCallback { - (pos: number, end: number): void; + (message: DiagnosticMessage, length: number): void; } interface Scanner { getStartPos(): number; @@ -1355,17 +1368,19 @@ declare module ts { declare module ts { function getNodeConstructor(kind: SyntaxKind): new () => Node; function createNode(kind: SyntaxKind): Node; - function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodes?: (nodes: Node[]) => T): T; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T; function modifierToFlag(token: SyntaxKind): NodeFlags; function isEvalOrArgumentsIdentifier(node: Node): boolean; function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile; function isLeftHandSideExpression(expr: Expression): boolean; function isAssignmentOperator(token: SyntaxKind): boolean; - function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program; } declare module ts { - function createTypeChecker(program: Program, fullTypeCheck: boolean): TypeChecker; + function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker; +} +declare module ts { + function createCompilerHost(options: CompilerOptions): CompilerHost; + function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program; } declare module ts { var servicesVersion: string; @@ -1412,9 +1427,8 @@ declare module ts { interface SourceFile { isOpen: boolean; version: string; - getScriptSnapshot(): IScriptSnapshot; + scriptSnapshot: IScriptSnapshot; getNamedDeclarations(): Declaration[]; - update(scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TextChangeRange): SourceFile; } /** * Represents an immutable snapshot of a script at a specified time.Once acquired, the @@ -1496,96 +1510,6 @@ declare module ts { getSourceFile(filename: string): SourceFile; dispose(): void; } - class TextSpan { - private _start; - private _length; - /** - * Creates a TextSpan instance beginning with the position Start and having the Length - * specified with length. - */ - constructor(start: number, length: number); - toJSON(key: any): any; - start(): number; - length(): number; - end(): number; - isEmpty(): boolean; - /** - * Determines whether the position lies within the span. Returns true if the position is greater than or equal to Start and strictly less - * than End, otherwise false. - * @param position The position to check. - */ - containsPosition(position: number): boolean; - /** - * Determines whether span falls completely within this span. Returns true if the specified span falls completely within this span, otherwise false. - * @param span The span to check. - */ - containsTextSpan(span: TextSpan): boolean; - /** - * Determines whether the given span overlaps this span. Two spans are considered to overlap - * if they have positions in common and neither is empty. Empty spans do not overlap with any - * other span. Returns true if the spans overlap, false otherwise. - * @param span The span to check. - */ - overlapsWith(span: TextSpan): boolean; - /** - * Returns the overlap with the given span, or undefined if there is no overlap. - * @param span The span to check. - */ - overlap(span: TextSpan): TextSpan; - /** - * Determines whether span intersects this span. Two spans are considered to - * intersect if they have positions in common or the end of one span - * coincides with the start of the other span. Returns true if the spans intersect, false otherwise. - * @param The span to check. - */ - intersectsWithTextSpan(span: TextSpan): boolean; - intersectsWith(start: number, length: number): boolean; - /** - * Determines whether the given position intersects this span. - * A position is considered to intersect if it is between the start and - * end positions (inclusive) of this span. Returns true if the position intersects, false otherwise. - * @param position The position to check. - */ - intersectsWithPosition(position: number): boolean; - /** - * Returns the intersection with the given span, or undefined if there is no intersection. - * @param span The span to check. - */ - intersection(span: TextSpan): TextSpan; - /** - * Creates a new TextSpan from the given start and end positions - * as opposed to a position and length. - */ - static fromBounds(start: number, end: number): TextSpan; - } - class TextChangeRange { - static unchanged: TextChangeRange; - private _span; - private _newLength; - /** - * Initializes a new instance of TextChangeRange. - */ - constructor(span: TextSpan, newLength: number); - /** - * The span of text before the edit which is being changed - */ - span(): TextSpan; - /** - * Width of the span after the edit. A 0 here would represent a delete - */ - newLength(): number; - newSpan(): TextSpan; - isUnchanged(): boolean; - /** - * Called to merge all the changes that occurred across several versions of a script snapshot - * into a single change. i.e. if a user keeps making successive edits to a script we will - * have a text change from V1 to V2, V2 to V3, ..., Vn. - * - * This function will then merge those changes into a single change range valid between V1 and - * Vn. - */ - static collapseChangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; - } interface ClassifiedSpan { textSpan: TextSpan; classificationType: string; @@ -1877,6 +1801,8 @@ declare module ts { throwIfCancellationRequested(): void; } function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, isOpen: boolean, setNodeParents: boolean): SourceFile; + var disableIncrementalParsing: boolean; + function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TextChangeRange): SourceFile; function createDocumentRegistry(): DocumentRegistry; function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo; function createLanguageService(host: LanguageServiceHost, documentRegistry: DocumentRegistry): LanguageService; diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 11bce678504..c3725bdc367 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -15,6 +15,271 @@ and limitations under the License. var ts; (function (ts) { + (function (SyntaxKind) { + SyntaxKind[SyntaxKind["Unknown"] = 0] = "Unknown"; + SyntaxKind[SyntaxKind["EndOfFileToken"] = 1] = "EndOfFileToken"; + SyntaxKind[SyntaxKind["SingleLineCommentTrivia"] = 2] = "SingleLineCommentTrivia"; + SyntaxKind[SyntaxKind["MultiLineCommentTrivia"] = 3] = "MultiLineCommentTrivia"; + SyntaxKind[SyntaxKind["NewLineTrivia"] = 4] = "NewLineTrivia"; + SyntaxKind[SyntaxKind["WhitespaceTrivia"] = 5] = "WhitespaceTrivia"; + SyntaxKind[SyntaxKind["ConflictMarkerTrivia"] = 6] = "ConflictMarkerTrivia"; + SyntaxKind[SyntaxKind["NumericLiteral"] = 7] = "NumericLiteral"; + SyntaxKind[SyntaxKind["StringLiteral"] = 8] = "StringLiteral"; + SyntaxKind[SyntaxKind["RegularExpressionLiteral"] = 9] = "RegularExpressionLiteral"; + SyntaxKind[SyntaxKind["NoSubstitutionTemplateLiteral"] = 10] = "NoSubstitutionTemplateLiteral"; + SyntaxKind[SyntaxKind["TemplateHead"] = 11] = "TemplateHead"; + SyntaxKind[SyntaxKind["TemplateMiddle"] = 12] = "TemplateMiddle"; + SyntaxKind[SyntaxKind["TemplateTail"] = 13] = "TemplateTail"; + SyntaxKind[SyntaxKind["OpenBraceToken"] = 14] = "OpenBraceToken"; + SyntaxKind[SyntaxKind["CloseBraceToken"] = 15] = "CloseBraceToken"; + SyntaxKind[SyntaxKind["OpenParenToken"] = 16] = "OpenParenToken"; + SyntaxKind[SyntaxKind["CloseParenToken"] = 17] = "CloseParenToken"; + SyntaxKind[SyntaxKind["OpenBracketToken"] = 18] = "OpenBracketToken"; + SyntaxKind[SyntaxKind["CloseBracketToken"] = 19] = "CloseBracketToken"; + SyntaxKind[SyntaxKind["DotToken"] = 20] = "DotToken"; + SyntaxKind[SyntaxKind["DotDotDotToken"] = 21] = "DotDotDotToken"; + SyntaxKind[SyntaxKind["SemicolonToken"] = 22] = "SemicolonToken"; + SyntaxKind[SyntaxKind["CommaToken"] = 23] = "CommaToken"; + SyntaxKind[SyntaxKind["LessThanToken"] = 24] = "LessThanToken"; + SyntaxKind[SyntaxKind["GreaterThanToken"] = 25] = "GreaterThanToken"; + SyntaxKind[SyntaxKind["LessThanEqualsToken"] = 26] = "LessThanEqualsToken"; + SyntaxKind[SyntaxKind["GreaterThanEqualsToken"] = 27] = "GreaterThanEqualsToken"; + SyntaxKind[SyntaxKind["EqualsEqualsToken"] = 28] = "EqualsEqualsToken"; + SyntaxKind[SyntaxKind["ExclamationEqualsToken"] = 29] = "ExclamationEqualsToken"; + SyntaxKind[SyntaxKind["EqualsEqualsEqualsToken"] = 30] = "EqualsEqualsEqualsToken"; + SyntaxKind[SyntaxKind["ExclamationEqualsEqualsToken"] = 31] = "ExclamationEqualsEqualsToken"; + SyntaxKind[SyntaxKind["EqualsGreaterThanToken"] = 32] = "EqualsGreaterThanToken"; + SyntaxKind[SyntaxKind["PlusToken"] = 33] = "PlusToken"; + SyntaxKind[SyntaxKind["MinusToken"] = 34] = "MinusToken"; + SyntaxKind[SyntaxKind["AsteriskToken"] = 35] = "AsteriskToken"; + SyntaxKind[SyntaxKind["SlashToken"] = 36] = "SlashToken"; + SyntaxKind[SyntaxKind["PercentToken"] = 37] = "PercentToken"; + SyntaxKind[SyntaxKind["PlusPlusToken"] = 38] = "PlusPlusToken"; + SyntaxKind[SyntaxKind["MinusMinusToken"] = 39] = "MinusMinusToken"; + SyntaxKind[SyntaxKind["LessThanLessThanToken"] = 40] = "LessThanLessThanToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanToken"] = 41] = "GreaterThanGreaterThanToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanToken"] = 42] = "GreaterThanGreaterThanGreaterThanToken"; + SyntaxKind[SyntaxKind["AmpersandToken"] = 43] = "AmpersandToken"; + SyntaxKind[SyntaxKind["BarToken"] = 44] = "BarToken"; + SyntaxKind[SyntaxKind["CaretToken"] = 45] = "CaretToken"; + SyntaxKind[SyntaxKind["ExclamationToken"] = 46] = "ExclamationToken"; + SyntaxKind[SyntaxKind["TildeToken"] = 47] = "TildeToken"; + SyntaxKind[SyntaxKind["AmpersandAmpersandToken"] = 48] = "AmpersandAmpersandToken"; + SyntaxKind[SyntaxKind["BarBarToken"] = 49] = "BarBarToken"; + SyntaxKind[SyntaxKind["QuestionToken"] = 50] = "QuestionToken"; + SyntaxKind[SyntaxKind["ColonToken"] = 51] = "ColonToken"; + SyntaxKind[SyntaxKind["EqualsToken"] = 52] = "EqualsToken"; + SyntaxKind[SyntaxKind["PlusEqualsToken"] = 53] = "PlusEqualsToken"; + SyntaxKind[SyntaxKind["MinusEqualsToken"] = 54] = "MinusEqualsToken"; + SyntaxKind[SyntaxKind["AsteriskEqualsToken"] = 55] = "AsteriskEqualsToken"; + SyntaxKind[SyntaxKind["SlashEqualsToken"] = 56] = "SlashEqualsToken"; + SyntaxKind[SyntaxKind["PercentEqualsToken"] = 57] = "PercentEqualsToken"; + SyntaxKind[SyntaxKind["LessThanLessThanEqualsToken"] = 58] = "LessThanLessThanEqualsToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanEqualsToken"] = 59] = "GreaterThanGreaterThanEqualsToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanEqualsToken"] = 60] = "GreaterThanGreaterThanGreaterThanEqualsToken"; + SyntaxKind[SyntaxKind["AmpersandEqualsToken"] = 61] = "AmpersandEqualsToken"; + SyntaxKind[SyntaxKind["BarEqualsToken"] = 62] = "BarEqualsToken"; + SyntaxKind[SyntaxKind["CaretEqualsToken"] = 63] = "CaretEqualsToken"; + SyntaxKind[SyntaxKind["Identifier"] = 64] = "Identifier"; + SyntaxKind[SyntaxKind["BreakKeyword"] = 65] = "BreakKeyword"; + SyntaxKind[SyntaxKind["CaseKeyword"] = 66] = "CaseKeyword"; + SyntaxKind[SyntaxKind["CatchKeyword"] = 67] = "CatchKeyword"; + SyntaxKind[SyntaxKind["ClassKeyword"] = 68] = "ClassKeyword"; + SyntaxKind[SyntaxKind["ConstKeyword"] = 69] = "ConstKeyword"; + SyntaxKind[SyntaxKind["ContinueKeyword"] = 70] = "ContinueKeyword"; + SyntaxKind[SyntaxKind["DebuggerKeyword"] = 71] = "DebuggerKeyword"; + SyntaxKind[SyntaxKind["DefaultKeyword"] = 72] = "DefaultKeyword"; + SyntaxKind[SyntaxKind["DeleteKeyword"] = 73] = "DeleteKeyword"; + SyntaxKind[SyntaxKind["DoKeyword"] = 74] = "DoKeyword"; + SyntaxKind[SyntaxKind["ElseKeyword"] = 75] = "ElseKeyword"; + SyntaxKind[SyntaxKind["EnumKeyword"] = 76] = "EnumKeyword"; + SyntaxKind[SyntaxKind["ExportKeyword"] = 77] = "ExportKeyword"; + SyntaxKind[SyntaxKind["ExtendsKeyword"] = 78] = "ExtendsKeyword"; + SyntaxKind[SyntaxKind["FalseKeyword"] = 79] = "FalseKeyword"; + SyntaxKind[SyntaxKind["FinallyKeyword"] = 80] = "FinallyKeyword"; + SyntaxKind[SyntaxKind["ForKeyword"] = 81] = "ForKeyword"; + SyntaxKind[SyntaxKind["FunctionKeyword"] = 82] = "FunctionKeyword"; + SyntaxKind[SyntaxKind["IfKeyword"] = 83] = "IfKeyword"; + SyntaxKind[SyntaxKind["ImportKeyword"] = 84] = "ImportKeyword"; + SyntaxKind[SyntaxKind["InKeyword"] = 85] = "InKeyword"; + SyntaxKind[SyntaxKind["InstanceOfKeyword"] = 86] = "InstanceOfKeyword"; + SyntaxKind[SyntaxKind["NewKeyword"] = 87] = "NewKeyword"; + SyntaxKind[SyntaxKind["NullKeyword"] = 88] = "NullKeyword"; + SyntaxKind[SyntaxKind["ReturnKeyword"] = 89] = "ReturnKeyword"; + SyntaxKind[SyntaxKind["SuperKeyword"] = 90] = "SuperKeyword"; + SyntaxKind[SyntaxKind["SwitchKeyword"] = 91] = "SwitchKeyword"; + SyntaxKind[SyntaxKind["ThisKeyword"] = 92] = "ThisKeyword"; + SyntaxKind[SyntaxKind["ThrowKeyword"] = 93] = "ThrowKeyword"; + SyntaxKind[SyntaxKind["TrueKeyword"] = 94] = "TrueKeyword"; + SyntaxKind[SyntaxKind["TryKeyword"] = 95] = "TryKeyword"; + SyntaxKind[SyntaxKind["TypeOfKeyword"] = 96] = "TypeOfKeyword"; + SyntaxKind[SyntaxKind["VarKeyword"] = 97] = "VarKeyword"; + SyntaxKind[SyntaxKind["VoidKeyword"] = 98] = "VoidKeyword"; + SyntaxKind[SyntaxKind["WhileKeyword"] = 99] = "WhileKeyword"; + SyntaxKind[SyntaxKind["WithKeyword"] = 100] = "WithKeyword"; + SyntaxKind[SyntaxKind["ImplementsKeyword"] = 101] = "ImplementsKeyword"; + SyntaxKind[SyntaxKind["InterfaceKeyword"] = 102] = "InterfaceKeyword"; + SyntaxKind[SyntaxKind["LetKeyword"] = 103] = "LetKeyword"; + SyntaxKind[SyntaxKind["PackageKeyword"] = 104] = "PackageKeyword"; + SyntaxKind[SyntaxKind["PrivateKeyword"] = 105] = "PrivateKeyword"; + SyntaxKind[SyntaxKind["ProtectedKeyword"] = 106] = "ProtectedKeyword"; + SyntaxKind[SyntaxKind["PublicKeyword"] = 107] = "PublicKeyword"; + SyntaxKind[SyntaxKind["StaticKeyword"] = 108] = "StaticKeyword"; + SyntaxKind[SyntaxKind["YieldKeyword"] = 109] = "YieldKeyword"; + SyntaxKind[SyntaxKind["AnyKeyword"] = 110] = "AnyKeyword"; + SyntaxKind[SyntaxKind["BooleanKeyword"] = 111] = "BooleanKeyword"; + SyntaxKind[SyntaxKind["ConstructorKeyword"] = 112] = "ConstructorKeyword"; + SyntaxKind[SyntaxKind["DeclareKeyword"] = 113] = "DeclareKeyword"; + SyntaxKind[SyntaxKind["GetKeyword"] = 114] = "GetKeyword"; + SyntaxKind[SyntaxKind["ModuleKeyword"] = 115] = "ModuleKeyword"; + SyntaxKind[SyntaxKind["RequireKeyword"] = 116] = "RequireKeyword"; + SyntaxKind[SyntaxKind["NumberKeyword"] = 117] = "NumberKeyword"; + SyntaxKind[SyntaxKind["SetKeyword"] = 118] = "SetKeyword"; + SyntaxKind[SyntaxKind["StringKeyword"] = 119] = "StringKeyword"; + SyntaxKind[SyntaxKind["TypeKeyword"] = 120] = "TypeKeyword"; + SyntaxKind[SyntaxKind["QualifiedName"] = 121] = "QualifiedName"; + SyntaxKind[SyntaxKind["ComputedPropertyName"] = 122] = "ComputedPropertyName"; + SyntaxKind[SyntaxKind["TypeParameter"] = 123] = "TypeParameter"; + SyntaxKind[SyntaxKind["Parameter"] = 124] = "Parameter"; + SyntaxKind[SyntaxKind["PropertySignature"] = 125] = "PropertySignature"; + SyntaxKind[SyntaxKind["PropertyDeclaration"] = 126] = "PropertyDeclaration"; + SyntaxKind[SyntaxKind["MethodSignature"] = 127] = "MethodSignature"; + SyntaxKind[SyntaxKind["MethodDeclaration"] = 128] = "MethodDeclaration"; + SyntaxKind[SyntaxKind["Constructor"] = 129] = "Constructor"; + SyntaxKind[SyntaxKind["GetAccessor"] = 130] = "GetAccessor"; + SyntaxKind[SyntaxKind["SetAccessor"] = 131] = "SetAccessor"; + SyntaxKind[SyntaxKind["CallSignature"] = 132] = "CallSignature"; + SyntaxKind[SyntaxKind["ConstructSignature"] = 133] = "ConstructSignature"; + SyntaxKind[SyntaxKind["IndexSignature"] = 134] = "IndexSignature"; + SyntaxKind[SyntaxKind["TypeReference"] = 135] = "TypeReference"; + SyntaxKind[SyntaxKind["FunctionType"] = 136] = "FunctionType"; + SyntaxKind[SyntaxKind["ConstructorType"] = 137] = "ConstructorType"; + SyntaxKind[SyntaxKind["TypeQuery"] = 138] = "TypeQuery"; + SyntaxKind[SyntaxKind["TypeLiteral"] = 139] = "TypeLiteral"; + SyntaxKind[SyntaxKind["ArrayType"] = 140] = "ArrayType"; + SyntaxKind[SyntaxKind["TupleType"] = 141] = "TupleType"; + SyntaxKind[SyntaxKind["UnionType"] = 142] = "UnionType"; + SyntaxKind[SyntaxKind["ParenthesizedType"] = 143] = "ParenthesizedType"; + SyntaxKind[SyntaxKind["ObjectBindingPattern"] = 144] = "ObjectBindingPattern"; + SyntaxKind[SyntaxKind["ArrayBindingPattern"] = 145] = "ArrayBindingPattern"; + SyntaxKind[SyntaxKind["BindingElement"] = 146] = "BindingElement"; + SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 147] = "ArrayLiteralExpression"; + SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 148] = "ObjectLiteralExpression"; + SyntaxKind[SyntaxKind["PropertyAccessExpression"] = 149] = "PropertyAccessExpression"; + SyntaxKind[SyntaxKind["ElementAccessExpression"] = 150] = "ElementAccessExpression"; + SyntaxKind[SyntaxKind["CallExpression"] = 151] = "CallExpression"; + SyntaxKind[SyntaxKind["NewExpression"] = 152] = "NewExpression"; + SyntaxKind[SyntaxKind["TaggedTemplateExpression"] = 153] = "TaggedTemplateExpression"; + SyntaxKind[SyntaxKind["TypeAssertionExpression"] = 154] = "TypeAssertionExpression"; + SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 155] = "ParenthesizedExpression"; + SyntaxKind[SyntaxKind["FunctionExpression"] = 156] = "FunctionExpression"; + SyntaxKind[SyntaxKind["ArrowFunction"] = 157] = "ArrowFunction"; + SyntaxKind[SyntaxKind["DeleteExpression"] = 158] = "DeleteExpression"; + SyntaxKind[SyntaxKind["TypeOfExpression"] = 159] = "TypeOfExpression"; + SyntaxKind[SyntaxKind["VoidExpression"] = 160] = "VoidExpression"; + SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 161] = "PrefixUnaryExpression"; + SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 162] = "PostfixUnaryExpression"; + SyntaxKind[SyntaxKind["BinaryExpression"] = 163] = "BinaryExpression"; + SyntaxKind[SyntaxKind["ConditionalExpression"] = 164] = "ConditionalExpression"; + SyntaxKind[SyntaxKind["TemplateExpression"] = 165] = "TemplateExpression"; + SyntaxKind[SyntaxKind["YieldExpression"] = 166] = "YieldExpression"; + SyntaxKind[SyntaxKind["SpreadElementExpression"] = 167] = "SpreadElementExpression"; + SyntaxKind[SyntaxKind["OmittedExpression"] = 168] = "OmittedExpression"; + SyntaxKind[SyntaxKind["TemplateSpan"] = 169] = "TemplateSpan"; + SyntaxKind[SyntaxKind["Block"] = 170] = "Block"; + SyntaxKind[SyntaxKind["VariableStatement"] = 171] = "VariableStatement"; + SyntaxKind[SyntaxKind["EmptyStatement"] = 172] = "EmptyStatement"; + SyntaxKind[SyntaxKind["ExpressionStatement"] = 173] = "ExpressionStatement"; + SyntaxKind[SyntaxKind["IfStatement"] = 174] = "IfStatement"; + SyntaxKind[SyntaxKind["DoStatement"] = 175] = "DoStatement"; + SyntaxKind[SyntaxKind["WhileStatement"] = 176] = "WhileStatement"; + SyntaxKind[SyntaxKind["ForStatement"] = 177] = "ForStatement"; + SyntaxKind[SyntaxKind["ForInStatement"] = 178] = "ForInStatement"; + SyntaxKind[SyntaxKind["ContinueStatement"] = 179] = "ContinueStatement"; + SyntaxKind[SyntaxKind["BreakStatement"] = 180] = "BreakStatement"; + SyntaxKind[SyntaxKind["ReturnStatement"] = 181] = "ReturnStatement"; + SyntaxKind[SyntaxKind["WithStatement"] = 182] = "WithStatement"; + SyntaxKind[SyntaxKind["SwitchStatement"] = 183] = "SwitchStatement"; + SyntaxKind[SyntaxKind["LabeledStatement"] = 184] = "LabeledStatement"; + SyntaxKind[SyntaxKind["ThrowStatement"] = 185] = "ThrowStatement"; + SyntaxKind[SyntaxKind["TryStatement"] = 186] = "TryStatement"; + SyntaxKind[SyntaxKind["DebuggerStatement"] = 187] = "DebuggerStatement"; + SyntaxKind[SyntaxKind["VariableDeclaration"] = 188] = "VariableDeclaration"; + SyntaxKind[SyntaxKind["VariableDeclarationList"] = 189] = "VariableDeclarationList"; + SyntaxKind[SyntaxKind["FunctionDeclaration"] = 190] = "FunctionDeclaration"; + SyntaxKind[SyntaxKind["ClassDeclaration"] = 191] = "ClassDeclaration"; + SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 192] = "InterfaceDeclaration"; + SyntaxKind[SyntaxKind["TypeAliasDeclaration"] = 193] = "TypeAliasDeclaration"; + SyntaxKind[SyntaxKind["EnumDeclaration"] = 194] = "EnumDeclaration"; + SyntaxKind[SyntaxKind["ModuleDeclaration"] = 195] = "ModuleDeclaration"; + SyntaxKind[SyntaxKind["ModuleBlock"] = 196] = "ModuleBlock"; + SyntaxKind[SyntaxKind["ImportDeclaration"] = 197] = "ImportDeclaration"; + SyntaxKind[SyntaxKind["ExportAssignment"] = 198] = "ExportAssignment"; + SyntaxKind[SyntaxKind["ExternalModuleReference"] = 199] = "ExternalModuleReference"; + SyntaxKind[SyntaxKind["CaseClause"] = 200] = "CaseClause"; + SyntaxKind[SyntaxKind["DefaultClause"] = 201] = "DefaultClause"; + SyntaxKind[SyntaxKind["HeritageClause"] = 202] = "HeritageClause"; + SyntaxKind[SyntaxKind["CatchClause"] = 203] = "CatchClause"; + SyntaxKind[SyntaxKind["PropertyAssignment"] = 204] = "PropertyAssignment"; + SyntaxKind[SyntaxKind["ShorthandPropertyAssignment"] = 205] = "ShorthandPropertyAssignment"; + SyntaxKind[SyntaxKind["EnumMember"] = 206] = "EnumMember"; + SyntaxKind[SyntaxKind["SourceFile"] = 207] = "SourceFile"; + SyntaxKind[SyntaxKind["SyntaxList"] = 208] = "SyntaxList"; + SyntaxKind[SyntaxKind["Count"] = 209] = "Count"; + SyntaxKind[SyntaxKind["FirstAssignment"] = 52] = "FirstAssignment"; + SyntaxKind[SyntaxKind["LastAssignment"] = 63] = "LastAssignment"; + SyntaxKind[SyntaxKind["FirstReservedWord"] = 65] = "FirstReservedWord"; + SyntaxKind[SyntaxKind["LastReservedWord"] = 100] = "LastReservedWord"; + SyntaxKind[SyntaxKind["FirstKeyword"] = 65] = "FirstKeyword"; + SyntaxKind[SyntaxKind["LastKeyword"] = 120] = "LastKeyword"; + SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 101] = "FirstFutureReservedWord"; + SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 109] = "LastFutureReservedWord"; + SyntaxKind[SyntaxKind["FirstTypeNode"] = 135] = "FirstTypeNode"; + SyntaxKind[SyntaxKind["LastTypeNode"] = 143] = "LastTypeNode"; + SyntaxKind[SyntaxKind["FirstPunctuation"] = 14] = "FirstPunctuation"; + SyntaxKind[SyntaxKind["LastPunctuation"] = 63] = "LastPunctuation"; + SyntaxKind[SyntaxKind["FirstToken"] = 0] = "FirstToken"; + SyntaxKind[SyntaxKind["LastToken"] = 120] = "LastToken"; + SyntaxKind[SyntaxKind["FirstTriviaToken"] = 2] = "FirstTriviaToken"; + SyntaxKind[SyntaxKind["LastTriviaToken"] = 6] = "LastTriviaToken"; + SyntaxKind[SyntaxKind["FirstLiteralToken"] = 7] = "FirstLiteralToken"; + SyntaxKind[SyntaxKind["LastLiteralToken"] = 10] = "LastLiteralToken"; + SyntaxKind[SyntaxKind["FirstTemplateToken"] = 10] = "FirstTemplateToken"; + SyntaxKind[SyntaxKind["LastTemplateToken"] = 13] = "LastTemplateToken"; + SyntaxKind[SyntaxKind["FirstBinaryOperator"] = 24] = "FirstBinaryOperator"; + SyntaxKind[SyntaxKind["LastBinaryOperator"] = 63] = "LastBinaryOperator"; + SyntaxKind[SyntaxKind["FirstNode"] = 121] = "FirstNode"; + })(ts.SyntaxKind || (ts.SyntaxKind = {})); + var SyntaxKind = ts.SyntaxKind; + (function (NodeFlags) { + NodeFlags[NodeFlags["Export"] = 1] = "Export"; + NodeFlags[NodeFlags["Ambient"] = 2] = "Ambient"; + NodeFlags[NodeFlags["Public"] = 16] = "Public"; + NodeFlags[NodeFlags["Private"] = 32] = "Private"; + NodeFlags[NodeFlags["Protected"] = 64] = "Protected"; + NodeFlags[NodeFlags["Static"] = 128] = "Static"; + NodeFlags[NodeFlags["MultiLine"] = 256] = "MultiLine"; + NodeFlags[NodeFlags["Synthetic"] = 512] = "Synthetic"; + NodeFlags[NodeFlags["DeclarationFile"] = 1024] = "DeclarationFile"; + NodeFlags[NodeFlags["Let"] = 2048] = "Let"; + NodeFlags[NodeFlags["Const"] = 4096] = "Const"; + NodeFlags[NodeFlags["OctalLiteral"] = 8192] = "OctalLiteral"; + NodeFlags[NodeFlags["Modifier"] = 243] = "Modifier"; + NodeFlags[NodeFlags["AccessibilityModifier"] = 112] = "AccessibilityModifier"; + NodeFlags[NodeFlags["BlockScoped"] = 6144] = "BlockScoped"; + })(ts.NodeFlags || (ts.NodeFlags = {})); + var NodeFlags = ts.NodeFlags; + (function (ParserContextFlags) { + ParserContextFlags[ParserContextFlags["StrictMode"] = 1] = "StrictMode"; + ParserContextFlags[ParserContextFlags["DisallowIn"] = 2] = "DisallowIn"; + ParserContextFlags[ParserContextFlags["Yield"] = 4] = "Yield"; + ParserContextFlags[ParserContextFlags["GeneratorParameter"] = 8] = "GeneratorParameter"; + ParserContextFlags[ParserContextFlags["ThisNodeHasError"] = 16] = "ThisNodeHasError"; + ParserContextFlags[ParserContextFlags["ParserGeneratedFlags"] = 31] = "ParserGeneratedFlags"; + ParserContextFlags[ParserContextFlags["ThisNodeOrAnySubNodesHasError"] = 32] = "ThisNodeOrAnySubNodesHasError"; + ParserContextFlags[ParserContextFlags["HasAggregatedChildData"] = 64] = "HasAggregatedChildData"; + })(ts.ParserContextFlags || (ts.ParserContextFlags = {})); + var ParserContextFlags = ts.ParserContextFlags; (function (EmitReturnStatus) { EmitReturnStatus[EmitReturnStatus["Succeeded"] = 0] = "Succeeded"; EmitReturnStatus[EmitReturnStatus["AllOutputGenerationSkipped"] = 1] = "AllOutputGenerationSkipped"; @@ -24,19 +289,305 @@ var ts; EmitReturnStatus[EmitReturnStatus["CompilerOptionsErrors"] = 5] = "CompilerOptionsErrors"; })(ts.EmitReturnStatus || (ts.EmitReturnStatus = {})); var EmitReturnStatus = ts.EmitReturnStatus; + (function (TypeFormatFlags) { + TypeFormatFlags[TypeFormatFlags["None"] = 0] = "None"; + TypeFormatFlags[TypeFormatFlags["WriteArrayAsGenericType"] = 1] = "WriteArrayAsGenericType"; + TypeFormatFlags[TypeFormatFlags["UseTypeOfFunction"] = 2] = "UseTypeOfFunction"; + TypeFormatFlags[TypeFormatFlags["NoTruncation"] = 4] = "NoTruncation"; + TypeFormatFlags[TypeFormatFlags["WriteArrowStyleSignature"] = 8] = "WriteArrowStyleSignature"; + TypeFormatFlags[TypeFormatFlags["WriteOwnNameForAnyLike"] = 16] = "WriteOwnNameForAnyLike"; + TypeFormatFlags[TypeFormatFlags["WriteTypeArgumentsOfSignature"] = 32] = "WriteTypeArgumentsOfSignature"; + TypeFormatFlags[TypeFormatFlags["InElementType"] = 64] = "InElementType"; + })(ts.TypeFormatFlags || (ts.TypeFormatFlags = {})); + var TypeFormatFlags = ts.TypeFormatFlags; + (function (SymbolFormatFlags) { + SymbolFormatFlags[SymbolFormatFlags["None"] = 0] = "None"; + SymbolFormatFlags[SymbolFormatFlags["WriteTypeParametersOrArguments"] = 1] = "WriteTypeParametersOrArguments"; + SymbolFormatFlags[SymbolFormatFlags["UseOnlyExternalAliasing"] = 2] = "UseOnlyExternalAliasing"; + })(ts.SymbolFormatFlags || (ts.SymbolFormatFlags = {})); + var SymbolFormatFlags = ts.SymbolFormatFlags; + (function (SymbolAccessibility) { + SymbolAccessibility[SymbolAccessibility["Accessible"] = 0] = "Accessible"; + SymbolAccessibility[SymbolAccessibility["NotAccessible"] = 1] = "NotAccessible"; + SymbolAccessibility[SymbolAccessibility["CannotBeNamed"] = 2] = "CannotBeNamed"; + })(ts.SymbolAccessibility || (ts.SymbolAccessibility = {})); + var SymbolAccessibility = ts.SymbolAccessibility; + (function (SymbolFlags) { + SymbolFlags[SymbolFlags["FunctionScopedVariable"] = 1] = "FunctionScopedVariable"; + SymbolFlags[SymbolFlags["BlockScopedVariable"] = 2] = "BlockScopedVariable"; + SymbolFlags[SymbolFlags["Property"] = 4] = "Property"; + SymbolFlags[SymbolFlags["EnumMember"] = 8] = "EnumMember"; + SymbolFlags[SymbolFlags["Function"] = 16] = "Function"; + SymbolFlags[SymbolFlags["Class"] = 32] = "Class"; + SymbolFlags[SymbolFlags["Interface"] = 64] = "Interface"; + SymbolFlags[SymbolFlags["ConstEnum"] = 128] = "ConstEnum"; + SymbolFlags[SymbolFlags["RegularEnum"] = 256] = "RegularEnum"; + SymbolFlags[SymbolFlags["ValueModule"] = 512] = "ValueModule"; + SymbolFlags[SymbolFlags["NamespaceModule"] = 1024] = "NamespaceModule"; + SymbolFlags[SymbolFlags["TypeLiteral"] = 2048] = "TypeLiteral"; + SymbolFlags[SymbolFlags["ObjectLiteral"] = 4096] = "ObjectLiteral"; + SymbolFlags[SymbolFlags["Method"] = 8192] = "Method"; + SymbolFlags[SymbolFlags["Constructor"] = 16384] = "Constructor"; + SymbolFlags[SymbolFlags["GetAccessor"] = 32768] = "GetAccessor"; + SymbolFlags[SymbolFlags["SetAccessor"] = 65536] = "SetAccessor"; + SymbolFlags[SymbolFlags["Signature"] = 131072] = "Signature"; + SymbolFlags[SymbolFlags["TypeParameter"] = 262144] = "TypeParameter"; + SymbolFlags[SymbolFlags["TypeAlias"] = 524288] = "TypeAlias"; + SymbolFlags[SymbolFlags["ExportValue"] = 1048576] = "ExportValue"; + SymbolFlags[SymbolFlags["ExportType"] = 2097152] = "ExportType"; + SymbolFlags[SymbolFlags["ExportNamespace"] = 4194304] = "ExportNamespace"; + SymbolFlags[SymbolFlags["Import"] = 8388608] = "Import"; + SymbolFlags[SymbolFlags["Instantiated"] = 16777216] = "Instantiated"; + SymbolFlags[SymbolFlags["Merged"] = 33554432] = "Merged"; + SymbolFlags[SymbolFlags["Transient"] = 67108864] = "Transient"; + SymbolFlags[SymbolFlags["Prototype"] = 134217728] = "Prototype"; + SymbolFlags[SymbolFlags["UnionProperty"] = 268435456] = "UnionProperty"; + SymbolFlags[SymbolFlags["Optional"] = 536870912] = "Optional"; + SymbolFlags[SymbolFlags["Enum"] = 384] = "Enum"; + SymbolFlags[SymbolFlags["Variable"] = 3] = "Variable"; + SymbolFlags[SymbolFlags["Value"] = 107455] = "Value"; + SymbolFlags[SymbolFlags["Type"] = 793056] = "Type"; + SymbolFlags[SymbolFlags["Namespace"] = 1536] = "Namespace"; + SymbolFlags[SymbolFlags["Module"] = 1536] = "Module"; + SymbolFlags[SymbolFlags["Accessor"] = 98304] = "Accessor"; + SymbolFlags[SymbolFlags["FunctionScopedVariableExcludes"] = 107454] = "FunctionScopedVariableExcludes"; + SymbolFlags[SymbolFlags["BlockScopedVariableExcludes"] = 107455] = "BlockScopedVariableExcludes"; + SymbolFlags[SymbolFlags["ParameterExcludes"] = 107455] = "ParameterExcludes"; + SymbolFlags[SymbolFlags["PropertyExcludes"] = 107455] = "PropertyExcludes"; + SymbolFlags[SymbolFlags["EnumMemberExcludes"] = 107455] = "EnumMemberExcludes"; + SymbolFlags[SymbolFlags["FunctionExcludes"] = 106927] = "FunctionExcludes"; + SymbolFlags[SymbolFlags["ClassExcludes"] = 899583] = "ClassExcludes"; + SymbolFlags[SymbolFlags["InterfaceExcludes"] = 792992] = "InterfaceExcludes"; + SymbolFlags[SymbolFlags["RegularEnumExcludes"] = 899327] = "RegularEnumExcludes"; + SymbolFlags[SymbolFlags["ConstEnumExcludes"] = 899967] = "ConstEnumExcludes"; + SymbolFlags[SymbolFlags["ValueModuleExcludes"] = 106639] = "ValueModuleExcludes"; + SymbolFlags[SymbolFlags["NamespaceModuleExcludes"] = 0] = "NamespaceModuleExcludes"; + SymbolFlags[SymbolFlags["MethodExcludes"] = 99263] = "MethodExcludes"; + SymbolFlags[SymbolFlags["GetAccessorExcludes"] = 41919] = "GetAccessorExcludes"; + SymbolFlags[SymbolFlags["SetAccessorExcludes"] = 74687] = "SetAccessorExcludes"; + SymbolFlags[SymbolFlags["TypeParameterExcludes"] = 530912] = "TypeParameterExcludes"; + SymbolFlags[SymbolFlags["TypeAliasExcludes"] = 793056] = "TypeAliasExcludes"; + SymbolFlags[SymbolFlags["ImportExcludes"] = 8388608] = "ImportExcludes"; + SymbolFlags[SymbolFlags["ModuleMember"] = 8914931] = "ModuleMember"; + SymbolFlags[SymbolFlags["ExportHasLocal"] = 944] = "ExportHasLocal"; + SymbolFlags[SymbolFlags["HasLocals"] = 255504] = "HasLocals"; + SymbolFlags[SymbolFlags["HasExports"] = 1952] = "HasExports"; + SymbolFlags[SymbolFlags["HasMembers"] = 6240] = "HasMembers"; + SymbolFlags[SymbolFlags["IsContainer"] = 262128] = "IsContainer"; + SymbolFlags[SymbolFlags["PropertyOrAccessor"] = 98308] = "PropertyOrAccessor"; + SymbolFlags[SymbolFlags["Export"] = 7340032] = "Export"; + })(ts.SymbolFlags || (ts.SymbolFlags = {})); + var SymbolFlags = ts.SymbolFlags; + (function (NodeCheckFlags) { + NodeCheckFlags[NodeCheckFlags["TypeChecked"] = 1] = "TypeChecked"; + NodeCheckFlags[NodeCheckFlags["LexicalThis"] = 2] = "LexicalThis"; + NodeCheckFlags[NodeCheckFlags["CaptureThis"] = 4] = "CaptureThis"; + NodeCheckFlags[NodeCheckFlags["EmitExtends"] = 8] = "EmitExtends"; + NodeCheckFlags[NodeCheckFlags["SuperInstance"] = 16] = "SuperInstance"; + NodeCheckFlags[NodeCheckFlags["SuperStatic"] = 32] = "SuperStatic"; + NodeCheckFlags[NodeCheckFlags["ContextChecked"] = 64] = "ContextChecked"; + NodeCheckFlags[NodeCheckFlags["EnumValuesComputed"] = 128] = "EnumValuesComputed"; + })(ts.NodeCheckFlags || (ts.NodeCheckFlags = {})); + var NodeCheckFlags = ts.NodeCheckFlags; + (function (TypeFlags) { + TypeFlags[TypeFlags["Any"] = 1] = "Any"; + TypeFlags[TypeFlags["String"] = 2] = "String"; + TypeFlags[TypeFlags["Number"] = 4] = "Number"; + TypeFlags[TypeFlags["Boolean"] = 8] = "Boolean"; + TypeFlags[TypeFlags["Void"] = 16] = "Void"; + TypeFlags[TypeFlags["Undefined"] = 32] = "Undefined"; + TypeFlags[TypeFlags["Null"] = 64] = "Null"; + TypeFlags[TypeFlags["Enum"] = 128] = "Enum"; + TypeFlags[TypeFlags["StringLiteral"] = 256] = "StringLiteral"; + TypeFlags[TypeFlags["TypeParameter"] = 512] = "TypeParameter"; + TypeFlags[TypeFlags["Class"] = 1024] = "Class"; + TypeFlags[TypeFlags["Interface"] = 2048] = "Interface"; + TypeFlags[TypeFlags["Reference"] = 4096] = "Reference"; + TypeFlags[TypeFlags["Tuple"] = 8192] = "Tuple"; + TypeFlags[TypeFlags["Union"] = 16384] = "Union"; + TypeFlags[TypeFlags["Anonymous"] = 32768] = "Anonymous"; + TypeFlags[TypeFlags["FromSignature"] = 65536] = "FromSignature"; + TypeFlags[TypeFlags["Unwidened"] = 131072] = "Unwidened"; + TypeFlags[TypeFlags["Intrinsic"] = 127] = "Intrinsic"; + TypeFlags[TypeFlags["StringLike"] = 258] = "StringLike"; + TypeFlags[TypeFlags["NumberLike"] = 132] = "NumberLike"; + TypeFlags[TypeFlags["ObjectType"] = 48128] = "ObjectType"; + })(ts.TypeFlags || (ts.TypeFlags = {})); + var TypeFlags = ts.TypeFlags; + (function (SignatureKind) { + SignatureKind[SignatureKind["Call"] = 0] = "Call"; + SignatureKind[SignatureKind["Construct"] = 1] = "Construct"; + })(ts.SignatureKind || (ts.SignatureKind = {})); + var SignatureKind = ts.SignatureKind; + (function (IndexKind) { + IndexKind[IndexKind["String"] = 0] = "String"; + IndexKind[IndexKind["Number"] = 1] = "Number"; + })(ts.IndexKind || (ts.IndexKind = {})); + var IndexKind = ts.IndexKind; (function (DiagnosticCategory) { DiagnosticCategory[DiagnosticCategory["Warning"] = 0] = "Warning"; DiagnosticCategory[DiagnosticCategory["Error"] = 1] = "Error"; DiagnosticCategory[DiagnosticCategory["Message"] = 2] = "Message"; })(ts.DiagnosticCategory || (ts.DiagnosticCategory = {})); var DiagnosticCategory = ts.DiagnosticCategory; + (function (ModuleKind) { + ModuleKind[ModuleKind["None"] = 0] = "None"; + ModuleKind[ModuleKind["CommonJS"] = 1] = "CommonJS"; + ModuleKind[ModuleKind["AMD"] = 2] = "AMD"; + })(ts.ModuleKind || (ts.ModuleKind = {})); + var ModuleKind = ts.ModuleKind; + (function (ScriptTarget) { + ScriptTarget[ScriptTarget["ES3"] = 0] = "ES3"; + ScriptTarget[ScriptTarget["ES5"] = 1] = "ES5"; + ScriptTarget[ScriptTarget["ES6"] = 2] = "ES6"; + ScriptTarget[ScriptTarget["Latest"] = 2] = "Latest"; + })(ts.ScriptTarget || (ts.ScriptTarget = {})); + var ScriptTarget = ts.ScriptTarget; + (function (CharacterCodes) { + CharacterCodes[CharacterCodes["nullCharacter"] = 0] = "nullCharacter"; + CharacterCodes[CharacterCodes["maxAsciiCharacter"] = 127] = "maxAsciiCharacter"; + CharacterCodes[CharacterCodes["lineFeed"] = 10] = "lineFeed"; + CharacterCodes[CharacterCodes["carriageReturn"] = 13] = "carriageReturn"; + CharacterCodes[CharacterCodes["lineSeparator"] = 8232] = "lineSeparator"; + CharacterCodes[CharacterCodes["paragraphSeparator"] = 8233] = "paragraphSeparator"; + CharacterCodes[CharacterCodes["nextLine"] = 133] = "nextLine"; + CharacterCodes[CharacterCodes["space"] = 32] = "space"; + CharacterCodes[CharacterCodes["nonBreakingSpace"] = 160] = "nonBreakingSpace"; + CharacterCodes[CharacterCodes["enQuad"] = 8192] = "enQuad"; + CharacterCodes[CharacterCodes["emQuad"] = 8193] = "emQuad"; + CharacterCodes[CharacterCodes["enSpace"] = 8194] = "enSpace"; + CharacterCodes[CharacterCodes["emSpace"] = 8195] = "emSpace"; + CharacterCodes[CharacterCodes["threePerEmSpace"] = 8196] = "threePerEmSpace"; + CharacterCodes[CharacterCodes["fourPerEmSpace"] = 8197] = "fourPerEmSpace"; + CharacterCodes[CharacterCodes["sixPerEmSpace"] = 8198] = "sixPerEmSpace"; + CharacterCodes[CharacterCodes["figureSpace"] = 8199] = "figureSpace"; + CharacterCodes[CharacterCodes["punctuationSpace"] = 8200] = "punctuationSpace"; + CharacterCodes[CharacterCodes["thinSpace"] = 8201] = "thinSpace"; + CharacterCodes[CharacterCodes["hairSpace"] = 8202] = "hairSpace"; + CharacterCodes[CharacterCodes["zeroWidthSpace"] = 8203] = "zeroWidthSpace"; + CharacterCodes[CharacterCodes["narrowNoBreakSpace"] = 8239] = "narrowNoBreakSpace"; + CharacterCodes[CharacterCodes["ideographicSpace"] = 12288] = "ideographicSpace"; + CharacterCodes[CharacterCodes["mathematicalSpace"] = 8287] = "mathematicalSpace"; + CharacterCodes[CharacterCodes["ogham"] = 5760] = "ogham"; + CharacterCodes[CharacterCodes["_"] = 95] = "_"; + CharacterCodes[CharacterCodes["$"] = 36] = "$"; + CharacterCodes[CharacterCodes["_0"] = 48] = "_0"; + CharacterCodes[CharacterCodes["_1"] = 49] = "_1"; + CharacterCodes[CharacterCodes["_2"] = 50] = "_2"; + CharacterCodes[CharacterCodes["_3"] = 51] = "_3"; + CharacterCodes[CharacterCodes["_4"] = 52] = "_4"; + CharacterCodes[CharacterCodes["_5"] = 53] = "_5"; + CharacterCodes[CharacterCodes["_6"] = 54] = "_6"; + CharacterCodes[CharacterCodes["_7"] = 55] = "_7"; + CharacterCodes[CharacterCodes["_8"] = 56] = "_8"; + CharacterCodes[CharacterCodes["_9"] = 57] = "_9"; + CharacterCodes[CharacterCodes["a"] = 97] = "a"; + CharacterCodes[CharacterCodes["b"] = 98] = "b"; + CharacterCodes[CharacterCodes["c"] = 99] = "c"; + CharacterCodes[CharacterCodes["d"] = 100] = "d"; + CharacterCodes[CharacterCodes["e"] = 101] = "e"; + CharacterCodes[CharacterCodes["f"] = 102] = "f"; + CharacterCodes[CharacterCodes["g"] = 103] = "g"; + CharacterCodes[CharacterCodes["h"] = 104] = "h"; + CharacterCodes[CharacterCodes["i"] = 105] = "i"; + CharacterCodes[CharacterCodes["j"] = 106] = "j"; + CharacterCodes[CharacterCodes["k"] = 107] = "k"; + CharacterCodes[CharacterCodes["l"] = 108] = "l"; + CharacterCodes[CharacterCodes["m"] = 109] = "m"; + CharacterCodes[CharacterCodes["n"] = 110] = "n"; + CharacterCodes[CharacterCodes["o"] = 111] = "o"; + CharacterCodes[CharacterCodes["p"] = 112] = "p"; + CharacterCodes[CharacterCodes["q"] = 113] = "q"; + CharacterCodes[CharacterCodes["r"] = 114] = "r"; + CharacterCodes[CharacterCodes["s"] = 115] = "s"; + CharacterCodes[CharacterCodes["t"] = 116] = "t"; + CharacterCodes[CharacterCodes["u"] = 117] = "u"; + CharacterCodes[CharacterCodes["v"] = 118] = "v"; + CharacterCodes[CharacterCodes["w"] = 119] = "w"; + CharacterCodes[CharacterCodes["x"] = 120] = "x"; + CharacterCodes[CharacterCodes["y"] = 121] = "y"; + CharacterCodes[CharacterCodes["z"] = 122] = "z"; + CharacterCodes[CharacterCodes["A"] = 65] = "A"; + CharacterCodes[CharacterCodes["B"] = 66] = "B"; + CharacterCodes[CharacterCodes["C"] = 67] = "C"; + CharacterCodes[CharacterCodes["D"] = 68] = "D"; + CharacterCodes[CharacterCodes["E"] = 69] = "E"; + CharacterCodes[CharacterCodes["F"] = 70] = "F"; + CharacterCodes[CharacterCodes["G"] = 71] = "G"; + CharacterCodes[CharacterCodes["H"] = 72] = "H"; + CharacterCodes[CharacterCodes["I"] = 73] = "I"; + CharacterCodes[CharacterCodes["J"] = 74] = "J"; + CharacterCodes[CharacterCodes["K"] = 75] = "K"; + CharacterCodes[CharacterCodes["L"] = 76] = "L"; + CharacterCodes[CharacterCodes["M"] = 77] = "M"; + CharacterCodes[CharacterCodes["N"] = 78] = "N"; + CharacterCodes[CharacterCodes["O"] = 79] = "O"; + CharacterCodes[CharacterCodes["P"] = 80] = "P"; + CharacterCodes[CharacterCodes["Q"] = 81] = "Q"; + CharacterCodes[CharacterCodes["R"] = 82] = "R"; + CharacterCodes[CharacterCodes["S"] = 83] = "S"; + CharacterCodes[CharacterCodes["T"] = 84] = "T"; + CharacterCodes[CharacterCodes["U"] = 85] = "U"; + CharacterCodes[CharacterCodes["V"] = 86] = "V"; + CharacterCodes[CharacterCodes["W"] = 87] = "W"; + CharacterCodes[CharacterCodes["X"] = 88] = "X"; + CharacterCodes[CharacterCodes["Y"] = 89] = "Y"; + CharacterCodes[CharacterCodes["Z"] = 90] = "Z"; + CharacterCodes[CharacterCodes["ampersand"] = 38] = "ampersand"; + CharacterCodes[CharacterCodes["asterisk"] = 42] = "asterisk"; + CharacterCodes[CharacterCodes["at"] = 64] = "at"; + CharacterCodes[CharacterCodes["backslash"] = 92] = "backslash"; + CharacterCodes[CharacterCodes["backtick"] = 96] = "backtick"; + CharacterCodes[CharacterCodes["bar"] = 124] = "bar"; + CharacterCodes[CharacterCodes["caret"] = 94] = "caret"; + CharacterCodes[CharacterCodes["closeBrace"] = 125] = "closeBrace"; + CharacterCodes[CharacterCodes["closeBracket"] = 93] = "closeBracket"; + CharacterCodes[CharacterCodes["closeParen"] = 41] = "closeParen"; + CharacterCodes[CharacterCodes["colon"] = 58] = "colon"; + CharacterCodes[CharacterCodes["comma"] = 44] = "comma"; + CharacterCodes[CharacterCodes["dot"] = 46] = "dot"; + CharacterCodes[CharacterCodes["doubleQuote"] = 34] = "doubleQuote"; + CharacterCodes[CharacterCodes["equals"] = 61] = "equals"; + CharacterCodes[CharacterCodes["exclamation"] = 33] = "exclamation"; + CharacterCodes[CharacterCodes["greaterThan"] = 62] = "greaterThan"; + CharacterCodes[CharacterCodes["lessThan"] = 60] = "lessThan"; + CharacterCodes[CharacterCodes["minus"] = 45] = "minus"; + CharacterCodes[CharacterCodes["openBrace"] = 123] = "openBrace"; + CharacterCodes[CharacterCodes["openBracket"] = 91] = "openBracket"; + CharacterCodes[CharacterCodes["openParen"] = 40] = "openParen"; + CharacterCodes[CharacterCodes["percent"] = 37] = "percent"; + CharacterCodes[CharacterCodes["plus"] = 43] = "plus"; + CharacterCodes[CharacterCodes["question"] = 63] = "question"; + CharacterCodes[CharacterCodes["semicolon"] = 59] = "semicolon"; + CharacterCodes[CharacterCodes["singleQuote"] = 39] = "singleQuote"; + CharacterCodes[CharacterCodes["slash"] = 47] = "slash"; + CharacterCodes[CharacterCodes["tilde"] = 126] = "tilde"; + CharacterCodes[CharacterCodes["backspace"] = 8] = "backspace"; + CharacterCodes[CharacterCodes["formFeed"] = 12] = "formFeed"; + CharacterCodes[CharacterCodes["byteOrderMark"] = 65279] = "byteOrderMark"; + CharacterCodes[CharacterCodes["tab"] = 9] = "tab"; + CharacterCodes[CharacterCodes["verticalTab"] = 11] = "verticalTab"; + })(ts.CharacterCodes || (ts.CharacterCodes = {})); + var CharacterCodes = ts.CharacterCodes; })(ts || (ts = {})); var ts; (function (ts) { + (function (Ternary) { + Ternary[Ternary["False"] = 0] = "False"; + Ternary[Ternary["Maybe"] = 1] = "Maybe"; + Ternary[Ternary["True"] = -1] = "True"; + })(ts.Ternary || (ts.Ternary = {})); + var Ternary = ts.Ternary; + (function (Comparison) { + Comparison[Comparison["LessThan"] = -1] = "LessThan"; + Comparison[Comparison["EqualTo"] = 0] = "EqualTo"; + Comparison[Comparison["GreaterThan"] = 1] = "GreaterThan"; + })(ts.Comparison || (ts.Comparison = {})); + var Comparison = ts.Comparison; function forEach(array, callback) { if (array) { for (var i = 0, len = array.length; i < len; i++) { - var result = callback(array[i]); + var result = callback(array[i], i); if (result) { return result; } @@ -212,6 +763,12 @@ var ts; return result; } ts.mapToArray = mapToArray; + function copyMap(source, target) { + for (var p in source) { + target[p] = source[p]; + } + } + ts.copyMap = copyMap; function arrayToMap(array, makeKey) { var result = {}; forEach(array, function (value) { @@ -578,6 +1135,13 @@ var ts; getTypeConstructor: function () { return Type; }, getSignatureConstructor: function () { return Signature; } }; + (function (AssertionLevel) { + AssertionLevel[AssertionLevel["None"] = 0] = "None"; + AssertionLevel[AssertionLevel["Normal"] = 1] = "Normal"; + AssertionLevel[AssertionLevel["Aggressive"] = 2] = "Aggressive"; + AssertionLevel[AssertionLevel["VeryAggressive"] = 3] = "VeryAggressive"; + })(ts.AssertionLevel || (ts.AssertionLevel = {})); + var AssertionLevel = ts.AssertionLevel; var Debug; (function (Debug) { var currentAssertionLevel = 0 /* None */; @@ -943,7 +1507,9 @@ var ts; A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: 1 /* Error */, key: "A destructuring declaration must have an initializer.", isEarly: true }, Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: 1 /* Error */, key: "Destructuring declarations are not allowed in ambient contexts.", isEarly: true }, An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: 1 /* Error */, key: "An implementation cannot be declared in ambient contexts.", isEarly: true }, - Merge_conflict_marker_encountered: { code: 1184, category: 1 /* Error */, key: "Merge conflict marker encountered." }, + Modifiers_cannot_appear_here: { code: 1184, category: 1 /* Error */, key: "Modifiers cannot appear here." }, + Merge_conflict_marker_encountered: { code: 1185, category: 1 /* Error */, key: "Merge conflict marker encountered." }, + A_rest_element_cannot_have_an_initializer: { code: 1186, category: 1 /* Error */, key: "A rest element cannot have an initializer." }, 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." }, @@ -1094,6 +1660,7 @@ var ts; Type_0_has_no_property_1_and_no_string_index_signature: { code: 2459, category: 1 /* Error */, key: "Type '{0}' has no property '{1}' and no string index signature." }, Type_0_has_no_property_1: { code: 2460, category: 1 /* Error */, key: "Type '{0}' has no property '{1}'." }, Type_0_is_not_an_array_type: { code: 2461, category: 1 /* Error */, key: "Type '{0}' is not an array type." }, + A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: 1 /* Error */, key: "A rest element must be last in an array destructuring pattern" }, 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_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: 1 /* Error */, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1177,6 +1744,8 @@ var ts; Could_not_write_file_0_Colon_1: { code: 5033, category: 1 /* Error */, key: "Could not write file '{0}': {1}" }, Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: 1 /* Error */, key: "Option mapRoot cannot be specified without specifying sourcemap option." }, Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: 1 /* Error */, key: "Option sourceRoot cannot be specified without specifying sourcemap option." }, + Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: 1 /* Error */, key: "Option noEmit cannot be specified with option out or outDir." }, + Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: 1 /* Error */, key: "Option noEmit cannot be specified with option declaration." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: 2 /* Message */, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: 2 /* Message */, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: 2 /* Message */, key: "Specifies the location where debugger should locate map files instead of generated locations." }, @@ -1186,6 +1755,7 @@ var ts; Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: 2 /* Message */, key: "Do not erase const enum declarations in generated code." }, Do_not_emit_outputs_if_any_type_checking_errors_were_reported: { code: 6008, category: 2 /* Message */, key: "Do not emit outputs if any type checking errors were reported." }, Do_not_emit_comments_to_output: { code: 6009, category: 2 /* Message */, key: "Do not emit comments to output." }, + Do_not_emit_outputs: { code: 6010, category: 2 /* Message */, key: "Do not emit outputs." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: 2 /* Message */, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: 2 /* Message */, key: "Specify module code generation: 'commonjs' or 'amd'" }, Print_this_message: { code: 6017, category: 2 /* Message */, key: "Print this message." }, @@ -1213,7 +1783,7 @@ var ts; Unsupported_locale_0: { code: 6049, category: 1 /* Error */, key: "Unsupported locale '{0}'." }, Unable_to_open_file_0: { code: 6050, category: 1 /* Error */, key: "Unable to open file '{0}'." }, Corrupted_locale_file_0: { code: 6051, category: 1 /* Error */, key: "Corrupted locale file {0}." }, - Warn_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: 2 /* Message */, key: "Warn on expressions and declarations with an implied 'any' type." }, + Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: 2 /* Message */, key: "Warn on expressions and declarations with an implied 'any' type." }, File_0_not_found: { code: 6053, category: 1 /* Error */, key: "File '{0}' not found." }, File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: 1 /* Error */, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: 2 /* Message */, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, @@ -1521,25 +2091,42 @@ var ts; } } ts.skipTrivia = skipTrivia; + var mergeConflictMarkerLength = "<<<<<<<".length; function isConflictMarkerTrivia(text, pos) { - if (pos > 0 && isLineBreak(text.charCodeAt(pos - 1))) { + ts.Debug.assert(pos >= 0); + if (pos === 0 || isLineBreak(text.charCodeAt(pos - 1))) { var ch = text.charCodeAt(pos); - var markerLength = "<<<<<<<".length; - if ((pos + markerLength) < text.length) { - for (var i = 0, n = markerLength; i < n; i++) { + if ((pos + mergeConflictMarkerLength) < text.length) { + for (var i = 0, n = mergeConflictMarkerLength; i < n; i++) { if (text.charCodeAt(pos + i) !== ch) { return false; } } - return ch === 61 /* equals */ || text.charCodeAt(pos + markerLength) === 32 /* space */; + return ch === 61 /* equals */ || text.charCodeAt(pos + mergeConflictMarkerLength) === 32 /* space */; } } return false; } - function scanConflictMarkerTrivia(text, pos) { + function scanConflictMarkerTrivia(text, pos, error) { + if (error) { + error(ts.Diagnostics.Merge_conflict_marker_encountered, mergeConflictMarkerLength); + } + var ch = text.charCodeAt(pos); var len = text.length; - while (pos < len && !isLineBreak(text.charCodeAt(pos))) { - pos++; + if (ch === 60 /* lessThan */ || ch === 62 /* greaterThan */) { + while (pos < len && !isLineBreak(text.charCodeAt(pos))) { + pos++; + } + } + else { + ts.Debug.assert(ch === 61 /* equals */); + while (pos < len) { + var ch = text.charCodeAt(pos); + if (ch === 62 /* greaterThan */ && isConflictMarkerTrivia(text, pos)) { + break; + } + pos++; + } } return pos; } @@ -1638,9 +2225,9 @@ var ts; var tokenValue; var precedingLineBreak; var tokenIsUnterminated; - function error(message) { + function error(message, length) { if (onError) { - onError(message); + onError(message, length || 0); } } function isIdentifierStart(ch) { @@ -2103,8 +2690,7 @@ var ts; return pos++, token = 22 /* SemicolonToken */; case 60 /* lessThan */: if (isConflictMarkerTrivia(text, pos)) { - error(ts.Diagnostics.Merge_conflict_marker_encountered); - pos = scanConflictMarkerTrivia(text, pos); + pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } @@ -2124,8 +2710,7 @@ var ts; return pos++, token = 24 /* LessThanToken */; case 61 /* equals */: if (isConflictMarkerTrivia(text, pos)) { - error(ts.Diagnostics.Merge_conflict_marker_encountered); - pos = scanConflictMarkerTrivia(text, pos); + pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } @@ -2145,8 +2730,7 @@ var ts; return pos++, token = 52 /* EqualsToken */; case 62 /* greaterThan */: if (isConflictMarkerTrivia(text, pos)) { - error(ts.Diagnostics.Merge_conflict_marker_encountered); - pos = scanConflictMarkerTrivia(text, pos); + pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } @@ -2392,17 +2976,14 @@ var ts; return node.end - node.pos; } ts.getFullWidth = getFullWidth; - function hasFlag(val, flag) { - return (val & flag) !== 0; - } function containsParseError(node) { aggregateChildData(node); - return hasFlag(node.parserContextFlags, 32 /* ThisNodeOrAnySubNodesHasError */); + return (node.parserContextFlags & 32 /* ThisNodeOrAnySubNodesHasError */) !== 0; } ts.containsParseError = containsParseError; function aggregateChildData(node) { - if (!hasFlag(node.parserContextFlags, 64 /* HasAggregatedChildData */)) { - var thisNodeOrAnySubNodesHasError = hasFlag(node.parserContextFlags, 16 /* ThisNodeHasError */) || ts.forEachChild(node, containsParseError); + if (!(node.parserContextFlags & 64 /* HasAggregatedChildData */)) { + var thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & 16 /* ThisNodeHasError */) !== 0) || ts.forEachChild(node, containsParseError); if (thisNodeOrAnySubNodesHasError) { node.parserContextFlags |= 32 /* ThisNodeOrAnySubNodesHasError */; } @@ -2426,19 +3007,26 @@ var ts; return node.pos; } ts.getStartPosOfNode = getStartPosOfNode; - function isMissingNode(node) { + function nodeIsMissing(node) { + if (!node) { + return true; + } return node.pos === node.end && node.kind !== 1 /* EndOfFileToken */; } - ts.isMissingNode = isMissingNode; + ts.nodeIsMissing = nodeIsMissing; + function nodeIsPresent(node) { + return !nodeIsMissing(node); + } + ts.nodeIsPresent = nodeIsPresent; function getTokenPosOfNode(node, sourceFile) { - if (isMissingNode(node)) { + if (nodeIsMissing(node)) { return node.pos; } return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos); } ts.getTokenPosOfNode = getTokenPosOfNode; function getSourceTextOfNodeFromSourceFile(sourceFile, node) { - if (isMissingNode(node)) { + if (nodeIsMissing(node)) { return ""; } var text = sourceFile.text; @@ -2446,7 +3034,7 @@ var ts; } ts.getSourceTextOfNodeFromSourceFile = getSourceTextOfNodeFromSourceFile; function getTextOfNodeFromSourceText(sourceText, node) { - if (isMissingNode(node)) { + if (nodeIsMissing(node)) { return ""; } return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end); @@ -2487,7 +3075,7 @@ var ts; function getErrorSpanForNode(node) { var errorSpan; switch (node.kind) { - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: case 191 /* ClassDeclaration */: case 192 /* InterfaceDeclaration */: @@ -2512,16 +3100,38 @@ var ts; return node.kind === 194 /* EnumDeclaration */ && isConst(node); } ts.isConstEnumDeclaration = isConstEnumDeclaration; + function walkUpBindingElementsAndPatterns(node) { + while (node && (node.kind === 146 /* BindingElement */ || isBindingPattern(node))) { + node = node.parent; + } + return node; + } + function getCombinedNodeFlags(node) { + node = walkUpBindingElementsAndPatterns(node); + var flags = node.flags; + if (node.kind === 188 /* VariableDeclaration */) { + node = node.parent; + } + if (node && node.kind === 189 /* VariableDeclarationList */) { + flags |= node.flags; + node = node.parent; + } + if (node && node.kind === 171 /* VariableStatement */) { + flags |= node.flags; + } + return flags; + } + ts.getCombinedNodeFlags = getCombinedNodeFlags; function isConst(node) { - return !!(node.flags & 4096 /* Const */); + return !!(getCombinedNodeFlags(node) & 4096 /* Const */); } ts.isConst = isConst; function isLet(node) { - return !!(node.flags & 2048 /* Let */); + return !!(getCombinedNodeFlags(node) & 2048 /* Let */); } ts.isLet = isLet; function isPrologueDirective(node) { - return node.kind === 172 /* ExpressionStatement */ && node.expression.kind === 8 /* StringLiteral */; + return node.kind === 173 /* ExpressionStatement */ && node.expression.kind === 8 /* StringLiteral */; } ts.isPrologueDirective = isPrologueDirective; function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { @@ -2546,23 +3156,21 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 180 /* ReturnStatement */: + case 181 /* ReturnStatement */: return visitor(node); - case 169 /* Block */: - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 181 /* WithStatement */: - case 182 /* SwitchStatement */: + case 170 /* Block */: + case 174 /* IfStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 182 /* WithStatement */: + case 183 /* SwitchStatement */: case 200 /* CaseClause */: case 201 /* DefaultClause */: - case 183 /* LabeledStatement */: - case 185 /* TryStatement */: - case 186 /* TryBlock */: + case 184 /* LabeledStatement */: + case 186 /* TryStatement */: case 203 /* CatchClause */: - case 187 /* FinallyBlock */: return ts.forEachChild(node, traverse); } } @@ -2594,7 +3202,7 @@ var ts; } ts.isAnyFunction = isAnyFunction; function isFunctionBlock(node) { - return node && node.kind === 169 /* Block */ && isAnyFunction(node.parent); + return node && node.kind === 170 /* Block */ && isAnyFunction(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { @@ -2690,9 +3298,10 @@ var ts; case 162 /* PostfixUnaryExpression */: case 163 /* BinaryExpression */: case 164 /* ConditionalExpression */: + case 167 /* SpreadElementExpression */: case 165 /* TemplateExpression */: case 10 /* NoSubstitutionTemplateLiteral */: - case 167 /* OmittedExpression */: + case 168 /* OmittedExpression */: return true; case 121 /* QualifiedName */: while (node.parent.kind === 121 /* QualifiedName */) { @@ -2707,7 +3316,7 @@ var ts; case 8 /* StringLiteral */: var parent = node.parent; switch (parent.kind) { - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 124 /* Parameter */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: @@ -2715,24 +3324,26 @@ var ts; case 204 /* PropertyAssignment */: case 146 /* BindingElement */: return parent.initializer === node; - case 172 /* ExpressionStatement */: - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 180 /* ReturnStatement */: - case 181 /* WithStatement */: - case 182 /* SwitchStatement */: + case 173 /* ExpressionStatement */: + case 174 /* IfStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: + case 181 /* ReturnStatement */: + case 182 /* WithStatement */: + case 183 /* SwitchStatement */: case 200 /* CaseClause */: - case 184 /* ThrowStatement */: - case 182 /* SwitchStatement */: + case 185 /* ThrowStatement */: + case 183 /* SwitchStatement */: return parent.expression === node; - case 176 /* ForStatement */: - return parent.initializer === node || parent.condition === node || parent.iterator === node; - case 177 /* ForInStatement */: - return parent.variable === node || parent.expression === node; + case 177 /* ForStatement */: + var forStatement = parent; + return (forStatement.initializer === node && forStatement.initializer.kind !== 189 /* VariableDeclarationList */) || forStatement.condition === node || forStatement.iterator === node; + case 178 /* ForInStatement */: + var forInStatement = parent; + return (forInStatement.initializer === node && forInStatement.initializer.kind !== 189 /* VariableDeclarationList */) || forInStatement.expression === node; case 154 /* TypeAssertionExpression */: return node === parent.expression; - case 168 /* TemplateSpan */: + case 169 /* TemplateSpan */: return node === parent.expression; default: if (isExpression(parent)) { @@ -2743,6 +3354,11 @@ var ts; return false; } ts.isExpression = isExpression; + function isInstantiatedModule(node, preserveConstEnums) { + var moduleState = ts.getModuleInstanceState(node); + return moduleState === 1 /* Instantiated */ || (preserveConstEnums && moduleState === 2 /* ConstEnumOnly */); + } + ts.isInstantiatedModule = isInstantiatedModule; function isExternalModuleImportDeclaration(node) { return node.kind === 197 /* ImportDeclaration */ && node.moduleReference.kind === 199 /* ExternalModuleReference */; } @@ -2800,8 +3416,9 @@ var ts; ts.isBindingPattern = isBindingPattern; function isInAmbientContext(node) { while (node) { - if (node.flags & (2 /* Ambient */ | 1024 /* DeclarationFile */)) + if (node.flags & (2 /* Ambient */ | 1024 /* DeclarationFile */)) { return true; + } node = node.parent; } return false; @@ -2811,7 +3428,7 @@ var ts; switch (node.kind) { case 123 /* TypeParameter */: case 124 /* Parameter */: - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: @@ -2837,23 +3454,23 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 179 /* BreakStatement */: - case 178 /* ContinueStatement */: - case 188 /* DebuggerStatement */: - case 174 /* DoStatement */: - case 172 /* ExpressionStatement */: - case 171 /* EmptyStatement */: - case 177 /* ForInStatement */: - case 176 /* ForStatement */: - case 173 /* IfStatement */: - case 183 /* LabeledStatement */: - case 180 /* ReturnStatement */: - case 182 /* SwitchStatement */: + case 180 /* BreakStatement */: + case 179 /* ContinueStatement */: + case 187 /* DebuggerStatement */: + case 175 /* DoStatement */: + case 173 /* ExpressionStatement */: + case 172 /* EmptyStatement */: + case 178 /* ForInStatement */: + case 177 /* ForStatement */: + case 174 /* IfStatement */: + case 184 /* LabeledStatement */: + case 181 /* ReturnStatement */: + case 183 /* SwitchStatement */: case 93 /* ThrowKeyword */: - case 185 /* TryStatement */: - case 170 /* VariableStatement */: - case 175 /* WhileStatement */: - case 181 /* WithStatement */: + case 186 /* TryStatement */: + case 171 /* VariableStatement */: + case 176 /* WhileStatement */: + case 182 /* WithStatement */: case 198 /* ExportAssignment */: return true; default: @@ -2901,11 +3518,11 @@ var ts; return undefined; } ts.getHeritageClause = getHeritageClause; - function tryResolveScriptReference(program, sourceFile, reference) { - if (!program.getCompilerOptions().noResolve) { + function tryResolveScriptReference(host, sourceFile, reference) { + if (!host.getCompilerOptions().noResolve) { var referenceFileName = ts.isRootedDiskPath(reference.filename) ? reference.filename : ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename); - referenceFileName = ts.getNormalizedAbsolutePath(referenceFileName, program.getCompilerHost().getCurrentDirectory()); - return program.getSourceFile(referenceFileName); + referenceFileName = ts.getNormalizedAbsolutePath(referenceFileName, host.getCurrentDirectory()); + return host.getSourceFile(referenceFileName); } } ts.tryResolveScriptReference = tryResolveScriptReference; @@ -2996,10 +3613,134 @@ var ts; return false; } ts.isModifier = isModifier; + function createEmitHostFromProgram(program) { + var compilerHost = program.getCompilerHost(); + return { + getCanonicalFileName: compilerHost.getCanonicalFileName, + getCommonSourceDirectory: program.getCommonSourceDirectory, + getCompilerOptions: program.getCompilerOptions, + getCurrentDirectory: compilerHost.getCurrentDirectory, + getNewLine: compilerHost.getNewLine, + getSourceFile: program.getSourceFile, + getSourceFiles: program.getSourceFiles, + isEmitBlocked: program.isEmitBlocked, + writeFile: compilerHost.writeFile + }; + } + ts.createEmitHostFromProgram = createEmitHostFromProgram; + function textSpanEnd(span) { + return span.start + span.length; + } + ts.textSpanEnd = textSpanEnd; + function textSpanIsEmpty(span) { + return span.length === 0; + } + ts.textSpanIsEmpty = textSpanIsEmpty; + function textSpanContainsPosition(span, position) { + return position >= span.start && position < textSpanEnd(span); + } + ts.textSpanContainsPosition = textSpanContainsPosition; + function textSpanContainsTextSpan(span, other) { + return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); + } + ts.textSpanContainsTextSpan = textSpanContainsTextSpan; + function textSpanOverlapsWith(span, other) { + var overlapStart = Math.max(span.start, other.start); + var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); + return overlapStart < overlapEnd; + } + ts.textSpanOverlapsWith = textSpanOverlapsWith; + function textSpanOverlap(span1, span2) { + var overlapStart = Math.max(span1.start, span2.start); + var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (overlapStart < overlapEnd) { + return createTextSpanFromBounds(overlapStart, overlapEnd); + } + return undefined; + } + ts.textSpanOverlap = textSpanOverlap; + function textSpanIntersectsWithTextSpan(span, other) { + return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start; + } + ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan; + function textSpanIntersectsWith(span, start, length) { + var end = start + length; + return start <= textSpanEnd(span) && end >= span.start; + } + ts.textSpanIntersectsWith = textSpanIntersectsWith; + function textSpanIntersectsWithPosition(span, position) { + return position <= textSpanEnd(span) && position >= span.start; + } + ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition; + function textSpanIntersection(span1, span2) { + var intersectStart = Math.max(span1.start, span2.start); + var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (intersectStart <= intersectEnd) { + return createTextSpanFromBounds(intersectStart, intersectEnd); + } + return undefined; + } + ts.textSpanIntersection = textSpanIntersection; + function createTextSpan(start, length) { + if (start < 0) { + throw new Error("start < 0"); + } + if (length < 0) { + throw new Error("length < 0"); + } + return { start: start, length: length }; + } + ts.createTextSpan = createTextSpan; + function createTextSpanFromBounds(start, end) { + return createTextSpan(start, end - start); + } + ts.createTextSpanFromBounds = createTextSpanFromBounds; + function textChangeRangeNewSpan(range) { + return createTextSpan(range.span.start, range.newLength); + } + ts.textChangeRangeNewSpan = textChangeRangeNewSpan; + function textChangeRangeIsUnchanged(range) { + return textSpanIsEmpty(range.span) && range.newLength === 0; + } + ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged; + function createTextChangeRange(span, newLength) { + if (newLength < 0) { + throw new Error("newLength < 0"); + } + return { span: span, newLength: newLength }; + } + ts.createTextChangeRange = createTextChangeRange; + ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); + function collapseTextChangeRangesAcrossMultipleVersions(changes) { + if (changes.length === 0) { + return ts.unchangedTextChangeRange; + } + if (changes.length === 1) { + return changes[0]; + } + var change0 = changes[0]; + var oldStartN = change0.span.start; + var oldEndN = textSpanEnd(change0.span); + var newEndN = oldStartN + change0.newLength; + for (var i = 1; i < changes.length; i++) { + var nextChange = changes[i]; + var oldStart1 = oldStartN; + var oldEnd1 = oldEndN; + var newEnd1 = newEndN; + var oldStart2 = nextChange.span.start; + var oldEnd2 = textSpanEnd(nextChange.span); + var newEnd2 = oldStart2 + nextChange.newLength; + oldStartN = Math.min(oldStart1, oldStart2); + oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); + newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); + } + return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); + } + ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; })(ts || (ts = {})); var ts; (function (ts) { - var nodeConstructors = new Array(210 /* Count */); + var nodeConstructors = new Array(209 /* Count */); function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); } @@ -3008,48 +3749,51 @@ var ts; return new (getNodeConstructor(kind))(); } ts.createNode = createNode; - function forEachChild(node, cbNode, cbNodes) { - function child(node) { - if (node) { - return cbNode(node); - } + function visitNode(cbNode, node) { + if (node) { + return cbNode(node); } - function children(nodes) { - if (nodes) { - if (cbNodes) { - return cbNodes(nodes); - } - for (var i = 0, len = nodes.length; i < len; i++) { - var result = cbNode(nodes[i]); - if (result) { - return result; - } + } + function visitNodeArray(cbNodes, nodes) { + if (nodes) { + return cbNodes(nodes); + } + } + function visitEachNode(cbNode, nodes) { + if (nodes) { + for (var i = 0, len = nodes.length; i < len; i++) { + var result = cbNode(nodes[i]); + if (result) { + return result; } - return undefined; } } + } + function forEachChild(node, cbNode, cbNodeArray) { if (!node) { return; } + var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode; + var cbNodes = cbNodeArray || cbNode; switch (node.kind) { case 121 /* QualifiedName */: - return child(node.left) || child(node.right); + return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 123 /* TypeParameter */: - return child(node.name) || child(node.constraint) || child(node.expression); + return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 124 /* Parameter */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: case 204 /* PropertyAssignment */: case 205 /* ShorthandPropertyAssignment */: - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: - return children(node.modifiers) || child(node.propertyName) || child(node.dotDotDotToken) || child(node.name) || child(node.questionToken) || child(node.type) || child(node.initializer); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.dotDotDotToken) || visitNode(cbNode, node.name) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type) || visitNode(cbNode, node.initializer); case 136 /* FunctionType */: case 137 /* ConstructorType */: case 132 /* CallSignature */: case 133 /* ConstructSignature */: case 134 /* IndexSignature */: - return children(node.modifiers) || children(node.typeParameters) || children(node.parameters) || child(node.type); + return visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 128 /* MethodDeclaration */: case 127 /* MethodSignature */: case 129 /* Constructor */: @@ -3058,186 +3802,160 @@ var ts; case 156 /* FunctionExpression */: case 190 /* FunctionDeclaration */: case 157 /* ArrowFunction */: - return children(node.modifiers) || child(node.asteriskToken) || child(node.name) || child(node.questionToken) || children(node.typeParameters) || children(node.parameters) || child(node.type) || child(node.body); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.name) || visitNode(cbNode, node.questionToken) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type) || visitNode(cbNode, node.body); case 135 /* TypeReference */: - return child(node.typeName) || children(node.typeArguments); + return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 138 /* TypeQuery */: - return child(node.exprName); + return visitNode(cbNode, node.exprName); case 139 /* TypeLiteral */: - return children(node.members); + return visitNodes(cbNodes, node.members); case 140 /* ArrayType */: - return child(node.elementType); + return visitNode(cbNode, node.elementType); case 141 /* TupleType */: - return children(node.elementTypes); + return visitNodes(cbNodes, node.elementTypes); case 142 /* UnionType */: - return children(node.types); + return visitNodes(cbNodes, node.types); case 143 /* ParenthesizedType */: - return child(node.type); + return visitNode(cbNode, node.type); case 144 /* ObjectBindingPattern */: case 145 /* ArrayBindingPattern */: - return children(node.elements); + return visitNodes(cbNodes, node.elements); case 147 /* ArrayLiteralExpression */: - return children(node.elements); + return visitNodes(cbNodes, node.elements); case 148 /* ObjectLiteralExpression */: - return children(node.properties); + return visitNodes(cbNodes, node.properties); case 149 /* PropertyAccessExpression */: - return child(node.expression) || child(node.name); + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 150 /* ElementAccessExpression */: - return child(node.expression) || child(node.argumentExpression); + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 151 /* CallExpression */: case 152 /* NewExpression */: - return child(node.expression) || children(node.typeArguments) || children(node.arguments); + return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 153 /* TaggedTemplateExpression */: - return child(node.tag) || child(node.template); + return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 154 /* TypeAssertionExpression */: - return child(node.type) || child(node.expression); + return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 155 /* ParenthesizedExpression */: - return child(node.expression); + return visitNode(cbNode, node.expression); case 158 /* DeleteExpression */: - return child(node.expression); + return visitNode(cbNode, node.expression); case 159 /* TypeOfExpression */: - return child(node.expression); + return visitNode(cbNode, node.expression); case 160 /* VoidExpression */: - return child(node.expression); + return visitNode(cbNode, node.expression); case 161 /* PrefixUnaryExpression */: - return child(node.operand); + return visitNode(cbNode, node.operand); case 166 /* YieldExpression */: - return child(node.asteriskToken) || child(node.expression); + return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 162 /* PostfixUnaryExpression */: - return child(node.operand); + return visitNode(cbNode, node.operand); case 163 /* BinaryExpression */: - return child(node.left) || child(node.right); + return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 164 /* ConditionalExpression */: - return child(node.condition) || child(node.whenTrue) || child(node.whenFalse); - case 169 /* Block */: - case 186 /* TryBlock */: - case 187 /* FinallyBlock */: + return visitNode(cbNode, node.condition) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.whenFalse); + case 167 /* SpreadElementExpression */: + return visitNode(cbNode, node.expression); + case 170 /* Block */: case 196 /* ModuleBlock */: - return children(node.statements); + return visitNodes(cbNodes, node.statements); case 207 /* SourceFile */: - return children(node.statements) || child(node.endOfFileToken); - case 170 /* VariableStatement */: - return children(node.modifiers) || children(node.declarations); - case 172 /* ExpressionStatement */: - return child(node.expression); - case 173 /* IfStatement */: - return child(node.expression) || child(node.thenStatement) || child(node.elseStatement); - case 174 /* DoStatement */: - return child(node.statement) || child(node.expression); - case 175 /* WhileStatement */: - return child(node.expression) || child(node.statement); - case 176 /* ForStatement */: - return children(node.declarations) || child(node.initializer) || child(node.condition) || child(node.iterator) || child(node.statement); - case 177 /* ForInStatement */: - return children(node.declarations) || child(node.variable) || child(node.expression) || child(node.statement); - case 178 /* ContinueStatement */: - case 179 /* BreakStatement */: - return child(node.label); - case 180 /* ReturnStatement */: - return child(node.expression); - case 181 /* WithStatement */: - return child(node.expression) || child(node.statement); - case 182 /* SwitchStatement */: - return child(node.expression) || children(node.clauses); + return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); + case 171 /* VariableStatement */: + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); + case 189 /* VariableDeclarationList */: + return visitNodes(cbNodes, node.declarations); + case 173 /* ExpressionStatement */: + return visitNode(cbNode, node.expression); + case 174 /* IfStatement */: + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); + case 175 /* DoStatement */: + return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); + case 176 /* WhileStatement */: + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); + case 177 /* ForStatement */: + return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.iterator) || visitNode(cbNode, node.statement); + case 178 /* ForInStatement */: + return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); + case 179 /* ContinueStatement */: + case 180 /* BreakStatement */: + return visitNode(cbNode, node.label); + case 181 /* ReturnStatement */: + return visitNode(cbNode, node.expression); + case 182 /* WithStatement */: + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); + case 183 /* SwitchStatement */: + return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.clauses); case 200 /* CaseClause */: - return child(node.expression) || children(node.statements); + return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 201 /* DefaultClause */: - return children(node.statements); - case 183 /* LabeledStatement */: - return child(node.label) || child(node.statement); - case 184 /* ThrowStatement */: - return child(node.expression); - case 185 /* TryStatement */: - return child(node.tryBlock) || child(node.catchClause) || child(node.finallyBlock); + return visitNodes(cbNodes, node.statements); + case 184 /* LabeledStatement */: + return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); + case 185 /* ThrowStatement */: + return visitNode(cbNode, node.expression); + case 186 /* TryStatement */: + return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 203 /* CatchClause */: - return child(node.name) || child(node.type) || child(node.block); + return visitNode(cbNode, node.name) || visitNode(cbNode, node.type) || visitNode(cbNode, node.block); case 191 /* ClassDeclaration */: - return children(node.modifiers) || child(node.name) || children(node.typeParameters) || children(node.heritageClauses) || children(node.members); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); case 192 /* InterfaceDeclaration */: - return children(node.modifiers) || child(node.name) || children(node.typeParameters) || children(node.heritageClauses) || children(node.members); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); case 193 /* TypeAliasDeclaration */: - return children(node.modifiers) || child(node.name) || child(node.type); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 194 /* EnumDeclaration */: - return children(node.modifiers) || child(node.name) || children(node.members); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 206 /* EnumMember */: - return child(node.name) || child(node.initializer); + return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 195 /* ModuleDeclaration */: - return children(node.modifiers) || child(node.name) || child(node.body); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 197 /* ImportDeclaration */: - return children(node.modifiers) || child(node.name) || child(node.moduleReference); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 198 /* ExportAssignment */: - return children(node.modifiers) || child(node.exportName); + return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportName); case 165 /* TemplateExpression */: - return child(node.head) || children(node.templateSpans); - case 168 /* TemplateSpan */: - return child(node.expression) || child(node.literal); + return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); + case 169 /* TemplateSpan */: + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 122 /* ComputedPropertyName */: - return child(node.expression); + return visitNode(cbNode, node.expression); case 202 /* HeritageClause */: - return children(node.types); + return visitNodes(cbNodes, node.types); case 199 /* ExternalModuleReference */: - return child(node.expression); + return visitNode(cbNode, node.expression); } } ts.forEachChild = forEachChild; - function createCompilerHost(options) { - var currentDirectory; - var existingDirectories = {}; - function getCanonicalFileName(fileName) { - return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); - } - var unsupportedFileEncodingErrorCode = -2147024809; - function getSourceFile(filename, languageVersion, onError) { - try { - var text = ts.sys.readFile(filename, options.charset); - } - catch (e) { - if (onError) { - onError(e.number === unsupportedFileEncodingErrorCode ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText : e.message); - } - text = ""; - } - return text !== undefined ? createSourceFile(filename, text, languageVersion) : undefined; - } - function writeFile(fileName, data, writeByteOrderMark, onError) { - function directoryExists(directoryPath) { - if (ts.hasProperty(existingDirectories, directoryPath)) { - return true; - } - if (ts.sys.directoryExists(directoryPath)) { - existingDirectories[directoryPath] = true; - return true; - } - return false; - } - function ensureDirectoriesExist(directoryPath) { - if (directoryPath.length > ts.getRootLength(directoryPath) && !directoryExists(directoryPath)) { - var parentDirectory = ts.getDirectoryPath(directoryPath); - ensureDirectoriesExist(parentDirectory); - ts.sys.createDirectory(directoryPath); - } - } - try { - ensureDirectoriesExist(ts.getDirectoryPath(ts.normalizePath(fileName))); - ts.sys.writeFile(fileName, data, writeByteOrderMark); - } - catch (e) { - if (onError) { - onError(e.message); - } - } - } - return { - getSourceFile: getSourceFile, - getDefaultLibFilename: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"); }, - writeFile: writeFile, - getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, - useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, - getCanonicalFileName: getCanonicalFileName, - getNewLine: function () { return ts.sys.newLine; } - }; - } - ts.createCompilerHost = createCompilerHost; + var ParsingContext; + (function (ParsingContext) { + ParsingContext[ParsingContext["SourceElements"] = 0] = "SourceElements"; + ParsingContext[ParsingContext["ModuleElements"] = 1] = "ModuleElements"; + ParsingContext[ParsingContext["BlockStatements"] = 2] = "BlockStatements"; + ParsingContext[ParsingContext["SwitchClauses"] = 3] = "SwitchClauses"; + ParsingContext[ParsingContext["SwitchClauseStatements"] = 4] = "SwitchClauseStatements"; + ParsingContext[ParsingContext["TypeMembers"] = 5] = "TypeMembers"; + ParsingContext[ParsingContext["ClassMembers"] = 6] = "ClassMembers"; + ParsingContext[ParsingContext["EnumMembers"] = 7] = "EnumMembers"; + ParsingContext[ParsingContext["TypeReferences"] = 8] = "TypeReferences"; + ParsingContext[ParsingContext["VariableDeclarations"] = 9] = "VariableDeclarations"; + ParsingContext[ParsingContext["ObjectBindingElements"] = 10] = "ObjectBindingElements"; + ParsingContext[ParsingContext["ArrayBindingElements"] = 11] = "ArrayBindingElements"; + ParsingContext[ParsingContext["ArgumentExpressions"] = 12] = "ArgumentExpressions"; + ParsingContext[ParsingContext["ObjectLiteralMembers"] = 13] = "ObjectLiteralMembers"; + ParsingContext[ParsingContext["ArrayLiteralMembers"] = 14] = "ArrayLiteralMembers"; + ParsingContext[ParsingContext["Parameters"] = 15] = "Parameters"; + ParsingContext[ParsingContext["TypeParameters"] = 16] = "TypeParameters"; + ParsingContext[ParsingContext["TypeArguments"] = 17] = "TypeArguments"; + ParsingContext[ParsingContext["TupleElementTypes"] = 18] = "TupleElementTypes"; + ParsingContext[ParsingContext["HeritageClauses"] = 19] = "HeritageClauses"; + ParsingContext[ParsingContext["Count"] = 20] = "Count"; + })(ParsingContext || (ParsingContext = {})); + var Tristate; + (function (Tristate) { + Tristate[Tristate["False"] = 0] = "False"; + Tristate[Tristate["True"] = 1] = "True"; + Tristate[Tristate["Unknown"] = 2] = "Unknown"; + })(Tristate || (Tristate = {})); function parsingContextErrors(context) { switch (context) { case 0 /* SourceElements */: return ts.Diagnostics.Declaration_or_statement_expected; @@ -3298,45 +4016,269 @@ var ts; var nodeText = ts.getSourceTextOfNodeFromSourceFile(sourceFile, node.expression); return nodeText === '"use strict"' || nodeText === "'use strict'"; } + var InvalidPosition; + (function (InvalidPosition) { + InvalidPosition[InvalidPosition["Value"] = -1] = "Value"; + })(InvalidPosition || (InvalidPosition = {})); + function createSyntaxCursor(sourceFile) { + var currentArray = sourceFile.statements; + var currentArrayIndex = 0; + ts.Debug.assert(currentArrayIndex < currentArray.length); + var current = currentArray[currentArrayIndex]; + var lastQueriedPosition = -1 /* Value */; + return { + currentNode: function (position) { + if (position !== lastQueriedPosition) { + if (current && current.end === position && currentArrayIndex < currentArray.length) { + currentArrayIndex++; + current = currentArray[currentArrayIndex]; + } + if (!current || current.pos !== position) { + findHighestListElementThatStartsAtPosition(position); + } + } + lastQueriedPosition = position; + ts.Debug.assert(!current || current.pos === position); + return current; + } + }; + function findHighestListElementThatStartsAtPosition(position) { + currentArray = undefined; + currentArrayIndex = -1 /* Value */; + current = undefined; + forEachChild(sourceFile, visitNode, visitArray); + function visitNode(node) { + if (position >= node.pos && position < node.end) { + forEachChild(node, visitNode, visitArray); + return true; + } + return false; + } + function visitArray(array) { + if (position >= array.pos && position < array.end) { + for (var i = 0, n = array.length; i < n; i++) { + var child = array[i]; + if (child) { + if (child.pos === position) { + currentArray = array; + currentArrayIndex = i; + current = child; + return true; + } + else { + if (child.pos < position && position < child.end) { + forEachChild(child, visitNode, visitArray); + return true; + } + } + } + } + } + return false; + } + } + } function createSourceFile(filename, sourceText, languageVersion, setParentNodes) { if (setParentNodes === void 0) { setParentNodes = false; } var parsingContext; - var identifiers = {}; + var identifiers; var identifierCount = 0; var nodeCount = 0; var lineStarts; - var contextFlags = 0; - var parseErrorBeforeNextFinishedNode = false; - var sourceFile = createNode(207 /* SourceFile */, 0); - if (ts.fileExtensionIs(filename, ".d.ts")) { - sourceFile.flags = 1024 /* DeclarationFile */; + var syntacticDiagnostics; + var scanner; + var token; + var syntaxCursor; + var contextFlags; + var parseErrorBeforeNextFinishedNode; + var sourceFile; + return parseSourceFile(sourceText, setParentNodes); + function parseSourceFile(text, setParentNodes) { + sourceText = text; + parsingContext = 0; + identifiers = {}; + lineStarts = undefined; + syntacticDiagnostics = undefined; + contextFlags = 0; + parseErrorBeforeNextFinishedNode = false; + sourceFile = createNode(207 /* SourceFile */, 0); + sourceFile.referenceDiagnostics = []; + sourceFile.parseDiagnostics = []; + sourceFile.semanticDiagnostics = []; + scanner = ts.createScanner(languageVersion, true, sourceText, scanError); + token = nextToken(); + sourceFile.flags = ts.fileExtensionIs(filename, ".d.ts") ? 1024 /* DeclarationFile */ : 0; + sourceFile.end = sourceText.length; + sourceFile.filename = ts.normalizePath(filename); + sourceFile.text = sourceText; + sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition; + sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter; + sourceFile.getLineStarts = getLineStarts; + sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics; + sourceFile.update = update; + processReferenceComments(sourceFile); + sourceFile.statements = parseList(0 /* SourceElements */, true, parseSourceElement); + ts.Debug.assert(token === 1 /* EndOfFileToken */); + sourceFile.endOfFileToken = parseTokenNode(); + setExternalModuleIndicator(sourceFile); + sourceFile.nodeCount = nodeCount; + sourceFile.identifierCount = identifierCount; + sourceFile.languageVersion = languageVersion; + sourceFile.identifiers = identifiers; + if (setParentNodes) { + fixupParentReferences(sourceFile); + } + return sourceFile; } - sourceFile.end = sourceText.length; - sourceFile.filename = ts.normalizePath(filename); - sourceFile.text = sourceText; - sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition; - sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter; - sourceFile.getLineStarts = getLineStarts; - sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics; - sourceFile.referenceDiagnostics = []; - sourceFile.parseDiagnostics = []; - sourceFile.grammarDiagnostics = []; - sourceFile.semanticDiagnostics = []; - processReferenceComments(); - var scanner = ts.createScanner(languageVersion, true, sourceText, scanError); - var token = nextToken(); - sourceFile.statements = parseList(0 /* SourceElements */, true, parseSourceElement); - ts.Debug.assert(token === 1 /* EndOfFileToken */); - sourceFile.endOfFileToken = parseTokenNode(); - sourceFile.externalModuleIndicator = getExternalModuleIndicator(); - sourceFile.nodeCount = nodeCount; - sourceFile.identifierCount = identifierCount; - sourceFile.languageVersion = languageVersion; - sourceFile.identifiers = identifiers; - if (setParentNodes) { - fixupParentReferences(sourceFile); + function update(newText, textChangeRange) { + if (ts.textChangeRangeIsUnchanged(textChangeRange)) { + return sourceFile; + } + if (sourceFile.statements.length === 0) { + return parseSourceFile(newText, true); + } + syntaxCursor = createSyntaxCursor(sourceFile); + var changeRange = extendToAffectedRange(textChangeRange); + var delta = ts.textChangeRangeNewSpan(changeRange).length - changeRange.span.length; + updateTokenPositionsAndMarkElements(sourceFile, changeRange.span.start, ts.textSpanEnd(changeRange.span), ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)), delta); + var result = parseSourceFile(newText, true); + syntaxCursor = undefined; + return result; + } + function updateTokenPositionsAndMarkElements(node, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta) { + visitNode(node); + function visitNode(child) { + if (child.pos > changeRangeOldEnd) { + moveElementEntirelyPastChangeRange(child, delta); + return; + } + var fullEnd = child.end; + if (fullEnd >= changeStart) { + child.intersectsChange = true; + adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); + forEachChild(child, visitNode, visitArray); + return; + } + } + function visitArray(array) { + if (array.pos > changeRangeOldEnd) { + moveElementEntirelyPastChangeRange(array, delta); + } + else { + var fullEnd = array.end; + if (fullEnd >= changeStart) { + array.intersectsChange = true; + adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); + for (var i = 0, n = array.length; i < n; i++) { + visitNode(array[i]); + } + } + } + } + } + function adjustIntersectingElement(element, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta) { + ts.Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range"); + ts.Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range"); + element.pos = Math.min(element.pos, changeRangeNewEnd); + if (element.end >= changeRangeOldEnd) { + element.end += delta; + } + else { + element.end = Math.min(element.end, changeRangeNewEnd); + } + ts.Debug.assert(element.pos <= element.end); + if (element.parent) { + ts.Debug.assert(element.pos >= element.parent.pos); + ts.Debug.assert(element.end <= element.parent.end); + } + } + function moveElementEntirelyPastChangeRange(element, delta) { + if (element.length) { + visitArray(element); + } + else { + visitNode(element); + } + function visitNode(node) { + node._children = undefined; + node.pos += delta; + node.end += delta; + forEachChild(node, visitNode, visitArray); + } + function visitArray(array) { + array.pos += delta; + array.end += delta; + for (var i = 0, n = array.length; i < n; i++) { + visitNode(array[i]); + } + } + } + function extendToAffectedRange(changeRange) { + var maxLookahead = 1; + var start = changeRange.span.start; + for (var i = 0; start > 0 && i <= maxLookahead; i++) { + var nearestNode = findNearestNodeStartingBeforeOrAtPosition(start); + var position = nearestNode.pos; + start = Math.max(0, position - 1); + } + var finalSpan = ts.createTextSpanFromBounds(start, ts.textSpanEnd(changeRange.span)); + var finalLength = changeRange.newLength + (changeRange.span.start - start); + return ts.createTextChangeRange(finalSpan, finalLength); + } + function findNearestNodeStartingBeforeOrAtPosition(position) { + var bestResult = sourceFile; + var lastNodeEntirelyBeforePosition; + forEachChild(sourceFile, visit); + if (lastNodeEntirelyBeforePosition) { + var lastChildOfLastEntireNodeBeforePosition = getLastChild(lastNodeEntirelyBeforePosition); + if (lastChildOfLastEntireNodeBeforePosition.pos > bestResult.pos) { + bestResult = lastChildOfLastEntireNodeBeforePosition; + } + } + return bestResult; + function getLastChild(node) { + while (true) { + var lastChild = getLastChildWorker(node); + if (lastChild) { + node = lastChild; + } + else { + return node; + } + } + } + function getLastChildWorker(node) { + var last = undefined; + forEachChild(node, function (child) { + if (ts.nodeIsPresent(child)) { + last = child; + } + }); + return last; + } + function visit(child) { + if (ts.nodeIsMissing(child)) { + return; + } + if (child.pos <= position) { + if (child.pos >= bestResult.pos) { + bestResult = child; + } + if (position < child.end) { + forEachChild(child, visit); + return true; + } + else { + ts.Debug.assert(child.end <= position); + lastNodeEntirelyBeforePosition = child; + } + } + else { + ts.Debug.assert(child.pos > position); + return true; + } + } } - return sourceFile; function setContextFlag(val, flag) { if (val) { contextFlags |= flag; @@ -3426,9 +4368,9 @@ var ts; } parseErrorBeforeNextFinishedNode = true; } - function scanError(message) { + function scanError(message, length) { var pos = scanner.getTextPos(); - parseErrorAtPosition(pos, 0, message); + parseErrorAtPosition(pos, length || 0, message); } function getNodePos() { return scanner.getStartPos(); @@ -3480,13 +4422,13 @@ var ts; } return inStrictModeContext() ? token > 109 /* LastFutureReservedWord */ : token > 100 /* LastReservedWord */; } - function parseExpected(kind, diagnosticMessage, arg0) { + function parseExpected(kind, diagnosticMessage) { if (token === kind) { nextToken(); return true; } if (diagnosticMessage) { - parseErrorAtCurrentToken(diagnosticMessage, arg0); + parseErrorAtCurrentToken(diagnosticMessage); } else { parseErrorAtCurrentToken(ts.Diagnostics._0_expected, ts.tokenToString(kind)); @@ -3514,7 +4456,7 @@ var ts; } return token === 15 /* CloseBraceToken */ || token === 1 /* EndOfFileToken */ || scanner.hasPrecedingLineBreak(); } - function parseSemicolon(diagnosticMessage) { + function parseSemicolon() { if (canParseSemicolon()) { if (token === 22 /* SemicolonToken */) { nextToken(); @@ -3522,7 +4464,7 @@ var ts; return true; } else { - return parseExpected(22 /* SemicolonToken */, diagnosticMessage); + return parseExpected(22 /* SemicolonToken */); } } function createNode(kind, pos) { @@ -3623,14 +4565,18 @@ var ts; function canFollowModifier() { return token === 18 /* OpenBracketToken */ || token === 35 /* AsteriskToken */ || isLiteralPropertyName(); } - function isListElement(kind, inErrorRecovery) { - switch (kind) { + function isListElement(parsingContext, inErrorRecovery) { + var node = currentNode(parsingContext); + if (node) { + return true; + } + switch (parsingContext) { case 0 /* SourceElements */: case 1 /* ModuleElements */: return isSourceElement(inErrorRecovery); case 2 /* BlockStatements */: case 4 /* SwitchClauseStatements */: - return isStatement(inErrorRecovery); + return isStartOfStatement(inErrorRecovery); case 3 /* SwitchClauses */: return token === 66 /* CaseKeyword */ || token === 72 /* DefaultKeyword */; case 5 /* TypeMembers */: @@ -3648,13 +4594,13 @@ var ts; case 9 /* VariableDeclarations */: return isIdentifierOrPattern(); case 11 /* ArrayBindingElements */: - return token === 23 /* CommaToken */ || isIdentifierOrPattern(); + return token === 23 /* CommaToken */ || token === 21 /* DotDotDotToken */ || isIdentifierOrPattern(); case 16 /* TypeParameters */: return isIdentifier(); case 12 /* ArgumentExpressions */: return token === 23 /* CommaToken */ || isStartOfExpression(); case 14 /* ArrayLiteralMembers */: - return token === 23 /* CommaToken */ || isStartOfExpression(); + return token === 23 /* CommaToken */ || token === 21 /* DotDotDotToken */ || isStartOfExpression(); case 15 /* Parameters */: return isStartOfParameter(); case 17 /* TypeArguments */: @@ -3741,7 +4687,7 @@ var ts; var savedStrictModeContext = inStrictModeContext(); while (!isListTerminator(kind)) { if (isListElement(kind, false)) { - var element = parseElement(); + var element = parseListElement(kind, parseElement); result.push(element); if (checkForStrictMode && !inStrictModeContext()) { if (ts.isPrologueDirective(element)) { @@ -3765,6 +4711,183 @@ var ts; parsingContext = saveParsingContext; return result; } + function parseListElement(kind, parseElement) { + var node = currentNode(kind); + if (node) { + return consumeNode(node); + } + return parseElement(); + } + function currentNode(parsingContext) { + if (parseErrorBeforeNextFinishedNode) { + return undefined; + } + if (!syntaxCursor) { + return undefined; + } + var node = syntaxCursor.currentNode(scanner.getStartPos()); + if (ts.nodeIsMissing(node)) { + return undefined; + } + if (node.intersectsChange) { + return undefined; + } + if (ts.containsParseError(node)) { + return undefined; + } + var nodeContextFlags = node.parserContextFlags & 31 /* ParserGeneratedFlags */; + if (nodeContextFlags !== contextFlags) { + return undefined; + } + if (!canReuseNode(node, parsingContext)) { + return undefined; + } + return node; + } + function consumeNode(node) { + scanner.setTextPos(node.end); + nextToken(); + return node; + } + function canReuseNode(node, parsingContext) { + switch (parsingContext) { + case 1 /* ModuleElements */: + return isReusableModuleElement(node); + case 6 /* ClassMembers */: + return isReusableClassMember(node); + case 3 /* SwitchClauses */: + return isReusableSwitchClause(node); + case 2 /* BlockStatements */: + case 4 /* SwitchClauseStatements */: + return isReusableStatement(node); + case 7 /* EnumMembers */: + return isReusableEnumMember(node); + case 5 /* TypeMembers */: + return isReusableTypeMember(node); + case 9 /* VariableDeclarations */: + return isReusableVariableDeclaration(node); + case 15 /* Parameters */: + return isReusableParameter(node); + case 19 /* HeritageClauses */: + case 8 /* TypeReferences */: + case 16 /* TypeParameters */: + case 18 /* TupleElementTypes */: + case 17 /* TypeArguments */: + case 12 /* ArgumentExpressions */: + case 13 /* ObjectLiteralMembers */: + } + return false; + } + function isReusableModuleElement(node) { + if (node) { + switch (node.kind) { + case 197 /* ImportDeclaration */: + case 198 /* ExportAssignment */: + case 191 /* ClassDeclaration */: + case 192 /* InterfaceDeclaration */: + case 195 /* ModuleDeclaration */: + case 194 /* EnumDeclaration */: + case 190 /* FunctionDeclaration */: + case 171 /* VariableStatement */: + case 170 /* Block */: + case 174 /* IfStatement */: + case 173 /* ExpressionStatement */: + case 185 /* ThrowStatement */: + case 181 /* ReturnStatement */: + case 183 /* SwitchStatement */: + case 180 /* BreakStatement */: + case 179 /* ContinueStatement */: + case 178 /* ForInStatement */: + case 177 /* ForStatement */: + case 176 /* WhileStatement */: + case 182 /* WithStatement */: + case 172 /* EmptyStatement */: + case 186 /* TryStatement */: + case 184 /* LabeledStatement */: + case 175 /* DoStatement */: + case 187 /* DebuggerStatement */: + return true; + } + } + return false; + } + function isReusableClassMember(node) { + if (node) { + switch (node.kind) { + case 129 /* Constructor */: + case 134 /* IndexSignature */: + case 128 /* MethodDeclaration */: + case 130 /* GetAccessor */: + case 131 /* SetAccessor */: + case 126 /* PropertyDeclaration */: + return true; + } + } + return false; + } + function isReusableSwitchClause(node) { + if (node) { + switch (node.kind) { + case 200 /* CaseClause */: + case 201 /* DefaultClause */: + return true; + } + } + return false; + } + function isReusableStatement(node) { + if (node) { + switch (node.kind) { + case 190 /* FunctionDeclaration */: + case 171 /* VariableStatement */: + case 170 /* Block */: + case 174 /* IfStatement */: + case 173 /* ExpressionStatement */: + case 185 /* ThrowStatement */: + case 181 /* ReturnStatement */: + case 183 /* SwitchStatement */: + case 180 /* BreakStatement */: + case 179 /* ContinueStatement */: + case 178 /* ForInStatement */: + case 177 /* ForStatement */: + case 176 /* WhileStatement */: + case 182 /* WithStatement */: + case 172 /* EmptyStatement */: + case 186 /* TryStatement */: + case 184 /* LabeledStatement */: + case 175 /* DoStatement */: + case 187 /* DebuggerStatement */: + return true; + } + } + return false; + } + function isReusableEnumMember(node) { + return node.kind === 206 /* EnumMember */; + } + function isReusableTypeMember(node) { + if (node) { + switch (node.kind) { + case 133 /* ConstructSignature */: + case 127 /* MethodSignature */: + case 134 /* IndexSignature */: + case 125 /* PropertySignature */: + case 132 /* CallSignature */: + return true; + } + } + return false; + } + function isReusableVariableDeclaration(node) { + if (node.kind !== 188 /* VariableDeclaration */) { + return false; + } + var variableDeclarator = node; + return variableDeclarator.initializer === undefined; + } + function isReusableParameter(node) { + return node.kind === 124 /* Parameter */; + } function abortParsingListOrMoveToNextToken(kind) { parseErrorAtCurrentToken(parsingContextErrors(kind)); if (isInSomeParsingContext()) { @@ -3781,7 +4904,7 @@ var ts; var commaStart = -1; while (true) { if (isListElement(kind, false)) { - result.push(parseElement()); + result.push(parseListElement(kind, parseElement)); commaStart = scanner.getTokenPos(); if (parseOptional(23 /* CommaToken */)) { continue; @@ -3860,7 +4983,7 @@ var ts; return finishNode(template); } function parseTemplateSpan() { - var span = createNode(168 /* TemplateSpan */); + var span = createNode(169 /* TemplateSpan */); span.expression = allowInAnd(parseExpression); var literal; if (token === 15 /* CloseBraceToken */) { @@ -4026,7 +5149,8 @@ var ts; nextToken(); return token === 51 /* ColonToken */ || token === 23 /* CommaToken */ || token === 19 /* CloseBracketToken */; } - function parseIndexSignatureDeclaration(fullStart, modifiers) { + function parseIndexSignatureDeclaration(modifiers) { + var fullStart = modifiers ? modifiers.pos : scanner.getStartPos(); var node = createNode(134 /* IndexSignature */, fullStart); setModifiers(node, modifiers); node.parameters = parseBracketedList(15 /* Parameters */, parseParameter, 18 /* OpenBracketToken */, 19 /* CloseBracketToken */); @@ -4062,9 +5186,21 @@ var ts; case 18 /* OpenBracketToken */: return true; default: + if (ts.isModifier(token)) { + var result = lookAhead(isStartOfIndexSignatureDeclaration); + if (result) { + return result; + } + } return isLiteralPropertyName() && lookAhead(isTypeMemberWithLiteralPropertyName); } } + function isStartOfIndexSignatureDeclaration() { + while (ts.isModifier(token)) { + nextToken(); + } + return isIndexSignature(); + } function isTypeMemberWithLiteralPropertyName() { nextToken(); return token === 16 /* OpenParenToken */ || token === 24 /* LessThanToken */ || token === 50 /* QuestionToken */ || token === 51 /* ColonToken */ || canParseSemicolon(); @@ -4075,7 +5211,7 @@ var ts; case 24 /* LessThanToken */: return parseSignatureMember(132 /* CallSignature */); case 18 /* OpenBracketToken */: - return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), undefined) : parsePropertyOrMethodSignature(); + return isIndexSignature() ? parseIndexSignatureDeclaration(undefined) : parsePropertyOrMethodSignature(); case 87 /* NewKeyword */: if (lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(133 /* ConstructSignature */); @@ -4084,11 +5220,21 @@ var ts; case 7 /* NumericLiteral */: return parsePropertyOrMethodSignature(); default: + if (ts.isModifier(token)) { + var result = tryParse(parseIndexSignatureWithModifiers); + if (result) { + return result; + } + } if (isIdentifierOrKeyword()) { return parsePropertyOrMethodSignature(); } } } + function parseIndexSignatureWithModifiers() { + var modifiers = parseModifiers(); + return isIndexSignature() ? parseIndexSignatureDeclaration(modifiers) : undefined; + } function isStartOfConstructSignature() { nextToken(); return token === 16 /* OpenParenToken */ || token === 24 /* LessThanToken */; @@ -4445,7 +5591,7 @@ var ts; if (token === 14 /* OpenBraceToken */) { return parseFunctionBlock(false, false); } - if (isStatement(true) && !isStartOfExpressionStatement() && token !== 82 /* FunctionKeyword */) { + if (isStartOfStatement(true) && !isStartOfExpressionStatement() && token !== 82 /* FunctionKeyword */) { return parseFunctionBlock(false, true); } return parseAssignmentExpressionOrHigher(); @@ -4720,16 +5866,16 @@ var ts; } function parsePrimaryExpression() { switch (token) { + case 7 /* NumericLiteral */: + case 8 /* StringLiteral */: + case 10 /* NoSubstitutionTemplateLiteral */: + return parseLiteralNode(); case 92 /* ThisKeyword */: case 90 /* SuperKeyword */: case 88 /* NullKeyword */: case 94 /* TrueKeyword */: case 79 /* FalseKeyword */: return parseTokenNode(); - case 7 /* NumericLiteral */: - case 8 /* StringLiteral */: - case 10 /* NoSubstitutionTemplateLiteral */: - return parseLiteralNode(); case 16 /* OpenParenToken */: return parseParenthesizedExpression(); case 18 /* OpenBracketToken */: @@ -4759,10 +5905,16 @@ var ts; return finishNode(node); } function parseAssignmentExpressionOrOmittedExpression() { - return token === 23 /* CommaToken */ ? createNode(167 /* OmittedExpression */) : parseAssignmentExpressionOrHigher(); + return token === 23 /* CommaToken */ ? createNode(168 /* OmittedExpression */) : parseAssignmentExpressionOrHigher(); + } + function parseSpreadElement() { + var node = createNode(167 /* SpreadElementExpression */); + parseExpected(21 /* DotDotDotToken */); + node.expression = parseAssignmentExpressionOrHigher(); + return finishNode(node); } function parseArrayLiteralElement() { - return parseAssignmentExpressionOrOmittedExpression(); + return token === 21 /* DotDotDotToken */ ? parseSpreadElement() : parseAssignmentExpressionOrOmittedExpression(); } function parseArgumentExpression() { return allowInAnd(parseAssignmentExpressionOrOmittedExpression); @@ -4776,21 +5928,30 @@ var ts; parseExpected(19 /* CloseBracketToken */); return finishNode(node); } + function tryParseAccessorDeclaration(fullStart, modifiers) { + if (parseContextualModifier(114 /* GetKeyword */)) { + return parseAccessorDeclaration(130 /* GetAccessor */, fullStart, modifiers); + } + else if (parseContextualModifier(118 /* SetKeyword */)) { + return parseAccessorDeclaration(131 /* SetAccessor */, fullStart, modifiers); + } + return undefined; + } function parseObjectLiteralElement() { var fullStart = scanner.getStartPos(); - var initialToken = token; - if (parseContextualModifier(114 /* GetKeyword */) || parseContextualModifier(118 /* SetKeyword */)) { - var kind = initialToken === 114 /* GetKeyword */ ? 130 /* GetAccessor */ : 131 /* SetAccessor */; - return parseAccessorDeclaration(kind, fullStart, undefined); + var modifiers = parseModifiers(); + var accessor = tryParseAccessorDeclaration(fullStart, modifiers); + if (accessor) { + return accessor; } var asteriskToken = parseOptionalToken(35 /* AsteriskToken */); var tokenIsIdentifier = isIdentifier(); var nameToken = token; var propertyName = parsePropertyName(); - if (asteriskToken || token === 16 /* OpenParenToken */ || token === 24 /* LessThanToken */) { - return parseMethodDeclaration(fullStart, undefined, asteriskToken, propertyName, undefined, true); - } var questionToken = parseOptionalToken(50 /* QuestionToken */); + if (asteriskToken || token === 16 /* OpenParenToken */ || token === 24 /* LessThanToken */) { + return parseMethodDeclaration(fullStart, modifiers, asteriskToken, propertyName, questionToken); + } if ((token === 23 /* CommaToken */ || token === 15 /* CloseBraceToken */) && tokenIsIdentifier) { var shorthandDeclaration = createNode(205 /* ShorthandPropertyAssignment */, fullStart); shorthandDeclaration.name = propertyName; @@ -4838,9 +5999,9 @@ var ts; } return finishNode(node); } - function parseBlock(kind, ignoreMissingOpenBrace, checkForStrictMode) { - var node = createNode(kind); - if (parseExpected(14 /* OpenBraceToken */) || ignoreMissingOpenBrace) { + function parseBlock(ignoreMissingOpenBrace, checkForStrictMode, diagnosticMessage) { + var node = createNode(170 /* Block */); + if (parseExpected(14 /* OpenBraceToken */, diagnosticMessage) || ignoreMissingOpenBrace) { node.statements = parseList(2 /* BlockStatements */, checkForStrictMode, parseStatement); parseExpected(15 /* CloseBraceToken */); } @@ -4849,20 +6010,20 @@ var ts; } return finishNode(node); } - function parseFunctionBlock(allowYield, ignoreMissingOpenBrace) { + function parseFunctionBlock(allowYield, ignoreMissingOpenBrace, diagnosticMessage) { var savedYieldContext = inYieldContext(); setYieldContext(allowYield); - var block = parseBlock(169 /* Block */, ignoreMissingOpenBrace, true); + var block = parseBlock(ignoreMissingOpenBrace, true, diagnosticMessage); setYieldContext(savedYieldContext); return block; } function parseEmptyStatement() { - var node = createNode(171 /* EmptyStatement */); + var node = createNode(172 /* EmptyStatement */); parseExpected(22 /* SemicolonToken */); return finishNode(node); } function parseIfStatement() { - var node = createNode(173 /* IfStatement */); + var node = createNode(174 /* IfStatement */); parseExpected(83 /* IfKeyword */); parseExpected(16 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); @@ -4872,7 +6033,7 @@ var ts; return finishNode(node); } function parseDoStatement() { - var node = createNode(174 /* DoStatement */); + var node = createNode(175 /* DoStatement */); parseExpected(74 /* DoKeyword */); node.statement = parseStatement(); parseExpected(99 /* WhileKeyword */); @@ -4883,7 +6044,7 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(175 /* WhileStatement */); + var node = createNode(176 /* WhileStatement */); parseExpected(99 /* WhileKeyword */); parseExpected(16 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); @@ -4895,41 +6056,26 @@ var ts; var pos = getNodePos(); parseExpected(81 /* ForKeyword */); parseExpected(16 /* OpenParenToken */); + var initializer = undefined; if (token !== 22 /* SemicolonToken */) { - if (parseOptional(97 /* VarKeyword */)) { - var declarations = disallowInAnd(parseVariableDeclarationList); - } - else if (parseOptional(103 /* LetKeyword */)) { - var declarations = setFlag(disallowInAnd(parseVariableDeclarationList), 2048 /* Let */); - } - else if (parseOptional(69 /* ConstKeyword */)) { - var declarations = setFlag(disallowInAnd(parseVariableDeclarationList), 4096 /* Const */); + if (token === 97 /* VarKeyword */ || token === 103 /* LetKeyword */ || token === 69 /* ConstKeyword */) { + initializer = parseVariableDeclarationList(true); } else { - var varOrInit = disallowInAnd(parseExpression); + initializer = disallowInAnd(parseExpression); } } var forOrForInStatement; if (parseOptional(85 /* InKeyword */)) { - var forInStatement = createNode(177 /* ForInStatement */, pos); - if (declarations) { - forInStatement.declarations = declarations; - } - else { - forInStatement.variable = varOrInit; - } + var forInStatement = createNode(178 /* ForInStatement */, pos); + forInStatement.initializer = initializer; forInStatement.expression = allowInAnd(parseExpression); parseExpected(17 /* CloseParenToken */); forOrForInStatement = forInStatement; } else { - var forStatement = createNode(176 /* ForStatement */, pos); - if (declarations) { - forStatement.declarations = declarations; - } - if (varOrInit) { - forStatement.initializer = varOrInit; - } + var forStatement = createNode(177 /* ForStatement */, pos); + forStatement.initializer = initializer; parseExpected(22 /* SemicolonToken */); if (token !== 22 /* SemicolonToken */ && token !== 17 /* CloseParenToken */) { forStatement.condition = allowInAnd(parseExpression); @@ -4946,7 +6092,7 @@ var ts; } function parseBreakOrContinueStatement(kind) { var node = createNode(kind); - parseExpected(kind === 179 /* BreakStatement */ ? 65 /* BreakKeyword */ : 70 /* ContinueKeyword */); + parseExpected(kind === 180 /* BreakStatement */ ? 65 /* BreakKeyword */ : 70 /* ContinueKeyword */); if (!canParseSemicolon()) { node.label = parseIdentifier(); } @@ -4954,7 +6100,7 @@ var ts; return finishNode(node); } function parseReturnStatement() { - var node = createNode(180 /* ReturnStatement */); + var node = createNode(181 /* ReturnStatement */); parseExpected(89 /* ReturnKeyword */); if (!canParseSemicolon()) { node.expression = allowInAnd(parseExpression); @@ -4963,7 +6109,7 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(181 /* WithStatement */); + var node = createNode(182 /* WithStatement */); parseExpected(100 /* WithKeyword */); parseExpected(16 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); @@ -4990,7 +6136,7 @@ var ts; return token === 66 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(182 /* SwitchStatement */); + var node = createNode(183 /* SwitchStatement */); parseExpected(91 /* SwitchKeyword */); parseExpected(16 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); @@ -5001,26 +6147,23 @@ var ts; return finishNode(node); } function parseThrowStatement() { - var node = createNode(184 /* ThrowStatement */); + var node = createNode(185 /* ThrowStatement */); parseExpected(93 /* ThrowKeyword */); node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression); parseSemicolon(); return finishNode(node); } function parseTryStatement() { - var node = createNode(185 /* TryStatement */); - node.tryBlock = parseTokenAndBlock(95 /* TryKeyword */); + var node = createNode(186 /* TryStatement */); + parseExpected(95 /* TryKeyword */); + node.tryBlock = parseBlock(false, false); node.catchClause = token === 67 /* CatchKeyword */ ? parseCatchClause() : undefined; - node.finallyBlock = !node.catchClause || token === 80 /* FinallyKeyword */ ? parseTokenAndBlock(80 /* FinallyKeyword */) : undefined; + if (!node.catchClause || token === 80 /* FinallyKeyword */) { + parseExpected(80 /* FinallyKeyword */); + node.finallyBlock = parseBlock(false, false); + } return finishNode(node); } - function parseTokenAndBlock(token) { - var pos = getNodePos(); - parseExpected(token); - var result = parseBlock(token === 95 /* TryKeyword */ ? 186 /* TryBlock */ : 187 /* FinallyBlock */, false, false); - result.pos = pos; - return result; - } function parseCatchClause() { var result = createNode(203 /* CatchClause */); parseExpected(67 /* CatchKeyword */); @@ -5028,11 +6171,11 @@ var ts; result.name = parseIdentifier(); result.type = parseTypeAnnotation(); parseExpected(17 /* CloseParenToken */); - result.block = parseBlock(169 /* Block */, false, false); + result.block = parseBlock(false, false); return finishNode(result); } function parseDebuggerStatement() { - var node = createNode(188 /* DebuggerStatement */); + var node = createNode(187 /* DebuggerStatement */); parseExpected(71 /* DebuggerKeyword */); parseSemicolon(); return finishNode(node); @@ -5041,19 +6184,25 @@ var ts; var fullStart = scanner.getStartPos(); var expression = allowInAnd(parseExpression); if (expression.kind === 64 /* Identifier */ && parseOptional(51 /* ColonToken */)) { - var labeledStatement = createNode(183 /* LabeledStatement */, fullStart); + var labeledStatement = createNode(184 /* LabeledStatement */, fullStart); labeledStatement.label = expression; labeledStatement.statement = parseStatement(); return finishNode(labeledStatement); } else { - var expressionStatement = createNode(172 /* ExpressionStatement */, fullStart); + var expressionStatement = createNode(173 /* ExpressionStatement */, fullStart); expressionStatement.expression = expression; parseSemicolon(); return finishNode(expressionStatement); } } - function isStatement(inErrorRecovery) { + function isStartOfStatement(inErrorRecovery) { + if (ts.isModifier(token)) { + var result = lookAhead(parseVariableStatementOrFunctionDeclarationWithModifiers); + if (result) { + return true; + } + } switch (token) { case 22 /* SemicolonToken */: return !inErrorRecovery; @@ -5109,7 +6258,7 @@ var ts; function parseStatement() { switch (token) { case 14 /* OpenBraceToken */: - return parseBlock(169 /* Block */, false, false); + return parseBlock(false, false); case 97 /* VarKeyword */: case 69 /* ConstKeyword */: return parseVariableStatement(scanner.getStartPos(), undefined); @@ -5126,9 +6275,9 @@ var ts; case 81 /* ForKeyword */: return parseForOrForInStatement(); case 70 /* ContinueKeyword */: - return parseBreakOrContinueStatement(178 /* ContinueStatement */); + return parseBreakOrContinueStatement(179 /* ContinueStatement */); case 65 /* BreakKeyword */: - return parseBreakOrContinueStatement(179 /* BreakStatement */); + return parseBreakOrContinueStatement(180 /* BreakStatement */); case 89 /* ReturnKeyword */: return parseReturnStatement(); case 100 /* WithKeyword */: @@ -5148,21 +6297,50 @@ var ts; return parseVariableStatement(scanner.getStartPos(), undefined); } default: + if (ts.isModifier(token)) { + var result = tryParse(parseVariableStatementOrFunctionDeclarationWithModifiers); + if (result) { + return result; + } + } return parseExpressionOrLabeledStatement(); } } - function parseFunctionBlockOrSemicolon(isGenerator) { - if (token === 14 /* OpenBraceToken */) { - return parseFunctionBlock(isGenerator, false); + function parseVariableStatementOrFunctionDeclarationWithModifiers() { + var start = scanner.getStartPos(); + var modifiers = parseModifiers(); + switch (token) { + case 69 /* ConstKeyword */: + var nextTokenIsEnum = lookAhead(nextTokenIsEnumKeyword); + if (nextTokenIsEnum) { + return undefined; + } + return parseVariableStatement(start, modifiers); + case 103 /* LetKeyword */: + if (!isLetDeclaration()) { + return undefined; + } + return parseVariableStatement(start, modifiers); + case 97 /* VarKeyword */: + return parseVariableStatement(start, modifiers); + case 82 /* FunctionKeyword */: + return parseFunctionDeclaration(start, modifiers); } - parseSemicolon(ts.Diagnostics.or_expected); return undefined; } + function parseFunctionBlockOrSemicolon(isGenerator, diagnosticMessage) { + if (token !== 14 /* OpenBraceToken */ && canParseSemicolon()) { + parseSemicolon(); + return; + } + return parseFunctionBlock(isGenerator, false, diagnosticMessage); + } function parseArrayBindingElement() { if (token === 23 /* CommaToken */) { - return createNode(167 /* OmittedExpression */); + return createNode(168 /* OmittedExpression */); } var node = createNode(146 /* BindingElement */); + node.dotDotDotToken = parseOptionalToken(21 /* DotDotDotToken */); node.name = parseIdentifierOrPattern(); node.initializer = parseInitializer(false); return finishNode(node); @@ -5208,40 +6386,37 @@ var ts; return parseIdentifier(); } function parseVariableDeclaration() { - var node = createNode(189 /* VariableDeclaration */); + var node = createNode(188 /* VariableDeclaration */); node.name = parseIdentifierOrPattern(); node.type = parseTypeAnnotation(); node.initializer = parseInitializer(false); return finishNode(node); } - function setFlag(nodes, flag) { - for (var i = 0; i < nodes.length; i++) { - var node = nodes[i]; - node.flags |= flag; - if (node.name && ts.isBindingPattern(node.name)) { - setFlag(node.name.elements, flag); - } - } - return nodes; - } - function parseVariableDeclarationList() { - return parseDelimitedList(9 /* VariableDeclarations */, parseVariableDeclaration); - } - function parseVariableStatement(fullStart, modifiers) { - var node = createNode(170 /* VariableStatement */, fullStart); - setModifiers(node, modifiers); - if (token === 103 /* LetKeyword */) { - node.flags |= 2048 /* Let */; - } - else if (token === 69 /* ConstKeyword */) { - node.flags |= 4096 /* Const */; - } - else { - ts.Debug.assert(token === 97 /* VarKeyword */); + function parseVariableDeclarationList(disallowIn) { + var node = createNode(189 /* VariableDeclarationList */); + switch (token) { + case 97 /* VarKeyword */: + break; + case 103 /* LetKeyword */: + node.flags |= 2048 /* Let */; + break; + case 69 /* ConstKeyword */: + node.flags |= 4096 /* Const */; + break; + default: + ts.Debug.fail(); } nextToken(); - node.declarations = allowInAnd(parseVariableDeclarationList); - setFlag(node.declarations, node.flags); + var savedDisallowIn = inDisallowInContext(); + setDisallowInContext(disallowIn); + node.declarations = parseDelimitedList(9 /* VariableDeclarations */, parseVariableDeclaration); + setDisallowInContext(savedDisallowIn); + return finishNode(node); + } + function parseVariableStatement(fullStart, modifiers) { + var node = createNode(171 /* VariableStatement */, fullStart); + setModifiers(node, modifiers); + node.declarationList = parseVariableDeclarationList(false); parseSemicolon(); return finishNode(node); } @@ -5252,7 +6427,7 @@ var ts; node.asteriskToken = parseOptionalToken(35 /* AsteriskToken */); node.name = parseIdentifier(); fillSignature(51 /* ColonToken */, !!node.asteriskToken, false, node); - node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken); + node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, ts.Diagnostics.or_expected); return finishNode(node); } function parseConstructorDeclaration(pos, modifiers) { @@ -5260,17 +6435,17 @@ var ts; setModifiers(node, modifiers); parseExpected(112 /* ConstructorKeyword */); fillSignature(51 /* ColonToken */, false, false, node); - node.body = parseFunctionBlockOrSemicolon(false); + node.body = parseFunctionBlockOrSemicolon(false, ts.Diagnostics.or_expected); return finishNode(node); } - function parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, requireBlock) { + function parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, diagnosticMessage) { var method = createNode(128 /* MethodDeclaration */, fullStart); setModifiers(method, modifiers); method.asteriskToken = asteriskToken; method.name = name; method.questionToken = questionToken; fillSignature(51 /* ColonToken */, !!asteriskToken, false, method); - method.body = requireBlock ? parseFunctionBlock(!!asteriskToken, false) : parseFunctionBlockOrSemicolon(!!asteriskToken); + method.body = parseFunctionBlockOrSemicolon(!!asteriskToken, diagnosticMessage); return finishNode(method); } function parsePropertyOrMethodDeclaration(fullStart, modifiers) { @@ -5278,7 +6453,7 @@ var ts; var name = parsePropertyName(); var questionToken = parseOptionalToken(50 /* QuestionToken */); if (asteriskToken || token === 16 /* OpenParenToken */ || token === 24 /* LessThanToken */) { - return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, false); + return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected); } else { var property = createNode(126 /* PropertyDeclaration */, fullStart); @@ -5360,17 +6535,15 @@ var ts; function parseClassElement() { var fullStart = getNodePos(); var modifiers = parseModifiers(); - if (parseContextualModifier(114 /* GetKeyword */)) { - return parseAccessorDeclaration(130 /* GetAccessor */, fullStart, modifiers); - } - if (parseContextualModifier(118 /* SetKeyword */)) { - return parseAccessorDeclaration(131 /* SetAccessor */, fullStart, modifiers); + var accessor = tryParseAccessorDeclaration(fullStart, modifiers); + if (accessor) { + return accessor; } if (token === 112 /* ConstructorKeyword */) { return parseConstructorDeclaration(fullStart, modifiers); } if (isIndexSignature()) { - return parseIndexSignatureDeclaration(fullStart, modifiers); + return parseIndexSignatureDeclaration(modifiers); } if (isIdentifierOrKeyword() || token === 8 /* StringLiteral */ || token === 7 /* NumericLiteral */ || token === 35 /* AsteriskToken */ || token === 18 /* OpenBracketToken */) { return parsePropertyOrMethodDeclaration(fullStart, modifiers); @@ -5606,7 +6779,7 @@ var ts; } } function isSourceElement(inErrorRecovery) { - return isDeclarationStart() || isStatement(inErrorRecovery); + return isDeclarationStart() || isStartOfStatement(inErrorRecovery); } function parseSourceElement() { return parseSourceElementOrModuleElement(); @@ -5617,7 +6790,7 @@ var ts; function parseSourceElementOrModuleElement() { return isDeclarationStart() ? parseDeclaration() : parseStatement(); } - function processReferenceComments() { + function processReferenceComments(sourceFile) { var triviaScanner = ts.createScanner(languageVersion, false, sourceText); var referencedFiles = []; var amdDependencies = []; @@ -5664,10 +6837,9 @@ var ts; sourceFile.amdDependencies = amdDependencies; sourceFile.amdModuleName = amdModuleName; } - function getExternalModuleIndicator() { - return ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 197 /* ImportDeclaration */ && node.moduleReference.kind === 199 /* ExternalModuleReference */ || node.kind === 198 /* ExportAssignment */ ? node : undefined; }); + function setExternalModuleIndicator(sourceFile) { + sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 197 /* ImportDeclaration */ && node.moduleReference.kind === 199 /* ExternalModuleReference */ || node.kind === 198 /* ExportAssignment */ ? node : undefined; }); } - var syntacticDiagnostics; function getSyntacticDiagnostics() { if (syntacticDiagnostics === undefined) { syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics); @@ -5710,228 +6882,15 @@ var ts; return token >= 52 /* FirstAssignment */ && token <= 63 /* LastAssignment */; } ts.isAssignmentOperator = isAssignmentOperator; - function createProgram(rootNames, options, host) { - var program; - var files = []; - var filesByName = {}; - var errors = []; - var seenNoDefaultLib = options.noLib; - var commonSourceDirectory; - ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); - if (!seenNoDefaultLib) { - processRootFile(host.getDefaultLibFilename(options), true); - } - verifyCompilerOptions(); - errors.sort(ts.compareDiagnostics); - program = { - getSourceFile: getSourceFile, - getSourceFiles: function () { return files; }, - getCompilerOptions: function () { return options; }, - getCompilerHost: function () { return host; }, - getDiagnostics: getDiagnostics, - getGlobalDiagnostics: getGlobalDiagnostics, - getTypeChecker: function (fullTypeCheckMode) { return ts.createTypeChecker(program, fullTypeCheckMode); }, - getCommonSourceDirectory: function () { return commonSourceDirectory; } - }; - return program; - function getSourceFile(filename) { - filename = host.getCanonicalFileName(filename); - return ts.hasProperty(filesByName, filename) ? filesByName[filename] : undefined; - } - function getDiagnostics(sourceFile) { - return sourceFile ? ts.filter(errors, function (e) { return e.file === sourceFile; }) : errors; - } - function getGlobalDiagnostics() { - return ts.filter(errors, function (e) { return !e.file; }); - } - function hasExtension(filename) { - return ts.getBaseFilename(filename).indexOf(".") >= 0; - } - function processRootFile(filename, isDefaultLib) { - processSourceFile(ts.normalizePath(filename), isDefaultLib); - } - function processSourceFile(filename, isDefaultLib, refFile, refPos, refEnd) { - if (refEnd !== undefined && refPos !== undefined) { - var start = refPos; - var length = refEnd - refPos; - } - var diagnostic; - if (hasExtension(filename)) { - if (!options.allowNonTsExtensions && !ts.fileExtensionIs(filename, ".ts")) { - diagnostic = ts.Diagnostics.File_0_must_have_extension_ts_or_d_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))) { - diagnostic = ts.Diagnostics.File_0_not_found; - filename += ".ts"; - } - } - if (diagnostic) { - if (refFile) { - errors.push(ts.createFileDiagnostic(refFile, start, length, diagnostic, filename)); - } - else { - errors.push(ts.createCompilerDiagnostic(diagnostic, filename)); - } - } - } - function findSourceFile(filename, isDefaultLib, refFile, refStart, refLength) { - var canonicalName = host.getCanonicalFileName(filename); - if (ts.hasProperty(filesByName, canonicalName)) { - return getSourceFileFromCache(filename, canonicalName, false); - } - else { - var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(filename, host.getCurrentDirectory()); - var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (ts.hasProperty(filesByName, canonicalAbsolutePath)) { - return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); - } - var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, function (hostErrorMessage) { - if (refFile) { - errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); - } - else { - errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); - } - }); - if (file) { - seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; - filesByName[canonicalAbsolutePath] = file; - if (!options.noResolve) { - var basePath = ts.getDirectoryPath(filename); - processReferencedFiles(file, basePath); - processImportedModules(file, basePath); - } - if (isDefaultLib) { - files.unshift(file); - } - else { - files.push(file); - } - ts.forEach(file.getSyntacticDiagnostics(), function (e) { - errors.push(e); - }); - } - } - return file; - function getSourceFileFromCache(filename, canonicalName, useAbsolutePath) { - var file = filesByName[canonicalName]; - if (file && host.useCaseSensitiveFileNames()) { - var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.filename, host.getCurrentDirectory()) : file.filename; - if (canonicalName !== sourceFileName) { - errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, sourceFileName)); - } - } - return file; - } - } - function processReferencedFiles(file, basePath) { - ts.forEach(file.referencedFiles, function (ref) { - 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 (ts.isExternalModuleImportDeclaration(node) && ts.getExternalModuleImportDeclarationExpression(node).kind === 8 /* StringLiteral */) { - var nameLiteral = ts.getExternalModuleImportDeclarationExpression(node); - var moduleName = nameLiteral.text; - if (moduleName) { - var searchPath = basePath; - while (true) { - var searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleName)); - if (findModuleSourceFile(searchName + ".ts", nameLiteral) || findModuleSourceFile(searchName + ".d.ts", nameLiteral)) { - break; - } - var parentPath = ts.getDirectoryPath(searchPath); - if (parentPath === searchPath) { - break; - } - searchPath = parentPath; - } - } - } - else if (node.kind === 195 /* ModuleDeclaration */ && node.name.kind === 8 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || ts.isDeclarationFile(file))) { - forEachChild(node.body, function (node) { - if (ts.isExternalModuleImportDeclaration(node) && ts.getExternalModuleImportDeclarationExpression(node).kind === 8 /* StringLiteral */) { - var nameLiteral = ts.getExternalModuleImportDeclarationExpression(node); - var moduleName = nameLiteral.text; - if (moduleName) { - var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName)); - var tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral); - if (!tsFile) { - findModuleSourceFile(searchName + ".d.ts", nameLiteral); - } - } - } - }); - } - }); - function findModuleSourceFile(filename, nameLiteral) { - return findSourceFile(filename, false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos); - } - } - function verifyCompilerOptions() { - if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { - if (options.mapRoot) { - errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option)); - } - if (options.sourceRoot) { - errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option)); - } - return; - } - var firstExternalModule = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (firstExternalModule && options.module === 0 /* None */) { - var externalModuleErrorSpan = ts.getErrorSpanForNode(firstExternalModule.externalModuleIndicator); - var errorStart = ts.skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos); - var errorLength = externalModuleErrorSpan.end - errorStart; - errors.push(ts.createFileDiagnostic(firstExternalModule, errorStart, errorLength, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); - } - if (options.outDir || options.sourceRoot || (options.mapRoot && (!options.out || firstExternalModule !== undefined))) { - var commonPathComponents; - ts.forEach(files, function (sourceFile) { - if (!(sourceFile.flags & 1024 /* DeclarationFile */) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { - var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory()); - sourcePathComponents.pop(); - if (commonPathComponents) { - for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) { - if (commonPathComponents[i] !== sourcePathComponents[i]) { - if (i === 0) { - errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); - return; - } - commonPathComponents.length = i; - break; - } - } - if (sourcePathComponents.length < commonPathComponents.length) { - commonPathComponents.length = sourcePathComponents.length; - } - } - else { - commonPathComponents = sourcePathComponents; - } - } - }); - commonSourceDirectory = ts.getNormalizedPathFromPathComponents(commonPathComponents); - if (commonSourceDirectory) { - commonSourceDirectory += ts.directorySeparator; - } - } - } - } - ts.createProgram = createProgram; })(ts || (ts = {})); var ts; (function (ts) { + (function (ModuleInstanceState) { + ModuleInstanceState[ModuleInstanceState["NonInstantiated"] = 0] = "NonInstantiated"; + ModuleInstanceState[ModuleInstanceState["Instantiated"] = 1] = "Instantiated"; + ModuleInstanceState[ModuleInstanceState["ConstEnumOnly"] = 2] = "ConstEnumOnly"; + })(ts.ModuleInstanceState || (ts.ModuleInstanceState = {})); + var ModuleInstanceState = ts.ModuleInstanceState; function getModuleInstanceState(node) { if (node.kind === 192 /* InterfaceDeclaration */) { return 0 /* NonInstantiated */; @@ -6080,7 +7039,7 @@ var ts; if (symbolKind & 1536 /* Namespace */) { exportKind |= 4194304 /* ExportNamespace */; } - if (node.flags & 1 /* Export */ || (node.kind !== 197 /* ImportDeclaration */ && isAmbientContext(container))) { + if (ts.getCombinedNodeFlags(node) & 1 /* Export */ || (node.kind !== 197 /* 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); @@ -6104,9 +7063,7 @@ var ts; parent = node; if (symbolKind & 262128 /* IsContainer */) { container = node; - ts.Debug.assert(container.nextContainer === undefined); if (lastContainer) { - ts.Debug.assert(lastContainer.nextContainer === undefined); lastContainer.nextContainer = container; } lastContainer = container; @@ -6234,12 +7191,12 @@ var ts; case 124 /* Parameter */: bindParameter(node); break; - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: if (ts.isBindingPattern(node.name)) { bindChildren(node, 0, false); } - else if (node.flags & 6144 /* BlockScoped */) { + else if (ts.getCombinedNodeFlags(node) & 6144 /* BlockScoped */) { bindBlockScopedVariableDeclaration(node); } else { @@ -6323,13 +7280,11 @@ var ts; bindAnonymousDeclaration(node, 512 /* ValueModule */, '"' + ts.removeFileExtension(node.filename) + '"', true); break; } - case 169 /* Block */: - case 186 /* TryBlock */: + case 170 /* Block */: case 203 /* CatchClause */: - case 187 /* FinallyBlock */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 182 /* SwitchStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 183 /* SwitchStatement */: bindChildren(node, 0, true); break; default: @@ -6355,3434 +7310,27 @@ var ts; ts.bindSourceFile = bindSourceFile; })(ts || (ts = {})); var ts; -(function (ts) { - var indentStrings = ["", " "]; - function getIndentString(level) { - if (indentStrings[level] === undefined) { - indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; - } - return indentStrings[level]; - } - ts.getIndentString = getIndentString; - function getIndentSize() { - return indentStrings[1].length; - } - function shouldEmitToOwnFile(sourceFile, compilerOptions) { - if (!ts.isDeclarationFile(sourceFile)) { - if ((ts.isExternalModule(sourceFile) || !compilerOptions.out) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { - return true; - } - return false; - } - return false; - } - ts.shouldEmitToOwnFile = shouldEmitToOwnFile; - function isExternalModuleOrDeclarationFile(sourceFile) { - return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); - } - ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; - function createTextWriter(newLine) { - var output = ""; - var indent = 0; - var lineStart = true; - var lineCount = 0; - var linePos = 0; - function write(s) { - if (s && s.length) { - if (lineStart) { - output += getIndentString(indent); - lineStart = false; - } - output += s; - } - } - function rawWrite(s) { - if (s !== undefined) { - if (lineStart) { - lineStart = false; - } - output += s; - } - } - function writeLiteral(s) { - if (s && s.length) { - write(s); - var lineStartsOfS = ts.computeLineStarts(s); - if (lineStartsOfS.length > 1) { - lineCount = lineCount + lineStartsOfS.length - 1; - linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; - } - } - } - function writeLine() { - if (!lineStart) { - output += newLine; - lineCount++; - linePos = output.length; - lineStart = true; - } - } - function writeTextOfNode(sourceFile, node) { - write(ts.getSourceTextOfNodeFromSourceFile(sourceFile, node)); - } - return { - write: write, - rawWrite: rawWrite, - writeTextOfNode: writeTextOfNode, - writeLiteral: writeLiteral, - writeLine: writeLine, - increaseIndent: function () { return indent++; }, - decreaseIndent: function () { return indent--; }, - getIndent: function () { return indent; }, - getTextPos: function () { return output.length; }, - getLine: function () { return lineCount + 1; }, - getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; }, - getText: function () { return output; } - }; - } - function getLineOfLocalPosition(currentSourceFile, pos) { - return currentSourceFile.getLineAndCharacterFromPosition(pos).line; - } - function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) { - if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) { - writer.writeLine(); - } - } - function emitComments(currentSourceFile, writer, comments, trailingSeparator, newLine, writeComment) { - var emitLeadingSpace = !trailingSeparator; - ts.forEach(comments, function (comment) { - if (emitLeadingSpace) { - writer.write(" "); - emitLeadingSpace = false; - } - writeComment(currentSourceFile, writer, comment, newLine); - if (comment.hasTrailingNewLine) { - writer.writeLine(); - } - else if (trailingSeparator) { - writer.write(" "); - } - else { - emitLeadingSpace = true; - } - }); - } - function writeCommentRange(currentSourceFile, writer, comment, newLine) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) { - var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos); - var firstCommentLineIndent; - for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1); - if (pos !== comment.pos) { - if (firstCommentLineIndent === undefined) { - firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, 1), comment.pos); - } - var currentWriterIndentSpacing = writer.getIndent() * getIndentSize(); - var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart); - if (spacesToEmit > 0) { - var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize(); - var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize()); - writer.rawWrite(indentSizeSpaceString); - while (numberOfSingleSpacesToEmit) { - writer.rawWrite(" "); - numberOfSingleSpacesToEmit--; - } - } - else { - writer.rawWrite(""); - } - } - writeTrimmedCurrentLine(pos, nextLineStart); - pos = nextLineStart; - } - } - else { - writer.write(currentSourceFile.text.substring(comment.pos, comment.end)); - } - function writeTrimmedCurrentLine(pos, nextLineStart) { - var end = Math.min(comment.end, nextLineStart - 1); - var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ''); - if (currentLineText) { - writer.write(currentLineText); - if (end !== comment.end) { - writer.writeLine(); - } - } - else { - writer.writeLiteral(newLine); - } - } - function calculateIndent(pos, end) { - var currentLineIndent = 0; - for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { - if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) { - currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); - } - else { - currentLineIndent++; - } - } - return currentLineIndent; - } - } - function getFirstConstructorWithBody(node) { - return ts.forEach(node.members, function (member) { - if (member.kind === 129 /* Constructor */ && member.body) { - return member; - } - }); - } - function getAllAccessorDeclarations(node, accessor) { - var firstAccessor; - var getAccessor; - var setAccessor; - if (accessor.name.kind === 122 /* ComputedPropertyName */) { - firstAccessor = accessor; - if (accessor.kind === 130 /* GetAccessor */) { - getAccessor = accessor; - } - else if (accessor.kind === 131 /* SetAccessor */) { - setAccessor = accessor; - } - else { - ts.Debug.fail("Accessor has wrong kind"); - } - } - else { - ts.forEach(node.members, function (member) { - if ((member.kind === 130 /* GetAccessor */ || member.kind === 131 /* SetAccessor */) && member.name.text === accessor.name.text && (member.flags & 128 /* Static */) === (accessor.flags & 128 /* Static */)) { - if (!firstAccessor) { - firstAccessor = member; - } - if (member.kind === 130 /* GetAccessor */ && !getAccessor) { - getAccessor = member; - } - if (member.kind === 131 /* SetAccessor */ && !setAccessor) { - setAccessor = member; - } - } - }); - } - return { - firstAccessor: firstAccessor, - getAccessor: getAccessor, - setAccessor: setAccessor - }; - } - function getSourceFilePathInNewDir(sourceFile, program, newDirPath) { - var compilerHost = program.getCompilerHost(); - var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.filename, compilerHost.getCurrentDirectory()); - sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), ""); - return ts.combinePaths(newDirPath, sourceFilePath); - } - function getOwnEmitOutputFilePath(sourceFile, program, extension) { - var compilerOptions = program.getCompilerOptions(); - if (compilerOptions.outDir) { - var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, program, compilerOptions.outDir)); - } - else { - var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename); - } - return emitOutputFilePathWithoutExtension + extension; - } - function writeFile(compilerHost, diagnostics, filename, data, writeByteOrderMark) { - compilerHost.writeFile(filename, data, writeByteOrderMark, function (hostErrorMessage) { - diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage)); - }); - } - function emitDeclarations(program, resolver, diagnostics, jsFilePath, root) { - var newLine = program.getCompilerHost().getNewLine(); - var compilerOptions = program.getCompilerOptions(); - var compilerHost = program.getCompilerHost(); - var write; - var writeLine; - var increaseIndent; - var decreaseIndent; - var writeTextOfNode; - var writer = createAndSetNewTextWriterWithSymbolWriter(); - var enclosingDeclaration; - var currentSourceFile; - var reportedDeclarationError = false; - var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { - } : writeJsDocComments; - var aliasDeclarationEmitInfo = []; - function createAndSetNewTextWriterWithSymbolWriter() { - var writer = createTextWriter(newLine); - 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; - setWriter(writer); - return writer; - } - function setWriter(newWriter) { - writer = newWriter; - write = newWriter.write; - writeTextOfNode = newWriter.writeTextOfNode; - writeLine = newWriter.writeLine; - increaseIndent = newWriter.increaseIndent; - decreaseIndent = newWriter.decreaseIndent; - } - function writeAsychronousImportDeclarations(importDeclarations) { - var oldWriter = writer; - ts.forEach(importDeclarations, function (aliasToWrite) { - var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; }); - if (aliasEmitInfo) { - createAndSetNewTextWriterWithSymbolWriter(); - for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { - increaseIndent(); - } - writeImportDeclaration(aliasToWrite); - aliasEmitInfo.asynchronousOutput = writer.getText(); - } - }); - setWriter(oldWriter); - } - function handleSymbolAccessibilityError(symbolAccesibilityResult) { - if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) { - if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { - writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); - } - } - else { - reportedDeclarationError = true; - var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult); - if (errorInfo) { - if (errorInfo.typeName) { - diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName)); - } - else { - diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName)); - } - } - } - } - function trackSymbol(symbol, enclosingDeclaration, meaning) { - handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); - } - function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - write(": "); - if (type) { - emitType(type); - } - else { - resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); - } - } - function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - write(": "); - if (signature.type) { - emitType(signature.type); - } - else { - resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); - } - } - function emitLines(nodes) { - for (var i = 0, n = nodes.length; i < n; i++) { - emitNode(nodes[i]); - } - } - function emitSeparatedList(nodes, separator, eachNodeEmitFn) { - var currentWriterPos = writer.getTextPos(); - for (var i = 0, n = nodes.length; i < n; i++) { - if (currentWriterPos !== writer.getTextPos()) { - write(separator); - } - currentWriterPos = writer.getTextPos(); - eachNodeEmitFn(nodes[i]); - } - } - function emitCommaList(nodes, eachNodeEmitFn) { - emitSeparatedList(nodes, ", ", eachNodeEmitFn); - } - function writeJsDocComments(declaration) { - if (declaration) { - var jsDocComments = ts.getJsDocComments(declaration, currentSourceFile); - emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments); - emitComments(currentSourceFile, writer, jsDocComments, true, newLine, writeCommentRange); - } - } - function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type, getSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - emitType(type); - } - function emitType(type) { - switch (type.kind) { - case 110 /* AnyKeyword */: - case 119 /* StringKeyword */: - case 117 /* NumberKeyword */: - case 111 /* BooleanKeyword */: - case 98 /* VoidKeyword */: - case 8 /* StringLiteral */: - return writeTextOfNode(currentSourceFile, type); - case 135 /* TypeReference */: - return emitTypeReference(type); - case 138 /* TypeQuery */: - return emitTypeQuery(type); - case 140 /* ArrayType */: - return emitArrayType(type); - case 141 /* TupleType */: - return emitTupleType(type); - case 142 /* UnionType */: - return emitUnionType(type); - case 143 /* ParenthesizedType */: - return emitParenType(type); - case 136 /* FunctionType */: - case 137 /* ConstructorType */: - return emitSignatureDeclarationWithJsDocComments(type); - case 139 /* TypeLiteral */: - return emitTypeLiteral(type); - case 64 /* Identifier */: - return emitEntityName(type); - case 121 /* QualifiedName */: - return emitEntityName(type); - default: - ts.Debug.fail("Unknown type annotation: " + type.kind); - } - function emitEntityName(entityName) { - var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 197 /* ImportDeclaration */ ? entityName.parent : enclosingDeclaration); - handleSymbolAccessibilityError(visibilityResult); - writeEntityName(entityName); - function writeEntityName(entityName) { - if (entityName.kind === 64 /* Identifier */) { - writeTextOfNode(currentSourceFile, entityName); - } - else { - var qualifiedName = entityName; - writeEntityName(qualifiedName.left); - write("."); - writeTextOfNode(currentSourceFile, qualifiedName.right); - } - } - } - function emitTypeReference(type) { - emitEntityName(type.typeName); - if (type.typeArguments) { - write("<"); - emitCommaList(type.typeArguments, emitType); - write(">"); - } - } - function emitTypeQuery(type) { - write("typeof "); - emitEntityName(type.exprName); - } - function emitArrayType(type) { - emitType(type.elementType); - write("[]"); - } - function emitTupleType(type) { - write("["); - emitCommaList(type.elementTypes, emitType); - write("]"); - } - function emitUnionType(type) { - emitSeparatedList(type.types, " | ", emitType); - } - function emitParenType(type) { - write("("); - emitType(type.type); - write(")"); - } - function emitTypeLiteral(type) { - write("{"); - if (type.members.length) { - writeLine(); - increaseIndent(); - emitLines(type.members); - decreaseIndent(); - } - write("}"); - } - } - function emitSourceFile(node) { - currentSourceFile = node; - enclosingDeclaration = node; - emitLines(node.statements); - } - function emitExportAssignment(node) { - write("export = "); - writeTextOfNode(currentSourceFile, node.exportName); - write(";"); - writeLine(); - } - function emitModuleElementDeclarationFlags(node) { - if (node.parent === currentSourceFile) { - if (node.flags & 1 /* Export */) { - write("export "); - } - if (node.kind !== 192 /* InterfaceDeclaration */) { - write("declare "); - } - } - } - function emitClassMemberDeclarationFlags(node) { - if (node.flags & 32 /* Private */) { - write("private "); - } - else if (node.flags & 64 /* Protected */) { - write("protected "); - } - if (node.flags & 128 /* Static */) { - write("static "); - } - } - function emitImportDeclaration(node) { - var nodeEmitInfo = { - declaration: node, - outputPos: writer.getTextPos(), - indent: writer.getIndent(), - hasWritten: resolver.isDeclarationVisible(node) - }; - aliasDeclarationEmitInfo.push(nodeEmitInfo); - if (nodeEmitInfo.hasWritten) { - writeImportDeclaration(node); - } - } - function writeImportDeclaration(node) { - emitJsDocComments(node); - if (node.flags & 1 /* Export */) { - write("export "); - } - write("import "); - writeTextOfNode(currentSourceFile, node.name); - write(" = "); - if (ts.isInternalModuleImportDeclaration(node)) { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError); - write(";"); - } - else { - write("require("); - writeTextOfNode(currentSourceFile, ts.getExternalModuleImportDeclarationExpression(node)); - write(");"); - } - writer.writeLine(); - function getImportEntityNameVisibilityError(symbolAccesibilityResult) { - return { - diagnosticMessage: ts.Diagnostics.Import_declaration_0_is_using_private_name_1, - errorNode: node, - typeName: node.name - }; - } - } - function emitModuleDeclaration(node) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("module "); - writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== 196 /* ModuleBlock */) { - node = node.body; - write("."); - writeTextOfNode(currentSourceFile, node.name); - } - var prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.body.statements); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - function emitTypeAliasDeclaration(node) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("type "); - writeTextOfNode(currentSourceFile, node.name); - write(" = "); - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); - write(";"); - writeLine(); - } - function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) { - return { - diagnosticMessage: ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, - errorNode: node.type, - typeName: node.name - }; - } - } - function emitEnumDeclaration(node) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (ts.isConst(node)) { - write("const "); - } - write("enum "); - writeTextOfNode(currentSourceFile, node.name); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - } - } - function emitEnumMemberDeclaration(node) { - emitJsDocComments(node); - writeTextOfNode(currentSourceFile, node.name); - var enumMemberValue = resolver.getEnumMemberValue(node); - if (enumMemberValue !== undefined) { - write(" = "); - write(enumMemberValue.toString()); - } - write(","); - writeLine(); - } - function isPrivateMethodTypeParameter(node) { - return node.parent.kind === 128 /* MethodDeclaration */ && (node.parent.flags & 32 /* Private */); - } - function emitTypeParameters(typeParameters) { - function emitTypeParameter(node) { - increaseIndent(); - emitJsDocComments(node); - decreaseIndent(); - writeTextOfNode(currentSourceFile, node.name); - if (node.constraint && !isPrivateMethodTypeParameter(node)) { - write(" extends "); - if (node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || (node.parent.parent && node.parent.parent.kind === 139 /* TypeLiteral */)) { - ts.Debug.assert(node.parent.kind === 128 /* MethodDeclaration */ || node.parent.kind === 127 /* MethodSignature */ || node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || node.parent.kind === 132 /* CallSignature */ || node.parent.kind === 133 /* ConstructSignature */); - emitType(node.constraint); - } - else { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError); - } - } - function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - switch (node.parent.kind) { - case 191 /* ClassDeclaration */: - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; - break; - case 192 /* InterfaceDeclaration */: - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; - break; - case 133 /* ConstructSignature */: - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - case 132 /* CallSignature */: - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - if (node.parent.flags & 128 /* Static */) { - diagnosticMessage = 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 === 191 /* ClassDeclaration */) { - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; - } - else { - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; - } - break; - case 190 /* FunctionDeclaration */: - diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; - break; - default: - ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind); - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: node, - typeName: node.name - }; - } - } - if (typeParameters) { - write("<"); - emitCommaList(typeParameters, emitTypeParameter); - write(">"); - } - } - function emitHeritageClause(typeReferences, isImplementsList) { - if (typeReferences) { - write(isImplementsList ? " implements " : " extends "); - emitCommaList(typeReferences, emitTypeOfTypeReference); - } - function emitTypeOfTypeReference(node) { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); - function getHeritageClauseVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - if (node.parent.parent.kind === 191 /* ClassDeclaration */) { - diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; - } - else { - diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: node, - typeName: node.parent.parent.name - }; - } - } - } - function emitClassDeclaration(node) { - function emitParameterProperties(constructorDeclaration) { - if (constructorDeclaration) { - ts.forEach(constructorDeclaration.parameters, function (param) { - if (param.flags & 112 /* AccessibilityModifier */) { - emitPropertyDeclaration(param); - } - }); - } - } - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("class "); - writeTextOfNode(currentSourceFile, node.name); - var prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - var baseTypeNode = ts.getClassBaseTypeNode(node); - if (baseTypeNode) { - emitHeritageClause([baseTypeNode], false); - } - emitHeritageClause(ts.getClassImplementedTypeNodes(node), true); - write(" {"); - writeLine(); - increaseIndent(); - emitParameterProperties(getFirstConstructorWithBody(node)); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - function emitInterfaceDeclaration(node) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("interface "); - writeTextOfNode(currentSourceFile, node.name); - var prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - emitHeritageClause(ts.getInterfaceBaseTypeNodes(node), false); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - function emitPropertyDeclaration(node) { - emitJsDocComments(node); - emitClassMemberDeclarationFlags(node); - emitVariableDeclaration(node); - write(";"); - writeLine(); - } - function emitVariableDeclaration(node) { - if (node.kind !== 189 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { - writeTextOfNode(currentSourceFile, node.name); - if ((node.kind === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) && ts.hasQuestionToken(node)) { - write("?"); - } - if ((node.kind === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) && node.parent.kind === 139 /* TypeLiteral */) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); - } - else if (!(node.flags & 32 /* Private */)) { - writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); - } - } - function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - if (node.kind === 189 /* 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 === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) { - 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 === 191 /* 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 { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; - } - } - return diagnosticMessage !== undefined ? { - diagnosticMessage: diagnosticMessage, - errorNode: node, - typeName: node.name - } : undefined; - } - } - function emitTypeOfVariableDeclarationFromTypeLiteral(node) { - if (node.type) { - write(": "); - emitType(node.type); - } - } - function emitVariableStatement(node) { - var hasDeclarationWithEmit = ts.forEach(node.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); }); - if (hasDeclarationWithEmit) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (ts.isLet(node)) { - write("let "); - } - else if (ts.isConst(node)) { - write("const "); - } - else { - write("var "); - } - emitCommaList(node.declarations, emitVariableDeclaration); - write(";"); - writeLine(); - } - } - function emitAccessorDeclaration(node) { - var accessors = getAllAccessorDeclarations(node.parent, node); - if (node === accessors.firstAccessor) { - emitJsDocComments(accessors.getAccessor); - emitJsDocComments(accessors.setAccessor); - emitClassMemberDeclarationFlags(node); - writeTextOfNode(currentSourceFile, node.name); - if (!(node.flags & 32 /* Private */)) { - var accessorWithTypeAnnotation = node; - var type = getTypeAnnotationFromAccessor(node); - if (!type) { - var anotherAccessor = node.kind === 130 /* GetAccessor */ ? accessors.setAccessor : accessors.getAccessor; - type = getTypeAnnotationFromAccessor(anotherAccessor); - if (type) { - accessorWithTypeAnnotation = anotherAccessor; - } - } - writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError); - } - write(";"); - writeLine(); - } - function getTypeAnnotationFromAccessor(accessor) { - if (accessor) { - return accessor.kind === 130 /* GetAccessor */ ? accessor.type : accessor.parameters[0].type; - } - } - function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - if (accessorWithTypeAnnotation.kind === 131 /* SetAccessor */) { - if (accessorWithTypeAnnotation.parent.flags & 128 /* Static */) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; - } - else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: accessorWithTypeAnnotation.parameters[0], - typeName: accessorWithTypeAnnotation.name - }; - } - else { - if (accessorWithTypeAnnotation.flags & 128 /* Static */) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; - } - else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: accessorWithTypeAnnotation.name, - typeName: undefined - }; - } - } - } - function emitFunctionDeclaration(node) { - if ((node.kind !== 190 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { - emitJsDocComments(node); - if (node.kind === 190 /* FunctionDeclaration */) { - emitModuleElementDeclarationFlags(node); - } - else if (node.kind === 128 /* MethodDeclaration */) { - emitClassMemberDeclarationFlags(node); - } - if (node.kind === 190 /* FunctionDeclaration */) { - write("function "); - writeTextOfNode(currentSourceFile, node.name); - } - else if (node.kind === 129 /* Constructor */) { - write("constructor"); - } - else { - writeTextOfNode(currentSourceFile, node.name); - if (ts.hasQuestionToken(node)) { - write("?"); - } - } - emitSignatureDeclaration(node); - } - } - function emitSignatureDeclarationWithJsDocComments(node) { - emitJsDocComments(node); - emitSignatureDeclaration(node); - } - function emitSignatureDeclaration(node) { - if (node.kind === 133 /* ConstructSignature */ || node.kind === 137 /* ConstructorType */) { - write("new "); - } - emitTypeParameters(node.typeParameters); - if (node.kind === 134 /* IndexSignature */) { - write("["); - } - else { - write("("); - } - var prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitCommaList(node.parameters, emitParameterDeclaration); - if (node.kind === 134 /* IndexSignature */) { - write("]"); - } - else { - write(")"); - } - var isFunctionTypeOrConstructorType = node.kind === 136 /* FunctionType */ || node.kind === 137 /* ConstructorType */; - if (isFunctionTypeOrConstructorType || node.parent.kind === 139 /* TypeLiteral */) { - if (node.type) { - write(isFunctionTypeOrConstructorType ? " => " : ": "); - emitType(node.type); - } - } - else if (node.kind !== 129 /* Constructor */ && !(node.flags & 32 /* Private */)) { - writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); - } - enclosingDeclaration = prevEnclosingDeclaration; - if (!isFunctionTypeOrConstructorType) { - write(";"); - writeLine(); - } - function getReturnTypeVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - switch (node.kind) { - case 133 /* ConstructSignature */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - case 132 /* CallSignature */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - case 134 /* IndexSignature */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - 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 === 191 /* 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 190 /* 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: - ts.Debug.fail("This is unknown kind for signature: " + node.kind); - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: node.name || node - }; - } - } - function emitParameterDeclaration(node) { - increaseIndent(); - emitJsDocComments(node); - if (node.dotDotDotToken) { - write("..."); - } - if (ts.isBindingPattern(node.name)) { - write("_" + ts.indexOf(node.parent.parameters, node)); - } - else { - writeTextOfNode(currentSourceFile, node.name); - } - if (node.initializer || ts.hasQuestionToken(node)) { - write("?"); - } - decreaseIndent(); - if (node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || node.parent.parent.kind === 139 /* TypeLiteral */) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); - } - else if (!(node.parent.flags & 32 /* Private */)) { - writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError); - } - function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) { - var diagnosticMessage; - switch (node.parent.kind) { - case 129 /* Constructor */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; - break; - case 133 /* ConstructSignature */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - case 132 /* CallSignature */: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - 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 === 191 /* 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 190 /* 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: - ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind); - } - return { - diagnosticMessage: diagnosticMessage, - errorNode: node, - typeName: node.name - }; - } - } - function emitNode(node) { - switch (node.kind) { - case 129 /* Constructor */: - case 190 /* FunctionDeclaration */: - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - return emitFunctionDeclaration(node); - case 133 /* ConstructSignature */: - case 132 /* CallSignature */: - case 134 /* IndexSignature */: - return emitSignatureDeclarationWithJsDocComments(node); - case 130 /* GetAccessor */: - case 131 /* SetAccessor */: - return emitAccessorDeclaration(node); - case 170 /* VariableStatement */: - return emitVariableStatement(node); - case 126 /* PropertyDeclaration */: - case 125 /* PropertySignature */: - return emitPropertyDeclaration(node); - case 192 /* InterfaceDeclaration */: - return emitInterfaceDeclaration(node); - case 191 /* ClassDeclaration */: - return emitClassDeclaration(node); - case 193 /* TypeAliasDeclaration */: - return emitTypeAliasDeclaration(node); - case 206 /* EnumMember */: - return emitEnumMemberDeclaration(node); - case 194 /* EnumDeclaration */: - return emitEnumDeclaration(node); - case 195 /* ModuleDeclaration */: - return emitModuleDeclaration(node); - case 197 /* ImportDeclaration */: - return emitImportDeclaration(node); - case 198 /* ExportAssignment */: - return emitExportAssignment(node); - case 207 /* SourceFile */: - return emitSourceFile(node); - } - } - var referencePathsOutput = ""; - function writeReferencePath(referencedFile) { - var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, program, ".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 = ts.tryResolveScriptReference(program, root, fileReference); - if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { - writeReferencePath(referencedFile); - if (!isExternalModuleOrDeclarationFile(referencedFile)) { - addedGlobalFileReference = true; - } - } - }); - } - emitNode(root); - } - else { - var emittedReferencedFiles = []; - ts.forEach(program.getSourceFiles(), function (sourceFile) { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - if (!compilerOptions.noResolve) { - ts.forEach(sourceFile.referencedFiles, function (fileReference) { - var referencedFile = ts.tryResolveScriptReference(program, sourceFile, fileReference); - if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) { - writeReferencePath(referencedFile); - emittedReferencedFiles.push(referencedFile); - } - }); - } - emitNode(sourceFile); - } - }); - } - return { - reportedDeclarationError: reportedDeclarationError, - aliasDeclarationEmitInfo: aliasDeclarationEmitInfo, - synchronousDeclarationOutput: writer.getText(), - referencePathsOutput: referencePathsOutput - }; - } - function getDeclarationDiagnostics(program, resolver, targetSourceFile) { - var diagnostics = []; - var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, program, ".js"); - emitDeclarations(program, resolver, diagnostics, jsFilePath, targetSourceFile); - return diagnostics; - } - ts.getDeclarationDiagnostics = getDeclarationDiagnostics; - function emitFiles(resolver, targetSourceFile) { - var program = resolver.getProgram(); - var compilerHost = program.getCompilerHost(); - var compilerOptions = program.getCompilerOptions(); - var sourceMapDataList = compilerOptions.sourceMap ? [] : undefined; - var diagnostics = []; - var newLine = program.getCompilerHost().getNewLine(); - function emitJavaScript(jsFilePath, root) { - var writer = createTextWriter(newLine); - var write = writer.write; - var writeTextOfNode = writer.writeTextOfNode; - var writeLine = writer.writeLine; - var increaseIndent = writer.increaseIndent; - var decreaseIndent = writer.decreaseIndent; - var currentSourceFile; - var extendsEmitted = false; - var tempCount = 0; - var tempVariables; - var tempParameters; - var writeEmittedFiles = writeJavaScriptFile; - var emitLeadingComments = compilerOptions.removeComments ? function (node) { - } : emitLeadingDeclarationComments; - var emitTrailingComments = compilerOptions.removeComments ? function (node) { - } : emitTrailingDeclarationComments; - var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { - } : emitLeadingCommentsOfLocalPosition; - var detachedCommentsInfo; - var emitDetachedComments = compilerOptions.removeComments ? function (node) { - } : emitDetachedCommentsAtPosition; - var emitPinnedOrTripleSlashComments = compilerOptions.removeComments ? function (node) { - } : emitPinnedOrTripleSlashCommentsOfNode; - var writeComment = writeCommentRange; - var emit = emitNode; - var emitStart = function (node) { - }; - var emitEnd = function (node) { - }; - var emitToken = emitTokenText; - var scopeEmitStart = function (scopeDeclaration, scopeName) { - }; - var scopeEmitEnd = function () { - }; - var sourceMapData; - function initializeEmitterWithSourceMaps() { - var sourceMapDir; - var sourceMapSourceIndex = -1; - var sourceMapNameIndexMap = {}; - var sourceMapNameIndices = []; - function getSourceMapNameIndex() { - return sourceMapNameIndices.length ? sourceMapNameIndices[sourceMapNameIndices.length - 1] : -1; - } - var lastRecordedSourceMapSpan; - var lastEncodedSourceMapSpan = { - emittedLine: 1, - emittedColumn: 1, - sourceLine: 1, - sourceColumn: 1, - sourceIndex: 0 - }; - var lastEncodedNameIndex = 0; - function encodeLastRecordedSourceMapSpan() { - if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { - return; - } - var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; - if (lastEncodedSourceMapSpan.emittedLine == lastRecordedSourceMapSpan.emittedLine) { - if (sourceMapData.sourceMapMappings) { - sourceMapData.sourceMapMappings += ","; - } - } - else { - for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { - sourceMapData.sourceMapMappings += ";"; - } - prevEncodedEmittedColumn = 1; - } - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); - if (lastRecordedSourceMapSpan.nameIndex >= 0) { - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); - lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; - } - lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; - sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); - function base64VLQFormatEncode(inValue) { - function base64FormatEncode(inValue) { - if (inValue < 64) { - return 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.charAt(inValue); - } - throw TypeError(inValue + ": not a 64 based value"); - } - if (inValue < 0) { - inValue = ((-inValue) << 1) + 1; - } - else { - inValue = inValue << 1; - } - var encodedStr = ""; - do { - var currentDigit = inValue & 31; - inValue = inValue >> 5; - if (inValue > 0) { - currentDigit = currentDigit | 32; - } - encodedStr = encodedStr + base64FormatEncode(currentDigit); - } while (inValue > 0); - return encodedStr; - } - } - function recordSourceMapSpan(pos) { - var sourceLinePos = currentSourceFile.getLineAndCharacterFromPosition(pos); - var emittedLine = writer.getLine(); - var emittedColumn = writer.getColumn(); - if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan.emittedLine != emittedLine || lastRecordedSourceMapSpan.emittedColumn != emittedColumn || (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { - encodeLastRecordedSourceMapSpan(); - lastRecordedSourceMapSpan = { - emittedLine: emittedLine, - emittedColumn: emittedColumn, - sourceLine: sourceLinePos.line, - sourceColumn: sourceLinePos.character, - nameIndex: getSourceMapNameIndex(), - sourceIndex: sourceMapSourceIndex - }; - } - else { - lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; - lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; - lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; - } - } - function recordEmitNodeStartSpan(node) { - recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); - } - function recordEmitNodeEndSpan(node) { - recordSourceMapSpan(node.end); - } - function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { - var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); - recordSourceMapSpan(tokenStartPos); - var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); - recordSourceMapSpan(tokenEndPos); - return tokenEndPos; - } - function recordNewSourceFileStart(node) { - var sourcesDirectoryPath = compilerOptions.sourceRoot ? program.getCommonSourceDirectory() : sourceMapDir; - sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, true)); - sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; - sourceMapData.inputSourceFileNames.push(node.filename); - } - function recordScopeNameOfNode(node, scopeName) { - function recordScopeNameIndex(scopeNameIndex) { - sourceMapNameIndices.push(scopeNameIndex); - } - function recordScopeNameStart(scopeName) { - var scopeNameIndex = -1; - if (scopeName) { - var parentIndex = getSourceMapNameIndex(); - if (parentIndex !== -1) { - scopeName = sourceMapData.sourceMapNames[parentIndex] + "." + scopeName; - } - scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); - if (scopeNameIndex === undefined) { - scopeNameIndex = sourceMapData.sourceMapNames.length; - sourceMapData.sourceMapNames.push(scopeName); - sourceMapNameIndexMap[scopeName] = scopeNameIndex; - } - } - recordScopeNameIndex(scopeNameIndex); - } - if (scopeName) { - recordScopeNameStart(scopeName); - } - else if (node.kind === 190 /* FunctionDeclaration */ || node.kind === 156 /* FunctionExpression */ || node.kind === 128 /* MethodDeclaration */ || node.kind === 127 /* MethodSignature */ || node.kind === 130 /* GetAccessor */ || node.kind === 131 /* SetAccessor */ || node.kind === 195 /* ModuleDeclaration */ || node.kind === 191 /* ClassDeclaration */ || node.kind === 194 /* EnumDeclaration */) { - if (node.name) { - scopeName = node.name.text; - } - recordScopeNameStart(scopeName); - } - else { - recordScopeNameIndex(getSourceMapNameIndex()); - } - } - function recordScopeNameEnd() { - sourceMapNameIndices.pop(); - } - ; - function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { - recordSourceMapSpan(comment.pos); - writeCommentRange(currentSourceFile, writer, comment, newLine); - recordSourceMapSpan(comment.end); - } - function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings) { - if (typeof JSON !== "undefined") { - return JSON.stringify({ - version: version, - file: file, - sourceRoot: sourceRoot, - sources: sources, - names: names, - mappings: mappings - }); - } - 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 += "\"" + ts.escapeString(list[i]) + "\""; - } - return output; - } - } - function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { - encodeLastRecordedSourceMapSpan(); - writeFile(compilerHost, diagnostics, sourceMapData.sourceMapFilePath, serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings), false); - sourceMapDataList.push(sourceMapData); - writeJavaScriptFile(emitOutput + "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL, writeByteOrderMark); - } - var sourceMapJsFile = ts.getBaseFilename(ts.normalizeSlashes(jsFilePath)); - sourceMapData = { - sourceMapFilePath: jsFilePath + ".map", - jsSourceMappingURL: sourceMapJsFile + ".map", - sourceMapFile: sourceMapJsFile, - sourceMapSourceRoot: compilerOptions.sourceRoot || "", - sourceMapSources: [], - inputSourceFileNames: [], - sourceMapNames: [], - sourceMapMappings: "", - sourceMapDecodedMappings: [] - }; - sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); - if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47 /* slash */) { - sourceMapData.sourceMapSourceRoot += ts.directorySeparator; - } - if (compilerOptions.mapRoot) { - sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); - if (root) { - sourceMapDir = ts.getDirectoryPath(getSourceFilePathInNewDir(root, program, sourceMapDir)); - } - 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(), compilerHost.getCanonicalFileName, true); - } - else { - sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); - } - } - else { - sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); - } - function emitNodeWithMap(node) { - if (node) { - if (node.kind != 207 /* SourceFile */) { - recordEmitNodeStartSpan(node); - emitNode(node); - recordEmitNodeEndSpan(node); - } - else { - recordNewSourceFileStart(node); - emitNode(node); - } - } - } - writeEmittedFiles = writeJavaScriptAndSourceMapFile; - emit = emitNodeWithMap; - emitStart = recordEmitNodeStartSpan; - emitEnd = recordEmitNodeEndSpan; - emitToken = writeTextWithSpanRecord; - scopeEmitStart = recordScopeNameOfNode; - scopeEmitEnd = recordScopeNameEnd; - writeComment = writeCommentRangeWithMap; - } - function writeJavaScriptFile(emitOutput, writeByteOrderMark) { - writeFile(compilerHost, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); - } - function createTempVariable(location, forLoopVariable) { - var name = forLoopVariable ? "_i" : undefined; - while (true) { - if (name && resolver.isUnknownIdentifier(location, name)) { - break; - } - name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + 97 /* a */) : tempCount - 25); - tempCount++; - } - var result = ts.createNode(64 /* Identifier */); - result.text = name; - return result; - } - function recordTempDeclaration(name) { - if (!tempVariables) { - tempVariables = []; - } - tempVariables.push(name); - } - function emitTempDeclarations(newLine) { - if (tempVariables) { - if (newLine) { - writeLine(); - } - else { - write(" "); - } - write("var "); - emitCommaList(tempVariables); - write(";"); - } - } - function emitTokenText(tokenKind, startPos, emitFn) { - var tokenString = ts.tokenToString(tokenKind); - if (emitFn) { - emitFn(); - } - else { - write(tokenString); - } - return startPos + tokenString.length; - } - function emitOptional(prefix, node) { - if (node) { - write(prefix); - emit(node); - } - } - function emitTrailingCommaIfPresent(nodeList) { - if (nodeList.hasTrailingComma) { - write(","); - } - } - 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 emitMultiLineList(nodes) { - if (nodes) { - for (var i = 0; i < nodes.length; i++) { - if (i) { - write(","); - } - writeLine(); - emit(nodes[i]); - } - } - } - function emitLines(nodes) { - emitLinesStartingAt(nodes, 0); - } - function emitLinesStartingAt(nodes, startIndex) { - for (var i = startIndex; i < nodes.length; i++) { - writeLine(); - emit(nodes[i]); - } - } - function isBinaryOrOctalIntegerLiteral(text) { - if (text.length <= 0) { - return false; - } - if (text.charCodeAt(1) === 66 /* B */ || text.charCodeAt(1) === 98 /* b */ || text.charCodeAt(1) === 79 /* O */ || text.charCodeAt(1) === 111 /* o */) { - return true; - } - return false; - } - function emitLiteral(node) { - var text = compilerOptions.target < 2 /* ES6 */ && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; - if (compilerOptions.sourceMap && (node.kind === 8 /* StringLiteral */ || ts.isTemplateLiteralKind(node.kind))) { - writer.writeLiteral(text); - } - else if (compilerOptions.target < 2 /* ES6 */ && node.kind === 7 /* NumericLiteral */ && isBinaryOrOctalIntegerLiteral(text)) { - write(node.text); - } - else { - write(text); - } - } - function getTemplateLiteralAsStringLiteral(node) { - return '"' + ts.escapeString(node.text) + '"'; - } - function emitTemplateExpression(node) { - if (compilerOptions.target >= 2 /* ES6 */) { - ts.forEachChild(node, emit); - return; - } - ts.Debug.assert(node.parent.kind !== 153 /* TaggedTemplateExpression */); - var emitOuterParens = ts.isExpression(node.parent) && templateNeedsParens(node, node.parent); - if (emitOuterParens) { - write("("); - } - emitLiteral(node.head); - ts.forEach(node.templateSpans, function (templateSpan) { - var needsParens = templateSpan.expression.kind !== 155 /* ParenthesizedExpression */ && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1 /* GreaterThan */; - write(" + "); - if (needsParens) { - write("("); - } - emit(templateSpan.expression); - if (needsParens) { - write(")"); - } - if (templateSpan.literal.text.length !== 0) { - write(" + "); - emitLiteral(templateSpan.literal); - } - }); - if (emitOuterParens) { - write(")"); - } - function templateNeedsParens(template, parent) { - switch (parent.kind) { - case 151 /* CallExpression */: - case 152 /* NewExpression */: - return parent.expression === template; - case 155 /* ParenthesizedExpression */: - return false; - case 153 /* TaggedTemplateExpression */: - ts.Debug.fail("Path should be unreachable; tagged templates not supported pre-ES6."); - default: - return comparePrecedenceToBinaryPlus(parent) !== -1 /* LessThan */; - } - } - function comparePrecedenceToBinaryPlus(expression) { - ts.Debug.assert(compilerOptions.target <= 1 /* ES5 */); - switch (expression.kind) { - case 163 /* BinaryExpression */: - switch (expression.operator) { - case 35 /* AsteriskToken */: - case 36 /* SlashToken */: - case 37 /* PercentToken */: - return 1 /* GreaterThan */; - case 33 /* PlusToken */: - return 0 /* EqualTo */; - default: - return -1 /* LessThan */; - } - case 164 /* ConditionalExpression */: - return -1 /* LessThan */; - default: - return 1 /* GreaterThan */; - } - } - } - function emitTemplateSpan(span) { - emit(span.expression); - emit(span.literal); - } - function emitExpressionForPropertyName(node) { - if (node.kind === 8 /* StringLiteral */) { - emitLiteral(node); - } - else if (node.kind === 122 /* ComputedPropertyName */) { - emit(node.expression); - } - else { - write("\""); - if (node.kind === 7 /* NumericLiteral */) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - write("\""); - } - } - function isNotExpressionIdentifier(node) { - var parent = node.parent; - switch (parent.kind) { - case 124 /* Parameter */: - case 189 /* VariableDeclaration */: - case 146 /* BindingElement */: - case 126 /* PropertyDeclaration */: - case 125 /* PropertySignature */: - case 204 /* PropertyAssignment */: - case 205 /* ShorthandPropertyAssignment */: - case 206 /* EnumMember */: - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - case 190 /* FunctionDeclaration */: - case 130 /* GetAccessor */: - case 131 /* SetAccessor */: - case 156 /* FunctionExpression */: - case 191 /* ClassDeclaration */: - case 192 /* InterfaceDeclaration */: - case 194 /* EnumDeclaration */: - case 195 /* ModuleDeclaration */: - case 197 /* ImportDeclaration */: - return parent.name === node; - case 179 /* BreakStatement */: - case 178 /* ContinueStatement */: - case 198 /* ExportAssignment */: - return false; - case 183 /* LabeledStatement */: - return node.parent.label === node; - case 203 /* CatchClause */: - return node.parent.name === node; - } - } - function emitExpressionIdentifier(node) { - var prefix = resolver.getExpressionNamePrefix(node); - if (prefix) { - write(prefix); - write("."); - } - writeTextOfNode(currentSourceFile, node); - } - function emitIdentifier(node) { - if (!node.parent) { - write(node.text); - } - else if (!isNotExpressionIdentifier(node)) { - emitExpressionIdentifier(node); - } - else { - writeTextOfNode(currentSourceFile, node); - } - } - function emitThis(node) { - if (resolver.getNodeCheckFlags(node) & 2 /* LexicalThis */) { - write("_this"); - } - else { - write("this"); - } - } - function emitSuper(node) { - var flags = resolver.getNodeCheckFlags(node); - if (flags & 16 /* SuperInstance */) { - write("_super.prototype"); - } - else if (flags & 32 /* SuperStatic */) { - write("_super"); - } - else { - write("super"); - } - } - function emitObjectBindingPattern(node) { - write("{ "); - emitCommaList(node.elements); - emitTrailingCommaIfPresent(node.elements); - write(" }"); - } - function emitArrayBindingPattern(node) { - write("["); - emitCommaList(node.elements); - emitTrailingCommaIfPresent(node.elements); - write("]"); - } - function emitArrayLiteral(node) { - if (node.flags & 256 /* MultiLine */) { - write("["); - increaseIndent(); - emitMultiLineList(node.elements); - emitTrailingCommaIfPresent(node.elements); - decreaseIndent(); - writeLine(); - write("]"); - } - else { - write("["); - emitCommaList(node.elements); - emitTrailingCommaIfPresent(node.elements); - write("]"); - } - } - function emitObjectLiteral(node) { - if (!node.properties.length) { - write("{}"); - } - else if (node.flags & 256 /* MultiLine */) { - write("{"); - increaseIndent(); - emitMultiLineList(node.properties); - if (compilerOptions.target >= 1 /* ES5 */) { - emitTrailingCommaIfPresent(node.properties); - } - decreaseIndent(); - writeLine(); - write("}"); - } - else { - write("{ "); - emitCommaList(node.properties); - if (compilerOptions.target >= 1 /* ES5 */) { - emitTrailingCommaIfPresent(node.properties); - } - write(" }"); - } - } - function emitComputedPropertyName(node) { - write("["); - emit(node.expression); - write("]"); - } - function emitMethod(node) { - if (!ts.isObjectLiteralMethod(node)) { - return; - } - emitLeadingComments(node); - emit(node.name); - if (compilerOptions.target < 2 /* ES6 */) { - write(": function "); - } - emitSignatureAndBody(node); - emitTrailingComments(node); - } - function emitPropertyAssignment(node) { - emitLeadingComments(node); - emit(node.name); - write(": "); - emit(node.initializer); - emitTrailingComments(node); - } - function emitShorthandPropertyAssignment(node) { - emitLeadingComments(node); - emit(node.name); - if (compilerOptions.target < 2 /* ES6 */ || resolver.getExpressionNamePrefix(node.name)) { - write(": "); - emitExpressionIdentifier(node.name); - } - emitTrailingComments(node); - } - function tryEmitConstantValue(node) { - var constantValue = resolver.getConstantValue(node); - if (constantValue !== undefined) { - var propertyName = node.kind === 149 /* PropertyAccessExpression */ ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); - write(constantValue.toString() + " /* " + propertyName + " */"); - return true; - } - return false; - } - function emitPropertyAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - write("."); - emit(node.name); - } - function emitQualifiedName(node) { - emit(node.left); - write("."); - emit(node.right); - } - function emitIndexedAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - write("["); - emit(node.argumentExpression); - write("]"); - } - function emitCallExpression(node) { - var superCall = false; - if (node.expression.kind === 90 /* SuperKeyword */) { - write("_super"); - superCall = true; - } - else { - emit(node.expression); - superCall = node.expression.kind === 149 /* PropertyAccessExpression */ && node.expression.expression.kind === 90 /* SuperKeyword */; - } - if (superCall) { - write(".call("); - emitThis(node.expression); - if (node.arguments.length) { - write(", "); - emitCommaList(node.arguments); - } - write(")"); - } - else { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - function emitNewExpression(node) { - write("new "); - emit(node.expression); - if (node.arguments) { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - function emitTaggedTemplateExpression(node) { - ts.Debug.assert(compilerOptions.target >= 2 /* ES6 */, "Trying to emit a tagged template in pre-ES6 mode."); - emit(node.tag); - write(" "); - emit(node.template); - } - function emitParenExpression(node) { - if (node.expression.kind === 154 /* TypeAssertionExpression */) { - var operand = node.expression.expression; - while (operand.kind == 154 /* TypeAssertionExpression */) { - operand = operand.expression; - } - if (operand.kind !== 161 /* PrefixUnaryExpression */ && operand.kind !== 160 /* VoidExpression */ && operand.kind !== 159 /* TypeOfExpression */ && operand.kind !== 158 /* DeleteExpression */ && operand.kind !== 162 /* PostfixUnaryExpression */ && operand.kind !== 152 /* NewExpression */ && !(operand.kind === 151 /* CallExpression */ && node.parent.kind === 152 /* NewExpression */) && !(operand.kind === 156 /* FunctionExpression */ && node.parent.kind === 151 /* CallExpression */)) { - emit(operand); - return; - } - } - write("("); - emit(node.expression); - write(")"); - } - function emitDeleteExpression(node) { - write(ts.tokenToString(73 /* DeleteKeyword */)); - write(" "); - emit(node.expression); - } - function emitVoidExpression(node) { - write(ts.tokenToString(98 /* VoidKeyword */)); - write(" "); - emit(node.expression); - } - function emitTypeOfExpression(node) { - write(ts.tokenToString(96 /* TypeOfKeyword */)); - write(" "); - emit(node.expression); - } - function emitPrefixUnaryExpression(node) { - write(ts.tokenToString(node.operator)); - if (node.operand.kind === 161 /* PrefixUnaryExpression */) { - var operand = node.operand; - if (node.operator === 33 /* PlusToken */ && (operand.operator === 33 /* PlusToken */ || operand.operator === 38 /* PlusPlusToken */)) { - write(" "); - } - else if (node.operator === 34 /* MinusToken */ && (operand.operator === 34 /* MinusToken */ || operand.operator === 39 /* MinusMinusToken */)) { - write(" "); - } - } - emit(node.operand); - } - function emitPostfixUnaryExpression(node) { - emit(node.operand); - write(ts.tokenToString(node.operator)); - } - function emitBinaryExpression(node) { - if (node.operator === 52 /* EqualsToken */ && (node.left.kind === 148 /* ObjectLiteralExpression */ || node.left.kind === 147 /* ArrayLiteralExpression */)) { - emitDestructuring(node); - } - else { - emit(node.left); - if (node.operator !== 23 /* CommaToken */) - write(" "); - write(ts.tokenToString(node.operator)); - write(" "); - emit(node.right); - } - } - function emitConditionalExpression(node) { - emit(node.condition); - write(" ? "); - emit(node.whenTrue); - write(" : "); - emit(node.whenFalse); - } - function emitBlock(node) { - emitToken(14 /* OpenBraceToken */, node.pos); - increaseIndent(); - scopeEmitStart(node.parent); - if (node.kind === 196 /* ModuleBlock */) { - ts.Debug.assert(node.parent.kind === 195 /* ModuleDeclaration */); - emitCaptureThisForNodeIfNecessary(node.parent); - } - emitLines(node.statements); - if (node.kind === 196 /* ModuleBlock */) { - emitTempDeclarations(true); - } - decreaseIndent(); - writeLine(); - emitToken(15 /* CloseBraceToken */, node.statements.end); - scopeEmitEnd(); - } - function emitEmbeddedStatement(node) { - if (node.kind === 169 /* Block */) { - write(" "); - emit(node); - } - else { - increaseIndent(); - writeLine(); - emit(node); - decreaseIndent(); - } - } - function emitExpressionStatement(node) { - var isArrowExpression = node.expression.kind === 157 /* ArrowFunction */; - emitLeadingComments(node); - if (isArrowExpression) - write("("); - emit(node.expression); - if (isArrowExpression) - write(")"); - write(";"); - emitTrailingComments(node); - } - function emitIfStatement(node) { - emitLeadingComments(node); - var endPos = emitToken(83 /* IfKeyword */, node.pos); - write(" "); - endPos = emitToken(16 /* OpenParenToken */, endPos); - emit(node.expression); - emitToken(17 /* CloseParenToken */, node.expression.end); - emitEmbeddedStatement(node.thenStatement); - if (node.elseStatement) { - writeLine(); - emitToken(75 /* ElseKeyword */, node.thenStatement.end); - if (node.elseStatement.kind === 173 /* IfStatement */) { - write(" "); - emit(node.elseStatement); - } - else { - emitEmbeddedStatement(node.elseStatement); - } - } - emitTrailingComments(node); - } - function emitDoStatement(node) { - write("do"); - emitEmbeddedStatement(node.statement); - if (node.statement.kind === 169 /* Block */) { - write(" "); - } - else { - writeLine(); - } - write("while ("); - emit(node.expression); - write(");"); - } - function emitWhileStatement(node) { - write("while ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitForStatement(node) { - var endPos = emitToken(81 /* ForKeyword */, node.pos); - write(" "); - endPos = emitToken(16 /* OpenParenToken */, endPos); - if (node.declarations) { - if (node.declarations[0] && ts.isLet(node.declarations[0])) { - emitToken(103 /* LetKeyword */, endPos); - } - else if (node.declarations[0] && ts.isConst(node.declarations[0])) { - emitToken(69 /* ConstKeyword */, endPos); - } - else { - emitToken(97 /* VarKeyword */, endPos); - } - write(" "); - emitCommaList(node.declarations); - } - if (node.initializer) { - emit(node.initializer); - } - write(";"); - emitOptional(" ", node.condition); - write(";"); - emitOptional(" ", node.iterator); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitForInStatement(node) { - var endPos = emitToken(81 /* ForKeyword */, node.pos); - write(" "); - endPos = emitToken(16 /* OpenParenToken */, endPos); - if (node.declarations) { - if (node.declarations.length >= 1) { - var decl = node.declarations[0]; - if (ts.isLet(decl)) { - emitToken(103 /* LetKeyword */, endPos); - } - else { - emitToken(97 /* VarKeyword */, endPos); - } - write(" "); - emit(decl); - } - } - else { - emit(node.variable); - } - write(" in "); - emit(node.expression); - emitToken(17 /* CloseParenToken */, node.expression.end); - emitEmbeddedStatement(node.statement); - } - function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 179 /* BreakStatement */ ? 65 /* BreakKeyword */ : 70 /* ContinueKeyword */, node.pos); - emitOptional(" ", node.label); - write(";"); - } - function emitReturnStatement(node) { - emitLeadingComments(node); - emitToken(89 /* ReturnKeyword */, node.pos); - emitOptional(" ", node.expression); - write(";"); - emitTrailingComments(node); - } - function emitWithStatement(node) { - write("with ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitSwitchStatement(node) { - var endPos = emitToken(91 /* SwitchKeyword */, node.pos); - write(" "); - emitToken(16 /* OpenParenToken */, endPos); - emit(node.expression); - endPos = emitToken(17 /* CloseParenToken */, node.expression.end); - write(" "); - emitToken(14 /* OpenBraceToken */, endPos); - increaseIndent(); - emitLines(node.clauses); - decreaseIndent(); - writeLine(); - emitToken(15 /* CloseBraceToken */, node.clauses.end); - } - function isOnSameLine(node1, node2) { - return getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); - } - function emitCaseOrDefaultClause(node) { - if (node.kind === 200 /* CaseClause */) { - write("case "); - emit(node.expression); - write(":"); - } - else { - write("default:"); - } - if (node.statements.length === 1 && isOnSameLine(node, node.statements[0])) { - write(" "); - emit(node.statements[0]); - } - else { - increaseIndent(); - emitLines(node.statements); - decreaseIndent(); - } - } - function emitThrowStatement(node) { - write("throw "); - emit(node.expression); - write(";"); - } - function emitTryStatement(node) { - write("try "); - emit(node.tryBlock); - emit(node.catchClause); - if (node.finallyBlock) { - writeLine(); - write("finally "); - emit(node.finallyBlock); - } - } - function emitCatchClause(node) { - writeLine(); - var endPos = emitToken(67 /* CatchKeyword */, node.pos); - write(" "); - emitToken(16 /* OpenParenToken */, endPos); - emit(node.name); - emitToken(17 /* CloseParenToken */, node.name.end); - write(" "); - emitBlock(node.block); - } - function emitDebuggerStatement(node) { - emitToken(71 /* DebuggerKeyword */, node.pos); - write(";"); - } - function emitLabelledStatement(node) { - emit(node.label); - write(": "); - emit(node.statement); - } - function getContainingModule(node) { - do { - node = node.parent; - } while (node && node.kind !== 195 /* ModuleDeclaration */); - return node; - } - function emitModuleMemberName(node) { - emitStart(node.name); - if (node.flags & 1 /* Export */) { - var container = getContainingModule(node); - write(container ? resolver.getLocalNameOfContainer(container) : "exports"); - write("."); - } - emitNode(node.name); - emitEnd(node.name); - } - function emitDestructuring(root, value) { - var emitCount = 0; - var isDeclaration = (root.kind === 189 /* VariableDeclaration */ && !(root.flags & 1 /* Export */)) || root.kind === 124 /* Parameter */; - if (root.kind === 163 /* BinaryExpression */) { - emitAssignmentExpression(root); - } - else { - emitBindingElement(root, value); - } - function emitAssignment(name, value) { - if (emitCount++) { - write(", "); - } - if (name.parent && (name.parent.kind === 189 /* VariableDeclaration */ || name.parent.kind === 146 /* BindingElement */)) { - emitModuleMemberName(name.parent); - } - else { - emit(name); - } - write(" = "); - emit(value); - } - function ensureIdentifier(expr) { - if (expr.kind !== 64 /* Identifier */) { - var identifier = createTempVariable(root); - if (!isDeclaration) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - expr = identifier; - } - return expr; - } - function createVoidZero() { - var zero = ts.createNode(7 /* NumericLiteral */); - zero.text = "0"; - var result = ts.createNode(160 /* VoidExpression */); - result.expression = zero; - return result; - } - function createDefaultValueCheck(value, defaultValue) { - value = ensureIdentifier(value); - var equals = ts.createNode(163 /* BinaryExpression */); - equals.left = value; - equals.operator = 30 /* EqualsEqualsEqualsToken */; - equals.right = createVoidZero(); - var cond = ts.createNode(164 /* ConditionalExpression */); - cond.condition = equals; - cond.whenTrue = defaultValue; - cond.whenFalse = value; - return cond; - } - function createNumericLiteral(value) { - var node = ts.createNode(7 /* NumericLiteral */); - node.text = "" + value; - return node; - } - function parenthesizeForAccess(expr) { - if (expr.kind === 64 /* Identifier */ || expr.kind === 149 /* PropertyAccessExpression */ || expr.kind === 150 /* ElementAccessExpression */) { - return expr; - } - var node = ts.createNode(155 /* ParenthesizedExpression */); - node.expression = expr; - return node; - } - function createPropertyAccess(object, propName) { - if (propName.kind !== 64 /* Identifier */) { - return createElementAccess(object, propName); - } - var node = ts.createNode(149 /* PropertyAccessExpression */); - node.expression = parenthesizeForAccess(object); - node.name = propName; - return node; - } - function createElementAccess(object, index) { - var node = ts.createNode(150 /* ElementAccessExpression */); - node.expression = parenthesizeForAccess(object); - node.argumentExpression = index; - return node; - } - function emitObjectLiteralAssignment(target, value) { - var properties = target.properties; - if (properties.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < properties.length; i++) { - var p = properties[i]; - if (p.kind === 204 /* PropertyAssignment */ || p.kind === 205 /* ShorthandPropertyAssignment */) { - var propName = (p.name); - emitDestructuringAssignment(p.initializer || propName, createPropertyAccess(value, propName)); - } - } - } - function emitArrayLiteralAssignment(target, value) { - var elements = target.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < elements.length; i++) { - var e = elements[i]; - if (e.kind !== 167 /* OmittedExpression */) { - emitDestructuringAssignment(e, createElementAccess(value, createNumericLiteral(i))); - } - } - } - function emitDestructuringAssignment(target, value) { - if (target.kind === 163 /* BinaryExpression */ && target.operator === 52 /* EqualsToken */) { - value = createDefaultValueCheck(value, target.right); - target = target.left; - } - if (target.kind === 148 /* ObjectLiteralExpression */) { - emitObjectLiteralAssignment(target, value); - } - else if (target.kind === 147 /* ArrayLiteralExpression */) { - emitArrayLiteralAssignment(target, value); - } - else { - emitAssignment(target, value); - } - } - function emitAssignmentExpression(root) { - var target = root.left; - var value = root.right; - if (root.parent.kind === 172 /* ExpressionStatement */) { - emitDestructuringAssignment(target, value); - } - else { - if (root.parent.kind !== 155 /* ParenthesizedExpression */) { - write("("); - } - value = ensureIdentifier(value); - emitDestructuringAssignment(target, value); - write(", "); - emit(value); - if (root.parent.kind !== 155 /* ParenthesizedExpression */) { - write(")"); - } - } - } - function emitBindingElement(target, value) { - if (target.initializer) { - value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; - } - else if (!value) { - value = createVoidZero(); - } - if (ts.isBindingPattern(target.name)) { - var pattern = target.name; - var elements = pattern.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < elements.length; i++) { - var element = elements[i]; - if (pattern.kind === 144 /* ObjectBindingPattern */) { - var propName = element.propertyName || element.name; - emitBindingElement(element, createPropertyAccess(value, propName)); - } - else if (element.kind !== 167 /* OmittedExpression */) { - emitBindingElement(element, createElementAccess(value, createNumericLiteral(i))); - } - } - } - else { - emitAssignment(target.name, value); - } - } - } - function emitVariableDeclaration(node) { - emitLeadingComments(node); - if (ts.isBindingPattern(node.name)) { - emitDestructuring(node); - } - else { - emitModuleMemberName(node); - emitOptional(" = ", node.initializer); - } - emitTrailingComments(node); - } - function emitVariableStatement(node) { - emitLeadingComments(node); - if (!(node.flags & 1 /* Export */)) { - if (ts.isLet(node)) { - write("let "); - } - else if (ts.isConst(node)) { - write("const "); - } - else { - write("var "); - } - } - emitCommaList(node.declarations); - write(";"); - emitTrailingComments(node); - } - function emitParameter(node) { - emitLeadingComments(node); - if (ts.isBindingPattern(node.name)) { - var name = createTempVariable(node); - if (!tempParameters) { - tempParameters = []; - } - tempParameters.push(name); - emit(name); - } - else { - emit(node.name); - } - emitTrailingComments(node); - } - function emitDefaultValueAssignments(node) { - var tempIndex = 0; - ts.forEach(node.parameters, function (p) { - if (ts.isBindingPattern(p.name)) { - writeLine(); - write("var "); - emitDestructuring(p, tempParameters[tempIndex]); - write(";"); - tempIndex++; - } - else if (p.initializer) { - writeLine(); - emitStart(p); - write("if ("); - emitNode(p.name); - write(" === void 0)"); - emitEnd(p); - write(" { "); - emitStart(p); - emitNode(p.name); - write(" = "); - emitNode(p.initializer); - emitEnd(p); - write("; }"); - } - }); - } - function emitRestParameter(node) { - if (ts.hasRestParameters(node)) { - var restIndex = node.parameters.length - 1; - var restParam = node.parameters[restIndex]; - var tempName = createTempVariable(node, true).text; - writeLine(); - emitLeadingComments(restParam); - emitStart(restParam); - write("var "); - emitNode(restParam.name); - write(" = [];"); - emitEnd(restParam); - emitTrailingComments(restParam); - writeLine(); - write("for ("); - emitStart(restParam); - write("var " + tempName + " = " + restIndex + ";"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + " < arguments.length;"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + "++"); - emitEnd(restParam); - write(") {"); - increaseIndent(); - writeLine(); - emitStart(restParam); - emitNode(restParam.name); - write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); - emitEnd(restParam); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function emitAccessor(node) { - emitLeadingComments(node); - write(node.kind === 130 /* GetAccessor */ ? "get " : "set "); - emit(node.name); - emitSignatureAndBody(node); - emitTrailingComments(node); - } - function emitFunctionDeclaration(node) { - if (!node.body) { - return emitPinnedOrTripleSlashComments(node); - } - if (node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { - emitLeadingComments(node); - } - write("function "); - if (node.kind === 190 /* FunctionDeclaration */ || (node.kind === 156 /* FunctionExpression */ && node.name)) { - emit(node.name); - } - emitSignatureAndBody(node); - if (node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { - emitTrailingComments(node); - } - } - function emitCaptureThisForNodeIfNecessary(node) { - if (resolver.getNodeCheckFlags(node) & 4 /* CaptureThis */) { - writeLine(); - emitStart(node); - write("var _this = this;"); - emitEnd(node); - } - } - function emitSignatureParameters(node) { - increaseIndent(); - write("("); - if (node) { - emitCommaList(node.parameters, node.parameters.length - (ts.hasRestParameters(node) ? 1 : 0)); - } - write(")"); - decreaseIndent(); - } - function emitSignatureAndBody(node) { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; - tempParameters = undefined; - emitSignatureParameters(node); - write(" {"); - scopeEmitStart(node); - increaseIndent(); - emitDetachedComments(node.body.kind === 169 /* Block */ ? node.body.statements : node.body); - var startIndex = 0; - if (node.body.kind === 169 /* Block */) { - startIndex = emitDirectivePrologues(node.body.statements, true); - } - var outPos = writer.getTextPos(); - emitCaptureThisForNodeIfNecessary(node); - emitDefaultValueAssignments(node); - emitRestParameter(node); - if (node.body.kind !== 169 /* Block */ && outPos === writer.getTextPos()) { - decreaseIndent(); - write(" "); - emitStart(node.body); - write("return "); - emitNode(node.body); - emitEnd(node.body); - write(";"); - emitTempDeclarations(false); - write(" "); - emitStart(node.body); - write("}"); - emitEnd(node.body); - } - else { - if (node.body.kind === 169 /* Block */) { - emitLinesStartingAt(node.body.statements, startIndex); - } - else { - writeLine(); - emitLeadingComments(node.body); - write("return "); - emit(node.body); - write(";"); - emitTrailingComments(node.body); - } - emitTempDeclarations(true); - writeLine(); - if (node.body.kind === 169 /* Block */) { - emitLeadingCommentsOfPosition(node.body.statements.end); - decreaseIndent(); - emitToken(15 /* CloseBraceToken */, node.body.statements.end); - } - else { - decreaseIndent(); - emitStart(node.body); - write("}"); - emitEnd(node.body); - } - } - scopeEmitEnd(); - if (node.flags & 1 /* Export */) { - writeLine(); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emit(node.name); - emitEnd(node); - write(";"); - } - tempCount = saveTempCount; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - function findInitialSuperCall(ctor) { - if (ctor.body) { - var statement = ctor.body.statements[0]; - if (statement && statement.kind === 172 /* ExpressionStatement */) { - var expr = statement.expression; - if (expr && expr.kind === 151 /* CallExpression */) { - var func = expr.expression; - if (func && func.kind === 90 /* SuperKeyword */) { - return statement; - } - } - } - } - } - function emitParameterPropertyAssignments(node) { - ts.forEach(node.parameters, function (param) { - if (param.flags & 112 /* AccessibilityModifier */) { - writeLine(); - emitStart(param); - emitStart(param.name); - write("this."); - emitNode(param.name); - emitEnd(param.name); - write(" = "); - emit(param.name); - write(";"); - emitEnd(param); - } - }); - } - function emitMemberAccessForPropertyName(memberName) { - if (memberName.kind === 8 /* StringLiteral */ || memberName.kind === 7 /* NumericLiteral */) { - write("["); - emitNode(memberName); - write("]"); - } - else if (memberName.kind === 122 /* ComputedPropertyName */) { - emitComputedPropertyName(memberName); - } - else { - write("."); - emitNode(memberName); - } - } - function emitMemberAssignments(node, staticFlag) { - ts.forEach(node.members, function (member) { - if (member.kind === 126 /* PropertyDeclaration */ && (member.flags & 128 /* Static */) === staticFlag && member.initializer) { - writeLine(); - emitLeadingComments(member); - emitStart(member); - emitStart(member.name); - if (staticFlag) { - emitNode(node.name); - } - else { - write("this"); - } - emitMemberAccessForPropertyName(member.name); - emitEnd(member.name); - write(" = "); - emit(member.initializer); - write(";"); - emitEnd(member); - emitTrailingComments(member); - } - }); - } - function emitMemberFunctions(node) { - ts.forEach(node.members, function (member) { - if (member.kind === 128 /* MethodDeclaration */ || node.kind === 127 /* MethodSignature */) { - if (!member.body) { - return emitPinnedOrTripleSlashComments(member); - } - writeLine(); - emitLeadingComments(member); - emitStart(member); - emitStart(member.name); - emitNode(node.name); - if (!(member.flags & 128 /* Static */)) { - write(".prototype"); - } - emitMemberAccessForPropertyName(member.name); - emitEnd(member.name); - write(" = "); - emitStart(member); - emitFunctionDeclaration(member); - emitEnd(member); - emitEnd(member); - write(";"); - emitTrailingComments(member); - } - else if (member.kind === 130 /* GetAccessor */ || member.kind === 131 /* SetAccessor */) { - var accessors = getAllAccessorDeclarations(node, member); - if (member === accessors.firstAccessor) { - writeLine(); - emitStart(member); - write("Object.defineProperty("); - emitStart(member.name); - emitNode(node.name); - if (!(member.flags & 128 /* Static */)) { - write(".prototype"); - } - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write(", {"); - increaseIndent(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - write("get: "); - emitStart(accessors.getAccessor); - write("function "); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - write(","); - } - if (accessors.setAccessor) { - writeLine(); - emitLeadingComments(accessors.setAccessor); - write("set: "); - emitStart(accessors.setAccessor); - write("function "); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor); - write(","); - } - writeLine(); - write("enumerable: true,"); - writeLine(); - write("configurable: true"); - decreaseIndent(); - writeLine(); - write("});"); - emitEnd(member); - } - } - }); - } - function emitClassDeclaration(node) { - emitLeadingComments(node); - write("var "); - emit(node.name); - write(" = (function ("); - var baseTypeNode = ts.getClassBaseTypeNode(node); - if (baseTypeNode) { - write("_super"); - } - write(") {"); - increaseIndent(); - scopeEmitStart(node); - if (baseTypeNode) { - writeLine(); - emitStart(baseTypeNode); - write("__extends("); - emit(node.name); - write(", _super);"); - emitEnd(baseTypeNode); - } - writeLine(); - emitConstructorOfClass(); - emitMemberFunctions(node); - emitMemberAssignments(node, 128 /* Static */); - writeLine(); - function emitClassReturnStatement() { - write("return "); - emitNode(node.name); - } - emitToken(15 /* CloseBraceToken */, node.members.end, emitClassReturnStatement); - write(";"); - decreaseIndent(); - writeLine(); - emitToken(15 /* CloseBraceToken */, node.members.end); - scopeEmitEnd(); - emitStart(node); - write(")("); - if (baseTypeNode) { - emit(baseTypeNode.typeName); - } - write(");"); - emitEnd(node); - if (node.flags & 1 /* Export */) { - writeLine(); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emit(node.name); - emitEnd(node); - write(";"); - } - emitTrailingComments(node); - function emitConstructorOfClass() { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; - tempParameters = undefined; - ts.forEach(node.members, function (member) { - if (member.kind === 129 /* Constructor */ && !member.body) { - emitPinnedOrTripleSlashComments(member); - } - }); - var ctor = getFirstConstructorWithBody(node); - if (ctor) { - emitLeadingComments(ctor); - } - emitStart(ctor || node); - write("function "); - emit(node.name); - emitSignatureParameters(ctor); - write(" {"); - scopeEmitStart(node, "constructor"); - increaseIndent(); - if (ctor) { - emitDetachedComments(ctor.body.statements); - } - emitCaptureThisForNodeIfNecessary(node); - if (ctor) { - emitDefaultValueAssignments(ctor); - emitRestParameter(ctor); - if (baseTypeNode) { - var superCall = findInitialSuperCall(ctor); - if (superCall) { - writeLine(); - emit(superCall); - } - } - emitParameterPropertyAssignments(ctor); - } - else { - if (baseTypeNode) { - writeLine(); - emitStart(baseTypeNode); - write("_super.apply(this, arguments);"); - emitEnd(baseTypeNode); - } - } - emitMemberAssignments(node, 0); - if (ctor) { - var statements = ctor.body.statements; - if (superCall) - statements = statements.slice(1); - emitLines(statements); - } - emitTempDeclarations(true); - writeLine(); - if (ctor) { - emitLeadingCommentsOfPosition(ctor.body.statements.end); - } - decreaseIndent(); - emitToken(15 /* CloseBraceToken */, ctor ? ctor.body.statements.end : node.members.end); - scopeEmitEnd(); - emitEnd(ctor || node); - if (ctor) { - emitTrailingComments(ctor); - } - tempCount = saveTempCount; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - } - function emitInterfaceDeclaration(node) { - emitPinnedOrTripleSlashComments(node); - } - function emitEnumDeclaration(node) { - var isConstEnum = ts.isConst(node); - if (isConstEnum && !compilerOptions.preserveConstEnums) { - return; - } - emitLeadingComments(node); - if (!(node.flags & 1 /* Export */)) { - emitStart(node); - write("var "); - emit(node.name); - emitEnd(node); - write(";"); - } - writeLine(); - emitStart(node); - write("(function ("); - emitStart(node.name); - write(resolver.getLocalNameOfContainer(node)); - emitEnd(node.name); - write(") {"); - increaseIndent(); - scopeEmitStart(node); - emitEnumMemberDeclarations(isConstEnum); - decreaseIndent(); - writeLine(); - emitToken(15 /* CloseBraceToken */, node.members.end); - scopeEmitEnd(); - write(")("); - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - if (node.flags & 1 /* Export */) { - writeLine(); - emitStart(node); - write("var "); - emit(node.name); - write(" = "); - emitModuleMemberName(node); - emitEnd(node); - write(";"); - } - emitTrailingComments(node); - function emitEnumMemberDeclarations(isConstEnum) { - ts.forEach(node.members, function (member) { - writeLine(); - emitLeadingComments(member); - emitStart(member); - write(resolver.getLocalNameOfContainer(node)); - write("["); - write(resolver.getLocalNameOfContainer(node)); - write("["); - emitExpressionForPropertyName(member.name); - write("] = "); - if (member.initializer && !isConstEnum) { - emit(member.initializer); - } - else { - write(resolver.getEnumMemberValue(member).toString()); - } - write("] = "); - emitExpressionForPropertyName(member.name); - emitEnd(member); - write(";"); - emitTrailingComments(member); - }); - } - } - function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 195 /* ModuleDeclaration */) { - var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); - return recursiveInnerModule || moduleDeclaration.body; - } - } - function emitModuleDeclaration(node) { - var shouldEmit = ts.getModuleInstanceState(node) === 1 /* Instantiated */ || (ts.getModuleInstanceState(node) === 2 /* ConstEnumOnly */ && compilerOptions.preserveConstEnums); - if (!shouldEmit) { - return emitPinnedOrTripleSlashComments(node); - } - emitLeadingComments(node); - emitStart(node); - write("var "); - emit(node.name); - write(";"); - emitEnd(node); - writeLine(); - emitStart(node); - write("(function ("); - emitStart(node.name); - write(resolver.getLocalNameOfContainer(node)); - emitEnd(node.name); - write(") "); - if (node.body.kind === 196 /* ModuleBlock */) { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - tempCount = 0; - tempVariables = undefined; - emit(node.body); - tempCount = saveTempCount; - tempVariables = saveTempVariables; - } - else { - write("{"); - increaseIndent(); - scopeEmitStart(node); - emitCaptureThisForNodeIfNecessary(node); - writeLine(); - emit(node.body); - decreaseIndent(); - writeLine(); - var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; - emitToken(15 /* CloseBraceToken */, moduleBlock.statements.end); - scopeEmitEnd(); - } - write(")("); - if (node.flags & 1 /* Export */) { - emit(node.name); - write(" = "); - } - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - emitTrailingComments(node); - } - function emitImportDeclaration(node) { - var emitImportDeclaration = resolver.isReferencedImportDeclaration(node); - if (!emitImportDeclaration) { - emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportWithEntityName(node); - } - if (emitImportDeclaration) { - if (ts.isExternalModuleImportDeclaration(node) && node.parent.kind === 207 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { - if (node.flags & 1 /* Export */) { - writeLine(); - emitLeadingComments(node); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emit(node.name); - write(";"); - emitEnd(node); - emitTrailingComments(node); - } - } - else { - writeLine(); - emitLeadingComments(node); - emitStart(node); - if (!(node.flags & 1 /* Export */)) - write("var "); - emitModuleMemberName(node); - write(" = "); - if (ts.isInternalModuleImportDeclaration(node)) { - emit(node.moduleReference); - } - else { - var literal = ts.getExternalModuleImportDeclarationExpression(node); - write("require("); - emitStart(literal); - emitLiteral(literal); - emitEnd(literal); - emitToken(17 /* CloseParenToken */, literal.end); - } - write(";"); - emitEnd(node); - emitTrailingComments(node); - } - } - } - function getExternalImportDeclarations(node) { - var result = []; - ts.forEach(node.statements, function (statement) { - if (ts.isExternalModuleImportDeclaration(statement) && resolver.isReferencedImportDeclaration(statement)) { - result.push(statement); - } - }); - return result; - } - function getFirstExportAssignment(sourceFile) { - return ts.forEach(sourceFile.statements, function (node) { - if (node.kind === 198 /* ExportAssignment */) { - return node; - } - }); - } - function emitAMDModule(node, startIndex) { - var imports = getExternalImportDeclarations(node); - writeLine(); - write("define("); - if (node.amdModuleName) { - write("\"" + node.amdModuleName + "\", "); - } - write("[\"require\", \"exports\""); - ts.forEach(imports, function (imp) { - write(", "); - emitLiteral(ts.getExternalModuleImportDeclarationExpression(imp)); - }); - ts.forEach(node.amdDependencies, function (amdDependency) { - var text = "\"" + amdDependency + "\""; - write(", "); - write(text); - }); - write("], function (require, exports"); - ts.forEach(imports, function (imp) { - write(", "); - emit(imp.name); - }); - write(") {"); - increaseIndent(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { - writeLine(); - var exportAssignement = getFirstExportAssignment(node); - emitStart(exportAssignement); - write("return "); - emitStart(exportAssignement.exportName); - write(exportName); - emitEnd(exportAssignement.exportName); - write(";"); - emitEnd(exportAssignement); - } - decreaseIndent(); - writeLine(); - write("});"); - } - function emitCommonJSModule(node, startIndex) { - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { - writeLine(); - var exportAssignement = getFirstExportAssignment(node); - emitStart(exportAssignement); - write("module.exports = "); - emitStart(exportAssignement.exportName); - write(exportName); - emitEnd(exportAssignement.exportName); - write(";"); - emitEnd(exportAssignement); - } - } - function emitDirectivePrologues(statements, startWithNewLine) { - for (var i = 0; i < statements.length; ++i) { - if (ts.isPrologueDirective(statements[i])) { - if (startWithNewLine || i > 0) { - writeLine(); - } - emit(statements[i]); - } - else { - return i; - } - } - return statements.length; - } - function emitSourceFile(node) { - currentSourceFile = node; - writeLine(); - emitDetachedComments(node); - var startIndex = emitDirectivePrologues(node.statements, false); - if (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8 /* EmitExtends */) { - writeLine(); - write("var __extends = this.__extends || function (d, b) {"); - increaseIndent(); - writeLine(); - write("for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];"); - writeLine(); - write("function __() { this.constructor = d; }"); - writeLine(); - write("__.prototype = b.prototype;"); - writeLine(); - write("d.prototype = new __();"); - decreaseIndent(); - writeLine(); - write("};"); - extendsEmitted = true; - } - if (ts.isExternalModule(node)) { - if (compilerOptions.module === 2 /* AMD */) { - emitAMDModule(node, startIndex); - } - else { - emitCommonJSModule(node, startIndex); - } - } - else { - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - } - emitLeadingComments(node.endOfFileToken); - } - function emitNode(node) { - if (!node) { - return; - } - if (node.flags & 2 /* Ambient */) { - return emitPinnedOrTripleSlashComments(node); - } - switch (node.kind) { - case 64 /* Identifier */: - return emitIdentifier(node); - case 124 /* Parameter */: - return emitParameter(node); - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - return emitMethod(node); - case 130 /* GetAccessor */: - case 131 /* SetAccessor */: - return emitAccessor(node); - case 92 /* ThisKeyword */: - return emitThis(node); - case 90 /* SuperKeyword */: - return emitSuper(node); - case 88 /* NullKeyword */: - return write("null"); - case 94 /* TrueKeyword */: - return write("true"); - case 79 /* FalseKeyword */: - return write("false"); - case 7 /* NumericLiteral */: - case 8 /* StringLiteral */: - case 9 /* RegularExpressionLiteral */: - case 10 /* NoSubstitutionTemplateLiteral */: - case 11 /* TemplateHead */: - case 12 /* TemplateMiddle */: - case 13 /* TemplateTail */: - return emitLiteral(node); - case 165 /* TemplateExpression */: - return emitTemplateExpression(node); - case 168 /* TemplateSpan */: - return emitTemplateSpan(node); - case 121 /* QualifiedName */: - return emitQualifiedName(node); - case 144 /* ObjectBindingPattern */: - return emitObjectBindingPattern(node); - case 145 /* ArrayBindingPattern */: - return emitArrayBindingPattern(node); - case 147 /* ArrayLiteralExpression */: - return emitArrayLiteral(node); - case 148 /* ObjectLiteralExpression */: - return emitObjectLiteral(node); - case 204 /* PropertyAssignment */: - return emitPropertyAssignment(node); - case 205 /* ShorthandPropertyAssignment */: - return emitShorthandPropertyAssignment(node); - case 122 /* ComputedPropertyName */: - return emitComputedPropertyName(node); - case 149 /* PropertyAccessExpression */: - return emitPropertyAccess(node); - case 150 /* ElementAccessExpression */: - return emitIndexedAccess(node); - case 151 /* CallExpression */: - return emitCallExpression(node); - case 152 /* NewExpression */: - return emitNewExpression(node); - case 153 /* TaggedTemplateExpression */: - return emitTaggedTemplateExpression(node); - case 154 /* TypeAssertionExpression */: - return emit(node.expression); - case 155 /* ParenthesizedExpression */: - return emitParenExpression(node); - case 190 /* FunctionDeclaration */: - case 156 /* FunctionExpression */: - case 157 /* ArrowFunction */: - return emitFunctionDeclaration(node); - case 158 /* DeleteExpression */: - return emitDeleteExpression(node); - case 159 /* TypeOfExpression */: - return emitTypeOfExpression(node); - case 160 /* VoidExpression */: - return emitVoidExpression(node); - case 161 /* PrefixUnaryExpression */: - return emitPrefixUnaryExpression(node); - case 162 /* PostfixUnaryExpression */: - return emitPostfixUnaryExpression(node); - case 163 /* BinaryExpression */: - return emitBinaryExpression(node); - case 164 /* ConditionalExpression */: - return emitConditionalExpression(node); - case 167 /* OmittedExpression */: - return; - case 169 /* Block */: - case 186 /* TryBlock */: - case 187 /* FinallyBlock */: - case 196 /* ModuleBlock */: - return emitBlock(node); - case 170 /* VariableStatement */: - return emitVariableStatement(node); - case 171 /* EmptyStatement */: - return write(";"); - case 172 /* ExpressionStatement */: - return emitExpressionStatement(node); - case 173 /* IfStatement */: - return emitIfStatement(node); - case 174 /* DoStatement */: - return emitDoStatement(node); - case 175 /* WhileStatement */: - return emitWhileStatement(node); - case 176 /* ForStatement */: - return emitForStatement(node); - case 177 /* ForInStatement */: - return emitForInStatement(node); - case 178 /* ContinueStatement */: - case 179 /* BreakStatement */: - return emitBreakOrContinueStatement(node); - case 180 /* ReturnStatement */: - return emitReturnStatement(node); - case 181 /* WithStatement */: - return emitWithStatement(node); - case 182 /* SwitchStatement */: - return emitSwitchStatement(node); - case 200 /* CaseClause */: - case 201 /* DefaultClause */: - return emitCaseOrDefaultClause(node); - case 183 /* LabeledStatement */: - return emitLabelledStatement(node); - case 184 /* ThrowStatement */: - return emitThrowStatement(node); - case 185 /* TryStatement */: - return emitTryStatement(node); - case 203 /* CatchClause */: - return emitCatchClause(node); - case 188 /* DebuggerStatement */: - return emitDebuggerStatement(node); - case 189 /* VariableDeclaration */: - return emitVariableDeclaration(node); - case 191 /* ClassDeclaration */: - return emitClassDeclaration(node); - case 192 /* InterfaceDeclaration */: - return emitInterfaceDeclaration(node); - case 194 /* EnumDeclaration */: - return emitEnumDeclaration(node); - case 195 /* ModuleDeclaration */: - return emitModuleDeclaration(node); - case 197 /* ImportDeclaration */: - return emitImportDeclaration(node); - case 207 /* SourceFile */: - return emitSourceFile(node); - } - } - function hasDetachedComments(pos) { - return detachedCommentsInfo !== undefined && detachedCommentsInfo[detachedCommentsInfo.length - 1].nodePos === pos; - } - function getLeadingCommentsWithoutDetachedComments() { - var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); - if (detachedCommentsInfo.length - 1) { - detachedCommentsInfo.pop(); - } - else { - detachedCommentsInfo = undefined; - } - return leadingComments; - } - function getLeadingCommentsToEmit(node) { - if (node.parent.kind === 207 /* SourceFile */ || node.pos !== node.parent.pos) { - var leadingComments; - if (hasDetachedComments(node.pos)) { - leadingComments = getLeadingCommentsWithoutDetachedComments(); - } - else { - leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); - } - return leadingComments; - } - } - function emitLeadingDeclarationComments(node) { - var leadingComments = getLeadingCommentsToEmit(node); - emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); - } - function emitTrailingDeclarationComments(node) { - if (node.parent.kind === 207 /* SourceFile */ || node.end !== node.parent.end) { - var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); - emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); - } - } - function emitLeadingCommentsOfLocalPosition(pos) { - var leadingComments; - if (hasDetachedComments(pos)) { - leadingComments = getLeadingCommentsWithoutDetachedComments(); - } - else { - leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); - } - emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); - emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); - } - function emitDetachedCommentsAtPosition(node) { - var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); - if (leadingComments) { - var detachedComments = []; - var lastComment; - ts.forEach(leadingComments, function (comment) { - if (lastComment) { - var lastCommentLine = getLineOfLocalPosition(currentSourceFile, lastComment.end); - var commentLine = getLineOfLocalPosition(currentSourceFile, comment.pos); - if (commentLine >= lastCommentLine + 2) { - return detachedComments; - } - } - detachedComments.push(comment); - lastComment = comment; - }); - if (detachedComments.length) { - var lastCommentLine = getLineOfLocalPosition(currentSourceFile, detachedComments[detachedComments.length - 1].end); - var astLine = getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); - if (astLine >= lastCommentLine + 2) { - emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment); - var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: detachedComments[detachedComments.length - 1].end }; - if (detachedCommentsInfo) { - detachedCommentsInfo.push(currentDetachedCommentInfo); - } - else { - detachedCommentsInfo = [currentDetachedCommentInfo]; - } - } - } - } - } - function emitPinnedOrTripleSlashCommentsOfNode(node) { - var pinnedComments = ts.filter(getLeadingCommentsToEmit(node), isPinnedOrTripleSlashComment); - function isPinnedOrTripleSlashComment(comment) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) { - return currentSourceFile.text.charCodeAt(comment.pos + 2) === 33 /* exclamation */; - } - else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 /* slash */ && comment.pos + 2 < comment.end && currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 /* slash */ && currentSourceFile.text.substring(comment.pos, comment.end).match(ts.fullTripleSlashReferencePathRegEx)) { - return true; - } - } - emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, pinnedComments); - emitComments(currentSourceFile, writer, pinnedComments, true, newLine, writeComment); - } - if (compilerOptions.sourceMap) { - initializeEmitterWithSourceMaps(); - } - if (root) { - emit(root); - } - else { - ts.forEach(program.getSourceFiles(), function (sourceFile) { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - emit(sourceFile); - } - }); - } - writeLine(); - writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); - } - function writeDeclarationFile(jsFilePath, sourceFile) { - var emitDeclarationResult = emitDeclarations(program, resolver, diagnostics, jsFilePath, sourceFile); - if (!emitDeclarationResult.reportedDeclarationError) { - var declarationOutput = emitDeclarationResult.referencePathsOutput; - var appliedSyncOutputPos = 0; - ts.forEach(emitDeclarationResult.aliasDeclarationEmitInfo, function (aliasEmitInfo) { - if (aliasEmitInfo.asynchronousOutput) { - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); - declarationOutput += aliasEmitInfo.asynchronousOutput; - appliedSyncOutputPos = aliasEmitInfo.outputPos; - } - }); - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos); - writeFile(compilerHost, diagnostics, ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); - } - } - var hasSemanticErrors = false; - var isEmitBlocked = false; - if (targetSourceFile === undefined) { - hasSemanticErrors = resolver.hasSemanticErrors(); - isEmitBlocked = resolver.isEmitBlocked(); - ts.forEach(program.getSourceFiles(), function (sourceFile) { - if (shouldEmitToOwnFile(sourceFile, compilerOptions)) { - var jsFilePath = getOwnEmitOutputFilePath(sourceFile, program, ".js"); - emitFile(jsFilePath, sourceFile); - } - }); - if (compilerOptions.out) { - emitFile(compilerOptions.out); - } - } - else { - if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { - hasSemanticErrors = resolver.hasSemanticErrors(targetSourceFile); - isEmitBlocked = resolver.isEmitBlocked(targetSourceFile); - var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, program, ".js"); - emitFile(jsFilePath, targetSourceFile); - } - else if (!ts.isDeclarationFile(targetSourceFile) && compilerOptions.out) { - ts.forEach(program.getSourceFiles(), function (sourceFile) { - if (!shouldEmitToOwnFile(sourceFile, compilerOptions)) { - hasSemanticErrors = hasSemanticErrors || resolver.hasSemanticErrors(sourceFile); - isEmitBlocked = isEmitBlocked || resolver.isEmitBlocked(sourceFile); - } - }); - emitFile(compilerOptions.out); - } - } - function emitFile(jsFilePath, sourceFile) { - if (!isEmitBlocked) { - emitJavaScript(jsFilePath, sourceFile); - if (!hasSemanticErrors && compilerOptions.declaration) { - writeDeclarationFile(jsFilePath, sourceFile); - } - } - } - diagnostics.sort(ts.compareDiagnostics); - diagnostics = ts.deduplicateSortedDiagnostics(diagnostics); - var hasEmitterError = ts.forEach(diagnostics, function (diagnostic) { return diagnostic.category === 1 /* Error */; }); - var emitResultStatus; - if (isEmitBlocked) { - emitResultStatus = 1 /* AllOutputGenerationSkipped */; - } - else if (hasEmitterError) { - emitResultStatus = 4 /* EmitErrorsEncountered */; - } - else if (hasSemanticErrors && compilerOptions.declaration) { - emitResultStatus = 3 /* DeclarationGenerationSkipped */; - } - else if (hasSemanticErrors && !compilerOptions.declaration) { - emitResultStatus = 2 /* JSGeneratedWithSemanticErrors */; - } - else { - emitResultStatus = 0 /* Succeeded */; - } - return { - emitResultStatus: emitResultStatus, - diagnostics: diagnostics, - sourceMaps: sourceMapDataList - }; - } - ts.emitFiles = emitFiles; -})(ts || (ts = {})); -var ts; (function (ts) { var nextSymbolId = 1; var nextNodeId = 1; var nextMergeId = 1; - function createTypeChecker(program, fullTypeCheck) { + function createTypeChecker(host, produceDiagnostics) { var Symbol = ts.objectAllocator.getSymbolConstructor(); var Type = ts.objectAllocator.getTypeConstructor(); var Signature = ts.objectAllocator.getSignatureConstructor(); var typeCount = 0; var emptyArray = []; var emptySymbols = {}; - var compilerOptions = program.getCompilerOptions(); + var compilerOptions = host.getCompilerOptions(); + var emitResolver = createResolver(); var checker = { - getProgram: function () { return program; }, - getNodeCount: function () { return ts.sum(program.getSourceFiles(), "nodeCount"); }, - getIdentifierCount: function () { return ts.sum(program.getSourceFiles(), "identifierCount"); }, - getSymbolCount: function () { return ts.sum(program.getSourceFiles(), "symbolCount"); }, + getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); }, + getIdentifierCount: function () { return ts.sum(host.getSourceFiles(), "identifierCount"); }, + getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount"); }, getTypeCount: function () { return typeCount; }, isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; }, isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; }, - emitFiles: invokeEmitter, getDiagnostics: getDiagnostics, - getDeclarationDiagnostics: getDeclarationDiagnostics, getGlobalDiagnostics: getGlobalDiagnostics, getTypeOfSymbolAtLocation: getTypeOfSymbolAtLocation, getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol, @@ -9808,8 +7356,7 @@ var ts; getSignatureFromDeclaration: getSignatureFromDeclaration, isImplementationOfOverload: isImplementationOfOverload, getAliasedSymbol: resolveImport, - hasEarlyErrors: hasEarlyErrors, - isEmitBlocked: isEmitBlocked + getEmitResolver: function () { return emitResolver; } }; var undefinedSymbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "undefined"); var argumentsSymbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "arguments"); @@ -10018,7 +7565,7 @@ var ts; if (!compilerOptions.out) { return true; } - var sourceFiles = program.getSourceFiles(); + var sourceFiles = host.getSourceFiles(); return sourceFiles.indexOf(file1) <= sourceFiles.indexOf(file2); } function resolveName(location, name, meaning, nameNotFoundMessage, nameArg) { @@ -10117,7 +7664,7 @@ var ts; return undefined; } if (result.flags & 2 /* BlockScopedVariable */) { - var declaration = ts.forEach(result.declarations, function (d) { return d.flags & 6144 /* BlockScoped */ ? d : undefined; }); + var declaration = ts.forEach(result.declarations, function (d) { return ts.getCombinedNodeFlags(d) & 6144 /* BlockScoped */ ? d : undefined; }); ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); if (!isDefinedBefore(declaration, errorLocation)) { error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name)); @@ -10213,7 +7760,7 @@ var ts; } while (true) { var filename = ts.normalizePath(ts.combinePaths(searchPath, moduleName)); - var sourceFile = program.getSourceFile(filename + ".ts") || program.getSourceFile(filename + ".d.ts"); + var sourceFile = host.getSourceFile(filename + ".ts") || host.getSourceFile(filename + ".d.ts"); if (sourceFile || isRelative) break; var parentPath = ts.getDirectoryPath(searchPath); @@ -10315,7 +7862,7 @@ var ts; var members = node.members; for (var i = 0; i < members.length; i++) { var member = members[i]; - if (member.kind === 129 /* Constructor */ && member.body) { + if (member.kind === 129 /* Constructor */ && ts.nodeIsPresent(member.body)) { return member; } } @@ -10410,7 +7957,7 @@ var ts; } function isAccessible(symbolFromSymbolTable, resolvedAliasSymbol) { if (symbol === (resolvedAliasSymbol || symbolFromSymbolTable)) { - return !ts.forEach(symbolFromSymbolTable.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); }) && canQualifySymbol(symbolFromSymbolTable, meaning); + return !ts.forEach(symbolFromSymbolTable.declarations, hasExternalModuleSymbol) && canQualifySymbol(symbolFromSymbolTable, meaning); } } if (isAccessible(ts.lookUp(symbols, symbol.name))) { @@ -10474,7 +8021,7 @@ var ts; meaningToLook = getQualifiedLeftMeaning(meaning); symbol = getParentOfSymbol(symbol); } - var symbolExternalModule = ts.forEach(initialSymbol.declarations, function (declaration) { return getExternalModuleContainer(declaration); }); + var symbolExternalModule = ts.forEach(initialSymbol.declarations, getExternalModuleContainer); if (symbolExternalModule) { var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration); if (symbolExternalModule !== enclosingExternalModule) { @@ -10627,7 +8174,7 @@ var ts; } } else { - if (!parentSymbol && ts.forEach(symbol.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); })) { + if (!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) { return; } if (symbol.flags & 2048 /* TypeLiteral */ || symbol.flags & 4096 /* ObjectLiteral */) { @@ -11016,7 +8563,7 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: case 195 /* ModuleDeclaration */: case 191 /* ClassDeclaration */: @@ -11026,7 +8573,7 @@ var ts; case 194 /* EnumDeclaration */: case 197 /* ImportDeclaration */: var parent = getDeclarationContainer(node); - if (!(node.flags & 1 /* Export */) && !(node.kind !== 197 /* ImportDeclaration */ && parent.kind !== 207 /* SourceFile */ && ts.isInAmbientContext(parent))) { + if (!(ts.getCombinedNodeFlags(node) & 1 /* Export */) && !(node.kind !== 197 /* ImportDeclaration */ && parent.kind !== 207 /* SourceFile */ && ts.isInAmbientContext(parent))) { return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); } return isDeclarationVisible(parent); @@ -11045,7 +8592,6 @@ var ts; case 134 /* IndexSignature */: case 124 /* Parameter */: case 196 /* ModuleBlock */: - case 123 /* TypeParameter */: case 136 /* FunctionType */: case 137 /* ConstructorType */: case 139 /* TypeLiteral */: @@ -11055,6 +8601,7 @@ var ts; case 142 /* UnionType */: case 143 /* ParenthesizedType */: return isDeclarationVisible(node.parent); + case 123 /* TypeParameter */: case 207 /* SourceFile */: return true; default: @@ -11077,7 +8624,7 @@ var ts; } function getDeclarationContainer(node) { node = getRootDeclaration(node); - return node.kind === 189 /* VariableDeclaration */ ? node.parent.parent : node.parent; + return node.kind === 188 /* VariableDeclaration */ ? node.parent.parent.parent : node.parent; } function getTypeOfPrototypeProperty(prototype) { var classType = getDeclaredTypeOfSymbol(prototype.parent); @@ -11106,22 +8653,28 @@ var ts; error(name, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name)); return unknownType; } - return type; } - if (!isTypeAssignableTo(parentType, anyArrayType)) { - error(pattern, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(parentType)); - return unknownType; - } - var propName = "" + ts.indexOf(pattern.elements, declaration); - var type = isTupleLikeType(parentType) ? getTypeOfPropertyOfType(parentType, propName) : getIndexTypeOfType(parentType, 1 /* Number */); - if (!type) { - error(declaration, ts.Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName); - return unknownType; + else { + if (!isTypeAssignableTo(parentType, anyArrayType)) { + error(pattern, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(parentType)); + return unknownType; + } + if (!declaration.dotDotDotToken) { + var propName = "" + ts.indexOf(pattern.elements, declaration); + var type = isTupleLikeType(parentType) ? getTypeOfPropertyOfType(parentType, propName) : getIndexTypeOfType(parentType, 1 /* Number */); + if (!type) { + error(declaration, ts.Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName); + return unknownType; + } + } + else { + var type = createArrayType(getIndexTypeOfType(parentType, 1 /* Number */)); + } } return type; } function getTypeForVariableLikeDeclaration(declaration) { - if (declaration.parent.kind === 177 /* ForInStatement */) { + if (declaration.parent.parent.kind === 178 /* ForInStatement */) { return anyType; } if (ts.isBindingPattern(declaration.parent)) { @@ -11160,10 +8713,7 @@ var ts; } return anyType; } - function getTypeFromBindingPattern(pattern) { - if (pattern.kind === 145 /* ArrayBindingPattern */) { - return createTupleType(ts.map(pattern.elements, function (e) { return e.kind === 167 /* OmittedExpression */ ? anyType : getTypeFromBindingElement(e); })); - } + function getTypeFromObjectBindingPattern(pattern) { var members = {}; ts.forEach(pattern.elements, function (e) { var flags = 4 /* Property */ | 67108864 /* Transient */ | (e.initializer ? 536870912 /* Optional */ : 0); @@ -11174,6 +8724,20 @@ var ts; }); return createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined); } + function getTypeFromArrayBindingPattern(pattern) { + var hasSpreadElement = false; + var elementTypes = []; + ts.forEach(pattern.elements, function (e) { + elementTypes.push(e.kind === 168 /* OmittedExpression */ || e.dotDotDotToken ? anyType : getTypeFromBindingElement(e)); + if (e.dotDotDotToken) { + hasSpreadElement = true; + } + }); + return !elementTypes.length ? anyArrayType : hasSpreadElement ? createArrayType(getUnionType(elementTypes)) : createTupleType(elementTypes); + } + function getTypeFromBindingPattern(pattern) { + return pattern.kind === 144 /* ObjectBindingPattern */ ? getTypeFromObjectBindingPattern(pattern) : getTypeFromArrayBindingPattern(pattern); + } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { var type = getTypeForVariableLikeDeclaration(declaration); if (type) { @@ -11906,7 +9470,7 @@ var ts; var setter = ts.getDeclarationOfKind(declaration.symbol, 131 /* SetAccessor */); returnType = getAnnotatedAccessorType(setter); } - if (!returnType && !declaration.body) { + if (!returnType && ts.nodeIsMissing(declaration.body)) { returnType = anyType; } } @@ -12519,7 +10083,7 @@ var ts; return false; } function isContextSensitiveFunctionLikeDeclaration(node) { - return !node.typeParameters && !ts.forEach(node.parameters, function (p) { return p.type; }); + return !node.typeParameters && node.parameters.length && !ts.forEach(node.parameters, function (p) { return p.type; }); } function getTypeWithoutConstructors(type) { if (type.flags & 48128 /* ObjectType */) { @@ -12578,7 +10142,7 @@ var ts; if (containingMessageChain) { errorInfo = ts.concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); } - addDiagnostic(ts.createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, program.getCompilerHost().getNewLine())); + addDiagnostic(ts.createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, host.getCompilerHost().getNewLine())); } return result !== 0 /* False */; function reportError(message, arg0, arg1, arg2) { @@ -12793,9 +10357,7 @@ var ts; if (result) { var maybeCache = maybeStack[depth]; var destinationCache = result === -1 /* True */ || depth === 0 ? relation : maybeStack[depth - 1]; - for (var p in maybeCache) { - destinationCache[p] = maybeCache[p]; - } + ts.copyMap(maybeCache, destinationCache); } else { relation[id] = false; @@ -13118,7 +10680,7 @@ var ts; result &= related; } } - else if (source.typeParameters || source.typeParameters) { + else if (source.typeParameters || target.typeParameters) { return 0 /* False */; } source = getErasedSignature(source); @@ -13209,7 +10771,7 @@ var ts; return anyType; } if (type.flags & 16384 /* Union */) { - return getUnionType(ts.map(type.types, function (t) { return getWidenedType(t); })); + return getUnionType(ts.map(type.types, getWidenedType)); } if (isTypeOfObjectLiteral(type)) { return getWidenedTypeOfObjectLiteral(type); @@ -13277,7 +10839,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (fullTypeCheck && compilerOptions.noImplicitAny && type.flags & 131072 /* Unwidened */) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 131072 /* Unwidened */) { if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); } @@ -13547,7 +11109,7 @@ var ts; switch (node.kind) { case 163 /* BinaryExpression */: return isAssignedInBinaryExpression(node); - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: return isAssignedInVariableDeclaration(node); case 144 /* ObjectBindingPattern */: @@ -13566,25 +11128,24 @@ var ts; case 160 /* VoidExpression */: case 162 /* PostfixUnaryExpression */: case 164 /* ConditionalExpression */: - case 169 /* Block */: - case 170 /* VariableStatement */: - case 172 /* ExpressionStatement */: - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 180 /* ReturnStatement */: - case 181 /* WithStatement */: - case 182 /* SwitchStatement */: + case 167 /* SpreadElementExpression */: + case 170 /* Block */: + case 171 /* VariableStatement */: + case 173 /* ExpressionStatement */: + case 174 /* IfStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 181 /* ReturnStatement */: + case 182 /* WithStatement */: + case 183 /* SwitchStatement */: case 200 /* CaseClause */: case 201 /* DefaultClause */: - case 183 /* LabeledStatement */: - case 184 /* ThrowStatement */: - case 185 /* TryStatement */: - case 186 /* TryBlock */: + case 184 /* LabeledStatement */: + case 185 /* ThrowStatement */: + case 186 /* TryStatement */: case 203 /* CatchClause */: - case 187 /* FinallyBlock */: return ts.forEachChild(node, isAssignedIn); } return false; @@ -13615,13 +11176,13 @@ var ts; } function getNarrowedTypeOfSymbol(symbol, node) { var type = getTypeOfSymbol(symbol); - if (node && symbol.flags & 3 /* Variable */ && type.flags & (48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { + if (node && symbol.flags & 3 /* Variable */ && type.flags & (1 /* Any */ | 48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { loop: while (node.parent) { var child = node; node = node.parent; var narrowedType = type; switch (node.kind) { - case 173 /* IfStatement */: + case 174 /* IfStatement */: if (child !== node.expression) { narrowedType = narrowType(type, node.expression, child === node.thenStatement); } @@ -13704,7 +11265,7 @@ var ts; } } function narrowTypeByInstanceof(type, expr, assumeTrue) { - if (!assumeTrue || expr.left.kind !== 64 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + if (type.flags & 1 /* Any */ || !assumeTrue || expr.left.kind !== 64 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { return type; } var rightType = checkExpression(expr.right); @@ -13965,15 +11526,21 @@ var ts; } return undefined; } - function getContextualTypeForArgument(node) { - var callExpression = node.parent; - var argIndex = ts.indexOf(callExpression.arguments, node); + function getContextualTypeForArgument(callTarget, arg) { + var args = getEffectiveCallArguments(callTarget); + var argIndex = ts.indexOf(args, arg); if (argIndex >= 0) { - var signature = getResolvedSignature(callExpression); + var signature = getResolvedSignature(callTarget); return getTypeAtPosition(signature, argIndex); } return undefined; } + function getContextualTypeForSubstitutionExpression(template, substitutionExpression) { + if (template.parent.kind === 153 /* TaggedTemplateExpression */) { + return getContextualTypeForArgument(template.parent, substitutionExpression); + } + return undefined; + } function getContextualTypeForBinaryOperand(node) { var binaryExpression = node.parent; var operator = binaryExpression.operator; @@ -14024,7 +11591,7 @@ var ts; return applyToContextualType(type, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }); } function contextualTypeIsTupleLikeType(type) { - return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return isTupleLikeType(t); }) : isTupleLikeType(type)); + return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, isTupleLikeType) : isTupleLikeType(type)); } function contextualTypeHasIndexSignature(type, kind) { return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }) : getIndexTypeOfObjectOrUnionType(type, kind)); @@ -14067,18 +11634,18 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 124 /* Parameter */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: case 146 /* BindingElement */: return getContextualTypeForInitializerExpression(node); case 157 /* ArrowFunction */: - case 180 /* ReturnStatement */: + case 181 /* ReturnStatement */: return getContextualTypeForReturnExpression(node); case 151 /* CallExpression */: case 152 /* NewExpression */: - return getContextualTypeForArgument(node); + return getContextualTypeForArgument(parent, node); case 154 /* TypeAssertionExpression */: return getTypeFromTypeNode(parent.type); case 163 /* BinaryExpression */: @@ -14089,6 +11656,9 @@ var ts; return getContextualTypeForElementExpression(node); case 164 /* ConditionalExpression */: return getContextualTypeForConditionalOperand(node); + case 169 /* TemplateSpan */: + ts.Debug.assert(parent.parent.kind === 165 /* TemplateExpression */); + return getContextualTypeForSubstitutionExpression(parent.parent, node); } return undefined; } @@ -14159,15 +11729,36 @@ var ts; } return false; } + function checkSpreadElementExpression(node, contextualMapper) { + var type = checkExpressionCached(node.expression, contextualMapper); + if (!isTypeAssignableTo(type, anyArrayType)) { + error(node.expression, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(type)); + return unknownType; + } + return type; + } function checkArrayLiteral(node, contextualMapper) { var elements = node.elements; if (!elements.length) { return createArrayType(undefinedType); } - var elementTypes = ts.map(elements, function (e) { return checkExpression(e, contextualMapper); }); - var contextualType = getContextualType(node); - if ((contextualType && contextualTypeIsTupleLikeType(contextualType)) || isAssignmentTarget(node)) { - return createTupleType(elementTypes); + var hasSpreadElement = false; + var elementTypes = []; + ts.forEach(elements, function (e) { + var type = checkExpression(e, contextualMapper); + if (e.kind === 167 /* SpreadElementExpression */) { + elementTypes.push(getIndexTypeOfType(type, 1 /* Number */) || anyType); + hasSpreadElement = true; + } + else { + elementTypes.push(type); + } + }); + if (!hasSpreadElement) { + var contextualType = getContextualType(node); + if (contextualType && contextualTypeIsTupleLikeType(contextualType) || isAssignmentTarget(node)) { + return createTupleType(elementTypes); + } } return createArrayType(getUnionType(elementTypes)); } @@ -14246,7 +11837,7 @@ var ts; return s.valueDeclaration ? s.valueDeclaration.kind : 126 /* PropertyDeclaration */; } function getDeclarationFlagsFromSymbol(s) { - return s.valueDeclaration ? s.valueDeclaration.flags : s.flags & 134217728 /* Prototype */ ? 16 /* Public */ | 128 /* Static */ : 0; + return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 /* Prototype */ ? 16 /* Public */ | 128 /* Static */ : 0; } function checkClassPropertyAccess(node, left, type, prop) { var flags = getDeclarationFlagsFromSymbol(prop); @@ -14461,7 +12052,7 @@ var ts; var context = createInferenceContext(typeParameters, false); var mapper = createInferenceMapper(context); for (var i = 0; i < args.length; i++) { - if (args[i].kind === 167 /* OmittedExpression */) { + if (args[i].kind === 168 /* OmittedExpression */) { continue; } if (!excludeArgument || excludeArgument[i] === undefined) { @@ -14475,7 +12066,7 @@ var ts; } if (excludeArgument) { for (var i = 0; i < args.length; i++) { - if (args[i].kind === 167 /* OmittedExpression */) { + if (args[i].kind === 168 /* OmittedExpression */) { continue; } if (excludeArgument[i] === false) { @@ -14513,7 +12104,7 @@ var ts; for (var i = 0; i < args.length; i++) { var arg = args[i]; var argType; - if (arg.kind === 167 /* OmittedExpression */) { + if (arg.kind === 168 /* OmittedExpression */) { continue; } var paramType = getTypeAtPosition(signature, i); @@ -14600,7 +12191,7 @@ var ts; else { error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); } - if (!fullTypeCheck) { + if (!produceDiagnostics) { for (var i = 0, n = candidates.length; i < n; i++) { if (hasCorrectArity(node, args, candidates[i])) { return candidates[i]; @@ -14814,7 +12405,7 @@ var ts; function checkTypeAssertion(node) { var exprType = checkExpression(node.expression); var targetType = getTypeFromTypeNode(node.type); - if (fullTypeCheck && targetType !== unknownType) { + if (produceDiagnostics && targetType !== unknownType) { var widenedType = getWidenedType(exprType); if (!(isTypeAssignableTo(targetType, widenedType))) { checkTypeAssignableTo(exprType, targetType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); @@ -14840,7 +12431,7 @@ var ts; } function getReturnTypeFromBody(func, contextualMapper) { var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func); - if (func.body.kind !== 169 /* Block */) { + if (func.body.kind !== 170 /* Block */) { var type = checkExpressionCached(func.body, contextualMapper); } else { @@ -14878,16 +12469,16 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 184 /* ThrowStatement */); + return (body.statements.length === 1) && (body.statements[0].kind === 185 /* ThrowStatement */); } function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) { - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } if (returnType === voidType || returnType === anyType) { return; } - if (!func.body || func.body.kind !== 169 /* Block */) { + if (ts.nodeIsMissing(func.body) || func.body.kind !== 170 /* Block */) { return; } var bodyBlock = func.body; @@ -14930,7 +12521,7 @@ var ts; checkSignatureDeclaration(node); } } - if (fullTypeCheck && node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { + if (produceDiagnostics && node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); } @@ -14942,7 +12533,7 @@ var ts; checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } if (node.body) { - if (node.body.kind === 169 /* Block */) { + if (node.body.kind === 170 /* Block */) { checkSourceElement(node.body); } else { @@ -15117,14 +12708,24 @@ var ts; var elements = node.elements; for (var i = 0; i < elements.length; i++) { var e = elements[i]; - if (e.kind !== 167 /* OmittedExpression */) { - var propName = "" + i; - var type = sourceType.flags & 1 /* Any */ ? sourceType : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : getIndexTypeOfType(sourceType, 1 /* Number */); - if (type) { - checkDestructuringAssignment(e, type, contextualMapper); + if (e.kind !== 168 /* OmittedExpression */) { + if (e.kind !== 167 /* SpreadElementExpression */) { + var propName = "" + i; + var type = sourceType.flags & 1 /* Any */ ? sourceType : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : getIndexTypeOfType(sourceType, 1 /* Number */); + if (type) { + checkDestructuringAssignment(e, type, contextualMapper); + } + else { + error(e, ts.Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName); + } } else { - error(e, ts.Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName); + if (i === elements.length - 1) { + checkReferenceAssignment(e.expression, sourceType, contextualMapper); + } + else { + error(e, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); + } } } } @@ -15141,6 +12742,9 @@ var ts; if (target.kind === 147 /* ArrayLiteralExpression */) { return checkArrayLiteralAssignment(target, sourceType, contextualMapper); } + return checkReferenceAssignment(target, sourceType, contextualMapper); + } + function checkReferenceAssignment(target, sourceType, contextualMapper) { var targetType = checkExpression(target, contextualMapper); if (checkReferenceExpression(target, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant)) { checkTypeAssignableTo(sourceType, targetType, target, undefined); @@ -15260,7 +12864,7 @@ var ts; } } function checkAssignmentOperator(valueType) { - if (fullTypeCheck && operator >= 52 /* FirstAssignment */ && operator <= 63 /* LastAssignment */) { + if (produceDiagnostics && operator >= 52 /* FirstAssignment */ && operator <= 63 /* LastAssignment */) { var ok = checkReferenceExpression(node.left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); if (ok) { checkTypeAssignableTo(valueType, leftType, node.left, undefined); @@ -15405,7 +13009,9 @@ var ts; return checkBinaryExpression(node, contextualMapper); case 164 /* ConditionalExpression */: return checkConditionalExpression(node, contextualMapper); - case 167 /* OmittedExpression */: + case 167 /* SpreadElementExpression */: + return checkSpreadElementExpression(node, contextualMapper); + case 168 /* OmittedExpression */: return undefinedType; case 166 /* YieldExpression */: checkYieldExpression(node); @@ -15418,7 +13024,7 @@ var ts; grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected); } checkSourceElement(node.constraint); - if (fullTypeCheck) { + if (produceDiagnostics) { checkTypeParameterHasIllegalReferencesInConstraint(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0); } @@ -15429,7 +13035,7 @@ var ts; var func = ts.getContainingFunction(node); if (node.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */)) { func = ts.getContainingFunction(node); - if (!(func.kind === 129 /* Constructor */ && func.body)) { + if (!(func.kind === 129 /* Constructor */ && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } @@ -15451,7 +13057,7 @@ var ts; if (node.type) { checkSourceElement(node.type); } - if (fullTypeCheck) { + if (produceDiagnostics) { checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { @@ -15519,10 +13125,10 @@ var ts; if (node === firstDeclaration) { checkFunctionOrConstructorSymbol(symbol); } - if (!node.body) { + if (ts.nodeIsMissing(node.body)) { return; } - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } function isSuperCallExpression(n) { @@ -15556,7 +13162,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 !== 172 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) { + if (!statements.length || statements[0].kind !== 173 /* 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 { @@ -15570,10 +13176,10 @@ var ts; } } function checkAccessorDeclaration(node) { - checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); - if (fullTypeCheck) { + if (produceDiagnostics) { + checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); if (node.kind === 130 /* GetAccessor */) { - if (!ts.isInAmbientContext(node) && node.body && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { + if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement); } } @@ -15605,7 +13211,7 @@ var ts; for (var i = 0; i < len; i++) { checkSourceElement(node.typeArguments[i]); var constraint = getConstraintOfTypeParameter(type.target.typeParameters[i]); - if (fullTypeCheck && constraint) { + if (produceDiagnostics && constraint) { var typeArgument = type.typeArguments[i]; checkTypeAssignableTo(typeArgument, constraint, node, ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1); } @@ -15617,7 +13223,7 @@ var ts; } function checkTypeLiteral(node) { ts.forEach(node.members, checkSourceElement); - if (fullTypeCheck) { + if (produceDiagnostics) { var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); @@ -15640,14 +13246,14 @@ var ts; return (node.flags & 32 /* Private */) && ts.isInAmbientContext(node); } function checkSpecializedSignatureDeclaration(signatureDeclarationNode) { - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } var signature = getSignatureFromDeclaration(signatureDeclarationNode); if (!signature.hasStringLiterals) { return; } - if (signatureDeclarationNode.body) { + if (ts.nodeIsPresent(signatureDeclarationNode.body)) { error(signatureDeclarationNode, ts.Diagnostics.A_signature_with_an_implementation_cannot_use_a_string_literal_type); return; } @@ -15671,7 +13277,7 @@ var ts; error(signatureDeclarationNode, ts.Diagnostics.Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature); } function getEffectiveDeclarationFlags(n, flagsToCheck) { - var flags = n.flags; + var flags = ts.getCombinedNodeFlags(n); if (n.parent.kind !== 192 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { if (!(flags & 2 /* Ambient */)) { flags |= 1 /* Export */; @@ -15681,7 +13287,7 @@ var ts; return flags & flagsToCheck; } function checkFunctionOrConstructorSymbol(symbol) { - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } function getCanonicalOverload(overloads, implementation) { @@ -15751,7 +13357,7 @@ var ts; error(errorNode, diagnostic); return; } - else if (subsequentNode.body) { + else if (ts.nodeIsPresent(subsequentNode.body)) { error(errorNode, ts.Diagnostics.Function_implementation_name_must_be_0, ts.declarationNameToString(node.name)); return; } @@ -15781,7 +13387,7 @@ var ts; allNodeFlags &= currentNodeFlags; someHaveQuestionToken = someHaveQuestionToken || ts.hasQuestionToken(node); allHaveQuestionToken = allHaveQuestionToken && ts.hasQuestionToken(node); - if (node.body && bodyDeclaration) { + if (ts.nodeIsPresent(node.body) && bodyDeclaration) { if (isConstructor) { multipleConstructorImplementation = true; } @@ -15792,7 +13398,7 @@ var ts; else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) { reportImplementationExpectedError(previousDeclaration); } - if (node.body) { + if (ts.nodeIsPresent(node.body)) { if (!bodyDeclaration) { bodyDeclaration = node; } @@ -15837,7 +13443,7 @@ var ts; } } function checkExportsOnMergedDeclarations(node) { - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } var symbol; @@ -15892,9 +13498,8 @@ var ts; } } function checkFunctionDeclaration(node) { - checkFunctionLikeDeclaration(node); - checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); - if (fullTypeCheck) { + if (produceDiagnostics) { + checkFunctionLikeDeclaration(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -15919,12 +13524,12 @@ var ts; if (node.type && !isAccessor(node.kind)) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (compilerOptions.noImplicitAny && !node.body && !node.type && !isPrivateWithinAmbient(node)) { + if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) { reportImplicitAnyError(node, anyType); } } function checkBlock(node) { - if (node.kind === 169 /* Block */) { + if (node.kind === 170 /* Block */) { checkGrammarForStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); @@ -15933,7 +13538,7 @@ var ts; } } function checkCollisionWithArgumentsInGeneratedCode(node) { - if (!ts.hasRestParameters(node) || ts.isInAmbientContext(node) || !node.body) { + if (!ts.hasRestParameters(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { return; } ts.forEach(node.parameters, function (p) { @@ -15953,7 +13558,7 @@ var ts; return false; } var root = getRootDeclaration(node); - if (root.kind === 124 /* Parameter */ && !root.parent.body) { + if (root.kind === 124 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) { return false; } return true; @@ -16010,7 +13615,7 @@ var ts; } } function checkCollisionWithConstDeclarations(node) { - if (node.initializer && (node.flags & 6144 /* BlockScoped */) === 0) { + if (node.initializer && (ts.getCombinedNodeFlags(node) & 6144 /* BlockScoped */) === 0) { var symbol = getSymbolOfNode(node); if (symbol.flags & 1 /* FunctionScopedVariable */) { var localDeclarationSymbol = resolveName(node, node.name.text, 3 /* Variable */, undefined, undefined); @@ -16055,12 +13660,6 @@ var ts; } } function checkVariableLikeDeclaration(node) { - if (node.kind === 146 /* BindingElement */) { - checkGrammarEvalOrArgumentsInStrictMode(node, node.name); - } - else if (node.kind === 189 /* VariableDeclaration */) { - checkGrammarVariableDeclaration(node); - } checkSourceElement(node.type); if (ts.hasComputedNameButNotSymbol(node)) { if (node.initializer) { @@ -16071,7 +13670,7 @@ var ts; if (ts.isBindingPattern(node.name)) { ts.forEach(node.name.elements, checkSourceElement); } - if (node.initializer && getRootDeclaration(node).kind === 124 /* Parameter */ && !ts.getContainingFunction(node).body) { + if (node.initializer && getRootDeclaration(node).kind === 124 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } @@ -16107,9 +13706,32 @@ var ts; checkCollisionWithRequireExportsInGeneratedCode(node, node.name); } } + function checkVariableDeclaration(node) { + checkGrammarVariableDeclaration(node); + return checkVariableLikeDeclaration(node); + } + function checkBindingElement(node) { + checkGrammarBindingElement(node); + return checkVariableLikeDeclaration(node); + } function checkVariableStatement(node) { - checkGrammarModifiers(node) || checkGrammarVariableDeclarations(node, node.declarations) || checkGrammarForDisallowedLetOrConstStatement(node); - ts.forEach(node.declarations, checkSourceElement); + checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); + ts.forEach(node.declarationList.declarations, checkSourceElement); + } + function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) { + if (node.modifiers) { + if (inBlockOrObjectLiteralExpression(node)) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + } + } + function inBlockOrObjectLiteralExpression(node) { + while (node) { + if (node.kind === 170 /* Block */ || node.kind === 148 /* ObjectLiteralExpression */) { + return true; + } + node = node.parent; + } } function checkExpressionStatement(node) { checkGrammarForStatementInAmbientContext(node); @@ -16132,11 +13754,19 @@ var ts; checkSourceElement(node.statement); } function checkForStatement(node) { - checkGrammarForStatementInAmbientContext(node) || checkGrammarVariableDeclarations(node, node.declarations); - if (node.declarations) - ts.forEach(node.declarations, checkVariableLikeDeclaration); - if (node.initializer) - checkExpression(node.initializer); + if (!checkGrammarForStatementInAmbientContext(node)) { + if (node.initializer && node.initializer.kind == 189 /* VariableDeclarationList */) { + checkGrammarVariableDeclarationList(node.initializer); + } + } + if (node.initializer) { + if (node.initializer.kind === 189 /* VariableDeclarationList */) { + ts.forEach(node.initializer.declarations, checkVariableDeclaration); + } + else { + checkExpression(node.initializer); + } + } if (node.condition) checkExpression(node.condition); if (node.iterator) @@ -16145,29 +13775,33 @@ var ts; } function checkForInStatement(node) { if (!checkGrammarForStatementInAmbientContext(node)) { - var declarations = node.declarations; - if (!checkGrammarVariableDeclarations(node, declarations)) { - if (declarations && declarations.length > 1) { - grammarErrorOnFirstToken(declarations[1], ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); + if (node.initializer.kind === 189 /* VariableDeclarationList */) { + var variableList = node.initializer; + if (!checkGrammarVariableDeclarationList(variableList)) { + if (variableList.declarations.length > 1) { + grammarErrorOnFirstToken(variableList.declarations[1], ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); + } } } } - if (node.declarations) { - if (node.declarations.length >= 1) { - var decl = node.declarations[0]; - checkVariableLikeDeclaration(decl); + if (node.initializer.kind === 189 /* VariableDeclarationList */) { + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length >= 1) { + var decl = variableDeclarationList.declarations[0]; + checkVariableDeclaration(decl); if (decl.type) { error(decl, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation); } } } - if (node.variable) { - var exprType = checkExpression(node.variable); + else { + var varExpr = node.initializer; + var exprType = checkExpression(varExpr); if (exprType !== anyType && exprType !== stringType) { - error(node.variable, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); + error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { - checkReferenceExpression(node.variable, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); } } var exprType = checkExpression(node.expression); @@ -16237,7 +13871,7 @@ var ts; hasDuplicateDefaultClause = true; } } - if (fullTypeCheck && clause.kind === 200 /* CaseClause */) { + if (produceDiagnostics && clause.kind === 200 /* CaseClause */) { var caseClause = clause; var caseType = checkExpression(caseClause.expression); if (!isTypeAssignableTo(expressionType, caseType)) { @@ -16254,7 +13888,7 @@ var ts; if (ts.isAnyFunction(current)) { break; } - if (current.kind === 183 /* LabeledStatement */ && current.label.text === node.label.text) { + if (current.kind === 184 /* LabeledStatement */ && current.label.text === node.label.text) { var sourceFile = ts.getSourceFileOfNode(node); grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label)); break; @@ -16352,7 +13986,7 @@ var ts; for (var i = 0; i < typeParameterDeclarations.length; i++) { var node = typeParameterDeclarations[i]; checkTypeParameter(node); - if (fullTypeCheck) { + if (produceDiagnostics) { for (var j = 0; j < i; j++) { if (typeParameterDeclarations[j].symbol === node.symbol) { error(node.name, ts.Diagnostics.Duplicate_identifier_0, ts.declarationNameToString(node.name)); @@ -16378,7 +14012,7 @@ var ts; checkTypeReference(baseTypeNode); } if (type.baseTypes.length) { - if (fullTypeCheck) { + if (produceDiagnostics) { var baseType = type.baseTypes[0]; checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); var staticBaseType = getTypeOfSymbol(baseType.symbol); @@ -16394,7 +14028,7 @@ var ts; if (implementedTypeNodes) { ts.forEach(implementedTypeNodes, function (typeRefNode) { checkTypeReference(typeRefNode); - if (fullTypeCheck) { + if (produceDiagnostics) { var t = getTypeFromTypeReferenceNode(typeRefNode); if (t !== unknownType) { var declaredType = (t.flags & 4096 /* Reference */) ? t.target : t; @@ -16409,7 +14043,7 @@ var ts; }); } ts.forEach(node.members, checkSourceElement); - if (fullTypeCheck) { + if (produceDiagnostics) { checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); } @@ -16514,7 +14148,7 @@ var ts; var typeName2 = typeToString(base); var errorInfo = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.Named_properties_0_of_types_1_and_2_are_not_identical, prop.name, typeName1, typeName2); errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2); - addDiagnostic(ts.createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, program.getCompilerHost().getNewLine())); + addDiagnostic(ts.createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, host.getCompilerHost().getNewLine())); } } } @@ -16524,7 +14158,7 @@ var ts; function checkInterfaceDeclaration(node) { checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); - if (fullTypeCheck) { + if (produceDiagnostics) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); @@ -16546,7 +14180,7 @@ var ts; } ts.forEach(ts.getInterfaceBaseTypeNodes(node), checkTypeReference); ts.forEach(node.members, checkSourceElement); - if (fullTypeCheck) { + if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); } } @@ -16691,10 +14325,10 @@ var ts; } } function checkEnumDeclaration(node) { - checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); - if (!fullTypeCheck) { + if (!produceDiagnostics) { return; } + checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -16736,36 +14370,36 @@ var ts; var declarations = symbol.declarations; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; - if ((declaration.kind === 191 /* ClassDeclaration */ || (declaration.kind === 190 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) { + if ((declaration.kind === 191 /* ClassDeclaration */ || (declaration.kind === 190 /* FunctionDeclaration */ && ts.nodeIsPresent(declaration.body))) && !ts.isInAmbientContext(declaration)) { return declaration; } } return undefined; } function checkModuleDeclaration(node) { - if (!checkGrammarModifiers(node)) { - if (!ts.isInAmbientContext(node) && node.name.kind === 8 /* StringLiteral */) { - grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); - } - else if (node.name.kind === 64 /* Identifier */ && node.body.kind === 196 /* ModuleBlock */) { - var statements = node.body.statements; - for (var i = 0, n = statements.length; i < n; i++) { - var statement = statements[i]; - if (statement.kind === 198 /* ExportAssignment */) { - grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); - } - else if (ts.isExternalModuleImportDeclaration(statement)) { - grammarErrorOnNode(ts.getExternalModuleImportDeclarationExpression(statement), ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + if (produceDiagnostics) { + if (!checkGrammarModifiers(node)) { + if (!ts.isInAmbientContext(node) && node.name.kind === 8 /* StringLiteral */) { + grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); + } + else if (node.name.kind === 64 /* Identifier */ && node.body.kind === 196 /* ModuleBlock */) { + var statements = node.body.statements; + for (var i = 0, n = statements.length; i < n; i++) { + var statement = statements[i]; + if (statement.kind === 198 /* ExportAssignment */) { + grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + } + else if (ts.isExternalModuleImportDeclaration(statement)) { + grammarErrorOnNode(ts.getExternalModuleImportDeclarationExpression(statement), ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + } } } } - } - if (fullTypeCheck) { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - if (symbol.flags & 512 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node)) { + if (symbol.flags & 512 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node) && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums)) { var classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (classOrFunc) { if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(classOrFunc)) { @@ -16897,41 +14531,42 @@ var ts; return checkSourceElement(node.type); case 190 /* FunctionDeclaration */: return checkFunctionDeclaration(node); - case 169 /* Block */: + case 170 /* Block */: case 196 /* ModuleBlock */: return checkBlock(node); - case 170 /* VariableStatement */: + case 171 /* VariableStatement */: return checkVariableStatement(node); - case 172 /* ExpressionStatement */: + case 173 /* ExpressionStatement */: return checkExpressionStatement(node); - case 173 /* IfStatement */: + case 174 /* IfStatement */: return checkIfStatement(node); - case 174 /* DoStatement */: + case 175 /* DoStatement */: return checkDoStatement(node); - case 175 /* WhileStatement */: + case 176 /* WhileStatement */: return checkWhileStatement(node); - case 176 /* ForStatement */: + case 177 /* ForStatement */: return checkForStatement(node); - case 177 /* ForInStatement */: + case 178 /* ForInStatement */: return checkForInStatement(node); - case 178 /* ContinueStatement */: - case 179 /* BreakStatement */: + case 179 /* ContinueStatement */: + case 180 /* BreakStatement */: return checkBreakOrContinueStatement(node); - case 180 /* ReturnStatement */: + case 181 /* ReturnStatement */: return checkReturnStatement(node); - case 181 /* WithStatement */: + case 182 /* WithStatement */: return checkWithStatement(node); - case 182 /* SwitchStatement */: + case 183 /* SwitchStatement */: return checkSwitchStatement(node); - case 183 /* LabeledStatement */: + case 184 /* LabeledStatement */: return checkLabeledStatement(node); - case 184 /* ThrowStatement */: + case 185 /* ThrowStatement */: return checkThrowStatement(node); - case 185 /* TryStatement */: + case 186 /* TryStatement */: return checkTryStatement(node); - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: + return checkVariableDeclaration(node); case 146 /* BindingElement */: - return checkVariableLikeDeclaration(node); + return checkBindingElement(node); case 191 /* ClassDeclaration */: return checkClassDeclaration(node); case 192 /* InterfaceDeclaration */: @@ -16946,10 +14581,10 @@ var ts; return checkImportDeclaration(node); case 198 /* ExportAssignment */: return checkExportAssignment(node); - case 171 /* EmptyStatement */: + case 172 /* EmptyStatement */: checkGrammarForStatementInAmbientContext(node); return; - case 188 /* DebuggerStatement */: + case 187 /* DebuggerStatement */: checkGrammarForStatementInAmbientContext(node); return; } @@ -16974,7 +14609,7 @@ var ts; case 190 /* FunctionDeclaration */: ts.forEach(node.parameters, checkFunctionExpressionBodies); break; - case 181 /* WithStatement */: + case 182 /* WithStatement */: checkFunctionExpressionBodies(node.expression); break; case 124 /* Parameter */: @@ -16991,6 +14626,8 @@ var ts; case 151 /* CallExpression */: case 152 /* NewExpression */: case 153 /* TaggedTemplateExpression */: + case 165 /* TemplateExpression */: + case 169 /* TemplateSpan */: case 154 /* TypeAssertionExpression */: case 155 /* ParenthesizedExpression */: case 159 /* TypeOfExpression */: @@ -17000,28 +14637,28 @@ var ts; case 162 /* PostfixUnaryExpression */: case 163 /* BinaryExpression */: case 164 /* ConditionalExpression */: - case 169 /* Block */: + case 167 /* SpreadElementExpression */: + case 170 /* Block */: case 196 /* ModuleBlock */: - case 170 /* VariableStatement */: - case 172 /* ExpressionStatement */: - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 178 /* ContinueStatement */: - case 179 /* BreakStatement */: - case 180 /* ReturnStatement */: - case 182 /* SwitchStatement */: + case 171 /* VariableStatement */: + case 173 /* ExpressionStatement */: + case 174 /* IfStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 179 /* ContinueStatement */: + case 180 /* BreakStatement */: + case 181 /* ReturnStatement */: + case 183 /* SwitchStatement */: case 200 /* CaseClause */: case 201 /* DefaultClause */: - case 183 /* LabeledStatement */: - case 184 /* ThrowStatement */: - case 185 /* TryStatement */: - case 186 /* TryBlock */: + case 184 /* LabeledStatement */: + case 185 /* ThrowStatement */: + case 186 /* TryStatement */: case 203 /* CatchClause */: - case 187 /* FinallyBlock */: - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: + case 189 /* VariableDeclarationList */: case 191 /* ClassDeclaration */: case 194 /* EnumDeclaration */: case 206 /* EnumMember */: @@ -17056,7 +14693,7 @@ var ts; } } function getSortedDiagnostics() { - ts.Debug.assert(fullTypeCheck, "diagnostics are available only in the full typecheck mode"); + ts.Debug.assert(produceDiagnostics, "diagnostics are available only in the full typecheck mode"); if (diagnosticsModified) { diagnostics.sort(ts.compareDiagnostics); diagnostics = ts.deduplicateSortedDiagnostics(diagnostics); @@ -17065,25 +14702,27 @@ var ts; return diagnostics; } function getDiagnostics(sourceFile) { + throwIfNonDiagnosticsProducing(); if (sourceFile) { checkSourceFile(sourceFile); return ts.filter(getSortedDiagnostics(), function (d) { return d.file === sourceFile; }); } - ts.forEach(program.getSourceFiles(), checkSourceFile); + ts.forEach(host.getSourceFiles(), checkSourceFile); return getSortedDiagnostics(); } - function getDeclarationDiagnostics(targetSourceFile) { - var resolver = createResolver(); - checkSourceFile(targetSourceFile); - return ts.getDeclarationDiagnostics(program, resolver, targetSourceFile); - } function getGlobalDiagnostics() { + throwIfNonDiagnosticsProducing(); return ts.filter(getSortedDiagnostics(), function (d) { return !d.file; }); } + function throwIfNonDiagnosticsProducing() { + if (!produceDiagnostics) { + throw new Error("Trying to get diagnostics from a type checker that does not produce them."); + } + } function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 181 /* WithStatement */ && node.parent.statement === node) { + if (node.parent.kind === 182 /* WithStatement */ && node.parent.statement === node) { return true; } node = node.parent; @@ -17203,7 +14842,7 @@ var ts; case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: case 124 /* Parameter */: - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: return node === parent.type; case 190 /* FunctionDeclaration */: case 156 /* FunctionExpression */: @@ -17424,8 +15063,17 @@ var ts; } function isUniqueLocalName(name, container) { for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { - if (node.locals && ts.hasProperty(node.locals, name) && node.locals[name].flags & (107455 /* Value */ | 1048576 /* ExportValue */)) { - return false; + if (node.locals && ts.hasProperty(node.locals, name)) { + var symbolWithRelevantName = node.locals[name]; + if (symbolWithRelevantName.flags & (107455 /* Value */ | 1048576 /* ExportValue */)) { + return false; + } + if (symbolWithRelevantName.flags & 8388608 /* Import */) { + var importDeclarationWithRelevantName = ts.getDeclarationOfKind(symbolWithRelevantName, 197 /* ImportDeclaration */); + if (isReferencedImportDeclaration(importDeclarationWithRelevantName)) { + return false; + } + } } } return true; @@ -17477,12 +15125,6 @@ var ts; function hasSemanticErrors(sourceFile) { return getDiagnostics(sourceFile).length > 0 || getGlobalDiagnostics().length > 0; } - function isEmitBlocked(sourceFile) { - return program.getDiagnostics(sourceFile).length !== 0 || hasEarlyErrors(sourceFile) || (compilerOptions.noEmitOnError && getDiagnostics(sourceFile).length !== 0); - } - function hasEarlyErrors(sourceFile) { - return ts.forEach(getDiagnostics(sourceFile), function (d) { return d.isEarly; }); - } function isImportResolvedToValue(symbol) { var target = resolveImport(symbol); return target !== unknownSymbol && target.flags & 107455 /* Value */ && !isConstEnumOrConstEnumOnlyModule(target); @@ -17501,7 +15143,7 @@ var ts; return false; } function isImplementationOfOverload(node) { - if (node.body) { + if (ts.nodeIsPresent(node.body)) { var symbol = getSymbolOfNode(node); var signaturesOfSymbol = getSignaturesOfSymbol(symbol); return signaturesOfSymbol.length > 1 || (signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node); @@ -17540,7 +15182,6 @@ var ts; } function createResolver() { return { - getProgram: function () { return program; }, getLocalNameOfContainer: getLocalNameOfContainer, getExpressionNamePrefix: getExpressionNamePrefix, getExportAssignmentName: getExportAssignmentName, @@ -17549,7 +15190,6 @@ var ts; getEnumMemberValue: getEnumMemberValue, isTopLevelValueImportWithEntityName: isTopLevelValueImportWithEntityName, hasSemanticErrors: hasSemanticErrors, - isEmitBlocked: isEmitBlocked, isDeclarationVisible: isDeclarationVisible, isImplementationOfOverload: isImplementationOfOverload, writeTypeOfDeclaration: writeTypeOfDeclaration, @@ -17560,16 +15200,12 @@ var ts; isUnknownIdentifier: isUnknownIdentifier }; } - function invokeEmitter(targetSourceFile) { - var resolver = createResolver(); - return ts.emitFiles(resolver, targetSourceFile); - } function initializeTypeChecker() { - ts.forEach(program.getSourceFiles(), function (file) { + ts.forEach(host.getSourceFiles(), function (file) { ts.bindSourceFile(file); ts.forEach(file.semanticDiagnostics, addDiagnostic); }); - ts.forEach(program.getSourceFiles(), function (file) { + ts.forEach(host.getSourceFiles(), function (file) { if (!ts.isExternalModule(file)) { extendSymbolTable(globals, file.locals); } @@ -17604,7 +15240,7 @@ var ts; case 195 /* ModuleDeclaration */: case 194 /* EnumDeclaration */: case 198 /* ExportAssignment */: - case 170 /* VariableStatement */: + case 171 /* VariableStatement */: case 190 /* FunctionDeclaration */: case 193 /* TypeAliasDeclaration */: case 197 /* ImportDeclaration */: @@ -17821,7 +15457,7 @@ var ts; var sourceFile = ts.getSourceFileOfNode(node); for (var i = 0, n = arguments.length; i < n; i++) { var arg = arguments[i]; - if (arg.kind === 167 /* OmittedExpression */) { + if (arg.kind === 168 /* OmittedExpression */) { return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected); } } @@ -17929,7 +15565,7 @@ var ts; for (var i = 0, n = node.properties.length; i < n; i++) { var prop = node.properties[i]; var name = prop.name; - if (prop.kind === 167 /* OmittedExpression */ || name.kind === 122 /* ComputedPropertyName */) { + if (prop.kind === 168 /* OmittedExpression */ || name.kind === 122 /* ComputedPropertyName */) { checkGrammarComputedPropertyName(name); continue; } @@ -18024,9 +15660,17 @@ var ts; } } function checkGrammarMethod(node) { - if (checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { + if (checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { return true; } + if (node.parent.kind === 148 /* ObjectLiteralExpression */) { + if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { + return true; + } + else if (node.body === undefined) { + return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); + } + } if (node.parent.kind === 191 /* ClassDeclaration */) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; @@ -18047,12 +15691,12 @@ var ts; } function isIterationStatement(node, lookInLabeledStatements) { switch (node.kind) { - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: return true; - case 183 /* LabeledStatement */: + case 184 /* LabeledStatement */: return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); } return false; @@ -18064,17 +15708,17 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { - case 183 /* LabeledStatement */: + case 184 /* LabeledStatement */: if (node.label && current.label.text === node.label.text) { - var isMisplacedContinueLabel = node.kind === 178 /* ContinueStatement */ && !isIterationStatement(current.statement, true); + var isMisplacedContinueLabel = node.kind === 179 /* ContinueStatement */ && !isIterationStatement(current.statement, true); if (isMisplacedContinueLabel) { return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); } return false; } break; - case 182 /* SwitchStatement */: - if (node.kind === 179 /* BreakStatement */ && !node.label) { + case 183 /* SwitchStatement */: + if (node.kind === 180 /* BreakStatement */ && !node.label) { return false; } break; @@ -18087,14 +15731,26 @@ var ts; current = current.parent; } if (node.label) { - var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; + var message = node.kind === 180 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } else { - var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; + var message = node.kind === 180 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } } + function checkGrammarBindingElement(node) { + if (node.dotDotDotToken) { + var elements = node.parent.elements; + if (node !== elements[elements.length - 1]) { + return grammarErrorOnNode(node, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); + } + if (node.initializer) { + return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.A_rest_element_cannot_have_an_initializer); + } + } + return checkGrammarEvalOrArgumentsInStrictMode(node, node.name); + } function checkGrammarVariableDeclaration(node) { if (ts.isInAmbientContext(node)) { if (ts.isBindingPattern(node.name)) { @@ -18116,45 +15772,43 @@ var ts; } return checkGrammarEvalOrArgumentsInStrictMode(node, node.name); } - function checkGrammarVariableDeclarations(container, declarations) { - if (declarations) { - if (checkGrammarForDisallowedTrailingComma(declarations)) { - return true; + function checkGrammarVariableDeclarationList(declarationList) { + var declarations = declarationList.declarations; + if (checkGrammarForDisallowedTrailingComma(declarationList.declarations)) { + return true; + } + if (!declarationList.declarations.length) { + return grammarErrorAtPos(ts.getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); + } + if (compilerOptions.target < 2 /* ES6 */) { + if (ts.isLet(declarationList)) { + return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } - if (!declarations.length) { - return grammarErrorAtPos(ts.getSourceFileOfNode(container), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); - } - var decl = declarations[0]; - if (compilerOptions.target < 2 /* ES6 */) { - if (ts.isLet(decl)) { - return grammarErrorOnFirstToken(decl, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (ts.isConst(decl)) { - return grammarErrorOnFirstToken(decl, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } + else if (ts.isConst(declarationList)) { + return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } } } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 181 /* WithStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: + case 174 /* IfStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: + case 182 /* WithStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: return false; - case 183 /* LabeledStatement */: + case 184 /* LabeledStatement */: return allowLetAndConstDeclarations(parent.parent); } return true; } function checkGrammarForDisallowedLetOrConstStatement(node) { if (!allowLetAndConstDeclarations(node.parent)) { - if (ts.isLet(node)) { + if (ts.isLet(node.declarationList)) { return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block); } - else if (ts.isConst(node)) { + else if (ts.isConst(node.declarationList)) { return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block); } } @@ -18275,7 +15929,7 @@ var ts; function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) { for (var i = 0, n = file.statements.length; i < n; i++) { var decl = file.statements[i]; - if (ts.isDeclaration(decl) || decl.kind === 170 /* VariableStatement */) { + if (ts.isDeclaration(decl) || decl.kind === 171 /* VariableStatement */) { if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) { return true; } @@ -18294,7 +15948,7 @@ var ts; if (!links.hasReportedStatementInAmbientContext && ts.isAnyFunction(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); } - if (node.parent.kind === 169 /* Block */ || node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { + if (node.parent.kind === 170 /* Block */ || node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { var links = getNodeLinks(node.parent); if (!links.hasReportedStatementInAmbientContext) { return links.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts); @@ -18329,6 +15983,4095 @@ var ts; ts.createTypeChecker = createTypeChecker; })(ts || (ts = {})); var ts; +(function (ts) { + var indentStrings = ["", " "]; + function getIndentString(level) { + if (indentStrings[level] === undefined) { + indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; + } + return indentStrings[level]; + } + ts.getIndentString = getIndentString; + function getIndentSize() { + return indentStrings[1].length; + } + function shouldEmitToOwnFile(sourceFile, compilerOptions) { + if (!ts.isDeclarationFile(sourceFile)) { + if ((ts.isExternalModule(sourceFile) || !compilerOptions.out) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { + return true; + } + return false; + } + return false; + } + ts.shouldEmitToOwnFile = shouldEmitToOwnFile; + function isExternalModuleOrDeclarationFile(sourceFile) { + return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); + } + ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; + function createTextWriter(newLine) { + var output = ""; + var indent = 0; + var lineStart = true; + var lineCount = 0; + var linePos = 0; + function write(s) { + if (s && s.length) { + if (lineStart) { + output += getIndentString(indent); + lineStart = false; + } + output += s; + } + } + function rawWrite(s) { + if (s !== undefined) { + if (lineStart) { + lineStart = false; + } + output += s; + } + } + function writeLiteral(s) { + if (s && s.length) { + write(s); + var lineStartsOfS = ts.computeLineStarts(s); + if (lineStartsOfS.length > 1) { + lineCount = lineCount + lineStartsOfS.length - 1; + linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; + } + } + } + function writeLine() { + if (!lineStart) { + output += newLine; + lineCount++; + linePos = output.length; + lineStart = true; + } + } + function writeTextOfNode(sourceFile, node) { + write(ts.getSourceTextOfNodeFromSourceFile(sourceFile, node)); + } + return { + write: write, + rawWrite: rawWrite, + writeTextOfNode: writeTextOfNode, + writeLiteral: writeLiteral, + writeLine: writeLine, + increaseIndent: function () { return indent++; }, + decreaseIndent: function () { return indent--; }, + getIndent: function () { return indent; }, + getTextPos: function () { return output.length; }, + getLine: function () { return lineCount + 1; }, + getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; }, + getText: function () { return output; } + }; + } + function getLineOfLocalPosition(currentSourceFile, pos) { + return currentSourceFile.getLineAndCharacterFromPosition(pos).line; + } + function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) { + if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) { + writer.writeLine(); + } + } + function emitComments(currentSourceFile, writer, comments, trailingSeparator, newLine, writeComment) { + var emitLeadingSpace = !trailingSeparator; + ts.forEach(comments, function (comment) { + if (emitLeadingSpace) { + writer.write(" "); + emitLeadingSpace = false; + } + writeComment(currentSourceFile, writer, comment, newLine); + if (comment.hasTrailingNewLine) { + writer.writeLine(); + } + else if (trailingSeparator) { + writer.write(" "); + } + else { + emitLeadingSpace = true; + } + }); + } + function writeCommentRange(currentSourceFile, writer, comment, newLine) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) { + var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos); + var firstCommentLineIndent; + for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { + var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1); + if (pos !== comment.pos) { + if (firstCommentLineIndent === undefined) { + firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, 1), comment.pos); + } + var currentWriterIndentSpacing = writer.getIndent() * getIndentSize(); + var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart); + if (spacesToEmit > 0) { + var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize(); + var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize()); + writer.rawWrite(indentSizeSpaceString); + while (numberOfSingleSpacesToEmit) { + writer.rawWrite(" "); + numberOfSingleSpacesToEmit--; + } + } + else { + writer.rawWrite(""); + } + } + writeTrimmedCurrentLine(pos, nextLineStart); + pos = nextLineStart; + } + } + else { + writer.write(currentSourceFile.text.substring(comment.pos, comment.end)); + } + function writeTrimmedCurrentLine(pos, nextLineStart) { + var end = Math.min(comment.end, nextLineStart - 1); + var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ''); + if (currentLineText) { + writer.write(currentLineText); + if (end !== comment.end) { + writer.writeLine(); + } + } + else { + writer.writeLiteral(newLine); + } + } + function calculateIndent(pos, end) { + var currentLineIndent = 0; + for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { + if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) { + currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); + } + else { + currentLineIndent++; + } + } + return currentLineIndent; + } + } + function getFirstConstructorWithBody(node) { + return ts.forEach(node.members, function (member) { + if (member.kind === 129 /* Constructor */ && ts.nodeIsPresent(member.body)) { + return member; + } + }); + } + function getAllAccessorDeclarations(node, accessor) { + var firstAccessor; + var getAccessor; + var setAccessor; + if (accessor.name.kind === 122 /* ComputedPropertyName */) { + firstAccessor = accessor; + if (accessor.kind === 130 /* GetAccessor */) { + getAccessor = accessor; + } + else if (accessor.kind === 131 /* SetAccessor */) { + setAccessor = accessor; + } + else { + ts.Debug.fail("Accessor has wrong kind"); + } + } + else { + ts.forEach(node.members, function (member) { + if ((member.kind === 130 /* GetAccessor */ || member.kind === 131 /* SetAccessor */) && member.name.text === accessor.name.text && (member.flags & 128 /* Static */) === (accessor.flags & 128 /* Static */)) { + if (!firstAccessor) { + firstAccessor = member; + } + if (member.kind === 130 /* GetAccessor */ && !getAccessor) { + getAccessor = member; + } + if (member.kind === 131 /* SetAccessor */ && !setAccessor) { + setAccessor = member; + } + } + }); + } + return { + firstAccessor: firstAccessor, + getAccessor: getAccessor, + setAccessor: setAccessor + }; + } + function getSourceFilePathInNewDir(sourceFile, host, newDirPath) { + var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.filename, host.getCurrentDirectory()); + sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), ""); + return ts.combinePaths(newDirPath, sourceFilePath); + } + function getOwnEmitOutputFilePath(sourceFile, host, extension) { + var compilerOptions = host.getCompilerOptions(); + if (compilerOptions.outDir) { + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); + } + else { + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename); + } + return emitOutputFilePathWithoutExtension + extension; + } + function writeFile(host, diagnostics, filename, data, writeByteOrderMark) { + host.writeFile(filename, data, writeByteOrderMark, function (hostErrorMessage) { + diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage)); + }); + } + function emitDeclarations(host, resolver, diagnostics, jsFilePath, root) { + var newLine = host.getNewLine(); + var compilerOptions = host.getCompilerOptions(); + var write; + var writeLine; + var increaseIndent; + var decreaseIndent; + var writeTextOfNode; + var writer = createAndSetNewTextWriterWithSymbolWriter(); + var enclosingDeclaration; + var currentSourceFile; + var reportedDeclarationError = false; + var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { + } : writeJsDocComments; + var aliasDeclarationEmitInfo = []; + function createAndSetNewTextWriterWithSymbolWriter() { + var writer = createTextWriter(newLine); + 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; + setWriter(writer); + return writer; + } + function setWriter(newWriter) { + writer = newWriter; + write = newWriter.write; + writeTextOfNode = newWriter.writeTextOfNode; + writeLine = newWriter.writeLine; + increaseIndent = newWriter.increaseIndent; + decreaseIndent = newWriter.decreaseIndent; + } + function writeAsychronousImportDeclarations(importDeclarations) { + var oldWriter = writer; + ts.forEach(importDeclarations, function (aliasToWrite) { + var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; }); + if (aliasEmitInfo) { + createAndSetNewTextWriterWithSymbolWriter(); + for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { + increaseIndent(); + } + writeImportDeclaration(aliasToWrite); + aliasEmitInfo.asynchronousOutput = writer.getText(); + } + }); + setWriter(oldWriter); + } + function handleSymbolAccessibilityError(symbolAccesibilityResult) { + if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) { + if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { + writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); + } + } + else { + reportedDeclarationError = true; + var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult); + if (errorInfo) { + if (errorInfo.typeName) { + diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName)); + } + else { + diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName)); + } + } + } + } + function trackSymbol(symbol, enclosingDeclaration, meaning) { + handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); + } + function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + write(": "); + if (type) { + emitType(type); + } + else { + resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); + } + } + function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + write(": "); + if (signature.type) { + emitType(signature.type); + } + else { + resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); + } + } + function emitLines(nodes) { + for (var i = 0, n = nodes.length; i < n; i++) { + emitNode(nodes[i]); + } + } + function emitSeparatedList(nodes, separator, eachNodeEmitFn) { + var currentWriterPos = writer.getTextPos(); + for (var i = 0, n = nodes.length; i < n; i++) { + if (currentWriterPos !== writer.getTextPos()) { + write(separator); + } + currentWriterPos = writer.getTextPos(); + eachNodeEmitFn(nodes[i]); + } + } + function emitCommaList(nodes, eachNodeEmitFn) { + emitSeparatedList(nodes, ", ", eachNodeEmitFn); + } + function writeJsDocComments(declaration) { + if (declaration) { + var jsDocComments = ts.getJsDocComments(declaration, currentSourceFile); + emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments); + emitComments(currentSourceFile, writer, jsDocComments, true, newLine, writeCommentRange); + } + } + function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type, getSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + emitType(type); + } + function emitType(type) { + switch (type.kind) { + case 110 /* AnyKeyword */: + case 119 /* StringKeyword */: + case 117 /* NumberKeyword */: + case 111 /* BooleanKeyword */: + case 98 /* VoidKeyword */: + case 8 /* StringLiteral */: + return writeTextOfNode(currentSourceFile, type); + case 135 /* TypeReference */: + return emitTypeReference(type); + case 138 /* TypeQuery */: + return emitTypeQuery(type); + case 140 /* ArrayType */: + return emitArrayType(type); + case 141 /* TupleType */: + return emitTupleType(type); + case 142 /* UnionType */: + return emitUnionType(type); + case 143 /* ParenthesizedType */: + return emitParenType(type); + case 136 /* FunctionType */: + case 137 /* ConstructorType */: + return emitSignatureDeclarationWithJsDocComments(type); + case 139 /* TypeLiteral */: + return emitTypeLiteral(type); + case 64 /* Identifier */: + return emitEntityName(type); + case 121 /* QualifiedName */: + return emitEntityName(type); + default: + ts.Debug.fail("Unknown type annotation: " + type.kind); + } + function emitEntityName(entityName) { + var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 197 /* ImportDeclaration */ ? entityName.parent : enclosingDeclaration); + handleSymbolAccessibilityError(visibilityResult); + writeEntityName(entityName); + function writeEntityName(entityName) { + if (entityName.kind === 64 /* Identifier */) { + writeTextOfNode(currentSourceFile, entityName); + } + else { + var qualifiedName = entityName; + writeEntityName(qualifiedName.left); + write("."); + writeTextOfNode(currentSourceFile, qualifiedName.right); + } + } + } + function emitTypeReference(type) { + emitEntityName(type.typeName); + if (type.typeArguments) { + write("<"); + emitCommaList(type.typeArguments, emitType); + write(">"); + } + } + function emitTypeQuery(type) { + write("typeof "); + emitEntityName(type.exprName); + } + function emitArrayType(type) { + emitType(type.elementType); + write("[]"); + } + function emitTupleType(type) { + write("["); + emitCommaList(type.elementTypes, emitType); + write("]"); + } + function emitUnionType(type) { + emitSeparatedList(type.types, " | ", emitType); + } + function emitParenType(type) { + write("("); + emitType(type.type); + write(")"); + } + function emitTypeLiteral(type) { + write("{"); + if (type.members.length) { + writeLine(); + increaseIndent(); + emitLines(type.members); + decreaseIndent(); + } + write("}"); + } + } + function emitSourceFile(node) { + currentSourceFile = node; + enclosingDeclaration = node; + emitLines(node.statements); + } + function emitExportAssignment(node) { + write("export = "); + writeTextOfNode(currentSourceFile, node.exportName); + write(";"); + writeLine(); + } + function emitModuleElementDeclarationFlags(node) { + if (node.parent === currentSourceFile) { + if (node.flags & 1 /* Export */) { + write("export "); + } + if (node.kind !== 192 /* InterfaceDeclaration */) { + write("declare "); + } + } + } + function emitClassMemberDeclarationFlags(node) { + if (node.flags & 32 /* Private */) { + write("private "); + } + else if (node.flags & 64 /* Protected */) { + write("protected "); + } + if (node.flags & 128 /* Static */) { + write("static "); + } + } + function emitImportDeclaration(node) { + var nodeEmitInfo = { + declaration: node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + hasWritten: resolver.isDeclarationVisible(node) + }; + aliasDeclarationEmitInfo.push(nodeEmitInfo); + if (nodeEmitInfo.hasWritten) { + writeImportDeclaration(node); + } + } + function writeImportDeclaration(node) { + emitJsDocComments(node); + if (node.flags & 1 /* Export */) { + write("export "); + } + write("import "); + writeTextOfNode(currentSourceFile, node.name); + write(" = "); + if (ts.isInternalModuleImportDeclaration(node)) { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError); + write(";"); + } + else { + write("require("); + writeTextOfNode(currentSourceFile, ts.getExternalModuleImportDeclarationExpression(node)); + write(");"); + } + writer.writeLine(); + function getImportEntityNameVisibilityError(symbolAccesibilityResult) { + return { + diagnosticMessage: ts.Diagnostics.Import_declaration_0_is_using_private_name_1, + errorNode: node, + typeName: node.name + }; + } + } + function emitModuleDeclaration(node) { + if (resolver.isDeclarationVisible(node)) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("module "); + writeTextOfNode(currentSourceFile, node.name); + while (node.body.kind !== 196 /* ModuleBlock */) { + node = node.body; + write("."); + writeTextOfNode(currentSourceFile, node.name); + } + var prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.body.statements); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + } + function emitTypeAliasDeclaration(node) { + if (resolver.isDeclarationVisible(node)) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("type "); + writeTextOfNode(currentSourceFile, node.name); + write(" = "); + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); + write(";"); + writeLine(); + } + function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) { + return { + diagnosticMessage: ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, + errorNode: node.type, + typeName: node.name + }; + } + } + function emitEnumDeclaration(node) { + if (resolver.isDeclarationVisible(node)) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (ts.isConst(node)) { + write("const "); + } + write("enum "); + writeTextOfNode(currentSourceFile, node.name); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + } + } + function emitEnumMemberDeclaration(node) { + emitJsDocComments(node); + writeTextOfNode(currentSourceFile, node.name); + var enumMemberValue = resolver.getEnumMemberValue(node); + if (enumMemberValue !== undefined) { + write(" = "); + write(enumMemberValue.toString()); + } + write(","); + writeLine(); + } + function isPrivateMethodTypeParameter(node) { + return node.parent.kind === 128 /* MethodDeclaration */ && (node.parent.flags & 32 /* Private */); + } + function emitTypeParameters(typeParameters) { + function emitTypeParameter(node) { + increaseIndent(); + emitJsDocComments(node); + decreaseIndent(); + writeTextOfNode(currentSourceFile, node.name); + if (node.constraint && !isPrivateMethodTypeParameter(node)) { + write(" extends "); + if (node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || (node.parent.parent && node.parent.parent.kind === 139 /* TypeLiteral */)) { + ts.Debug.assert(node.parent.kind === 128 /* MethodDeclaration */ || node.parent.kind === 127 /* MethodSignature */ || node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || node.parent.kind === 132 /* CallSignature */ || node.parent.kind === 133 /* ConstructSignature */); + emitType(node.constraint); + } + else { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError); + } + } + function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + switch (node.parent.kind) { + case 191 /* ClassDeclaration */: + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; + break; + case 192 /* InterfaceDeclaration */: + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; + break; + case 133 /* ConstructSignature */: + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + case 132 /* CallSignature */: + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + if (node.parent.flags & 128 /* Static */) { + diagnosticMessage = 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 === 191 /* ClassDeclaration */) { + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; + } + break; + case 190 /* FunctionDeclaration */: + diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; + break; + default: + ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind); + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: node, + typeName: node.name + }; + } + } + if (typeParameters) { + write("<"); + emitCommaList(typeParameters, emitTypeParameter); + write(">"); + } + } + function emitHeritageClause(typeReferences, isImplementsList) { + if (typeReferences) { + write(isImplementsList ? " implements " : " extends "); + emitCommaList(typeReferences, emitTypeOfTypeReference); + } + function emitTypeOfTypeReference(node) { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); + function getHeritageClauseVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + if (node.parent.parent.kind === 191 /* ClassDeclaration */) { + diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: node, + typeName: node.parent.parent.name + }; + } + } + } + function emitClassDeclaration(node) { + function emitParameterProperties(constructorDeclaration) { + if (constructorDeclaration) { + ts.forEach(constructorDeclaration.parameters, function (param) { + if (param.flags & 112 /* AccessibilityModifier */) { + emitPropertyDeclaration(param); + } + }); + } + } + if (resolver.isDeclarationVisible(node)) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("class "); + writeTextOfNode(currentSourceFile, node.name); + var prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + var baseTypeNode = ts.getClassBaseTypeNode(node); + if (baseTypeNode) { + emitHeritageClause([baseTypeNode], false); + } + emitHeritageClause(ts.getClassImplementedTypeNodes(node), true); + write(" {"); + writeLine(); + increaseIndent(); + emitParameterProperties(getFirstConstructorWithBody(node)); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + } + function emitInterfaceDeclaration(node) { + if (resolver.isDeclarationVisible(node)) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("interface "); + writeTextOfNode(currentSourceFile, node.name); + var prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + emitHeritageClause(ts.getInterfaceBaseTypeNodes(node), false); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + } + function emitPropertyDeclaration(node) { + emitJsDocComments(node); + emitClassMemberDeclarationFlags(node); + emitVariableDeclaration(node); + write(";"); + writeLine(); + } + function emitVariableDeclaration(node) { + if (node.kind !== 188 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { + writeTextOfNode(currentSourceFile, node.name); + if ((node.kind === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) && ts.hasQuestionToken(node)) { + write("?"); + } + if ((node.kind === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) && node.parent.kind === 139 /* TypeLiteral */) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.flags & 32 /* Private */)) { + writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); + } + } + function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + if (node.kind === 188 /* 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 === 126 /* PropertyDeclaration */ || node.kind === 125 /* PropertySignature */) { + 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 === 191 /* 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 { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + } + } + return diagnosticMessage !== undefined ? { + diagnosticMessage: diagnosticMessage, + errorNode: node, + typeName: node.name + } : undefined; + } + } + function emitTypeOfVariableDeclarationFromTypeLiteral(node) { + if (node.type) { + write(": "); + emitType(node.type); + } + } + function emitVariableStatement(node) { + var hasDeclarationWithEmit = ts.forEach(node.declarationList.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); }); + if (hasDeclarationWithEmit) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (ts.isLet(node.declarationList)) { + write("let "); + } + else if (ts.isConst(node.declarationList)) { + write("const "); + } + else { + write("var "); + } + emitCommaList(node.declarationList.declarations, emitVariableDeclaration); + write(";"); + writeLine(); + } + } + function emitAccessorDeclaration(node) { + var accessors = getAllAccessorDeclarations(node.parent, node); + if (node === accessors.firstAccessor) { + emitJsDocComments(accessors.getAccessor); + emitJsDocComments(accessors.setAccessor); + emitClassMemberDeclarationFlags(node); + writeTextOfNode(currentSourceFile, node.name); + if (!(node.flags & 32 /* Private */)) { + var accessorWithTypeAnnotation = node; + var type = getTypeAnnotationFromAccessor(node); + if (!type) { + var anotherAccessor = node.kind === 130 /* GetAccessor */ ? accessors.setAccessor : accessors.getAccessor; + type = getTypeAnnotationFromAccessor(anotherAccessor); + if (type) { + accessorWithTypeAnnotation = anotherAccessor; + } + } + writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError); + } + write(";"); + writeLine(); + } + function getTypeAnnotationFromAccessor(accessor) { + if (accessor) { + return accessor.kind === 130 /* GetAccessor */ ? accessor.type : accessor.parameters[0].type; + } + } + function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + if (accessorWithTypeAnnotation.kind === 131 /* SetAccessor */) { + if (accessorWithTypeAnnotation.parent.flags & 128 /* Static */) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: accessorWithTypeAnnotation.parameters[0], + typeName: accessorWithTypeAnnotation.name + }; + } + else { + if (accessorWithTypeAnnotation.flags & 128 /* Static */) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; + } + else { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: accessorWithTypeAnnotation.name, + typeName: undefined + }; + } + } + } + function emitFunctionDeclaration(node) { + if ((node.kind !== 190 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { + emitJsDocComments(node); + if (node.kind === 190 /* FunctionDeclaration */) { + emitModuleElementDeclarationFlags(node); + } + else if (node.kind === 128 /* MethodDeclaration */) { + emitClassMemberDeclarationFlags(node); + } + if (node.kind === 190 /* FunctionDeclaration */) { + write("function "); + writeTextOfNode(currentSourceFile, node.name); + } + else if (node.kind === 129 /* Constructor */) { + write("constructor"); + } + else { + writeTextOfNode(currentSourceFile, node.name); + if (ts.hasQuestionToken(node)) { + write("?"); + } + } + emitSignatureDeclaration(node); + } + } + function emitSignatureDeclarationWithJsDocComments(node) { + emitJsDocComments(node); + emitSignatureDeclaration(node); + } + function emitSignatureDeclaration(node) { + if (node.kind === 133 /* ConstructSignature */ || node.kind === 137 /* ConstructorType */) { + write("new "); + } + emitTypeParameters(node.typeParameters); + if (node.kind === 134 /* IndexSignature */) { + write("["); + } + else { + write("("); + } + var prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitCommaList(node.parameters, emitParameterDeclaration); + if (node.kind === 134 /* IndexSignature */) { + write("]"); + } + else { + write(")"); + } + var isFunctionTypeOrConstructorType = node.kind === 136 /* FunctionType */ || node.kind === 137 /* ConstructorType */; + if (isFunctionTypeOrConstructorType || node.parent.kind === 139 /* TypeLiteral */) { + if (node.type) { + write(isFunctionTypeOrConstructorType ? " => " : ": "); + emitType(node.type); + } + } + else if (node.kind !== 129 /* Constructor */ && !(node.flags & 32 /* Private */)) { + writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); + } + enclosingDeclaration = prevEnclosingDeclaration; + if (!isFunctionTypeOrConstructorType) { + write(";"); + writeLine(); + } + function getReturnTypeVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + switch (node.kind) { + case 133 /* ConstructSignature */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + case 132 /* CallSignature */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + case 134 /* IndexSignature */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + 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 === 191 /* 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 190 /* 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: + ts.Debug.fail("This is unknown kind for signature: " + node.kind); + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: node.name || node + }; + } + } + function emitParameterDeclaration(node) { + increaseIndent(); + emitJsDocComments(node); + if (node.dotDotDotToken) { + write("..."); + } + if (ts.isBindingPattern(node.name)) { + write("_" + ts.indexOf(node.parent.parameters, node)); + } + else { + writeTextOfNode(currentSourceFile, node.name); + } + if (node.initializer || ts.hasQuestionToken(node)) { + write("?"); + } + decreaseIndent(); + if (node.parent.kind === 136 /* FunctionType */ || node.parent.kind === 137 /* ConstructorType */ || node.parent.parent.kind === 139 /* TypeLiteral */) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.parent.flags & 32 /* Private */)) { + writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError); + } + function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) { + var diagnosticMessage; + switch (node.parent.kind) { + case 129 /* Constructor */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; + break; + case 133 /* ConstructSignature */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + case 132 /* CallSignature */: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + 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 === 191 /* 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 190 /* 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: + ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind); + } + return { + diagnosticMessage: diagnosticMessage, + errorNode: node, + typeName: node.name + }; + } + } + function emitNode(node) { + switch (node.kind) { + case 129 /* Constructor */: + case 190 /* FunctionDeclaration */: + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + return emitFunctionDeclaration(node); + case 133 /* ConstructSignature */: + case 132 /* CallSignature */: + case 134 /* IndexSignature */: + return emitSignatureDeclarationWithJsDocComments(node); + case 130 /* GetAccessor */: + case 131 /* SetAccessor */: + return emitAccessorDeclaration(node); + case 171 /* VariableStatement */: + return emitVariableStatement(node); + case 126 /* PropertyDeclaration */: + case 125 /* PropertySignature */: + return emitPropertyDeclaration(node); + case 192 /* InterfaceDeclaration */: + return emitInterfaceDeclaration(node); + case 191 /* ClassDeclaration */: + return emitClassDeclaration(node); + case 193 /* TypeAliasDeclaration */: + return emitTypeAliasDeclaration(node); + case 206 /* EnumMember */: + return emitEnumMemberDeclaration(node); + case 194 /* EnumDeclaration */: + return emitEnumDeclaration(node); + case 195 /* ModuleDeclaration */: + return emitModuleDeclaration(node); + case 197 /* ImportDeclaration */: + return emitImportDeclaration(node); + case 198 /* ExportAssignment */: + return emitExportAssignment(node); + case 207 /* SourceFile */: + return emitSourceFile(node); + } + } + var referencePathsOutput = ""; + function writeReferencePath(referencedFile) { + var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; + declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, host.getCurrentDirectory(), host.getCanonicalFileName, false); + referencePathsOutput += "/// " + newLine; + } + if (root) { + if (!compilerOptions.noResolve) { + var addedGlobalFileReference = false; + ts.forEach(root.referencedFiles, function (fileReference) { + var referencedFile = ts.tryResolveScriptReference(host, root, fileReference); + if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { + writeReferencePath(referencedFile); + if (!isExternalModuleOrDeclarationFile(referencedFile)) { + addedGlobalFileReference = true; + } + } + }); + } + emitNode(root); + } + else { + var emittedReferencedFiles = []; + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + if (!compilerOptions.noResolve) { + ts.forEach(sourceFile.referencedFiles, function (fileReference) { + var referencedFile = ts.tryResolveScriptReference(host, sourceFile, fileReference); + if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) { + writeReferencePath(referencedFile); + emittedReferencedFiles.push(referencedFile); + } + }); + } + emitNode(sourceFile); + } + }); + } + return { + reportedDeclarationError: reportedDeclarationError, + aliasDeclarationEmitInfo: aliasDeclarationEmitInfo, + synchronousDeclarationOutput: writer.getText(), + referencePathsOutput: referencePathsOutput + }; + } + function getDeclarationDiagnostics(host, resolver, targetSourceFile) { + var diagnostics = []; + var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); + emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile); + return diagnostics; + } + ts.getDeclarationDiagnostics = getDeclarationDiagnostics; + function emitFiles(resolver, host, targetSourceFile) { + var compilerOptions = host.getCompilerOptions(); + var sourceMapDataList = compilerOptions.sourceMap ? [] : undefined; + var diagnostics = []; + var newLine = host.getNewLine(); + function emitJavaScript(jsFilePath, root) { + var writer = createTextWriter(newLine); + var write = writer.write; + var writeTextOfNode = writer.writeTextOfNode; + var writeLine = writer.writeLine; + var increaseIndent = writer.increaseIndent; + var decreaseIndent = writer.decreaseIndent; + var currentSourceFile; + var extendsEmitted = false; + var tempCount = 0; + var tempVariables; + var tempParameters; + var writeEmittedFiles = writeJavaScriptFile; + var emitLeadingComments = compilerOptions.removeComments ? function (node) { + } : emitLeadingDeclarationComments; + var emitTrailingComments = compilerOptions.removeComments ? function (node) { + } : emitTrailingDeclarationComments; + var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { + } : emitLeadingCommentsOfLocalPosition; + var detachedCommentsInfo; + var emitDetachedComments = compilerOptions.removeComments ? function (node) { + } : emitDetachedCommentsAtPosition; + var emitPinnedOrTripleSlashComments = compilerOptions.removeComments ? function (node) { + } : emitPinnedOrTripleSlashCommentsOfNode; + var writeComment = writeCommentRange; + var emit = emitNode; + var emitStart = function (node) { + }; + var emitEnd = function (node) { + }; + var emitToken = emitTokenText; + var scopeEmitStart = function (scopeDeclaration, scopeName) { + }; + var scopeEmitEnd = function () { + }; + var sourceMapData; + function initializeEmitterWithSourceMaps() { + var sourceMapDir; + var sourceMapSourceIndex = -1; + var sourceMapNameIndexMap = {}; + var sourceMapNameIndices = []; + function getSourceMapNameIndex() { + return sourceMapNameIndices.length ? sourceMapNameIndices[sourceMapNameIndices.length - 1] : -1; + } + var lastRecordedSourceMapSpan; + var lastEncodedSourceMapSpan = { + emittedLine: 1, + emittedColumn: 1, + sourceLine: 1, + sourceColumn: 1, + sourceIndex: 0 + }; + var lastEncodedNameIndex = 0; + function encodeLastRecordedSourceMapSpan() { + if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { + return; + } + var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; + if (lastEncodedSourceMapSpan.emittedLine == lastRecordedSourceMapSpan.emittedLine) { + if (sourceMapData.sourceMapMappings) { + sourceMapData.sourceMapMappings += ","; + } + } + else { + for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { + sourceMapData.sourceMapMappings += ";"; + } + prevEncodedEmittedColumn = 1; + } + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); + if (lastRecordedSourceMapSpan.nameIndex >= 0) { + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); + lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; + } + lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; + sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); + function base64VLQFormatEncode(inValue) { + function base64FormatEncode(inValue) { + if (inValue < 64) { + return 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.charAt(inValue); + } + throw TypeError(inValue + ": not a 64 based value"); + } + if (inValue < 0) { + inValue = ((-inValue) << 1) + 1; + } + else { + inValue = inValue << 1; + } + var encodedStr = ""; + do { + var currentDigit = inValue & 31; + inValue = inValue >> 5; + if (inValue > 0) { + currentDigit = currentDigit | 32; + } + encodedStr = encodedStr + base64FormatEncode(currentDigit); + } while (inValue > 0); + return encodedStr; + } + } + function recordSourceMapSpan(pos) { + var sourceLinePos = currentSourceFile.getLineAndCharacterFromPosition(pos); + var emittedLine = writer.getLine(); + var emittedColumn = writer.getColumn(); + if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan.emittedLine != emittedLine || lastRecordedSourceMapSpan.emittedColumn != emittedColumn || (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { + encodeLastRecordedSourceMapSpan(); + lastRecordedSourceMapSpan = { + emittedLine: emittedLine, + emittedColumn: emittedColumn, + sourceLine: sourceLinePos.line, + sourceColumn: sourceLinePos.character, + nameIndex: getSourceMapNameIndex(), + sourceIndex: sourceMapSourceIndex + }; + } + else { + lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; + lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; + lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; + } + } + function recordEmitNodeStartSpan(node) { + recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); + } + function recordEmitNodeEndSpan(node) { + recordSourceMapSpan(node.end); + } + function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { + var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); + recordSourceMapSpan(tokenStartPos); + var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); + recordSourceMapSpan(tokenEndPos); + return tokenEndPos; + } + function recordNewSourceFileStart(node) { + var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; + sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, host.getCurrentDirectory(), host.getCanonicalFileName, true)); + sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; + sourceMapData.inputSourceFileNames.push(node.filename); + } + function recordScopeNameOfNode(node, scopeName) { + function recordScopeNameIndex(scopeNameIndex) { + sourceMapNameIndices.push(scopeNameIndex); + } + function recordScopeNameStart(scopeName) { + var scopeNameIndex = -1; + if (scopeName) { + var parentIndex = getSourceMapNameIndex(); + if (parentIndex !== -1) { + scopeName = sourceMapData.sourceMapNames[parentIndex] + "." + scopeName; + } + scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); + if (scopeNameIndex === undefined) { + scopeNameIndex = sourceMapData.sourceMapNames.length; + sourceMapData.sourceMapNames.push(scopeName); + sourceMapNameIndexMap[scopeName] = scopeNameIndex; + } + } + recordScopeNameIndex(scopeNameIndex); + } + if (scopeName) { + recordScopeNameStart(scopeName); + } + else if (node.kind === 190 /* FunctionDeclaration */ || node.kind === 156 /* FunctionExpression */ || node.kind === 128 /* MethodDeclaration */ || node.kind === 127 /* MethodSignature */ || node.kind === 130 /* GetAccessor */ || node.kind === 131 /* SetAccessor */ || node.kind === 195 /* ModuleDeclaration */ || node.kind === 191 /* ClassDeclaration */ || node.kind === 194 /* EnumDeclaration */) { + if (node.name) { + scopeName = node.name.text; + } + recordScopeNameStart(scopeName); + } + else { + recordScopeNameIndex(getSourceMapNameIndex()); + } + } + function recordScopeNameEnd() { + sourceMapNameIndices.pop(); + } + ; + function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { + recordSourceMapSpan(comment.pos); + writeCommentRange(currentSourceFile, writer, comment, newLine); + recordSourceMapSpan(comment.end); + } + function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings) { + if (typeof JSON !== "undefined") { + return JSON.stringify({ + version: version, + file: file, + sourceRoot: sourceRoot, + sources: sources, + names: names, + mappings: mappings + }); + } + 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 += "\"" + ts.escapeString(list[i]) + "\""; + } + return output; + } + } + function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { + encodeLastRecordedSourceMapSpan(); + writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings), false); + sourceMapDataList.push(sourceMapData); + writeJavaScriptFile(emitOutput + "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL, writeByteOrderMark); + } + var sourceMapJsFile = ts.getBaseFilename(ts.normalizeSlashes(jsFilePath)); + sourceMapData = { + sourceMapFilePath: jsFilePath + ".map", + jsSourceMappingURL: sourceMapJsFile + ".map", + sourceMapFile: sourceMapJsFile, + sourceMapSourceRoot: compilerOptions.sourceRoot || "", + sourceMapSources: [], + inputSourceFileNames: [], + sourceMapNames: [], + sourceMapMappings: "", + sourceMapDecodedMappings: [] + }; + sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); + if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47 /* slash */) { + sourceMapData.sourceMapSourceRoot += ts.directorySeparator; + } + if (compilerOptions.mapRoot) { + sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); + if (root) { + sourceMapDir = ts.getDirectoryPath(getSourceFilePathInNewDir(root, host, sourceMapDir)); + } + if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { + sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir); + sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), host.getCurrentDirectory(), host.getCanonicalFileName, true); + } + else { + sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); + } + } + else { + sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); + } + function emitNodeWithMap(node) { + if (node) { + if (node.kind != 207 /* SourceFile */) { + recordEmitNodeStartSpan(node); + emitNode(node); + recordEmitNodeEndSpan(node); + } + else { + recordNewSourceFileStart(node); + emitNode(node); + } + } + } + writeEmittedFiles = writeJavaScriptAndSourceMapFile; + emit = emitNodeWithMap; + emitStart = recordEmitNodeStartSpan; + emitEnd = recordEmitNodeEndSpan; + emitToken = writeTextWithSpanRecord; + scopeEmitStart = recordScopeNameOfNode; + scopeEmitEnd = recordScopeNameEnd; + writeComment = writeCommentRangeWithMap; + } + function writeJavaScriptFile(emitOutput, writeByteOrderMark) { + writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); + } + function createTempVariable(location, forLoopVariable) { + var name = forLoopVariable ? "_i" : undefined; + while (true) { + if (name && resolver.isUnknownIdentifier(location, name)) { + break; + } + name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + 97 /* a */) : tempCount - 25); + tempCount++; + } + var result = ts.createNode(64 /* Identifier */); + result.text = name; + return result; + } + function recordTempDeclaration(name) { + if (!tempVariables) { + tempVariables = []; + } + tempVariables.push(name); + } + function emitTempDeclarations(newLine) { + if (tempVariables) { + if (newLine) { + writeLine(); + } + else { + write(" "); + } + write("var "); + emitCommaList(tempVariables); + write(";"); + } + } + function emitTokenText(tokenKind, startPos, emitFn) { + var tokenString = ts.tokenToString(tokenKind); + if (emitFn) { + emitFn(); + } + else { + write(tokenString); + } + return startPos + tokenString.length; + } + function emitOptional(prefix, node) { + if (node) { + write(prefix); + emit(node); + } + } + function emitParenthesized(node, parenthesized) { + if (parenthesized) { + write("("); + } + emit(node); + if (parenthesized) { + write(")"); + } + } + function emitTrailingCommaIfPresent(nodeList) { + if (nodeList.hasTrailingComma) { + write(","); + } + } + function emitList(nodes, start, count, multiLine, trailingComma) { + if (multiLine) { + increaseIndent(); + } + for (var i = 0; i < count; i++) { + if (multiLine) { + if (i) { + write(","); + } + writeLine(); + } + else { + if (i) { + write(", "); + } + } + emit(nodes[start + i]); + } + if (trailingComma) { + write(","); + } + if (multiLine) { + decreaseIndent(); + writeLine(); + } + } + function emitCommaList(nodes) { + if (nodes) { + emitList(nodes, 0, nodes.length, false, false); + } + } + function emitMultiLineList(nodes) { + if (nodes) { + emitList(nodes, 0, nodes.length, true, false); + } + } + function emitLines(nodes) { + emitLinesStartingAt(nodes, 0); + } + function emitLinesStartingAt(nodes, startIndex) { + for (var i = startIndex; i < nodes.length; i++) { + writeLine(); + emit(nodes[i]); + } + } + function isBinaryOrOctalIntegerLiteral(text) { + if (text.length <= 0) { + return false; + } + if (text.charCodeAt(1) === 66 /* B */ || text.charCodeAt(1) === 98 /* b */ || text.charCodeAt(1) === 79 /* O */ || text.charCodeAt(1) === 111 /* o */) { + return true; + } + return false; + } + function emitLiteral(node) { + var text = compilerOptions.target < 2 /* ES6 */ && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; + if (compilerOptions.sourceMap && (node.kind === 8 /* StringLiteral */ || ts.isTemplateLiteralKind(node.kind))) { + writer.writeLiteral(text); + } + else if (compilerOptions.target < 2 /* ES6 */ && node.kind === 7 /* NumericLiteral */ && isBinaryOrOctalIntegerLiteral(text)) { + write(node.text); + } + else { + write(text); + } + } + function getTemplateLiteralAsStringLiteral(node) { + return '"' + ts.escapeString(node.text) + '"'; + } + function emitTemplateExpression(node) { + if (compilerOptions.target >= 2 /* ES6 */) { + ts.forEachChild(node, emit); + return; + } + ts.Debug.assert(node.parent.kind !== 153 /* TaggedTemplateExpression */); + var emitOuterParens = ts.isExpression(node.parent) && templateNeedsParens(node, node.parent); + if (emitOuterParens) { + write("("); + } + var headEmitted = false; + if (shouldEmitTemplateHead()) { + emitLiteral(node.head); + headEmitted = true; + } + for (var i = 0; i < node.templateSpans.length; i++) { + var templateSpan = node.templateSpans[i]; + var needsParens = templateSpan.expression.kind !== 155 /* ParenthesizedExpression */ && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1 /* GreaterThan */; + if (i > 0 || headEmitted) { + write(" + "); + } + emitParenthesized(templateSpan.expression, needsParens); + if (templateSpan.literal.text.length !== 0) { + write(" + "); + emitLiteral(templateSpan.literal); + } + } + if (emitOuterParens) { + write(")"); + } + function shouldEmitTemplateHead() { + ts.Debug.assert(node.templateSpans.length !== 0); + return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; + } + function templateNeedsParens(template, parent) { + switch (parent.kind) { + case 151 /* CallExpression */: + case 152 /* NewExpression */: + return parent.expression === template; + case 155 /* ParenthesizedExpression */: + return false; + case 153 /* TaggedTemplateExpression */: + ts.Debug.fail("Path should be unreachable; tagged templates not supported pre-ES6."); + default: + return comparePrecedenceToBinaryPlus(parent) !== -1 /* LessThan */; + } + } + function comparePrecedenceToBinaryPlus(expression) { + ts.Debug.assert(compilerOptions.target <= 1 /* ES5 */); + switch (expression.kind) { + case 163 /* BinaryExpression */: + switch (expression.operator) { + case 35 /* AsteriskToken */: + case 36 /* SlashToken */: + case 37 /* PercentToken */: + return 1 /* GreaterThan */; + case 33 /* PlusToken */: + case 34 /* MinusToken */: + return 0 /* EqualTo */; + default: + return -1 /* LessThan */; + } + case 164 /* ConditionalExpression */: + return -1 /* LessThan */; + default: + return 1 /* GreaterThan */; + } + } + } + function emitTemplateSpan(span) { + emit(span.expression); + emit(span.literal); + } + function emitExpressionForPropertyName(node) { + if (node.kind === 8 /* StringLiteral */) { + emitLiteral(node); + } + else if (node.kind === 122 /* ComputedPropertyName */) { + emit(node.expression); + } + else { + write("\""); + if (node.kind === 7 /* NumericLiteral */) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + write("\""); + } + } + function isNotExpressionIdentifier(node) { + var parent = node.parent; + switch (parent.kind) { + case 124 /* Parameter */: + case 188 /* VariableDeclaration */: + case 146 /* BindingElement */: + case 126 /* PropertyDeclaration */: + case 125 /* PropertySignature */: + case 204 /* PropertyAssignment */: + case 205 /* ShorthandPropertyAssignment */: + case 206 /* EnumMember */: + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + case 190 /* FunctionDeclaration */: + case 130 /* GetAccessor */: + case 131 /* SetAccessor */: + case 156 /* FunctionExpression */: + case 191 /* ClassDeclaration */: + case 192 /* InterfaceDeclaration */: + case 194 /* EnumDeclaration */: + case 195 /* ModuleDeclaration */: + case 197 /* ImportDeclaration */: + return parent.name === node; + case 180 /* BreakStatement */: + case 179 /* ContinueStatement */: + case 198 /* ExportAssignment */: + return false; + case 184 /* LabeledStatement */: + return node.parent.label === node; + case 203 /* CatchClause */: + return node.parent.name === node; + } + } + function emitExpressionIdentifier(node) { + var prefix = resolver.getExpressionNamePrefix(node); + if (prefix) { + write(prefix); + write("."); + } + writeTextOfNode(currentSourceFile, node); + } + function emitIdentifier(node) { + if (!node.parent) { + write(node.text); + } + else if (!isNotExpressionIdentifier(node)) { + emitExpressionIdentifier(node); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } + function emitThis(node) { + if (resolver.getNodeCheckFlags(node) & 2 /* LexicalThis */) { + write("_this"); + } + else { + write("this"); + } + } + function emitSuper(node) { + var flags = resolver.getNodeCheckFlags(node); + if (flags & 16 /* SuperInstance */) { + write("_super.prototype"); + } + else if (flags & 32 /* SuperStatic */) { + write("_super"); + } + else { + write("super"); + } + } + function emitObjectBindingPattern(node) { + write("{ "); + var elements = node.elements; + emitList(elements, 0, elements.length, false, elements.hasTrailingComma); + write(" }"); + } + function emitArrayBindingPattern(node) { + write("["); + var elements = node.elements; + emitList(elements, 0, elements.length, false, elements.hasTrailingComma); + write("]"); + } + function emitBindingElement(node) { + if (node.propertyName) { + emit(node.propertyName); + write(": "); + } + if (node.dotDotDotToken) { + write("..."); + } + if (ts.isBindingPattern(node.name)) { + emit(node.name); + } + else { + emitModuleMemberName(node); + } + emitOptional(" = ", node.initializer); + } + function emitSpreadElementExpression(node) { + write("..."); + emit(node.expression); + } + function needsParenthesisForPropertyAccess(node) { + switch (node.kind) { + case 64 /* Identifier */: + case 147 /* ArrayLiteralExpression */: + case 149 /* PropertyAccessExpression */: + case 150 /* ElementAccessExpression */: + case 151 /* CallExpression */: + case 155 /* ParenthesizedExpression */: + return false; + } + return true; + } + function emitArrayLiteral(node) { + var elements = node.elements; + var length = elements.length; + if (length === 0) { + write("[]"); + return; + } + if (compilerOptions.target >= 2 /* ES6 */) { + write("["); + emitList(elements, 0, elements.length, (node.flags & 256 /* MultiLine */) !== 0, elements.hasTrailingComma); + write("]"); + return; + } + var pos = 0; + var group = 0; + while (pos < length) { + if (group === 1) { + write(".concat("); + } + else if (group > 1) { + write(", "); + } + var e = elements[pos]; + if (e.kind === 167 /* SpreadElementExpression */) { + e = e.expression; + emitParenthesized(e, group === 0 && needsParenthesisForPropertyAccess(e)); + pos++; + } + else { + var i = pos; + while (i < length && elements[i].kind !== 167 /* SpreadElementExpression */) { + i++; + } + write("["); + emitList(elements, pos, i - pos, (node.flags & 256 /* MultiLine */) !== 0, elements.hasTrailingComma); + write("]"); + pos = i; + } + group++; + } + if (group > 1) { + write(")"); + } + } + function emitObjectLiteral(node) { + write("{"); + var properties = node.properties; + if (properties.length) { + var multiLine = (node.flags & 256 /* MultiLine */) !== 0; + if (!multiLine) { + write(" "); + } + emitList(properties, 0, properties.length, multiLine, properties.hasTrailingComma && compilerOptions.target >= 1 /* ES5 */); + if (!multiLine) { + write(" "); + } + } + write("}"); + } + function emitComputedPropertyName(node) { + write("["); + emit(node.expression); + write("]"); + } + function emitMethod(node) { + if (!ts.isObjectLiteralMethod(node)) { + return; + } + emitLeadingComments(node); + emit(node.name); + if (compilerOptions.target < 2 /* ES6 */) { + write(": function "); + } + emitSignatureAndBody(node); + emitTrailingComments(node); + } + function emitPropertyAssignment(node) { + emitLeadingComments(node); + emit(node.name); + write(": "); + emit(node.initializer); + emitTrailingComments(node); + } + function emitShorthandPropertyAssignment(node) { + emitLeadingComments(node); + emit(node.name); + if (compilerOptions.target < 2 /* ES6 */ || resolver.getExpressionNamePrefix(node.name)) { + write(": "); + emitExpressionIdentifier(node.name); + } + emitTrailingComments(node); + } + function tryEmitConstantValue(node) { + var constantValue = resolver.getConstantValue(node); + if (constantValue !== undefined) { + var propertyName = node.kind === 149 /* PropertyAccessExpression */ ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); + write(constantValue.toString() + " /* " + propertyName + " */"); + return true; + } + return false; + } + function emitPropertyAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + write("."); + emit(node.name); + } + function emitQualifiedName(node) { + emit(node.left); + write("."); + emit(node.right); + } + function emitIndexedAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + write("["); + emit(node.argumentExpression); + write("]"); + } + function emitCallExpression(node) { + var superCall = false; + if (node.expression.kind === 90 /* SuperKeyword */) { + write("_super"); + superCall = true; + } + else { + emit(node.expression); + superCall = node.expression.kind === 149 /* PropertyAccessExpression */ && node.expression.expression.kind === 90 /* SuperKeyword */; + } + if (superCall) { + write(".call("); + emitThis(node.expression); + if (node.arguments.length) { + write(", "); + emitCommaList(node.arguments); + } + write(")"); + } + else { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + function emitNewExpression(node) { + write("new "); + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + function emitTaggedTemplateExpression(node) { + ts.Debug.assert(compilerOptions.target >= 2 /* ES6 */, "Trying to emit a tagged template in pre-ES6 mode."); + emit(node.tag); + write(" "); + emit(node.template); + } + function emitParenExpression(node) { + if (node.expression.kind === 154 /* TypeAssertionExpression */) { + var operand = node.expression.expression; + while (operand.kind == 154 /* TypeAssertionExpression */) { + operand = operand.expression; + } + if (operand.kind !== 161 /* PrefixUnaryExpression */ && operand.kind !== 160 /* VoidExpression */ && operand.kind !== 159 /* TypeOfExpression */ && operand.kind !== 158 /* DeleteExpression */ && operand.kind !== 162 /* PostfixUnaryExpression */ && operand.kind !== 152 /* NewExpression */ && !(operand.kind === 151 /* CallExpression */ && node.parent.kind === 152 /* NewExpression */) && !(operand.kind === 156 /* FunctionExpression */ && node.parent.kind === 151 /* CallExpression */)) { + emit(operand); + return; + } + } + write("("); + emit(node.expression); + write(")"); + } + function emitDeleteExpression(node) { + write(ts.tokenToString(73 /* DeleteKeyword */)); + write(" "); + emit(node.expression); + } + function emitVoidExpression(node) { + write(ts.tokenToString(98 /* VoidKeyword */)); + write(" "); + emit(node.expression); + } + function emitTypeOfExpression(node) { + write(ts.tokenToString(96 /* TypeOfKeyword */)); + write(" "); + emit(node.expression); + } + function emitPrefixUnaryExpression(node) { + write(ts.tokenToString(node.operator)); + if (node.operand.kind === 161 /* PrefixUnaryExpression */) { + var operand = node.operand; + if (node.operator === 33 /* PlusToken */ && (operand.operator === 33 /* PlusToken */ || operand.operator === 38 /* PlusPlusToken */)) { + write(" "); + } + else if (node.operator === 34 /* MinusToken */ && (operand.operator === 34 /* MinusToken */ || operand.operator === 39 /* MinusMinusToken */)) { + write(" "); + } + } + emit(node.operand); + } + function emitPostfixUnaryExpression(node) { + emit(node.operand); + write(ts.tokenToString(node.operator)); + } + function emitBinaryExpression(node) { + if (compilerOptions.target < 2 /* ES6 */ && node.operator === 52 /* EqualsToken */ && (node.left.kind === 148 /* ObjectLiteralExpression */ || node.left.kind === 147 /* ArrayLiteralExpression */)) { + emitDestructuring(node); + } + else { + emit(node.left); + if (node.operator !== 23 /* CommaToken */) + write(" "); + write(ts.tokenToString(node.operator)); + write(" "); + emit(node.right); + } + } + function emitConditionalExpression(node) { + emit(node.condition); + write(" ? "); + emit(node.whenTrue); + write(" : "); + emit(node.whenFalse); + } + function emitBlock(node) { + emitToken(14 /* OpenBraceToken */, node.pos); + increaseIndent(); + scopeEmitStart(node.parent); + if (node.kind === 196 /* ModuleBlock */) { + ts.Debug.assert(node.parent.kind === 195 /* ModuleDeclaration */); + emitCaptureThisForNodeIfNecessary(node.parent); + } + emitLines(node.statements); + if (node.kind === 196 /* ModuleBlock */) { + emitTempDeclarations(true); + } + decreaseIndent(); + writeLine(); + emitToken(15 /* CloseBraceToken */, node.statements.end); + scopeEmitEnd(); + } + function emitEmbeddedStatement(node) { + if (node.kind === 170 /* Block */) { + write(" "); + emit(node); + } + else { + increaseIndent(); + writeLine(); + emit(node); + decreaseIndent(); + } + } + function emitExpressionStatement(node) { + emitLeadingComments(node); + emitParenthesized(node.expression, node.expression.kind === 157 /* ArrowFunction */); + write(";"); + emitTrailingComments(node); + } + function emitIfStatement(node) { + emitLeadingComments(node); + var endPos = emitToken(83 /* IfKeyword */, node.pos); + write(" "); + endPos = emitToken(16 /* OpenParenToken */, endPos); + emit(node.expression); + emitToken(17 /* CloseParenToken */, node.expression.end); + emitEmbeddedStatement(node.thenStatement); + if (node.elseStatement) { + writeLine(); + emitToken(75 /* ElseKeyword */, node.thenStatement.end); + if (node.elseStatement.kind === 174 /* IfStatement */) { + write(" "); + emit(node.elseStatement); + } + else { + emitEmbeddedStatement(node.elseStatement); + } + } + emitTrailingComments(node); + } + function emitDoStatement(node) { + write("do"); + emitEmbeddedStatement(node.statement); + if (node.statement.kind === 170 /* Block */) { + write(" "); + } + else { + writeLine(); + } + write("while ("); + emit(node.expression); + write(");"); + } + function emitWhileStatement(node) { + write("while ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitForStatement(node) { + var endPos = emitToken(81 /* ForKeyword */, node.pos); + write(" "); + endPos = emitToken(16 /* OpenParenToken */, endPos); + if (node.initializer && node.initializer.kind === 189 /* VariableDeclarationList */) { + var variableDeclarationList = node.initializer; + var declarations = variableDeclarationList.declarations; + if (declarations[0] && ts.isLet(declarations[0])) { + emitToken(103 /* LetKeyword */, endPos); + } + else if (declarations[0] && ts.isConst(declarations[0])) { + emitToken(69 /* ConstKeyword */, endPos); + } + else { + emitToken(97 /* VarKeyword */, endPos); + } + write(" "); + emitCommaList(variableDeclarationList.declarations); + } + else if (node.initializer) { + emit(node.initializer); + } + write(";"); + emitOptional(" ", node.condition); + write(";"); + emitOptional(" ", node.iterator); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitForInStatement(node) { + var endPos = emitToken(81 /* ForKeyword */, node.pos); + write(" "); + endPos = emitToken(16 /* OpenParenToken */, endPos); + if (node.initializer.kind === 189 /* VariableDeclarationList */) { + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length >= 1) { + var decl = variableDeclarationList.declarations[0]; + if (ts.isLet(decl)) { + emitToken(103 /* LetKeyword */, endPos); + } + else { + emitToken(97 /* VarKeyword */, endPos); + } + write(" "); + emit(decl); + } + } + else { + emit(node.initializer); + } + write(" in "); + emit(node.expression); + emitToken(17 /* CloseParenToken */, node.expression.end); + emitEmbeddedStatement(node.statement); + } + function emitBreakOrContinueStatement(node) { + emitToken(node.kind === 180 /* BreakStatement */ ? 65 /* BreakKeyword */ : 70 /* ContinueKeyword */, node.pos); + emitOptional(" ", node.label); + write(";"); + } + function emitReturnStatement(node) { + emitLeadingComments(node); + emitToken(89 /* ReturnKeyword */, node.pos); + emitOptional(" ", node.expression); + write(";"); + emitTrailingComments(node); + } + function emitWithStatement(node) { + write("with ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitSwitchStatement(node) { + var endPos = emitToken(91 /* SwitchKeyword */, node.pos); + write(" "); + emitToken(16 /* OpenParenToken */, endPos); + emit(node.expression); + endPos = emitToken(17 /* CloseParenToken */, node.expression.end); + write(" "); + emitToken(14 /* OpenBraceToken */, endPos); + increaseIndent(); + emitLines(node.clauses); + decreaseIndent(); + writeLine(); + emitToken(15 /* CloseBraceToken */, node.clauses.end); + } + function isOnSameLine(node1, node2) { + return getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); + } + function emitCaseOrDefaultClause(node) { + if (node.kind === 200 /* CaseClause */) { + write("case "); + emit(node.expression); + write(":"); + } + else { + write("default:"); + } + if (node.statements.length === 1 && isOnSameLine(node, node.statements[0])) { + write(" "); + emit(node.statements[0]); + } + else { + increaseIndent(); + emitLines(node.statements); + decreaseIndent(); + } + } + function emitThrowStatement(node) { + write("throw "); + emit(node.expression); + write(";"); + } + function emitTryStatement(node) { + write("try "); + emit(node.tryBlock); + emit(node.catchClause); + if (node.finallyBlock) { + writeLine(); + write("finally "); + emit(node.finallyBlock); + } + } + function emitCatchClause(node) { + writeLine(); + var endPos = emitToken(67 /* CatchKeyword */, node.pos); + write(" "); + emitToken(16 /* OpenParenToken */, endPos); + emit(node.name); + emitToken(17 /* CloseParenToken */, node.name.end); + write(" "); + emitBlock(node.block); + } + function emitDebuggerStatement(node) { + emitToken(71 /* DebuggerKeyword */, node.pos); + write(";"); + } + function emitLabelledStatement(node) { + emit(node.label); + write(": "); + emit(node.statement); + } + function getContainingModule(node) { + do { + node = node.parent; + } while (node && node.kind !== 195 /* ModuleDeclaration */); + return node; + } + function emitModuleMemberName(node) { + emitStart(node.name); + if (ts.getCombinedNodeFlags(node) & 1 /* Export */) { + var container = getContainingModule(node); + write(container ? resolver.getLocalNameOfContainer(container) : "exports"); + write("."); + } + emitNode(node.name); + emitEnd(node.name); + } + function emitDestructuring(root, value) { + var emitCount = 0; + var isDeclaration = (root.kind === 188 /* VariableDeclaration */ && !(ts.getCombinedNodeFlags(root) & 1 /* Export */)) || root.kind === 124 /* Parameter */; + if (root.kind === 163 /* BinaryExpression */) { + emitAssignmentExpression(root); + } + else { + emitBindingElement(root, value); + } + function emitAssignment(name, value) { + if (emitCount++) { + write(", "); + } + if (name.parent && (name.parent.kind === 188 /* VariableDeclaration */ || name.parent.kind === 146 /* BindingElement */)) { + emitModuleMemberName(name.parent); + } + else { + emit(name); + } + write(" = "); + emit(value); + } + function ensureIdentifier(expr) { + if (expr.kind !== 64 /* Identifier */) { + var identifier = createTempVariable(root); + if (!isDeclaration) { + recordTempDeclaration(identifier); + } + emitAssignment(identifier, expr); + expr = identifier; + } + return expr; + } + function createVoidZero() { + var zero = ts.createNode(7 /* NumericLiteral */); + zero.text = "0"; + var result = ts.createNode(160 /* VoidExpression */); + result.expression = zero; + return result; + } + function createDefaultValueCheck(value, defaultValue) { + value = ensureIdentifier(value); + var equals = ts.createNode(163 /* BinaryExpression */); + equals.left = value; + equals.operator = 30 /* EqualsEqualsEqualsToken */; + equals.right = createVoidZero(); + var cond = ts.createNode(164 /* ConditionalExpression */); + cond.condition = equals; + cond.whenTrue = defaultValue; + cond.whenFalse = value; + return cond; + } + function createNumericLiteral(value) { + var node = ts.createNode(7 /* NumericLiteral */); + node.text = "" + value; + return node; + } + function parenthesizeForAccess(expr) { + if (expr.kind === 64 /* Identifier */ || expr.kind === 149 /* PropertyAccessExpression */ || expr.kind === 150 /* ElementAccessExpression */) { + return expr; + } + var node = ts.createNode(155 /* ParenthesizedExpression */); + node.expression = expr; + return node; + } + function createPropertyAccess(object, propName) { + if (propName.kind !== 64 /* Identifier */) { + return createElementAccess(object, propName); + } + var node = ts.createNode(149 /* PropertyAccessExpression */); + node.expression = parenthesizeForAccess(object); + node.name = propName; + return node; + } + function createElementAccess(object, index) { + var node = ts.createNode(150 /* ElementAccessExpression */); + node.expression = parenthesizeForAccess(object); + node.argumentExpression = index; + return node; + } + function emitObjectLiteralAssignment(target, value) { + var properties = target.properties; + if (properties.length !== 1) { + value = ensureIdentifier(value); + } + for (var i = 0; i < properties.length; i++) { + var p = properties[i]; + if (p.kind === 204 /* PropertyAssignment */ || p.kind === 205 /* ShorthandPropertyAssignment */) { + var propName = (p.name); + emitDestructuringAssignment(p.initializer || propName, createPropertyAccess(value, propName)); + } + } + } + function emitArrayLiteralAssignment(target, value) { + var elements = target.elements; + if (elements.length !== 1) { + value = ensureIdentifier(value); + } + for (var i = 0; i < elements.length; i++) { + var e = elements[i]; + if (e.kind !== 168 /* OmittedExpression */) { + if (e.kind !== 167 /* SpreadElementExpression */) { + emitDestructuringAssignment(e, createElementAccess(value, createNumericLiteral(i))); + } + else { + if (i === elements.length - 1) { + value = ensureIdentifier(value); + emitAssignment(e.expression, value); + write(".slice(" + i + ")"); + } + } + } + } + } + function emitDestructuringAssignment(target, value) { + if (target.kind === 163 /* BinaryExpression */ && target.operator === 52 /* EqualsToken */) { + value = createDefaultValueCheck(value, target.right); + target = target.left; + } + if (target.kind === 148 /* ObjectLiteralExpression */) { + emitObjectLiteralAssignment(target, value); + } + else if (target.kind === 147 /* ArrayLiteralExpression */) { + emitArrayLiteralAssignment(target, value); + } + else { + emitAssignment(target, value); + } + } + function emitAssignmentExpression(root) { + var target = root.left; + var value = root.right; + if (root.parent.kind === 173 /* ExpressionStatement */) { + emitDestructuringAssignment(target, value); + } + else { + if (root.parent.kind !== 155 /* ParenthesizedExpression */) { + write("("); + } + value = ensureIdentifier(value); + emitDestructuringAssignment(target, value); + write(", "); + emit(value); + if (root.parent.kind !== 155 /* ParenthesizedExpression */) { + write(")"); + } + } + } + function emitBindingElement(target, value) { + if (target.initializer) { + value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; + } + else if (!value) { + value = createVoidZero(); + } + if (ts.isBindingPattern(target.name)) { + var pattern = target.name; + var elements = pattern.elements; + if (elements.length !== 1) { + value = ensureIdentifier(value); + } + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + if (pattern.kind === 144 /* ObjectBindingPattern */) { + var propName = element.propertyName || element.name; + emitBindingElement(element, createPropertyAccess(value, propName)); + } + else if (element.kind !== 168 /* OmittedExpression */) { + if (!element.dotDotDotToken) { + emitBindingElement(element, createElementAccess(value, createNumericLiteral(i))); + } + else { + if (i === elements.length - 1) { + value = ensureIdentifier(value); + emitAssignment(element.name, value); + write(".slice(" + i + ")"); + } + } + } + } + } + else { + emitAssignment(target.name, value); + } + } + } + function emitVariableDeclaration(node) { + emitLeadingComments(node); + if (ts.isBindingPattern(node.name)) { + if (compilerOptions.target < 2 /* ES6 */) { + emitDestructuring(node); + } + else { + emit(node.name); + emitOptional(" = ", node.initializer); + } + } + else { + emitModuleMemberName(node); + emitOptional(" = ", node.initializer); + } + emitTrailingComments(node); + } + function emitVariableStatement(node) { + emitLeadingComments(node); + if (!(node.flags & 1 /* Export */)) { + if (ts.isLet(node.declarationList)) { + write("let "); + } + else if (ts.isConst(node.declarationList)) { + write("const "); + } + else { + write("var "); + } + } + emitCommaList(node.declarationList.declarations); + write(";"); + emitTrailingComments(node); + } + function emitParameter(node) { + emitLeadingComments(node); + if (compilerOptions.target < 2 /* ES6 */) { + if (ts.isBindingPattern(node.name)) { + var name = createTempVariable(node); + if (!tempParameters) { + tempParameters = []; + } + tempParameters.push(name); + emit(name); + } + else { + emit(node.name); + } + } + else { + if (node.dotDotDotToken) { + write("..."); + } + emit(node.name); + emitOptional(" = ", node.initializer); + } + emitTrailingComments(node); + } + function emitDefaultValueAssignments(node) { + if (compilerOptions.target < 2 /* ES6 */) { + var tempIndex = 0; + ts.forEach(node.parameters, function (p) { + if (ts.isBindingPattern(p.name)) { + writeLine(); + write("var "); + emitDestructuring(p, tempParameters[tempIndex]); + write(";"); + tempIndex++; + } + else if (p.initializer) { + writeLine(); + emitStart(p); + write("if ("); + emitNode(p.name); + write(" === void 0)"); + emitEnd(p); + write(" { "); + emitStart(p); + emitNode(p.name); + write(" = "); + emitNode(p.initializer); + emitEnd(p); + write("; }"); + } + }); + } + } + function emitRestParameter(node) { + if (compilerOptions.target < 2 /* ES6 */ && ts.hasRestParameters(node)) { + var restIndex = node.parameters.length - 1; + var restParam = node.parameters[restIndex]; + var tempName = createTempVariable(node, true).text; + writeLine(); + emitLeadingComments(restParam); + emitStart(restParam); + write("var "); + emitNode(restParam.name); + write(" = [];"); + emitEnd(restParam); + emitTrailingComments(restParam); + writeLine(); + write("for ("); + emitStart(restParam); + write("var " + tempName + " = " + restIndex + ";"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + " < arguments.length;"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + "++"); + emitEnd(restParam); + write(") {"); + increaseIndent(); + writeLine(); + emitStart(restParam); + emitNode(restParam.name); + write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); + emitEnd(restParam); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function emitAccessor(node) { + emitLeadingComments(node); + write(node.kind === 130 /* GetAccessor */ ? "get " : "set "); + emit(node.name); + emitSignatureAndBody(node); + emitTrailingComments(node); + } + function emitFunctionDeclaration(node) { + if (ts.nodeIsMissing(node.body)) { + return emitPinnedOrTripleSlashComments(node); + } + if (node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { + emitLeadingComments(node); + } + write("function "); + if (node.kind === 190 /* FunctionDeclaration */ || (node.kind === 156 /* FunctionExpression */ && node.name)) { + emit(node.name); + } + emitSignatureAndBody(node); + if (node.kind !== 128 /* MethodDeclaration */ && node.kind !== 127 /* MethodSignature */) { + emitTrailingComments(node); + } + } + function emitCaptureThisForNodeIfNecessary(node) { + if (resolver.getNodeCheckFlags(node) & 4 /* CaptureThis */) { + writeLine(); + emitStart(node); + write("var _this = this;"); + emitEnd(node); + } + } + function emitSignatureParameters(node) { + increaseIndent(); + write("("); + if (node) { + var parameters = node.parameters; + var omitCount = compilerOptions.target < 2 /* ES6 */ && ts.hasRestParameters(node) ? 1 : 0; + emitList(parameters, 0, parameters.length - omitCount, false, false); + } + write(")"); + decreaseIndent(); + } + function emitSignatureAndBody(node) { + var saveTempCount = tempCount; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; + emitSignatureParameters(node); + write(" {"); + scopeEmitStart(node); + increaseIndent(); + emitDetachedComments(node.body.kind === 170 /* Block */ ? node.body.statements : node.body); + var startIndex = 0; + if (node.body.kind === 170 /* Block */) { + startIndex = emitDirectivePrologues(node.body.statements, true); + } + var outPos = writer.getTextPos(); + emitCaptureThisForNodeIfNecessary(node); + emitDefaultValueAssignments(node); + emitRestParameter(node); + if (node.body.kind !== 170 /* Block */ && outPos === writer.getTextPos()) { + decreaseIndent(); + write(" "); + emitStart(node.body); + write("return "); + emitNode(node.body); + emitEnd(node.body); + write(";"); + emitTempDeclarations(false); + write(" "); + emitStart(node.body); + write("}"); + emitEnd(node.body); + } + else { + if (node.body.kind === 170 /* Block */) { + emitLinesStartingAt(node.body.statements, startIndex); + } + else { + writeLine(); + emitLeadingComments(node.body); + write("return "); + emit(node.body); + write(";"); + emitTrailingComments(node.body); + } + emitTempDeclarations(true); + writeLine(); + if (node.body.kind === 170 /* Block */) { + emitLeadingCommentsOfPosition(node.body.statements.end); + decreaseIndent(); + emitToken(15 /* CloseBraceToken */, node.body.statements.end); + } + else { + decreaseIndent(); + emitStart(node.body); + write("}"); + emitEnd(node.body); + } + } + scopeEmitEnd(); + if (node.flags & 1 /* Export */) { + writeLine(); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emit(node.name); + emitEnd(node); + write(";"); + } + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + function findInitialSuperCall(ctor) { + if (ctor.body) { + var statement = ctor.body.statements[0]; + if (statement && statement.kind === 173 /* ExpressionStatement */) { + var expr = statement.expression; + if (expr && expr.kind === 151 /* CallExpression */) { + var func = expr.expression; + if (func && func.kind === 90 /* SuperKeyword */) { + return statement; + } + } + } + } + } + function emitParameterPropertyAssignments(node) { + ts.forEach(node.parameters, function (param) { + if (param.flags & 112 /* AccessibilityModifier */) { + writeLine(); + emitStart(param); + emitStart(param.name); + write("this."); + emitNode(param.name); + emitEnd(param.name); + write(" = "); + emit(param.name); + write(";"); + emitEnd(param); + } + }); + } + function emitMemberAccessForPropertyName(memberName) { + if (memberName.kind === 8 /* StringLiteral */ || memberName.kind === 7 /* NumericLiteral */) { + write("["); + emitNode(memberName); + write("]"); + } + else if (memberName.kind === 122 /* ComputedPropertyName */) { + emitComputedPropertyName(memberName); + } + else { + write("."); + emitNode(memberName); + } + } + function emitMemberAssignments(node, staticFlag) { + ts.forEach(node.members, function (member) { + if (member.kind === 126 /* PropertyDeclaration */ && (member.flags & 128 /* Static */) === staticFlag && member.initializer) { + writeLine(); + emitLeadingComments(member); + emitStart(member); + emitStart(member.name); + if (staticFlag) { + emitNode(node.name); + } + else { + write("this"); + } + emitMemberAccessForPropertyName(member.name); + emitEnd(member.name); + write(" = "); + emit(member.initializer); + write(";"); + emitEnd(member); + emitTrailingComments(member); + } + }); + } + function emitMemberFunctions(node) { + ts.forEach(node.members, function (member) { + if (member.kind === 128 /* MethodDeclaration */ || node.kind === 127 /* MethodSignature */) { + if (!member.body) { + return emitPinnedOrTripleSlashComments(member); + } + writeLine(); + emitLeadingComments(member); + emitStart(member); + emitStart(member.name); + emitNode(node.name); + if (!(member.flags & 128 /* Static */)) { + write(".prototype"); + } + emitMemberAccessForPropertyName(member.name); + emitEnd(member.name); + write(" = "); + emitStart(member); + emitFunctionDeclaration(member); + emitEnd(member); + emitEnd(member); + write(";"); + emitTrailingComments(member); + } + else if (member.kind === 130 /* GetAccessor */ || member.kind === 131 /* SetAccessor */) { + var accessors = getAllAccessorDeclarations(node, member); + if (member === accessors.firstAccessor) { + writeLine(); + emitStart(member); + write("Object.defineProperty("); + emitStart(member.name); + emitNode(node.name); + if (!(member.flags & 128 /* Static */)) { + write(".prototype"); + } + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + write(", {"); + increaseIndent(); + if (accessors.getAccessor) { + writeLine(); + emitLeadingComments(accessors.getAccessor); + write("get: "); + emitStart(accessors.getAccessor); + write("function "); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + write(","); + } + if (accessors.setAccessor) { + writeLine(); + emitLeadingComments(accessors.setAccessor); + write("set: "); + emitStart(accessors.setAccessor); + write("function "); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor); + write(","); + } + writeLine(); + write("enumerable: true,"); + writeLine(); + write("configurable: true"); + decreaseIndent(); + writeLine(); + write("});"); + emitEnd(member); + } + } + }); + } + function emitClassDeclaration(node) { + emitLeadingComments(node); + write("var "); + emit(node.name); + write(" = (function ("); + var baseTypeNode = ts.getClassBaseTypeNode(node); + if (baseTypeNode) { + write("_super"); + } + write(") {"); + increaseIndent(); + scopeEmitStart(node); + if (baseTypeNode) { + writeLine(); + emitStart(baseTypeNode); + write("__extends("); + emit(node.name); + write(", _super);"); + emitEnd(baseTypeNode); + } + writeLine(); + emitConstructorOfClass(); + emitMemberFunctions(node); + emitMemberAssignments(node, 128 /* Static */); + writeLine(); + function emitClassReturnStatement() { + write("return "); + emitNode(node.name); + } + emitToken(15 /* CloseBraceToken */, node.members.end, emitClassReturnStatement); + write(";"); + decreaseIndent(); + writeLine(); + emitToken(15 /* CloseBraceToken */, node.members.end); + scopeEmitEnd(); + emitStart(node); + write(")("); + if (baseTypeNode) { + emit(baseTypeNode.typeName); + } + write(");"); + emitEnd(node); + if (node.flags & 1 /* Export */) { + writeLine(); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emit(node.name); + emitEnd(node); + write(";"); + } + emitTrailingComments(node); + function emitConstructorOfClass() { + var saveTempCount = tempCount; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; + ts.forEach(node.members, function (member) { + if (member.kind === 129 /* Constructor */ && !member.body) { + emitPinnedOrTripleSlashComments(member); + } + }); + var ctor = getFirstConstructorWithBody(node); + if (ctor) { + emitLeadingComments(ctor); + } + emitStart(ctor || node); + write("function "); + emit(node.name); + emitSignatureParameters(ctor); + write(" {"); + scopeEmitStart(node, "constructor"); + increaseIndent(); + if (ctor) { + emitDetachedComments(ctor.body.statements); + } + emitCaptureThisForNodeIfNecessary(node); + if (ctor) { + emitDefaultValueAssignments(ctor); + emitRestParameter(ctor); + if (baseTypeNode) { + var superCall = findInitialSuperCall(ctor); + if (superCall) { + writeLine(); + emit(superCall); + } + } + emitParameterPropertyAssignments(ctor); + } + else { + if (baseTypeNode) { + writeLine(); + emitStart(baseTypeNode); + write("_super.apply(this, arguments);"); + emitEnd(baseTypeNode); + } + } + emitMemberAssignments(node, 0); + if (ctor) { + var statements = ctor.body.statements; + if (superCall) + statements = statements.slice(1); + emitLines(statements); + } + emitTempDeclarations(true); + writeLine(); + if (ctor) { + emitLeadingCommentsOfPosition(ctor.body.statements.end); + } + decreaseIndent(); + emitToken(15 /* CloseBraceToken */, ctor ? ctor.body.statements.end : node.members.end); + scopeEmitEnd(); + emitEnd(ctor || node); + if (ctor) { + emitTrailingComments(ctor); + } + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + } + function emitInterfaceDeclaration(node) { + emitPinnedOrTripleSlashComments(node); + } + function emitEnumDeclaration(node) { + var isConstEnum = ts.isConst(node); + if (isConstEnum && !compilerOptions.preserveConstEnums) { + return; + } + emitLeadingComments(node); + if (!(node.flags & 1 /* Export */)) { + emitStart(node); + write("var "); + emit(node.name); + emitEnd(node); + write(";"); + } + writeLine(); + emitStart(node); + write("(function ("); + emitStart(node.name); + write(resolver.getLocalNameOfContainer(node)); + emitEnd(node.name); + write(") {"); + increaseIndent(); + scopeEmitStart(node); + emitEnumMemberDeclarations(isConstEnum); + decreaseIndent(); + writeLine(); + emitToken(15 /* CloseBraceToken */, node.members.end); + scopeEmitEnd(); + write(")("); + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + if (node.flags & 1 /* Export */) { + writeLine(); + emitStart(node); + write("var "); + emit(node.name); + write(" = "); + emitModuleMemberName(node); + emitEnd(node); + write(";"); + } + emitTrailingComments(node); + function emitEnumMemberDeclarations(isConstEnum) { + ts.forEach(node.members, function (member) { + writeLine(); + emitLeadingComments(member); + emitStart(member); + write(resolver.getLocalNameOfContainer(node)); + write("["); + write(resolver.getLocalNameOfContainer(node)); + write("["); + emitExpressionForPropertyName(member.name); + write("] = "); + if (member.initializer && !isConstEnum) { + emit(member.initializer); + } + else { + write(resolver.getEnumMemberValue(member).toString()); + } + write("] = "); + emitExpressionForPropertyName(member.name); + emitEnd(member); + write(";"); + emitTrailingComments(member); + }); + } + } + function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { + if (moduleDeclaration.body.kind === 195 /* ModuleDeclaration */) { + var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); + return recursiveInnerModule || moduleDeclaration.body; + } + } + function emitModuleDeclaration(node) { + var shouldEmit = ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums); + if (!shouldEmit) { + return emitPinnedOrTripleSlashComments(node); + } + emitLeadingComments(node); + emitStart(node); + write("var "); + emit(node.name); + write(";"); + emitEnd(node); + writeLine(); + emitStart(node); + write("(function ("); + emitStart(node.name); + write(resolver.getLocalNameOfContainer(node)); + emitEnd(node.name); + write(") "); + if (node.body.kind === 196 /* ModuleBlock */) { + var saveTempCount = tempCount; + var saveTempVariables = tempVariables; + tempCount = 0; + tempVariables = undefined; + emit(node.body); + tempCount = saveTempCount; + tempVariables = saveTempVariables; + } + else { + write("{"); + increaseIndent(); + scopeEmitStart(node); + emitCaptureThisForNodeIfNecessary(node); + writeLine(); + emit(node.body); + decreaseIndent(); + writeLine(); + var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; + emitToken(15 /* CloseBraceToken */, moduleBlock.statements.end); + scopeEmitEnd(); + } + write(")("); + if (node.flags & 1 /* Export */) { + emit(node.name); + write(" = "); + } + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + emitTrailingComments(node); + } + function emitImportDeclaration(node) { + var emitImportDeclaration = resolver.isReferencedImportDeclaration(node); + if (!emitImportDeclaration) { + emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportWithEntityName(node); + } + if (emitImportDeclaration) { + if (ts.isExternalModuleImportDeclaration(node) && node.parent.kind === 207 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { + if (node.flags & 1 /* Export */) { + writeLine(); + emitLeadingComments(node); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emit(node.name); + write(";"); + emitEnd(node); + emitTrailingComments(node); + } + } + else { + writeLine(); + emitLeadingComments(node); + emitStart(node); + if (!(node.flags & 1 /* Export */)) + write("var "); + emitModuleMemberName(node); + write(" = "); + if (ts.isInternalModuleImportDeclaration(node)) { + emit(node.moduleReference); + } + else { + var literal = ts.getExternalModuleImportDeclarationExpression(node); + write("require("); + emitStart(literal); + emitLiteral(literal); + emitEnd(literal); + emitToken(17 /* CloseParenToken */, literal.end); + } + write(";"); + emitEnd(node); + emitTrailingComments(node); + } + } + } + function getExternalImportDeclarations(node) { + var result = []; + ts.forEach(node.statements, function (statement) { + if (ts.isExternalModuleImportDeclaration(statement) && resolver.isReferencedImportDeclaration(statement)) { + result.push(statement); + } + }); + return result; + } + function getFirstExportAssignment(sourceFile) { + return ts.forEach(sourceFile.statements, function (node) { + if (node.kind === 198 /* ExportAssignment */) { + return node; + } + }); + } + function emitAMDModule(node, startIndex) { + var imports = getExternalImportDeclarations(node); + writeLine(); + write("define("); + if (node.amdModuleName) { + write("\"" + node.amdModuleName + "\", "); + } + write("[\"require\", \"exports\""); + ts.forEach(imports, function (imp) { + write(", "); + emitLiteral(ts.getExternalModuleImportDeclarationExpression(imp)); + }); + ts.forEach(node.amdDependencies, function (amdDependency) { + var text = "\"" + amdDependency + "\""; + write(", "); + write(text); + }); + write("], function (require, exports"); + ts.forEach(imports, function (imp) { + write(", "); + emit(imp.name); + }); + write(") {"); + increaseIndent(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + var exportName = resolver.getExportAssignmentName(node); + if (exportName) { + writeLine(); + var exportAssignment = getFirstExportAssignment(node); + emitStart(exportAssignment); + write("return "); + emitStart(exportAssignment.exportName); + write(exportName); + emitEnd(exportAssignment.exportName); + write(";"); + emitEnd(exportAssignment); + } + decreaseIndent(); + writeLine(); + write("});"); + } + function emitCommonJSModule(node, startIndex) { + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + var exportName = resolver.getExportAssignmentName(node); + if (exportName) { + writeLine(); + var exportAssignment = getFirstExportAssignment(node); + emitStart(exportAssignment); + write("module.exports = "); + emitStart(exportAssignment.exportName); + write(exportName); + emitEnd(exportAssignment.exportName); + write(";"); + emitEnd(exportAssignment); + } + } + function emitDirectivePrologues(statements, startWithNewLine) { + for (var i = 0; i < statements.length; ++i) { + if (ts.isPrologueDirective(statements[i])) { + if (startWithNewLine || i > 0) { + writeLine(); + } + emit(statements[i]); + } + else { + return i; + } + } + return statements.length; + } + function emitSourceFile(node) { + currentSourceFile = node; + writeLine(); + emitDetachedComments(node); + var startIndex = emitDirectivePrologues(node.statements, false); + if (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8 /* EmitExtends */) { + writeLine(); + write("var __extends = this.__extends || function (d, b) {"); + increaseIndent(); + writeLine(); + write("for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];"); + writeLine(); + write("function __() { this.constructor = d; }"); + writeLine(); + write("__.prototype = b.prototype;"); + writeLine(); + write("d.prototype = new __();"); + decreaseIndent(); + writeLine(); + write("};"); + extendsEmitted = true; + } + if (ts.isExternalModule(node)) { + if (compilerOptions.module === 2 /* AMD */) { + emitAMDModule(node, startIndex); + } + else { + emitCommonJSModule(node, startIndex); + } + } + else { + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + } + emitLeadingComments(node.endOfFileToken); + } + function emitNode(node) { + if (!node) { + return; + } + if (node.flags & 2 /* Ambient */) { + return emitPinnedOrTripleSlashComments(node); + } + switch (node.kind) { + case 64 /* Identifier */: + return emitIdentifier(node); + case 124 /* Parameter */: + return emitParameter(node); + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + return emitMethod(node); + case 130 /* GetAccessor */: + case 131 /* SetAccessor */: + return emitAccessor(node); + case 92 /* ThisKeyword */: + return emitThis(node); + case 90 /* SuperKeyword */: + return emitSuper(node); + case 88 /* NullKeyword */: + return write("null"); + case 94 /* TrueKeyword */: + return write("true"); + case 79 /* FalseKeyword */: + return write("false"); + case 7 /* NumericLiteral */: + case 8 /* StringLiteral */: + case 9 /* RegularExpressionLiteral */: + case 10 /* NoSubstitutionTemplateLiteral */: + case 11 /* TemplateHead */: + case 12 /* TemplateMiddle */: + case 13 /* TemplateTail */: + return emitLiteral(node); + case 165 /* TemplateExpression */: + return emitTemplateExpression(node); + case 169 /* TemplateSpan */: + return emitTemplateSpan(node); + case 121 /* QualifiedName */: + return emitQualifiedName(node); + case 144 /* ObjectBindingPattern */: + return emitObjectBindingPattern(node); + case 145 /* ArrayBindingPattern */: + return emitArrayBindingPattern(node); + case 146 /* BindingElement */: + return emitBindingElement(node); + case 147 /* ArrayLiteralExpression */: + return emitArrayLiteral(node); + case 148 /* ObjectLiteralExpression */: + return emitObjectLiteral(node); + case 204 /* PropertyAssignment */: + return emitPropertyAssignment(node); + case 205 /* ShorthandPropertyAssignment */: + return emitShorthandPropertyAssignment(node); + case 122 /* ComputedPropertyName */: + return emitComputedPropertyName(node); + case 149 /* PropertyAccessExpression */: + return emitPropertyAccess(node); + case 150 /* ElementAccessExpression */: + return emitIndexedAccess(node); + case 151 /* CallExpression */: + return emitCallExpression(node); + case 152 /* NewExpression */: + return emitNewExpression(node); + case 153 /* TaggedTemplateExpression */: + return emitTaggedTemplateExpression(node); + case 154 /* TypeAssertionExpression */: + return emit(node.expression); + case 155 /* ParenthesizedExpression */: + return emitParenExpression(node); + case 190 /* FunctionDeclaration */: + case 156 /* FunctionExpression */: + case 157 /* ArrowFunction */: + return emitFunctionDeclaration(node); + case 158 /* DeleteExpression */: + return emitDeleteExpression(node); + case 159 /* TypeOfExpression */: + return emitTypeOfExpression(node); + case 160 /* VoidExpression */: + return emitVoidExpression(node); + case 161 /* PrefixUnaryExpression */: + return emitPrefixUnaryExpression(node); + case 162 /* PostfixUnaryExpression */: + return emitPostfixUnaryExpression(node); + case 163 /* BinaryExpression */: + return emitBinaryExpression(node); + case 164 /* ConditionalExpression */: + return emitConditionalExpression(node); + case 167 /* SpreadElementExpression */: + return emitSpreadElementExpression(node); + case 168 /* OmittedExpression */: + return; + case 170 /* Block */: + case 196 /* ModuleBlock */: + return emitBlock(node); + case 171 /* VariableStatement */: + return emitVariableStatement(node); + case 172 /* EmptyStatement */: + return write(";"); + case 173 /* ExpressionStatement */: + return emitExpressionStatement(node); + case 174 /* IfStatement */: + return emitIfStatement(node); + case 175 /* DoStatement */: + return emitDoStatement(node); + case 176 /* WhileStatement */: + return emitWhileStatement(node); + case 177 /* ForStatement */: + return emitForStatement(node); + case 178 /* ForInStatement */: + return emitForInStatement(node); + case 179 /* ContinueStatement */: + case 180 /* BreakStatement */: + return emitBreakOrContinueStatement(node); + case 181 /* ReturnStatement */: + return emitReturnStatement(node); + case 182 /* WithStatement */: + return emitWithStatement(node); + case 183 /* SwitchStatement */: + return emitSwitchStatement(node); + case 200 /* CaseClause */: + case 201 /* DefaultClause */: + return emitCaseOrDefaultClause(node); + case 184 /* LabeledStatement */: + return emitLabelledStatement(node); + case 185 /* ThrowStatement */: + return emitThrowStatement(node); + case 186 /* TryStatement */: + return emitTryStatement(node); + case 203 /* CatchClause */: + return emitCatchClause(node); + case 187 /* DebuggerStatement */: + return emitDebuggerStatement(node); + case 188 /* VariableDeclaration */: + return emitVariableDeclaration(node); + case 191 /* ClassDeclaration */: + return emitClassDeclaration(node); + case 192 /* InterfaceDeclaration */: + return emitInterfaceDeclaration(node); + case 194 /* EnumDeclaration */: + return emitEnumDeclaration(node); + case 195 /* ModuleDeclaration */: + return emitModuleDeclaration(node); + case 197 /* ImportDeclaration */: + return emitImportDeclaration(node); + case 207 /* SourceFile */: + return emitSourceFile(node); + } + } + function hasDetachedComments(pos) { + return detachedCommentsInfo !== undefined && detachedCommentsInfo[detachedCommentsInfo.length - 1].nodePos === pos; + } + function getLeadingCommentsWithoutDetachedComments() { + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); + if (detachedCommentsInfo.length - 1) { + detachedCommentsInfo.pop(); + } + else { + detachedCommentsInfo = undefined; + } + return leadingComments; + } + function getLeadingCommentsToEmit(node) { + if (node.parent.kind === 207 /* SourceFile */ || node.pos !== node.parent.pos) { + var leadingComments; + if (hasDetachedComments(node.pos)) { + leadingComments = getLeadingCommentsWithoutDetachedComments(); + } + else { + leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); + } + return leadingComments; + } + } + function emitLeadingDeclarationComments(node) { + var leadingComments = getLeadingCommentsToEmit(node); + emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); + } + function emitTrailingDeclarationComments(node) { + if (node.parent.kind === 207 /* SourceFile */ || node.end !== node.parent.end) { + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); + emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); + } + } + function emitLeadingCommentsOfLocalPosition(pos) { + var leadingComments; + if (hasDetachedComments(pos)) { + leadingComments = getLeadingCommentsWithoutDetachedComments(); + } + else { + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); + } + emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); + emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); + } + function emitDetachedCommentsAtPosition(node) { + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); + if (leadingComments) { + var detachedComments = []; + var lastComment; + ts.forEach(leadingComments, function (comment) { + if (lastComment) { + var lastCommentLine = getLineOfLocalPosition(currentSourceFile, lastComment.end); + var commentLine = getLineOfLocalPosition(currentSourceFile, comment.pos); + if (commentLine >= lastCommentLine + 2) { + return detachedComments; + } + } + detachedComments.push(comment); + lastComment = comment; + }); + if (detachedComments.length) { + var lastCommentLine = getLineOfLocalPosition(currentSourceFile, detachedComments[detachedComments.length - 1].end); + var astLine = getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); + if (astLine >= lastCommentLine + 2) { + emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment); + var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: detachedComments[detachedComments.length - 1].end }; + if (detachedCommentsInfo) { + detachedCommentsInfo.push(currentDetachedCommentInfo); + } + else { + detachedCommentsInfo = [currentDetachedCommentInfo]; + } + } + } + } + } + function emitPinnedOrTripleSlashCommentsOfNode(node) { + var pinnedComments = ts.filter(getLeadingCommentsToEmit(node), isPinnedOrTripleSlashComment); + function isPinnedOrTripleSlashComment(comment) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) { + return currentSourceFile.text.charCodeAt(comment.pos + 2) === 33 /* exclamation */; + } + else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 /* slash */ && comment.pos + 2 < comment.end && currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 /* slash */ && currentSourceFile.text.substring(comment.pos, comment.end).match(ts.fullTripleSlashReferencePathRegEx)) { + return true; + } + } + emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, pinnedComments); + emitComments(currentSourceFile, writer, pinnedComments, true, newLine, writeComment); + } + if (compilerOptions.sourceMap) { + initializeEmitterWithSourceMaps(); + } + if (root) { + emit(root); + } + else { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + emit(sourceFile); + } + }); + } + writeLine(); + writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); + } + function writeDeclarationFile(jsFilePath, sourceFile) { + var emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile); + if (!emitDeclarationResult.reportedDeclarationError) { + var declarationOutput = emitDeclarationResult.referencePathsOutput; + var appliedSyncOutputPos = 0; + ts.forEach(emitDeclarationResult.aliasDeclarationEmitInfo, function (aliasEmitInfo) { + if (aliasEmitInfo.asynchronousOutput) { + declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); + declarationOutput += aliasEmitInfo.asynchronousOutput; + appliedSyncOutputPos = aliasEmitInfo.outputPos; + } + }); + declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos); + writeFile(host, diagnostics, ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); + } + } + var hasSemanticErrors = false; + var isEmitBlocked = false; + if (targetSourceFile === undefined) { + hasSemanticErrors = resolver.hasSemanticErrors(); + isEmitBlocked = host.isEmitBlocked(); + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (shouldEmitToOwnFile(sourceFile, compilerOptions)) { + var jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, ".js"); + emitFile(jsFilePath, sourceFile); + } + }); + if (compilerOptions.out) { + emitFile(compilerOptions.out); + } + } + else { + if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { + hasSemanticErrors = resolver.hasSemanticErrors(targetSourceFile); + isEmitBlocked = host.isEmitBlocked(targetSourceFile); + var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); + emitFile(jsFilePath, targetSourceFile); + } + else if (!ts.isDeclarationFile(targetSourceFile) && compilerOptions.out) { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (!shouldEmitToOwnFile(sourceFile, compilerOptions)) { + hasSemanticErrors = hasSemanticErrors || resolver.hasSemanticErrors(sourceFile); + isEmitBlocked = isEmitBlocked || host.isEmitBlocked(sourceFile); + } + }); + emitFile(compilerOptions.out); + } + } + function emitFile(jsFilePath, sourceFile) { + if (!isEmitBlocked) { + emitJavaScript(jsFilePath, sourceFile); + if (!hasSemanticErrors && compilerOptions.declaration) { + writeDeclarationFile(jsFilePath, sourceFile); + } + } + } + diagnostics.sort(ts.compareDiagnostics); + diagnostics = ts.deduplicateSortedDiagnostics(diagnostics); + var hasEmitterError = ts.forEach(diagnostics, function (diagnostic) { return diagnostic.category === 1 /* Error */; }); + var emitResultStatus; + if (isEmitBlocked) { + emitResultStatus = 1 /* AllOutputGenerationSkipped */; + } + else if (hasEmitterError) { + emitResultStatus = 4 /* EmitErrorsEncountered */; + } + else if (hasSemanticErrors && compilerOptions.declaration) { + emitResultStatus = 3 /* DeclarationGenerationSkipped */; + } + else if (hasSemanticErrors && !compilerOptions.declaration) { + emitResultStatus = 2 /* JSGeneratedWithSemanticErrors */; + } + else { + emitResultStatus = 0 /* Succeeded */; + } + return { + emitResultStatus: emitResultStatus, + diagnostics: diagnostics, + sourceMaps: sourceMapDataList + }; + } + ts.emitFiles = emitFiles; +})(ts || (ts = {})); +var ts; +(function (ts) { + function createCompilerHost(options) { + var currentDirectory; + var existingDirectories = {}; + function getCanonicalFileName(fileName) { + return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); + } + var unsupportedFileEncodingErrorCode = -2147024809; + function getSourceFile(filename, languageVersion, onError) { + try { + var text = ts.sys.readFile(filename, options.charset); + } + catch (e) { + if (onError) { + onError(e.number === unsupportedFileEncodingErrorCode ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText : e.message); + } + text = ""; + } + return text !== undefined ? ts.createSourceFile(filename, text, languageVersion) : undefined; + } + function writeFile(fileName, data, writeByteOrderMark, onError) { + function directoryExists(directoryPath) { + if (ts.hasProperty(existingDirectories, directoryPath)) { + return true; + } + if (ts.sys.directoryExists(directoryPath)) { + existingDirectories[directoryPath] = true; + return true; + } + return false; + } + function ensureDirectoriesExist(directoryPath) { + if (directoryPath.length > ts.getRootLength(directoryPath) && !directoryExists(directoryPath)) { + var parentDirectory = ts.getDirectoryPath(directoryPath); + ensureDirectoriesExist(parentDirectory); + ts.sys.createDirectory(directoryPath); + } + } + try { + ensureDirectoriesExist(ts.getDirectoryPath(ts.normalizePath(fileName))); + ts.sys.writeFile(fileName, data, writeByteOrderMark); + } + catch (e) { + if (onError) { + onError(e.message); + } + } + } + return { + getSourceFile: getSourceFile, + getDefaultLibFilename: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"); }, + writeFile: writeFile, + getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, + useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, + getCanonicalFileName: getCanonicalFileName, + getNewLine: function () { return ts.sys.newLine; } + }; + } + ts.createCompilerHost = createCompilerHost; + function createProgram(rootNames, options, host) { + var program; + var files = []; + var filesByName = {}; + var errors = []; + var seenNoDefaultLib = options.noLib; + var commonSourceDirectory; + ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); + if (!seenNoDefaultLib) { + processRootFile(host.getDefaultLibFilename(options), true); + } + verifyCompilerOptions(); + errors.sort(ts.compareDiagnostics); + var diagnosticsProducingTypeChecker; + var noDiagnosticsTypeChecker; + var emitHost; + program = { + getSourceFile: getSourceFile, + getSourceFiles: function () { return files; }, + getCompilerOptions: function () { return options; }, + getCompilerHost: function () { return host; }, + getDiagnostics: getDiagnostics, + getGlobalDiagnostics: getGlobalDiagnostics, + getDeclarationDiagnostics: getDeclarationDiagnostics, + getTypeChecker: getTypeChecker, + getCommonSourceDirectory: function () { return commonSourceDirectory; }, + emitFiles: invokeEmitter, + isEmitBlocked: isEmitBlocked, + getCurrentDirectory: host.getCurrentDirectory + }; + return program; + function getEmitHost() { + return emitHost || (emitHost = ts.createEmitHostFromProgram(program)); + } + function hasEarlyErrors(sourceFile) { + return ts.forEach(getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile), function (d) { return d.isEarly; }); + } + function isEmitBlocked(sourceFile) { + return getDiagnostics(sourceFile).length !== 0 || hasEarlyErrors(sourceFile) || (options.noEmitOnError && getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile).length !== 0); + } + function getDiagnosticsProducingTypeChecker() { + return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, true)); + } + function getTypeChecker(produceDiagnostics) { + if (produceDiagnostics) { + return getDiagnosticsProducingTypeChecker(); + } + else { + return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = ts.createTypeChecker(program, produceDiagnostics)); + } + } + function getDeclarationDiagnostics(targetSourceFile) { + var typeChecker = getDiagnosticsProducingTypeChecker(); + typeChecker.getDiagnostics(targetSourceFile); + var resolver = typeChecker.getEmitResolver(); + return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile); + } + function invokeEmitter(targetSourceFile) { + var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(); + return ts.emitFiles(resolver, getEmitHost(), targetSourceFile); + } + function getSourceFile(filename) { + filename = host.getCanonicalFileName(filename); + return ts.hasProperty(filesByName, filename) ? filesByName[filename] : undefined; + } + function getDiagnostics(sourceFile) { + return sourceFile ? ts.filter(errors, function (e) { return e.file === sourceFile; }) : errors; + } + function getGlobalDiagnostics() { + return ts.filter(errors, function (e) { return !e.file; }); + } + function hasExtension(filename) { + return ts.getBaseFilename(filename).indexOf(".") >= 0; + } + function processRootFile(filename, isDefaultLib) { + processSourceFile(ts.normalizePath(filename), isDefaultLib); + } + function processSourceFile(filename, isDefaultLib, refFile, refPos, refEnd) { + if (refEnd !== undefined && refPos !== undefined) { + var start = refPos; + var length = refEnd - refPos; + } + var diagnostic; + if (hasExtension(filename)) { + if (!options.allowNonTsExtensions && !ts.fileExtensionIs(filename, ".ts")) { + diagnostic = ts.Diagnostics.File_0_must_have_extension_ts_or_d_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 (options.allowNonTsExtensions && !findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) { + diagnostic = ts.Diagnostics.File_0_not_found; + } + else if (!findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) { + diagnostic = ts.Diagnostics.File_0_not_found; + filename += ".ts"; + } + } + if (diagnostic) { + if (refFile) { + errors.push(ts.createFileDiagnostic(refFile, start, length, diagnostic, filename)); + } + else { + errors.push(ts.createCompilerDiagnostic(diagnostic, filename)); + } + } + } + function findSourceFile(filename, isDefaultLib, refFile, refStart, refLength) { + var canonicalName = host.getCanonicalFileName(filename); + if (ts.hasProperty(filesByName, canonicalName)) { + return getSourceFileFromCache(filename, canonicalName, false); + } + else { + var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(filename, host.getCurrentDirectory()); + var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); + if (ts.hasProperty(filesByName, canonicalAbsolutePath)) { + return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); + } + var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, function (hostErrorMessage) { + if (refFile) { + errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); + } + else { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); + } + }); + if (file) { + seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; + filesByName[canonicalAbsolutePath] = file; + if (!options.noResolve) { + var basePath = ts.getDirectoryPath(filename); + processReferencedFiles(file, basePath); + processImportedModules(file, basePath); + } + if (isDefaultLib) { + files.unshift(file); + } + else { + files.push(file); + } + ts.forEach(file.getSyntacticDiagnostics(), function (e) { + errors.push(e); + }); + } + } + return file; + function getSourceFileFromCache(filename, canonicalName, useAbsolutePath) { + var file = filesByName[canonicalName]; + if (file && host.useCaseSensitiveFileNames()) { + var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.filename, host.getCurrentDirectory()) : file.filename; + if (canonicalName !== sourceFileName) { + errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, sourceFileName)); + } + } + return file; + } + } + function processReferencedFiles(file, basePath) { + ts.forEach(file.referencedFiles, function (ref) { + 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 (ts.isExternalModuleImportDeclaration(node) && ts.getExternalModuleImportDeclarationExpression(node).kind === 8 /* StringLiteral */) { + var nameLiteral = ts.getExternalModuleImportDeclarationExpression(node); + var moduleName = nameLiteral.text; + if (moduleName) { + var searchPath = basePath; + while (true) { + var searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleName)); + if (findModuleSourceFile(searchName + ".ts", nameLiteral) || findModuleSourceFile(searchName + ".d.ts", nameLiteral)) { + break; + } + var parentPath = ts.getDirectoryPath(searchPath); + if (parentPath === searchPath) { + break; + } + searchPath = parentPath; + } + } + } + else if (node.kind === 195 /* ModuleDeclaration */ && node.name.kind === 8 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || ts.isDeclarationFile(file))) { + ts.forEachChild(node.body, function (node) { + if (ts.isExternalModuleImportDeclaration(node) && ts.getExternalModuleImportDeclarationExpression(node).kind === 8 /* StringLiteral */) { + var nameLiteral = ts.getExternalModuleImportDeclarationExpression(node); + var moduleName = nameLiteral.text; + if (moduleName) { + var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName)); + var tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral); + if (!tsFile) { + findModuleSourceFile(searchName + ".d.ts", nameLiteral); + } + } + } + }); + } + }); + function findModuleSourceFile(filename, nameLiteral) { + return findSourceFile(filename, false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos); + } + } + function verifyCompilerOptions() { + if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { + if (options.mapRoot) { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option)); + } + if (options.sourceRoot) { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option)); + } + return; + } + var firstExternalModule = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); + if (firstExternalModule && options.module === 0 /* None */) { + var externalModuleErrorSpan = ts.getErrorSpanForNode(firstExternalModule.externalModuleIndicator); + var errorStart = ts.skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos); + var errorLength = externalModuleErrorSpan.end - errorStart; + errors.push(ts.createFileDiagnostic(firstExternalModule, errorStart, errorLength, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + } + if (options.outDir || options.sourceRoot || (options.mapRoot && (!options.out || firstExternalModule !== undefined))) { + var commonPathComponents; + ts.forEach(files, function (sourceFile) { + if (!(sourceFile.flags & 1024 /* DeclarationFile */) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { + var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory()); + sourcePathComponents.pop(); + if (commonPathComponents) { + for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) { + if (commonPathComponents[i] !== sourcePathComponents[i]) { + if (i === 0) { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + return; + } + commonPathComponents.length = i; + break; + } + } + if (sourcePathComponents.length < commonPathComponents.length) { + commonPathComponents.length = sourcePathComponents.length; + } + } + else { + commonPathComponents = sourcePathComponents; + } + } + }); + commonSourceDirectory = ts.getNormalizedPathFromPathComponents(commonPathComponents); + if (commonSourceDirectory) { + commonSourceDirectory += ts.directorySeparator; + } + } + if (options.noEmit) { + if (options.out || options.outDir) { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmit_cannot_be_specified_with_option_out_or_outDir)); + } + if (options.declaration) { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration)); + } + } + } + } + ts.createProgram = createProgram; +})(ts || (ts = {})); +var ts; +(function (ts) { + ts.optionDeclarations = [ + { + name: "charset", + type: "string" + }, + { + name: "codepage", + type: "number" + }, + { + name: "declaration", + shortName: "d", + type: "boolean", + description: ts.Diagnostics.Generates_corresponding_d_ts_file + }, + { + name: "diagnostics", + type: "boolean" + }, + { + name: "emitBOM", + type: "boolean" + }, + { + name: "help", + shortName: "h", + type: "boolean", + description: ts.Diagnostics.Print_this_message + }, + { + name: "locale", + type: "string" + }, + { + name: "mapRoot", + type: "string", + description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations, + paramType: ts.Diagnostics.LOCATION + }, + { + name: "module", + shortName: "m", + type: { + "commonjs": 1 /* CommonJS */, + "amd": 2 /* AMD */ + }, + description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_or_amd, + paramType: ts.Diagnostics.KIND, + error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd + }, + { + name: "noEmit", + type: "boolean", + description: ts.Diagnostics.Do_not_emit_outputs + }, + { + name: "noEmitOnError", + type: "boolean", + description: ts.Diagnostics.Do_not_emit_outputs_if_any_type_checking_errors_were_reported + }, + { + name: "noImplicitAny", + type: "boolean", + description: ts.Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type + }, + { + name: "noLib", + type: "boolean" + }, + { + name: "noLibCheck", + type: "boolean" + }, + { + name: "noResolve", + type: "boolean" + }, + { + name: "out", + type: "string", + description: ts.Diagnostics.Concatenate_and_emit_output_to_single_file, + paramType: ts.Diagnostics.FILE + }, + { + name: "outDir", + type: "string", + description: ts.Diagnostics.Redirect_output_structure_to_the_directory, + paramType: ts.Diagnostics.DIRECTORY + }, + { + name: "preserveConstEnums", + type: "boolean", + description: ts.Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code + }, + { + name: "removeComments", + type: "boolean", + description: ts.Diagnostics.Do_not_emit_comments_to_output + }, + { + name: "sourceMap", + type: "boolean", + description: ts.Diagnostics.Generates_corresponding_map_file + }, + { + name: "sourceRoot", + type: "string", + description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations, + paramType: ts.Diagnostics.LOCATION + }, + { + name: "suppressImplicitAnyIndexErrors", + type: "boolean", + description: ts.Diagnostics.Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures + }, + { + name: "target", + shortName: "t", + type: { "es3": 0 /* ES3 */, "es5": 1 /* ES5 */, "es6": 2 /* ES6 */ }, + description: ts.Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental, + paramType: ts.Diagnostics.VERSION, + error: ts.Diagnostics.Argument_for_target_option_must_be_es3_es5_or_es6 + }, + { + name: "version", + shortName: "v", + type: "boolean", + description: ts.Diagnostics.Print_the_compiler_s_version + }, + { + name: "watch", + shortName: "w", + type: "boolean", + description: ts.Diagnostics.Watch_input_files + } + ]; + var shortOptionNames = {}; + var optionNameMap = {}; + ts.forEach(ts.optionDeclarations, function (option) { + optionNameMap[option.name.toLowerCase()] = option; + if (option.shortName) { + shortOptionNames[option.shortName] = option.name; + } + }); + function parseCommandLine(commandLine) { + var options = { + target: 0 /* ES3 */, + module: 0 /* None */ + }; + var filenames = []; + var errors = []; + parseStrings(commandLine); + return { + options: options, + filenames: filenames, + errors: errors + }; + function parseStrings(args) { + var i = 0; + while (i < args.length) { + var s = args[i++]; + if (s.charCodeAt(0) === 64 /* at */) { + parseResponseFile(s.slice(1)); + } + else if (s.charCodeAt(0) === 45 /* minus */) { + s = s.slice(s.charCodeAt(1) === 45 /* minus */ ? 2 : 1).toLowerCase(); + if (ts.hasProperty(shortOptionNames, s)) { + s = shortOptionNames[s]; + } + if (ts.hasProperty(optionNameMap, s)) { + var opt = optionNameMap[s]; + if (!args[i] && opt.type !== "boolean") { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Compiler_option_0_expects_an_argument, opt.name)); + } + switch (opt.type) { + case "number": + options[opt.name] = parseInt(args[i++]); + break; + case "boolean": + options[opt.name] = true; + break; + case "string": + options[opt.name] = args[i++] || ""; + break; + default: + var map = opt.type; + var key = (args[i++] || "").toLowerCase(); + if (ts.hasProperty(map, key)) { + options[opt.name] = map[key]; + } + else { + errors.push(ts.createCompilerDiagnostic(opt.error)); + } + } + } + else { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unknown_compiler_option_0, s)); + } + } + else { + filenames.push(s); + } + } + } + function parseResponseFile(filename) { + var text = ts.sys.readFile(filename); + if (!text) { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_not_found, filename)); + return; + } + var args = []; + var pos = 0; + while (true) { + while (pos < text.length && text.charCodeAt(pos) <= 32 /* space */) + pos++; + if (pos >= text.length) + break; + var start = pos; + if (text.charCodeAt(start) === 34 /* doubleQuote */) { + pos++; + while (pos < text.length && text.charCodeAt(pos) !== 34 /* doubleQuote */) + pos++; + if (pos < text.length) { + args.push(text.substring(start + 1, pos)); + pos++; + } + else { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unterminated_quoted_string_in_response_file_0, filename)); + } + } + else { + while (text.charCodeAt(pos) > 32 /* space */) + pos++; + args.push(text.substring(start, pos)); + } + } + parseStrings(args); + } + } + ts.parseCommandLine = parseCommandLine; +})(ts || (ts = {})); +var ts; (function (ts) { var OutliningElementsCollector; (function (OutliningElementsCollector) { @@ -18338,8 +20081,8 @@ var ts; function addOutliningSpan(hintSpanNode, startElement, endElement, autoCollapse) { if (hintSpanNode && startElement && endElement) { var span = { - textSpan: ts.TextSpan.fromBounds(startElement.pos, endElement.end), - hintSpan: ts.TextSpan.fromBounds(hintSpanNode.getStart(), hintSpanNode.end), + textSpan: ts.createTextSpanFromBounds(startElement.pos, endElement.end), + hintSpan: ts.createTextSpanFromBounds(hintSpanNode.getStart(), hintSpanNode.end), bannerText: collapseText, autoCollapse: autoCollapse }; @@ -18363,28 +20106,39 @@ var ts; return; } switch (n.kind) { - case 169 /* Block */: + case 170 /* Block */: if (!ts.isFunctionBlock(n)) { var parent = n.parent; var openBrace = ts.findChildOfKind(n, 14 /* OpenBraceToken */, sourceFile); var closeBrace = ts.findChildOfKind(n, 15 /* CloseBraceToken */, sourceFile); - if (parent.kind === 174 /* DoStatement */ || parent.kind === 177 /* ForInStatement */ || parent.kind === 176 /* ForStatement */ || parent.kind === 173 /* IfStatement */ || parent.kind === 175 /* WhileStatement */ || parent.kind === 181 /* WithStatement */ || parent.kind === 203 /* CatchClause */) { + if (parent.kind === 175 /* DoStatement */ || parent.kind === 178 /* ForInStatement */ || parent.kind === 177 /* ForStatement */ || parent.kind === 174 /* IfStatement */ || parent.kind === 176 /* WhileStatement */ || parent.kind === 182 /* WithStatement */ || parent.kind === 203 /* CatchClause */) { addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); + break; } - else { - var span = ts.TextSpan.fromBounds(n.getStart(), n.end); - elements.push({ - textSpan: span, - hintSpan: span, - bannerText: collapseText, - autoCollapse: autoCollapse(n) - }); + if (parent.kind === 186 /* TryStatement */) { + var tryStatement = parent; + if (tryStatement.tryBlock === n) { + addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); + break; + } + else if (tryStatement.finallyBlock === n) { + var finallyKeyword = ts.findChildOfKind(tryStatement, 80 /* FinallyKeyword */, sourceFile); + if (finallyKeyword) { + addOutliningSpan(finallyKeyword, openBrace, closeBrace, autoCollapse(n)); + break; + } + } } + var span = ts.createTextSpanFromBounds(n.getStart(), n.end); + elements.push({ + textSpan: span, + hintSpan: span, + bannerText: collapseText, + autoCollapse: autoCollapse(n) + }); break; } case 196 /* ModuleBlock */: - case 186 /* TryBlock */: - case 187 /* FinallyBlock */: var openBrace = ts.findChildOfKind(n, 14 /* OpenBraceToken */, sourceFile); var closeBrace = ts.findChildOfKind(n, 15 /* CloseBraceToken */, sourceFile); addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n)); @@ -18393,7 +20147,7 @@ var ts; case 192 /* InterfaceDeclaration */: case 194 /* EnumDeclaration */: case 148 /* ObjectLiteralExpression */: - case 182 /* SwitchStatement */: + case 183 /* SwitchStatement */: var openBrace = ts.findChildOfKind(n, 14 /* OpenBraceToken */, sourceFile); var closeBrace = ts.findChildOfKind(n, 15 /* CloseBraceToken */, sourceFile); addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n)); @@ -18444,14 +20198,14 @@ var ts; var childNodes = []; function visit(node) { switch (node.kind) { - case 170 /* VariableStatement */: - ts.forEach(node.declarations, visit); + case 171 /* VariableStatement */: + ts.forEach(node.declarationList.declarations, visit); break; case 144 /* ObjectBindingPattern */: case 145 /* ArrayBindingPattern */: ts.forEach(node.elements, visit); break; - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: if (ts.isBindingPattern(node)) { visit(node.name); break; @@ -18516,7 +20270,7 @@ var ts; } function isTopLevelFunctionDeclaration(functionDeclaration) { if (functionDeclaration.kind === 190 /* FunctionDeclaration */) { - if (functionDeclaration.body && functionDeclaration.body.kind === 169 /* Block */) { + if (functionDeclaration.body && functionDeclaration.body.kind === 170 /* Block */) { if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 190 /* FunctionDeclaration */ && !isEmpty(s.name.text); })) { return true; } @@ -18598,7 +20352,7 @@ var ts; return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); case 190 /* FunctionDeclaration */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.functionElement); - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: if (ts.isBindingPattern(node.name)) { break; } @@ -18673,7 +20427,7 @@ var ts; return getNavigationBarItem(moduleName, ts.ScriptElementKind.moduleElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } function createFunctionItem(node) { - if (node.name && node.body && node.body.kind === 169 /* Block */) { + if (node.name && node.body && node.body.kind === 170 /* Block */) { var childItems = getItemsWorker(sortNodes(node.body.statements), createChildItem); return getNavigationBarItem(node.name.text, ts.ScriptElementKind.functionElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } @@ -18721,7 +20475,7 @@ var ts; return node; } function getNodeSpan(node) { - return node.kind === 207 /* SourceFile */ ? ts.TextSpan.fromBounds(node.getFullStart(), node.getEnd()) : ts.TextSpan.fromBounds(node.getStart(), node.getEnd()); + return node.kind === 207 /* SourceFile */ ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); } function getTextOfNode(node) { return ts.getTextOfNodeFromSourceText(sourceFile.text, node); @@ -18735,6 +20489,12 @@ var ts; var SignatureHelp; (function (SignatureHelp) { var emptyArray = []; + var ArgumentListKind; + (function (ArgumentListKind) { + ArgumentListKind[ArgumentListKind["TypeArguments"] = 0] = "TypeArguments"; + ArgumentListKind[ArgumentListKind["CallArguments"] = 1] = "CallArguments"; + ArgumentListKind[ArgumentListKind["TaggedTemplateArguments"] = 2] = "TaggedTemplateArguments"; + })(ArgumentListKind || (ArgumentListKind = {})); function getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken) { var startingToken = ts.findTokenOnLeftOfPosition(sourceFile, position); if (!startingToken) { @@ -18794,7 +20554,7 @@ var ts; var argumentIndex = ts.isInsideTemplateLiteral(node, position) ? 0 : 1; return getArgumentListInfoForTemplate(tagExpression, argumentIndex); } - else if (node.parent.kind === 168 /* TemplateSpan */ && node.parent.parent.parent.kind === 153 /* TaggedTemplateExpression */) { + else if (node.parent.kind === 169 /* TemplateSpan */ && node.parent.parent.parent.kind === 153 /* TaggedTemplateExpression */) { var templateSpan = node.parent; var templateExpression = templateSpan.parent; var tagExpression = templateExpression.parent; @@ -18834,7 +20594,7 @@ var ts; function getApplicableSpanForArguments(argumentsList) { var applicableSpanStart = argumentsList.getFullStart(); var applicableSpanEnd = ts.skipTrivia(sourceFile.text, argumentsList.getEnd(), false); - return new ts.TextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart); + return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart); } function getApplicableSpanForTaggedTemplate(taggedTemplate) { var template = taggedTemplate.template; @@ -18846,7 +20606,7 @@ var ts; applicableSpanEnd = ts.skipTrivia(sourceFile.text, applicableSpanEnd, false); } } - return new ts.TextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart); + return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart); } function getContainingArgumentInfo(node) { for (var n = node; n.kind !== 207 /* SourceFile */; n = n.parent) { @@ -19034,7 +20794,7 @@ var ts; ts.findChildOfKind = findChildOfKind; function findContainingList(node) { var syntaxList = ts.forEach(node.parent.getChildren(), function (c) { - if (c.kind === 209 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { + if (c.kind === 208 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { return c; } }); @@ -19157,7 +20917,7 @@ var ts; return n.getWidth() !== 0; } function getNodeModifiers(node) { - var flags = node.flags; + var flags = ts.getCombinedNodeFlags(node); var result = []; if (flags & 32 /* Private */) result.push(ts.ScriptElementKindModifier.privateMemberModifier); @@ -19394,6 +21154,13 @@ var ts; var formatting; (function (formatting) { var scanner = ts.createScanner(2 /* Latest */, false); + var ScanAction; + (function (ScanAction) { + ScanAction[ScanAction["Scan"] = 0] = "Scan"; + ScanAction[ScanAction["RescanGreaterThanToken"] = 1] = "RescanGreaterThanToken"; + ScanAction[ScanAction["RescanSlashToken"] = 2] = "RescanSlashToken"; + ScanAction[ScanAction["RescanTemplateToken"] = 3] = "RescanTemplateToken"; + })(ScanAction || (ScanAction = {})); function getFormattingScanner(sourceFile, startPos, endPos) { scanner.setText(sourceFile.text); scanner.setTextPos(startPos); @@ -19634,6 +21401,20 @@ var ts; })(formatting = ts.formatting || (ts.formatting = {})); })(ts || (ts = {})); var ts; +(function (ts) { + var formatting; + (function (formatting) { + (function (FormattingRequestKind) { + FormattingRequestKind[FormattingRequestKind["FormatDocument"] = 0] = "FormatDocument"; + FormattingRequestKind[FormattingRequestKind["FormatSelection"] = 1] = "FormatSelection"; + FormattingRequestKind[FormattingRequestKind["FormatOnEnter"] = 2] = "FormatOnEnter"; + FormattingRequestKind[FormattingRequestKind["FormatOnSemicolon"] = 3] = "FormatOnSemicolon"; + FormattingRequestKind[FormattingRequestKind["FormatOnClosingCurlyBrace"] = 4] = "FormatOnClosingCurlyBrace"; + })(formatting.FormattingRequestKind || (formatting.FormattingRequestKind = {})); + var FormattingRequestKind = formatting.FormattingRequestKind; + })(formatting = ts.formatting || (ts.formatting = {})); +})(ts || (ts = {})); +var ts; (function (ts) { var formatting; (function (formatting) { @@ -19653,6 +21434,19 @@ var ts; })(formatting = ts.formatting || (ts.formatting = {})); })(ts || (ts = {})); var ts; +(function (ts) { + var formatting; + (function (formatting) { + (function (RuleAction) { + RuleAction[RuleAction["Ignore"] = 1] = "Ignore"; + RuleAction[RuleAction["Space"] = 2] = "Space"; + RuleAction[RuleAction["NewLine"] = 4] = "NewLine"; + RuleAction[RuleAction["Delete"] = 8] = "Delete"; + })(formatting.RuleAction || (formatting.RuleAction = {})); + var RuleAction = formatting.RuleAction; + })(formatting = ts.formatting || (ts.formatting = {})); +})(ts || (ts = {})); +var ts; (function (ts) { var formatting; (function (formatting) { @@ -19682,6 +21476,17 @@ var ts; })(formatting = ts.formatting || (ts.formatting = {})); })(ts || (ts = {})); var ts; +(function (ts) { + var formatting; + (function (formatting) { + (function (RuleFlags) { + RuleFlags[RuleFlags["None"] = 0] = "None"; + RuleFlags[RuleFlags["CanDeleteNewLines"] = 1] = "CanDeleteNewLines"; + })(formatting.RuleFlags || (formatting.RuleFlags = {})); + var RuleFlags = formatting.RuleFlags; + })(formatting = ts.formatting || (ts.formatting = {})); +})(ts || (ts = {})); +var ts; (function (ts) { var formatting; (function (formatting) { @@ -19909,7 +21714,7 @@ var ts; throw new Error("Unknown rule"); }; Rules.IsForContext = function (context) { - return context.contextNode.kind === 176 /* ForStatement */; + return context.contextNode.kind === 177 /* ForStatement */; }; Rules.IsNotForContext = function (context) { return !Rules.IsForContext(context); @@ -19920,13 +21725,13 @@ var ts; case 164 /* ConditionalExpression */: return true; case 197 /* ImportDeclaration */: - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 124 /* Parameter */: case 206 /* EnumMember */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: return context.currentTokenSpan.kind === 52 /* EqualsToken */ || context.nextTokenSpan.kind === 52 /* EqualsToken */; - case 177 /* ForInStatement */: + case 178 /* ForInStatement */: return context.currentTokenSpan.kind === 85 /* InKeyword */ || context.nextTokenSpan.kind === 85 /* InKeyword */; } return false; @@ -19957,11 +21762,9 @@ var ts; return true; } switch (node.kind) { - case 169 /* Block */: - case 182 /* SwitchStatement */: + case 170 /* Block */: + case 183 /* SwitchStatement */: case 148 /* ObjectLiteralExpression */: - case 186 /* TryBlock */: - case 187 /* FinallyBlock */: case 196 /* ModuleBlock */: return true; } @@ -20002,28 +21805,25 @@ var ts; case 191 /* ClassDeclaration */: case 195 /* ModuleDeclaration */: case 194 /* EnumDeclaration */: - case 169 /* Block */: - case 186 /* TryBlock */: + case 170 /* Block */: case 203 /* CatchClause */: - case 187 /* FinallyBlock */: case 196 /* ModuleBlock */: - case 182 /* SwitchStatement */: + case 183 /* SwitchStatement */: return true; } return false; }; Rules.IsControlDeclContext = function (context) { switch (context.contextNode.kind) { - case 173 /* IfStatement */: - case 182 /* SwitchStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 175 /* WhileStatement */: - case 185 /* TryStatement */: - case 174 /* DoStatement */: - case 181 /* WithStatement */: + case 174 /* IfStatement */: + case 183 /* SwitchStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 176 /* WhileStatement */: + case 186 /* TryStatement */: + case 175 /* DoStatement */: + case 182 /* WithStatement */: case 203 /* CatchClause */: - case 187 /* FinallyBlock */: return true; default: return false; @@ -20315,10 +22115,8 @@ var ts; TokenRange.Any = TokenRange.AllTokens(); TokenRange.AnyIncludingMultilineComments = TokenRange.FromTokens(TokenRange.Any.GetTokens().concat([3 /* MultiLineCommentTrivia */])); TokenRange.Keywords = TokenRange.FromRange(65 /* FirstKeyword */, 120 /* LastKeyword */); - TokenRange.Operators = TokenRange.FromRange(22 /* FirstOperator */, 63 /* LastOperator */); TokenRange.BinaryOperators = TokenRange.FromRange(24 /* FirstBinaryOperator */, 63 /* LastBinaryOperator */); TokenRange.BinaryKeywordOperators = TokenRange.FromTokens([85 /* InKeyword */, 86 /* InstanceOfKeyword */]); - TokenRange.ReservedKeywords = TokenRange.FromRange(101 /* FirstFutureReservedWord */, 109 /* LastFutureReservedWord */); TokenRange.UnaryPrefixOperators = TokenRange.FromTokens([38 /* PlusPlusToken */, 39 /* MinusMinusToken */, 47 /* TildeToken */, 46 /* ExclamationToken */]); TokenRange.UnaryPrefixExpressions = TokenRange.FromTokens([7 /* NumericLiteral */, 64 /* Identifier */, 16 /* OpenParenToken */, 18 /* OpenBracketToken */, 14 /* OpenBraceToken */, 92 /* ThisKeyword */, 87 /* NewKeyword */]); TokenRange.UnaryPreincrementExpressions = TokenRange.FromTokens([64 /* Identifier */, 16 /* OpenParenToken */, 92 /* ThisKeyword */, 87 /* NewKeyword */]); @@ -20423,6 +22221,10 @@ var ts; (function (ts) { var formatting; (function (formatting) { + var Constants; + (function (Constants) { + Constants[Constants["Unknown"] = -1] = "Unknown"; + })(Constants || (Constants = {})); function formatOnEnter(position, sourceFile, rulesProvider, options) { var line = sourceFile.getLineAndCharacterFromPosition(position).line; ts.Debug.assert(line >= 2); @@ -20486,11 +22288,9 @@ var ts; return ts.rangeContainsRange(parent.members, node); case 195 /* ModuleDeclaration */: var body = parent.body; - return body && body.kind === 169 /* Block */ && ts.rangeContainsRange(body.statements, node); + return body && body.kind === 170 /* Block */ && ts.rangeContainsRange(body.statements, node); case 207 /* SourceFile */: - case 169 /* Block */: - case 186 /* TryBlock */: - case 187 /* FinallyBlock */: + case 170 /* Block */: case 196 /* ModuleBlock */: return ts.rangeContainsRange(parent.statements, node); case 203 /* CatchClause */: @@ -20958,7 +22758,7 @@ var ts; } } function newTextChange(start, len, newText) { - return { span: new ts.TextSpan(start, len), newText: newText }; + return { span: ts.createTextSpan(start, len), newText: newText }; } function recordDelete(start, len) { if (len) { @@ -21003,10 +22803,7 @@ var ts; } function isSomeBlock(kind) { switch (kind) { - case 169 /* Block */: - case 169 /* Block */: - case 186 /* TryBlock */: - case 187 /* FinallyBlock */: + case 170 /* Block */: case 196 /* ModuleBlock */: return true; } @@ -21226,7 +23023,7 @@ var ts; return candidate.end > position || !isCompletedNode(candidate, sourceFile); } function childStartsOnTheSameLineWithElseInIfStatement(parent, child, childStartLine, sourceFile) { - if (parent.kind === 173 /* IfStatement */ && parent.elseStatement === child) { + if (parent.kind === 174 /* IfStatement */ && parent.elseStatement === child) { var elseKeyword = ts.findChildOfKind(parent, 75 /* ElseKeyword */, sourceFile); ts.Debug.assert(elseKeyword !== undefined); var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line; @@ -21327,22 +23124,20 @@ var ts; case 192 /* InterfaceDeclaration */: case 194 /* EnumDeclaration */: case 147 /* ArrayLiteralExpression */: - case 169 /* Block */: - case 186 /* TryBlock */: - case 187 /* FinallyBlock */: + case 170 /* Block */: case 196 /* ModuleBlock */: case 148 /* ObjectLiteralExpression */: case 139 /* TypeLiteral */: - case 182 /* SwitchStatement */: + case 183 /* SwitchStatement */: case 201 /* DefaultClause */: case 200 /* CaseClause */: case 155 /* ParenthesizedExpression */: case 151 /* CallExpression */: case 152 /* NewExpression */: - case 170 /* VariableStatement */: - case 189 /* VariableDeclaration */: + case 171 /* VariableStatement */: + case 188 /* VariableDeclaration */: case 198 /* ExportAssignment */: - case 180 /* ReturnStatement */: + case 181 /* ReturnStatement */: case 164 /* ConditionalExpression */: return true; } @@ -21353,11 +23148,11 @@ var ts; return true; } switch (parent) { - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 177 /* ForInStatement */: - case 176 /* ForStatement */: - case 173 /* IfStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: + case 178 /* ForInStatement */: + case 177 /* ForStatement */: + case 174 /* IfStatement */: case 190 /* FunctionDeclaration */: case 156 /* FunctionExpression */: case 128 /* MethodDeclaration */: @@ -21366,7 +23161,7 @@ var ts; case 129 /* Constructor */: case 130 /* GetAccessor */: case 131 /* SetAccessor */: - return child !== 169 /* Block */; + return child !== 170 /* Block */; default: return false; } @@ -21394,10 +23189,9 @@ var ts; case 192 /* InterfaceDeclaration */: case 194 /* EnumDeclaration */: case 148 /* ObjectLiteralExpression */: - case 169 /* Block */: - case 187 /* FinallyBlock */: + case 170 /* Block */: case 196 /* ModuleBlock */: - case 182 /* SwitchStatement */: + case 183 /* SwitchStatement */: return nodeEndsWith(n, 15 /* CloseBraceToken */, sourceFile); case 203 /* CatchClause */: return isCompletedNode(n.block, sourceFile); @@ -21414,21 +23208,21 @@ var ts; return !n.body || isCompletedNode(n.body, sourceFile); case 195 /* ModuleDeclaration */: return n.body && isCompletedNode(n.body, sourceFile); - case 173 /* IfStatement */: + case 174 /* IfStatement */: if (n.elseStatement) { return isCompletedNode(n.elseStatement, sourceFile); } return isCompletedNode(n.thenStatement, sourceFile); - case 172 /* ExpressionStatement */: + case 173 /* ExpressionStatement */: return isCompletedNode(n.expression, sourceFile); case 147 /* ArrayLiteralExpression */: return nodeEndsWith(n, 19 /* CloseBracketToken */, sourceFile); case 200 /* CaseClause */: case 201 /* DefaultClause */: return false; - case 175 /* WhileStatement */: + case 176 /* WhileStatement */: return isCompletedNode(n.statement, sourceFile); - case 174 /* DoStatement */: + case 175 /* DoStatement */: var hasWhileKeyword = ts.findChildOfKind(n, 99 /* WhileKeyword */, sourceFile); if (hasWhileKeyword) { return nodeEndsWith(n, 17 /* CloseParenToken */, sourceFile); @@ -21530,7 +23324,7 @@ var ts; return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(209 /* SyntaxList */, nodes.pos, nodes.end, 512 /* Synthetic */, this); + var list = createNode(208 /* SyntaxList */, nodes.pos, nodes.end, 512 /* Synthetic */, this); list._children = []; var pos = nodes.pos; for (var i = 0, len = nodes.length; i < len; i++) { @@ -21662,7 +23456,7 @@ var ts; while (declaration.kind === 195 /* ModuleDeclaration */ && declaration.parent.kind === 195 /* ModuleDeclaration */) { declaration = declaration.parent; } - ts.forEach(getJsDocCommentTextRange(declaration.kind === 189 /* VariableDeclaration */ ? declaration.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { + ts.forEach(getJsDocCommentTextRange(declaration.kind === 188 /* VariableDeclaration */ ? declaration.parent.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedJsDocComment) { jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment); @@ -21924,9 +23718,6 @@ var ts; function SourceFileObject() { _super.apply(this, arguments); } - SourceFileObject.prototype.getScriptSnapshot = function () { - return this.scriptSnapshot; - }; SourceFileObject.prototype.getNamedDeclarations = function () { if (!this.namedDeclarations) { var sourceFile = this; @@ -21963,13 +23754,14 @@ var ts; namedDeclarations.push(node); } case 129 /* Constructor */: - case 170 /* VariableStatement */: + case 171 /* VariableStatement */: + case 189 /* VariableDeclarationList */: case 144 /* ObjectBindingPattern */: case 145 /* ArrayBindingPattern */: case 196 /* ModuleBlock */: ts.forEachChild(node, visit); break; - case 169 /* Block */: + case 170 /* Block */: if (ts.isFunctionBlock(node)) { ts.forEachChild(node, visit); } @@ -21978,7 +23770,7 @@ var ts; if (!(node.flags & 112 /* AccessibilityModifier */)) { break; } - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: if (ts.isBindingPattern(node.name)) { ts.forEachChild(node.name, visit); @@ -21995,145 +23787,8 @@ var ts; } return this.namedDeclarations; }; - SourceFileObject.prototype.update = function (scriptSnapshot, version, isOpen, textChangeRange) { - if (textChangeRange && ts.Debug.shouldAssert(1 /* Normal */)) { - var oldText = this.scriptSnapshot; - var newText = scriptSnapshot; - ts.Debug.assert((oldText.getLength() - textChangeRange.span().length() + textChangeRange.newLength()) === newText.getLength()); - if (ts.Debug.shouldAssert(3 /* VeryAggressive */)) { - var oldTextPrefix = oldText.getText(0, textChangeRange.span().start()); - var newTextPrefix = newText.getText(0, textChangeRange.span().start()); - ts.Debug.assert(oldTextPrefix === newTextPrefix); - var oldTextSuffix = oldText.getText(textChangeRange.span().end(), oldText.getLength()); - var newTextSuffix = newText.getText(textChangeRange.newSpan().end(), newText.getLength()); - ts.Debug.assert(oldTextSuffix === newTextSuffix); - } - } - return createLanguageServiceSourceFile(this.filename, scriptSnapshot, this.languageVersion, version, isOpen, true); - }; - SourceFileObject.createSourceFileObject = function (filename, scriptSnapshot, languageVersion, version, isOpen, setParentNodes) { - var newSourceFile = ts.createSourceFile(filename, scriptSnapshot.getText(0, scriptSnapshot.getLength()), languageVersion, setParentNodes); - newSourceFile.version = version; - newSourceFile.isOpen = isOpen; - newSourceFile.scriptSnapshot = scriptSnapshot; - return newSourceFile; - }; return SourceFileObject; })(NodeObject); - var TextSpan = (function () { - function TextSpan(start, length) { - ts.Debug.assert(start >= 0, "start"); - ts.Debug.assert(length >= 0, "length"); - this._start = start; - this._length = length; - } - TextSpan.prototype.toJSON = function (key) { - return { start: this._start, length: this._length }; - }; - TextSpan.prototype.start = function () { - return this._start; - }; - TextSpan.prototype.length = function () { - return this._length; - }; - TextSpan.prototype.end = function () { - return this._start + this._length; - }; - TextSpan.prototype.isEmpty = function () { - return this._length === 0; - }; - TextSpan.prototype.containsPosition = function (position) { - return position >= this._start && position < this.end(); - }; - TextSpan.prototype.containsTextSpan = function (span) { - return span._start >= this._start && span.end() <= this.end(); - }; - TextSpan.prototype.overlapsWith = function (span) { - var overlapStart = Math.max(this._start, span._start); - var overlapEnd = Math.min(this.end(), span.end()); - return overlapStart < overlapEnd; - }; - TextSpan.prototype.overlap = function (span) { - var overlapStart = Math.max(this._start, span._start); - var overlapEnd = Math.min(this.end(), span.end()); - if (overlapStart < overlapEnd) { - return TextSpan.fromBounds(overlapStart, overlapEnd); - } - return undefined; - }; - TextSpan.prototype.intersectsWithTextSpan = function (span) { - return span._start <= this.end() && span.end() >= this._start; - }; - TextSpan.prototype.intersectsWith = function (start, length) { - var end = start + length; - return start <= this.end() && end >= this._start; - }; - TextSpan.prototype.intersectsWithPosition = function (position) { - return position <= this.end() && position >= this._start; - }; - TextSpan.prototype.intersection = function (span) { - var intersectStart = Math.max(this._start, span._start); - var intersectEnd = Math.min(this.end(), span.end()); - if (intersectStart <= intersectEnd) { - return TextSpan.fromBounds(intersectStart, intersectEnd); - } - return undefined; - }; - TextSpan.fromBounds = function (start, end) { - ts.Debug.assert(start >= 0); - ts.Debug.assert(end - start >= 0); - return new TextSpan(start, end - start); - }; - return TextSpan; - })(); - ts.TextSpan = TextSpan; - var TextChangeRange = (function () { - function TextChangeRange(span, newLength) { - ts.Debug.assert(newLength >= 0, "newLength"); - this._span = span; - this._newLength = newLength; - } - TextChangeRange.prototype.span = function () { - return this._span; - }; - TextChangeRange.prototype.newLength = function () { - return this._newLength; - }; - TextChangeRange.prototype.newSpan = function () { - return new TextSpan(this.span().start(), this.newLength()); - }; - TextChangeRange.prototype.isUnchanged = function () { - return this.span().isEmpty() && this.newLength() === 0; - }; - TextChangeRange.collapseChangesAcrossMultipleVersions = function (changes) { - if (changes.length === 0) { - return TextChangeRange.unchanged; - } - if (changes.length === 1) { - return changes[0]; - } - var change0 = changes[0]; - var oldStartN = change0.span().start(); - var oldEndN = change0.span().end(); - var newEndN = oldStartN + change0.newLength(); - for (var i = 1; i < changes.length; i++) { - var nextChange = changes[i]; - var oldStart1 = oldStartN; - var oldEnd1 = oldEndN; - var newEnd1 = newEndN; - var oldStart2 = nextChange.span().start(); - var oldEnd2 = nextChange.span().end(); - var newEnd2 = oldStart2 + nextChange.newLength(); - oldStartN = Math.min(oldStart1, oldStart2); - oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); - newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); - } - return new TextChangeRange(TextSpan.fromBounds(oldStartN, oldEndN), newEndN - oldStartN); - }; - TextChangeRange.unchanged = new TextChangeRange(new TextSpan(0, 0), 0); - return TextChangeRange; - })(); - ts.TextChangeRange = TextChangeRange; var TextChange = (function () { function TextChange() { } @@ -22165,6 +23820,19 @@ var ts; 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"; + OutputFileType[OutputFileType["Declaration"] = 2] = "Declaration"; + })(ts.OutputFileType || (ts.OutputFileType = {})); + var OutputFileType = ts.OutputFileType; + (function (EndOfLineState) { + EndOfLineState[EndOfLineState["Start"] = 0] = "Start"; + EndOfLineState[EndOfLineState["InMultiLineCommentTrivia"] = 1] = "InMultiLineCommentTrivia"; + EndOfLineState[EndOfLineState["InSingleQuoteStringLiteral"] = 2] = "InSingleQuoteStringLiteral"; + EndOfLineState[EndOfLineState["InDoubleQuoteStringLiteral"] = 3] = "InDoubleQuoteStringLiteral"; + })(ts.EndOfLineState || (ts.EndOfLineState = {})); + var EndOfLineState = ts.EndOfLineState; (function (TokenClass) { TokenClass[TokenClass["Punctuation"] = 0] = "Punctuation"; TokenClass[TokenClass["Keyword"] = 1] = "Keyword"; @@ -22266,7 +23934,7 @@ var ts; if (declaration.kind === 156 /* FunctionExpression */) { return true; } - if (declaration.kind !== 189 /* VariableDeclaration */ && declaration.kind !== 190 /* FunctionDeclaration */) { + if (declaration.kind !== 188 /* VariableDeclaration */ && declaration.kind !== 190 /* FunctionDeclaration */) { return false; } for (var parent = declaration.parent; !ts.isFunctionBlock(parent); parent = parent.parent) { @@ -22363,7 +24031,7 @@ var ts; HostCache.prototype.getChangeRange = function (filename, lastKnownVersion, oldScriptSnapshot) { var currentVersion = this.getVersion(filename); if (lastKnownVersion === currentVersion) { - return TextChangeRange.unchanged; + return ts.unchangedTextChangeRange; } var scriptSnapshot = this.getScriptSnapshot(filename); return scriptSnapshot.getChangeRange(oldScriptSnapshot); @@ -22386,19 +24054,15 @@ var ts; if (this.currentFilename !== filename) { var scriptSnapshot = this.hostCache.getScriptSnapshot(filename); var start = new Date().getTime(); - sourceFile = createLanguageServiceSourceFile(filename, scriptSnapshot, getDefaultCompilerOptions().target, version, true, true); + sourceFile = createLanguageServiceSourceFile(filename, scriptSnapshot, 2 /* Latest */, version, true, true); this.host.log("SyntaxTreeCache.Initialize: createSourceFile: " + (new Date().getTime() - start)); - var start = new Date().getTime(); - this.host.log("SyntaxTreeCache.Initialize: fixupParentRefs : " + (new Date().getTime() - start)); } else if (this.currentFileVersion !== version) { var scriptSnapshot = this.hostCache.getScriptSnapshot(filename); - var editRange = this.hostCache.getChangeRange(filename, this.currentFileVersion, this.currentSourceFile.getScriptSnapshot()); + var editRange = this.hostCache.getChangeRange(filename, this.currentFileVersion, this.currentSourceFile.scriptSnapshot); var start = new Date().getTime(); - sourceFile = !editRange ? createLanguageServiceSourceFile(filename, scriptSnapshot, getDefaultCompilerOptions().target, version, true, true) : this.currentSourceFile.update(scriptSnapshot, version, true, editRange); + sourceFile = updateLanguageServiceSourceFile(this.currentSourceFile, scriptSnapshot, version, true, editRange); this.host.log("SyntaxTreeCache.Initialize: updateSourceFile: " + (new Date().getTime() - start)); - var start = new Date().getTime(); - this.host.log("SyntaxTreeCache.Initialize: fixupParentRefs : " + (new Date().getTime() - start)); } if (sourceFile) { this.currentFileVersion = version; @@ -22411,14 +24075,48 @@ var ts; return this.currentSourceFile; }; SyntaxTreeCache.prototype.getCurrentScriptSnapshot = function (filename) { - return this.getCurrentSourceFile(filename).getScriptSnapshot(); + return this.getCurrentSourceFile(filename).scriptSnapshot; }; return SyntaxTreeCache; })(); + function setSourceFileFields(sourceFile, scriptSnapshot, version, isOpen) { + sourceFile.version = version; + sourceFile.isOpen = isOpen; + sourceFile.scriptSnapshot = scriptSnapshot; + } function createLanguageServiceSourceFile(filename, scriptSnapshot, scriptTarget, version, isOpen, setNodeParents) { - return SourceFileObject.createSourceFileObject(filename, scriptSnapshot, scriptTarget, version, isOpen, setNodeParents); + var sourceFile = ts.createSourceFile(filename, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents); + setSourceFileFields(sourceFile, scriptSnapshot, version, isOpen); + return sourceFile; } ts.createLanguageServiceSourceFile = createLanguageServiceSourceFile; + ts.disableIncrementalParsing = false; + function updateLanguageServiceSourceFile(sourceFile, scriptSnapshot, version, isOpen, textChangeRange) { + if (textChangeRange && ts.Debug.shouldAssert(1 /* Normal */)) { + var oldText = sourceFile.scriptSnapshot; + var newText = scriptSnapshot; + ts.Debug.assert((oldText.getLength() - textChangeRange.span.length + textChangeRange.newLength) === newText.getLength()); + if (ts.Debug.shouldAssert(3 /* VeryAggressive */)) { + var oldTextPrefix = oldText.getText(0, textChangeRange.span.start); + var newTextPrefix = newText.getText(0, textChangeRange.span.start); + ts.Debug.assert(oldTextPrefix === newTextPrefix); + var oldTextSuffix = oldText.getText(ts.textSpanEnd(textChangeRange.span), oldText.getLength()); + var newTextSuffix = newText.getText(ts.textSpanEnd(ts.textChangeRangeNewSpan(textChangeRange)), newText.getLength()); + ts.Debug.assert(oldTextSuffix === newTextSuffix); + } + } + if (textChangeRange) { + if (version !== sourceFile.version || isOpen != sourceFile.isOpen) { + if (!ts.disableIncrementalParsing) { + var newSourceFile = sourceFile.update(scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange); + setSourceFileFields(newSourceFile, scriptSnapshot, version, isOpen); + return newSourceFile; + } + } + } + return createLanguageServiceSourceFile(sourceFile.filename, scriptSnapshot, sourceFile.languageVersion, version, isOpen, true); + } + ts.updateLanguageServiceSourceFile = updateLanguageServiceSourceFile; function createDocumentRegistry() { var buckets = {}; function getKeyFromCompilationSettings(settings) { @@ -22471,10 +24169,7 @@ var ts; ts.Debug.assert(bucket !== undefined); var entry = ts.lookUp(bucket, filename); ts.Debug.assert(entry !== undefined); - if (entry.sourceFile.isOpen === isOpen && entry.sourceFile.version === version) { - return entry.sourceFile; - } - entry.sourceFile = entry.sourceFile.update(scriptSnapshot, version, isOpen, textChangeRange); + entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, isOpen, textChangeRange); return entry.sourceFile; } function releaseDocument(filename, compilationSettings) { @@ -22555,7 +24250,7 @@ var ts; ts.preProcessFile = preProcessFile; function getTargetLabel(referenceNode, labelName) { while (referenceNode) { - if (referenceNode.kind === 183 /* LabeledStatement */ && referenceNode.label.text === labelName) { + if (referenceNode.kind === 184 /* LabeledStatement */ && referenceNode.label.text === labelName) { return referenceNode.label; } referenceNode = referenceNode.parent; @@ -22563,13 +24258,13 @@ var ts; return undefined; } function isJumpStatementTarget(node) { - return node.kind === 64 /* Identifier */ && (node.parent.kind === 179 /* BreakStatement */ || node.parent.kind === 178 /* ContinueStatement */) && node.parent.label === node; + return node.kind === 64 /* Identifier */ && (node.parent.kind === 180 /* BreakStatement */ || node.parent.kind === 179 /* ContinueStatement */) && node.parent.label === node; } function isLabelOfLabeledStatement(node) { - return node.kind === 64 /* Identifier */ && node.parent.kind === 183 /* LabeledStatement */ && node.parent.label === node; + return node.kind === 64 /* Identifier */ && node.parent.kind === 184 /* LabeledStatement */ && node.parent.label === node; } function isLabeledBy(node, labelName) { - for (var owner = node.parent; owner.kind === 183 /* LabeledStatement */; owner = owner.parent) { + for (var owner = node.parent; owner.kind === 184 /* LabeledStatement */; owner = owner.parent) { if (owner.label.text === labelName) { return true; } @@ -22652,6 +24347,21 @@ var ts; }); } } + var SemanticMeaning; + (function (SemanticMeaning) { + SemanticMeaning[SemanticMeaning["None"] = 0] = "None"; + SemanticMeaning[SemanticMeaning["Value"] = 1] = "Value"; + SemanticMeaning[SemanticMeaning["Type"] = 2] = "Type"; + SemanticMeaning[SemanticMeaning["Namespace"] = 4] = "Namespace"; + SemanticMeaning[SemanticMeaning["All"] = 7] = "All"; + })(SemanticMeaning || (SemanticMeaning = {})); + var BreakContinueSearchType; + (function (BreakContinueSearchType) { + BreakContinueSearchType[BreakContinueSearchType["None"] = 0] = "None"; + BreakContinueSearchType[BreakContinueSearchType["Unlabeled"] = 1] = "Unlabeled"; + BreakContinueSearchType[BreakContinueSearchType["Labeled"] = 2] = "Labeled"; + BreakContinueSearchType[BreakContinueSearchType["All"] = 3] = "All"; + })(BreakContinueSearchType || (BreakContinueSearchType = {})); var keywordCompletions = []; for (var i = 65 /* FirstKeyword */; i <= 120 /* LastKeyword */; i++) { keywordCompletions.push({ @@ -22666,13 +24376,11 @@ var ts; var hostCache; var program; var typeInfoResolver; - var fullTypeCheckChecker_doNotAccessDirectly; var useCaseSensitivefilenames = false; var sourceFilesByName = {}; var documentRegistry = documentRegistry; var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); var activeCompletionSession; - var writer = undefined; if (!ts.localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) { ts.localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages(); } @@ -22682,8 +24390,8 @@ var ts; function getSourceFile(filename) { return ts.lookUp(sourceFilesByName, getCanonicalFileName(filename)); } - function getFullTypeCheckChecker() { - return fullTypeCheckChecker_doNotAccessDirectly || (fullTypeCheckChecker_doNotAccessDirectly = program.getTypeChecker(true)); + function getDiagnosticsProducingTypeChecker() { + return program.getTypeChecker(true); } function getRuleProvider(options) { if (!ruleProvider) { @@ -22706,7 +24414,6 @@ var ts; return host.getDefaultLibFilename(options); }, writeFile: function (filename, data, writeByteOrderMark) { - writer(filename, data, writeByteOrderMark); }, getCurrentDirectory: function () { return host.getCurrentDirectory(); @@ -22765,7 +24472,7 @@ var ts; } var textChangeRange = null; if (sourceFile.isOpen && isOpen) { - textChangeRange = hostCache.getChangeRange(filename, sourceFile.version, sourceFile.getScriptSnapshot()); + textChangeRange = hostCache.getChangeRange(filename, sourceFile.version, sourceFile.scriptSnapshot); } sourceFile = documentRegistry.updateDocument(sourceFile, filename, compilationSettings, scriptSnapshot, version, isOpen, textChangeRange); } @@ -22776,12 +24483,10 @@ var ts; } program = ts.createProgram(hostfilenames, compilationSettings, createCompilerHost()); typeInfoResolver = program.getTypeChecker(false); - fullTypeCheckChecker_doNotAccessDirectly = undefined; } function cleanupSemanticCache() { if (program) { typeInfoResolver = program.getTypeChecker(false); - fullTypeCheckChecker_doNotAccessDirectly = undefined; } } function dispose() { @@ -22800,11 +24505,11 @@ var ts; synchronizeHostData(); filename = ts.normalizeSlashes(filename); var compilerOptions = program.getCompilerOptions(); - var checker = getFullTypeCheckChecker(); + var checker = getDiagnosticsProducingTypeChecker(); var targetSourceFile = getSourceFile(filename); var allDiagnostics = checker.getDiagnostics(targetSourceFile); if (compilerOptions.declaration) { - allDiagnostics = allDiagnostics.concat(checker.getDeclarationDiagnostics(targetSourceFile)); + allDiagnostics = allDiagnostics.concat(program.getDeclarationDiagnostics(targetSourceFile)); } return allDiagnostics; } @@ -23018,7 +24723,7 @@ var ts; var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case 23 /* CommaToken */: - return containingNodeKind === 189 /* VariableDeclaration */ || containingNodeKind === 170 /* VariableStatement */ || containingNodeKind === 194 /* EnumDeclaration */ || isFunction(containingNodeKind); + return containingNodeKind === 188 /* VariableDeclaration */ || containingNodeKind === 189 /* VariableDeclarationList */ || containingNodeKind === 171 /* VariableStatement */ || containingNodeKind === 194 /* EnumDeclaration */ || isFunction(containingNodeKind); case 16 /* OpenParenToken */: return containingNodeKind === 203 /* CatchClause */ || isFunction(containingNodeKind); case 14 /* OpenBraceToken */: @@ -23175,7 +24880,7 @@ var ts; else if (symbol.valueDeclaration && ts.isConst(symbol.valueDeclaration)) { return ScriptElementKind.constElement; } - else if (ts.forEach(symbol.declarations, function (declaration) { return ts.isLet(declaration); })) { + else if (ts.forEach(symbol.declarations, ts.isLet)) { return ScriptElementKind.letElement; } return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement; @@ -23235,7 +24940,8 @@ var ts; case 192 /* InterfaceDeclaration */: return ScriptElementKind.interfaceElement; case 193 /* TypeAliasDeclaration */: return ScriptElementKind.typeElement; case 194 /* EnumDeclaration */: return ScriptElementKind.enumElement; - case 189 /* VariableDeclaration */: return ts.isConst(node) ? ScriptElementKind.constElement : node.flags & 2048 /* Let */ ? ScriptElementKind.letElement : ScriptElementKind.variableElement; + case 188 /* VariableDeclaration */: + return ts.isConst(node) ? ScriptElementKind.constElement : ts.isLet(node) ? ScriptElementKind.letElement : ScriptElementKind.variableElement; case 190 /* FunctionDeclaration */: return ScriptElementKind.functionElement; case 130 /* GetAccessor */: return ScriptElementKind.memberGetAccessorElement; case 131 /* SetAccessor */: return ScriptElementKind.memberSetAccessorElement; @@ -23386,7 +25092,7 @@ var ts; } if (symbolFlags & 384 /* Enum */) { addNewLineIfDisplayPartsExist(); - if (ts.forEach(symbol.declarations, function (declaration) { return ts.isConstEnumDeclaration(declaration); })) { + if (ts.forEach(symbol.declarations, ts.isConstEnumDeclaration)) { displayParts.push(ts.keywordPart(69 /* ConstKeyword */)); displayParts.push(ts.spacePart()); } @@ -23561,7 +25267,7 @@ var ts; return { kind: ScriptElementKind.unknown, kindModifiers: ScriptElementKindModifier.none, - textSpan: new TextSpan(node.getStart(), node.getWidth()), + textSpan: ts.createTextSpan(node.getStart(), node.getWidth()), displayParts: ts.typeToDisplayParts(typeInfoResolver, type, getContainerNode(node)), documentation: type.symbol ? type.symbol.getDocumentationComment() : undefined }; @@ -23573,16 +25279,70 @@ var ts; return { kind: displayPartsDocumentationsAndKind.symbolKind, kindModifiers: getSymbolModifiers(symbol), - textSpan: new TextSpan(node.getStart(), node.getWidth()), + textSpan: ts.createTextSpan(node.getStart(), node.getWidth()), displayParts: displayPartsDocumentationsAndKind.displayParts, documentation: displayPartsDocumentationsAndKind.documentation }; } function getDefinitionAtPosition(filename, position) { + synchronizeHostData(); + filename = ts.normalizeSlashes(filename); + var sourceFile = getSourceFile(filename); + var node = ts.getTouchingPropertyName(sourceFile, position); + if (!node) { + return undefined; + } + if (isJumpStatementTarget(node)) { + var labelName = node.text; + var label = getTargetLabel(node.parent, node.text); + return label ? [getDefinitionInfo(label, ScriptElementKind.label, labelName, undefined)] : undefined; + } + var comment = ts.forEach(sourceFile.referencedFiles, function (r) { return (r.pos <= position && position < r.end) ? r : undefined; }); + if (comment) { + var referenceFile = ts.tryResolveScriptReference(program, sourceFile, comment); + if (referenceFile) { + return [{ + fileName: referenceFile.filename, + textSpan: ts.createTextSpanFromBounds(0, 0), + kind: ScriptElementKind.scriptElement, + name: comment.filename, + containerName: undefined, + containerKind: undefined + }]; + } + return undefined; + } + var symbol = typeInfoResolver.getSymbolAtLocation(node); + if (!symbol) { + return undefined; + } + var result = []; + if (node.parent.kind === 205 /* ShorthandPropertyAssignment */) { + var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); + var shorthandDeclarations = shorthandSymbol.getDeclarations(); + var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver, node); + var shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol); + var shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node); + ts.forEach(shorthandDeclarations, function (declaration) { + result.push(getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); + }); + return result; + } + var declarations = symbol.getDeclarations(); + var symbolName = typeInfoResolver.symbolToString(symbol); + var symbolKind = getSymbolKind(symbol, typeInfoResolver, node); + var containerSymbol = symbol.parent; + var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : ""; + 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)); + }); + } + return result; function getDefinitionInfo(node, symbolKind, symbolName, containerName) { return { fileName: node.getSourceFile().filename, - textSpan: TextSpan.fromBounds(node.getStart(), node.getEnd()), + textSpan: ts.createTextSpanFromBounds(node.getStart(), node.getEnd()), kind: symbolKind, name: symbolName, containerKind: undefined, @@ -23625,60 +25385,6 @@ var ts; } return false; } - synchronizeHostData(); - filename = ts.normalizeSlashes(filename); - var sourceFile = getSourceFile(filename); - var node = ts.getTouchingPropertyName(sourceFile, position); - if (!node) { - return undefined; - } - if (isJumpStatementTarget(node)) { - var labelName = node.text; - var label = getTargetLabel(node.parent, node.text); - return label ? [getDefinitionInfo(label, ScriptElementKind.label, labelName, undefined)] : undefined; - } - var comment = ts.forEach(sourceFile.referencedFiles, function (r) { return (r.pos <= position && position < r.end) ? r : undefined; }); - if (comment) { - var referenceFile = ts.tryResolveScriptReference(program, sourceFile, comment); - if (referenceFile) { - return [{ - fileName: referenceFile.filename, - textSpan: TextSpan.fromBounds(0, 0), - kind: ScriptElementKind.scriptElement, - name: comment.filename, - containerName: undefined, - containerKind: undefined - }]; - } - return undefined; - } - var symbol = typeInfoResolver.getSymbolAtLocation(node); - if (!symbol) { - return undefined; - } - var result = []; - if (node.parent.kind === 205 /* ShorthandPropertyAssignment */) { - var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); - var shorthandDeclarations = shorthandSymbol.getDeclarations(); - var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver); - var shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol); - var shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node); - ts.forEach(shorthandDeclarations, function (declaration) { - result.push(getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); - }); - return result; - } - var declarations = symbol.getDeclarations(); - var symbolName = typeInfoResolver.symbolToString(symbol); - var symbolKind = getSymbolKind(symbol, typeInfoResolver); - var containerSymbol = symbol.parent; - var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : ""; - 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)); - }); - } - return result; } function getOccurrencesAtPosition(filename, position) { synchronizeHostData(); @@ -23694,52 +25400,56 @@ var ts; switch (node.kind) { case 83 /* IfKeyword */: case 75 /* ElseKeyword */: - if (hasKind(node.parent, 173 /* IfStatement */)) { + if (hasKind(node.parent, 174 /* IfStatement */)) { return getIfElseOccurrences(node.parent); } break; case 89 /* ReturnKeyword */: - if (hasKind(node.parent, 180 /* ReturnStatement */)) { + if (hasKind(node.parent, 181 /* ReturnStatement */)) { return getReturnOccurrences(node.parent); } break; case 93 /* ThrowKeyword */: - if (hasKind(node.parent, 184 /* ThrowStatement */)) { + if (hasKind(node.parent, 185 /* ThrowStatement */)) { return getThrowOccurrences(node.parent); } break; - case 95 /* TryKeyword */: case 67 /* CatchKeyword */: - case 80 /* FinallyKeyword */: - if (hasKind(parent(parent(node)), 185 /* TryStatement */)) { + if (hasKind(parent(parent(node)), 186 /* TryStatement */)) { return getTryCatchFinallyOccurrences(node.parent.parent); } break; + case 95 /* TryKeyword */: + case 80 /* FinallyKeyword */: + if (hasKind(parent(node), 186 /* TryStatement */)) { + return getTryCatchFinallyOccurrences(node.parent); + } + break; case 91 /* SwitchKeyword */: - if (hasKind(node.parent, 182 /* SwitchStatement */)) { + if (hasKind(node.parent, 183 /* SwitchStatement */)) { return getSwitchCaseDefaultOccurrences(node.parent); } break; case 66 /* CaseKeyword */: case 72 /* DefaultKeyword */: - if (hasKind(parent(parent(node)), 182 /* SwitchStatement */)) { + if (hasKind(parent(parent(node)), 183 /* SwitchStatement */)) { return getSwitchCaseDefaultOccurrences(node.parent.parent); } break; case 65 /* BreakKeyword */: case 70 /* ContinueKeyword */: - if (hasKind(node.parent, 179 /* BreakStatement */) || hasKind(node.parent, 178 /* ContinueStatement */)) { + if (hasKind(node.parent, 180 /* BreakStatement */) || hasKind(node.parent, 179 /* ContinueStatement */)) { return getBreakOrContinueStatementOccurences(node.parent); } break; case 81 /* ForKeyword */: - if (hasKind(node.parent, 176 /* ForStatement */) || hasKind(node.parent, 177 /* ForInStatement */)) { + if (hasKind(node.parent, 177 /* ForStatement */) || hasKind(node.parent, 178 /* ForInStatement */)) { return getLoopBreakContinueOccurrences(node.parent); } break; case 99 /* WhileKeyword */: case 74 /* DoKeyword */: - if (hasKind(node.parent, 175 /* WhileStatement */) || hasKind(node.parent, 174 /* DoStatement */)) { + if (hasKind(node.parent, 176 /* WhileStatement */) || hasKind(node.parent, 175 /* DoStatement */)) { return getLoopBreakContinueOccurrences(node.parent); } break; @@ -23754,14 +25464,14 @@ var ts; return getGetAndSetOccurrences(node.parent); } default: - if (ts.isModifier(node.kind) && node.parent && (ts.isDeclaration(node.parent) || node.parent.kind === 170 /* VariableStatement */)) { + if (ts.isModifier(node.kind) && node.parent && (ts.isDeclaration(node.parent) || node.parent.kind === 171 /* VariableStatement */)) { return getModifierOccurrences(node.kind, node.parent); } } return undefined; function getIfElseOccurrences(ifStatement) { var keywords = []; - while (hasKind(ifStatement.parent, 173 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) { + while (hasKind(ifStatement.parent, 174 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) { ifStatement = ifStatement.parent; } while (ifStatement) { @@ -23772,7 +25482,7 @@ var ts; break; } } - if (!hasKind(ifStatement.elseStatement, 173 /* IfStatement */)) { + if (!hasKind(ifStatement.elseStatement, 174 /* IfStatement */)) { break; } ifStatement = ifStatement.elseStatement; @@ -23792,7 +25502,7 @@ var ts; if (shouldHighlightNextKeyword) { result.push({ fileName: filename, - textSpan: TextSpan.fromBounds(elseKeyword.getStart(), ifKeyword.end), + textSpan: ts.createTextSpanFromBounds(elseKeyword.getStart(), ifKeyword.end), isWriteAccess: false }); i++; @@ -23805,7 +25515,7 @@ var ts; } function getReturnOccurrences(returnStatement) { var func = ts.getContainingFunction(returnStatement); - if (!(func && hasKind(func.body, 169 /* Block */))) { + if (!(func && hasKind(func.body, 170 /* Block */))) { return undefined; } var keywords = []; @@ -23838,10 +25548,10 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 184 /* ThrowStatement */) { + if (node.kind === 185 /* ThrowStatement */) { statementAccumulator.push(node); } - else if (node.kind === 185 /* TryStatement */) { + else if (node.kind === 186 /* TryStatement */) { var tryStatement = node; if (tryStatement.catchClause) { aggregate(tryStatement.catchClause); @@ -23866,7 +25576,7 @@ var ts; if (ts.isFunctionBlock(parent) || parent.kind === 207 /* SourceFile */) { return parent; } - if (parent.kind === 185 /* TryStatement */) { + if (parent.kind === 186 /* TryStatement */) { var tryStatement = parent; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; @@ -23883,14 +25593,15 @@ var ts; pushKeywordIf(keywords, tryStatement.catchClause.getFirstToken(), 67 /* CatchKeyword */); } if (tryStatement.finallyBlock) { - pushKeywordIf(keywords, tryStatement.finallyBlock.getFirstToken(), 80 /* FinallyKeyword */); + var finallyKeyword = ts.findChildOfKind(tryStatement, 80 /* FinallyKeyword */, sourceFile); + pushKeywordIf(keywords, finallyKeyword, 80 /* FinallyKeyword */); } return ts.map(keywords, getReferenceEntryFromNode); } function getLoopBreakContinueOccurrences(loopNode) { var keywords = []; if (pushKeywordIf(keywords, loopNode.getFirstToken(), 81 /* ForKeyword */, 99 /* WhileKeyword */, 74 /* DoKeyword */)) { - if (loopNode.kind === 174 /* DoStatement */) { + if (loopNode.kind === 175 /* DoStatement */) { var loopTokens = loopNode.getChildren(); for (var i = loopTokens.length - 1; i >= 0; i--) { if (pushKeywordIf(keywords, loopTokens[i], 99 /* WhileKeyword */)) { @@ -23925,12 +25636,12 @@ var ts; var owner = getBreakOrContinueOwner(breakOrContinueStatement); if (owner) { switch (owner.kind) { - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 175 /* DoStatement */: + case 176 /* WhileStatement */: return getLoopBreakContinueOccurrences(owner); - case 182 /* SwitchStatement */: + case 183 /* SwitchStatement */: return getSwitchCaseDefaultOccurrences(owner); } } @@ -23941,7 +25652,7 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 179 /* BreakStatement */ || node.kind === 178 /* ContinueStatement */) { + if (node.kind === 180 /* BreakStatement */ || node.kind === 179 /* ContinueStatement */) { statementAccumulator.push(node); } else if (!ts.isAnyFunction(node)) { @@ -23957,14 +25668,14 @@ var ts; function getBreakOrContinueOwner(statement) { for (var node = statement.parent; node; node = node.parent) { switch (node.kind) { - case 182 /* SwitchStatement */: - if (statement.kind === 178 /* ContinueStatement */) { + case 183 /* SwitchStatement */: + if (statement.kind === 179 /* ContinueStatement */) { continue; } - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 175 /* WhileStatement */: - case 174 /* DoStatement */: + case 177 /* ForStatement */: + case 178 /* ForInStatement */: + case 176 /* WhileStatement */: + case 175 /* DoStatement */: if (!statement.label || isLabeledBy(node, statement.label.text)) { return node; } @@ -24272,7 +25983,7 @@ var ts; if ((findInStrings && isInString(position)) || (findInComments && isInComment(position))) { result.push({ fileName: sourceFile.filename, - textSpan: new TextSpan(position, searchText.length), + textSpan: ts.createTextSpan(position, searchText.length), isWriteAccess: false }); } @@ -24549,7 +26260,7 @@ var ts; } return { fileName: node.getSourceFile().filename, - textSpan: TextSpan.fromBounds(start, end), + textSpan: ts.createTextSpanFromBounds(start, end), isWriteAccess: isWriteAccess(node) }; } @@ -24590,7 +26301,7 @@ var ts; kindModifiers: ts.getNodeModifiers(declaration), matchKind: MatchKind[matchKind], fileName: filename, - textSpan: TextSpan.fromBounds(declaration.getStart(), declaration.getEnd()), + textSpan: ts.createTextSpanFromBounds(declaration.getStart(), declaration.getEnd()), containerName: container && container.name ? container.name.text : "", containerKind: container && container.name ? getNodeKind(container) : "" }); @@ -24637,16 +26348,16 @@ var ts; filename = ts.normalizeSlashes(filename); var sourceFile = getSourceFile(filename); var outputFiles = []; - function getEmitOutputWriter(filename, data, writeByteOrderMark) { + function writeFile(filename, data, writeByteOrderMark) { outputFiles.push({ name: filename, writeByteOrderMark: writeByteOrderMark, text: data }); } - writer = getEmitOutputWriter; - var emitOutput = getFullTypeCheckChecker().emitFiles(sourceFile); - writer = undefined; + var emitHost = ts.createEmitHostFromProgram(program); + emitHost.writeFile = writeFile; + var emitOutput = ts.emitFiles(getDiagnosticsProducingTypeChecker().getEmitResolver(), emitHost, sourceFile); return { outputFiles: outputFiles, emitOutputStatus: emitOutput.emitResultStatus @@ -24655,7 +26366,7 @@ var ts; function getMeaningFromDeclaration(node) { switch (node.kind) { case 124 /* Parameter */: - case 189 /* VariableDeclaration */: + case 188 /* VariableDeclaration */: case 146 /* BindingElement */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: @@ -24794,7 +26505,7 @@ var ts; break; } } - return TextSpan.fromBounds(nodeForStartPos.getStart(), node.getEnd()); + return ts.createTextSpanFromBounds(nodeForStartPos.getStart(), node.getEnd()); } function getBreakpointStatementAtPosition(filename, position) { filename = ts.normalizeSlashes(filename); @@ -24843,14 +26554,14 @@ var ts; } } function processNode(node) { - if (node && span.intersectsWith(node.getStart(), node.getWidth())) { + if (node && ts.textSpanIntersectsWith(span, node.getStart(), node.getWidth())) { if (node.kind === 64 /* Identifier */ && node.getWidth() > 0) { var symbol = typeInfoResolver.getSymbolAtLocation(node); if (symbol) { var type = classifySymbol(symbol, getMeaningFromLocation(node)); if (type) { result.push({ - textSpan: new TextSpan(node.getStart(), node.getWidth()), + textSpan: ts.createTextSpan(node.getStart(), node.getWidth()), classificationType: type }); } @@ -24863,48 +26574,109 @@ var ts; function getSyntacticClassifications(fileName, span) { fileName = ts.normalizeSlashes(fileName); var sourceFile = getCurrentSourceFile(fileName); + var triviaScanner = ts.createScanner(2 /* Latest */, false, sourceFile.text); + var mergeConflictScanner = ts.createScanner(2 /* Latest */, false, sourceFile.text); var result = []; processElement(sourceFile); return result; - function classifyComment(comment) { - var width = comment.end - comment.pos; - if (span.intersectsWith(comment.pos, width)) { + function classifyLeadingTrivia(token) { + var tokenStart = ts.skipTrivia(sourceFile.text, token.pos, false); + if (tokenStart === token.pos) { + return; + } + triviaScanner.setTextPos(token.pos); + while (true) { + var start = triviaScanner.getTextPos(); + var kind = triviaScanner.scan(); + var end = triviaScanner.getTextPos(); + var width = end - start; + if (ts.textSpanIntersectsWith(span, start, width)) { + if (!ts.isTrivia(kind)) { + return; + } + if (ts.isComment(kind)) { + result.push({ + textSpan: ts.createTextSpan(start, width), + classificationType: ClassificationTypeNames.comment + }); + continue; + } + if (kind === 6 /* ConflictMarkerTrivia */) { + var text = sourceFile.text; + var ch = text.charCodeAt(start); + if (ch === 60 /* lessThan */ || ch === 62 /* greaterThan */) { + result.push({ + textSpan: ts.createTextSpan(start, width), + classificationType: ClassificationTypeNames.comment + }); + continue; + } + ts.Debug.assert(ch === 61 /* equals */); + classifyDisabledMergeCode(text, start, end); + } + } + } + } + function classifyDisabledMergeCode(text, start, end) { + for (var i = start; i < end; i++) { + if (ts.isLineBreak(text.charCodeAt(i))) { + break; + } + } + result.push({ + textSpan: ts.createTextSpanFromBounds(start, i), + classificationType: ClassificationTypeNames.comment + }); + mergeConflictScanner.setTextPos(i); + while (mergeConflictScanner.getTextPos() < end) { + classifyDisabledCodeToken(); + } + } + function classifyDisabledCodeToken() { + var start = mergeConflictScanner.getTextPos(); + var tokenKind = mergeConflictScanner.scan(); + var end = mergeConflictScanner.getTextPos(); + var type = classifyTokenType(tokenKind); + if (type) { result.push({ - textSpan: new TextSpan(comment.pos, width), - classificationType: ClassificationTypeNames.comment + textSpan: ts.createTextSpanFromBounds(start, end), + classificationType: type }); } } function classifyToken(token) { - ts.forEach(ts.getLeadingCommentRanges(sourceFile.text, token.getFullStart()), classifyComment); + classifyLeadingTrivia(token); if (token.getWidth() > 0) { - var type = classifyTokenType(token); + var type = classifyTokenType(token.kind, token); if (type) { result.push({ - textSpan: new TextSpan(token.getStart(), token.getWidth()), + textSpan: ts.createTextSpan(token.getStart(), token.getWidth()), classificationType: type }); } } - ts.forEach(ts.getTrailingCommentRanges(sourceFile.text, token.getEnd()), classifyComment); } - function classifyTokenType(token) { - var tokenKind = token.kind; + function classifyTokenType(tokenKind, token) { if (ts.isKeyword(tokenKind)) { return ClassificationTypeNames.keyword; } if (tokenKind === 24 /* LessThanToken */ || tokenKind === 25 /* GreaterThanToken */) { - if (ts.getTypeArgumentOrTypeParameterList(token.parent)) { + if (token && ts.getTypeArgumentOrTypeParameterList(token.parent)) { return ClassificationTypeNames.punctuation; } } - if (ts.isPunctuation(token.kind)) { - if (token.parent.kind === 163 /* BinaryExpression */ || token.parent.kind === 189 /* VariableDeclaration */ || token.parent.kind === 161 /* PrefixUnaryExpression */ || token.parent.kind === 162 /* PostfixUnaryExpression */ || token.parent.kind === 164 /* ConditionalExpression */) { - return ClassificationTypeNames.operator; - } - else { - return ClassificationTypeNames.punctuation; + if (ts.isPunctuation(tokenKind)) { + if (token) { + if (tokenKind === 52 /* EqualsToken */) { + if (token.parent.kind === 188 /* VariableDeclaration */ || token.parent.kind === 126 /* PropertyDeclaration */ || token.parent.kind === 124 /* Parameter */) { + return ClassificationTypeNames.operator; + } + } + if (token.parent.kind === 163 /* BinaryExpression */ || token.parent.kind === 161 /* PrefixUnaryExpression */ || token.parent.kind === 162 /* PostfixUnaryExpression */ || token.parent.kind === 164 /* ConditionalExpression */) { + return ClassificationTypeNames.operator; + } } + return ClassificationTypeNames.punctuation; } else if (tokenKind === 7 /* NumericLiteral */) { return ClassificationTypeNames.numericLiteral; @@ -24919,39 +26691,40 @@ var ts; return ClassificationTypeNames.stringLiteral; } else if (tokenKind === 64 /* Identifier */) { - switch (token.parent.kind) { - case 191 /* ClassDeclaration */: - if (token.parent.name === token) { - return ClassificationTypeNames.className; - } - return; - case 123 /* TypeParameter */: - if (token.parent.name === token) { - return ClassificationTypeNames.typeParameterName; - } - return; - case 192 /* InterfaceDeclaration */: - if (token.parent.name === token) { - return ClassificationTypeNames.interfaceName; - } - return; - case 194 /* EnumDeclaration */: - if (token.parent.name === token) { - return ClassificationTypeNames.enumName; - } - return; - case 195 /* ModuleDeclaration */: - if (token.parent.name === token) { - return ClassificationTypeNames.moduleName; - } - return; - default: - return ClassificationTypeNames.text; + if (token) { + switch (token.parent.kind) { + case 191 /* ClassDeclaration */: + if (token.parent.name === token) { + return ClassificationTypeNames.className; + } + return; + case 123 /* TypeParameter */: + if (token.parent.name === token) { + return ClassificationTypeNames.typeParameterName; + } + return; + case 192 /* InterfaceDeclaration */: + if (token.parent.name === token) { + return ClassificationTypeNames.interfaceName; + } + return; + case 194 /* EnumDeclaration */: + if (token.parent.name === token) { + return ClassificationTypeNames.enumName; + } + return; + case 195 /* ModuleDeclaration */: + if (token.parent.name === token) { + return ClassificationTypeNames.moduleName; + } + return; + } } + return ClassificationTypeNames.text; } } function processElement(element) { - if (span.intersectsWith(element.getFullStart(), element.getFullWidth())) { + if (ts.textSpanIntersectsWith(span, element.getFullStart(), element.getFullWidth())) { var children = element.getChildren(); for (var i = 0, n = children.length; i < n; i++) { var child = children[i]; @@ -24983,9 +26756,9 @@ var ts; 33; var current = childNodes[i]; if (current.kind === matchKind) { - var range1 = new TextSpan(token.getStart(sourceFile), token.getWidth(sourceFile)); - var range2 = new TextSpan(current.getStart(sourceFile), current.getWidth(sourceFile)); - if (range1.start() < range2.start()) { + var range1 = ts.createTextSpan(token.getStart(sourceFile), token.getWidth(sourceFile)); + var range2 = ts.createTextSpan(current.getStart(sourceFile), current.getWidth(sourceFile)); + if (range1.start < range2.start) { result.push(range1, range2); } else { @@ -25112,9 +26885,9 @@ var ts; if (node && node.kind === 64 /* Identifier */) { var symbol = typeInfoResolver.getSymbolAtLocation(node); if (symbol && symbol.getDeclarations() && symbol.getDeclarations().length > 0) { - var kind = getSymbolKind(symbol, typeInfoResolver); + var kind = getSymbolKind(symbol, typeInfoResolver, node); if (kind) { - return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, getSymbolModifiers(symbol), new TextSpan(node.getStart(), node.getWidth())); + return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, getSymbolModifiers(symbol), ts.createTextSpan(node.getStart(), node.getWidth())); } } } @@ -25428,7 +27201,7 @@ var ts; } return spanInNode(tokenAtLocation); function textSpan(startNode, endNode) { - return ts.TextSpan.fromBounds(startNode.getStart(), (endNode || startNode).getEnd()); + return ts.createTextSpanFromBounds(startNode.getStart(), (endNode || startNode).getEnd()); } function spanInNodeIfStartsOnSameLine(node, otherwiseOnNode) { if (node && lineOfPosition === sourceFile.getLineAndCharacterFromPosition(node.getStart()).line) { @@ -25445,10 +27218,10 @@ var ts; function spanInNode(node) { if (node) { if (ts.isExpression(node)) { - if (node.parent.kind === 174 /* DoStatement */) { + if (node.parent.kind === 175 /* DoStatement */) { return spanInPreviousNode(node); } - if (node.parent.kind === 176 /* ForStatement */) { + if (node.parent.kind === 177 /* ForStatement */) { return textSpan(node); } if (node.parent.kind === 163 /* BinaryExpression */ && node.parent.operator === 23 /* CommaToken */) { @@ -25459,9 +27232,9 @@ var ts; } } switch (node.kind) { - case 170 /* VariableStatement */: - return spanInVariableDeclaration(node.declarations[0]); - case 189 /* VariableDeclaration */: + case 171 /* VariableStatement */: + return spanInVariableDeclaration(node.declarationList.declarations[0]); + case 188 /* VariableDeclaration */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: return spanInVariableDeclaration(node); @@ -25476,45 +27249,43 @@ var ts; case 156 /* FunctionExpression */: case 157 /* ArrowFunction */: return spanInFunctionDeclaration(node); - case 169 /* Block */: + case 170 /* Block */: if (ts.isFunctionBlock(node)) { return spanInFunctionBlock(node); } - case 186 /* TryBlock */: - case 187 /* FinallyBlock */: case 196 /* ModuleBlock */: return spanInBlock(node); case 203 /* CatchClause */: return spanInBlock(node.block); - case 172 /* ExpressionStatement */: + case 173 /* ExpressionStatement */: return textSpan(node.expression); - case 180 /* ReturnStatement */: + case 181 /* ReturnStatement */: return textSpan(node.getChildAt(0), node.expression); - case 175 /* WhileStatement */: + case 176 /* WhileStatement */: return textSpan(node, ts.findNextToken(node.expression, node)); - case 174 /* DoStatement */: + case 175 /* DoStatement */: return spanInNode(node.statement); - case 188 /* DebuggerStatement */: + case 187 /* DebuggerStatement */: return textSpan(node.getChildAt(0)); - case 173 /* IfStatement */: + case 174 /* IfStatement */: return textSpan(node, ts.findNextToken(node.expression, node)); - case 183 /* LabeledStatement */: + case 184 /* LabeledStatement */: return spanInNode(node.statement); - case 179 /* BreakStatement */: - case 178 /* ContinueStatement */: + case 180 /* BreakStatement */: + case 179 /* ContinueStatement */: return textSpan(node.getChildAt(0), node.label); - case 176 /* ForStatement */: + case 177 /* ForStatement */: return spanInForStatement(node); - case 177 /* ForInStatement */: + case 178 /* ForInStatement */: return textSpan(node, ts.findNextToken(node.expression, node)); - case 182 /* SwitchStatement */: + case 183 /* SwitchStatement */: return textSpan(node, ts.findNextToken(node.expression, node)); case 200 /* CaseClause */: case 201 /* DefaultClause */: return spanInNode(node.statements[0]); - case 185 /* TryStatement */: + case 186 /* TryStatement */: return spanInBlock(node.tryBlock); - case 184 /* ThrowStatement */: + case 185 /* ThrowStatement */: return textSpan(node, node.expression); case 198 /* ExportAssignment */: return textSpan(node, node.exportName); @@ -25530,7 +27301,7 @@ var ts; case 151 /* CallExpression */: case 152 /* NewExpression */: return textSpan(node); - case 181 /* WithStatement */: + case 182 /* WithStatement */: return spanInNode(node.statement); case 192 /* InterfaceDeclaration */: case 193 /* TypeAliasDeclaration */: @@ -25573,12 +27344,12 @@ var ts; } } function spanInVariableDeclaration(variableDeclaration) { - if (variableDeclaration.parent.kind === 177 /* ForInStatement */) { - return spanInNode(variableDeclaration.parent); + if (variableDeclaration.parent.parent.kind === 178 /* ForInStatement */) { + return spanInNode(variableDeclaration.parent.parent); } - var isParentVariableStatement = variableDeclaration.parent.kind === 170 /* VariableStatement */; - var isDeclarationOfForStatement = variableDeclaration.parent.kind === 176 /* ForStatement */ && ts.contains(variableDeclaration.parent.declarations, variableDeclaration); - var declarations = isParentVariableStatement ? variableDeclaration.parent.declarations : isDeclarationOfForStatement ? variableDeclaration.parent.declarations : undefined; + var isParentVariableStatement = variableDeclaration.parent.parent.kind === 171 /* VariableStatement */; + var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === 177 /* ForStatement */ && ts.contains(variableDeclaration.parent.parent.initializer.declarations, variableDeclaration); + var declarations = isParentVariableStatement ? variableDeclaration.parent.parent.declarationList.declarations : isDeclarationOfForStatement ? variableDeclaration.parent.parent.initializer.declarations : undefined; if (variableDeclaration.initializer || (variableDeclaration.flags & 1 /* Export */)) { if (declarations && declarations[0] === variableDeclaration) { if (isParentVariableStatement) { @@ -25641,21 +27412,26 @@ var ts; if (ts.getModuleInstanceState(block.parent) !== 1 /* Instantiated */) { return undefined; } - case 175 /* WhileStatement */: - case 173 /* IfStatement */: - case 177 /* ForInStatement */: + case 176 /* WhileStatement */: + case 174 /* IfStatement */: + case 178 /* ForInStatement */: return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); - case 176 /* ForStatement */: + case 177 /* ForStatement */: return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(block.pos, sourceFile, block.parent), block.statements[0]); } return spanInNode(block.statements[0]); } function spanInForStatement(forStatement) { - if (forStatement.declarations) { - return spanInNode(forStatement.declarations[0]); - } if (forStatement.initializer) { - return spanInNode(forStatement.initializer); + if (forStatement.initializer.kind === 189 /* VariableDeclarationList */) { + var variableDeclarationList = forStatement.initializer; + if (variableDeclarationList.declarations.length > 0) { + return spanInNode(variableDeclarationList.declarations[0]); + } + } + else { + return spanInNode(forStatement.initializer); + } } if (forStatement.condition) { return textSpan(forStatement.condition); @@ -25672,7 +27448,7 @@ var ts; case 191 /* ClassDeclaration */: var classDeclaration = node.parent; return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile)); - case 182 /* SwitchStatement */: + case 183 /* SwitchStatement */: return spanInNodeIfStartsOnSameLine(node.parent, node.parent.clauses[0]); } return spanInNode(node.parent); @@ -25686,16 +27462,14 @@ var ts; case 194 /* EnumDeclaration */: case 191 /* ClassDeclaration */: return textSpan(node); - case 169 /* Block */: + case 170 /* Block */: if (ts.isFunctionBlock(node.parent)) { return textSpan(node); } - case 186 /* TryBlock */: case 203 /* CatchClause */: - case 187 /* FinallyBlock */: return spanInNode(node.parent.statements[node.parent.statements.length - 1]); ; - case 182 /* SwitchStatement */: + case 183 /* SwitchStatement */: var switchStatement = node.parent; var lastClause = switchStatement.clauses[switchStatement.clauses.length - 1]; if (lastClause) { @@ -25707,7 +27481,7 @@ var ts; } } function spanInOpenParenToken(node) { - if (node.parent.kind === 174 /* DoStatement */) { + if (node.parent.kind === 175 /* DoStatement */) { return spanInPreviousNode(node); } return spanInNode(node.parent); @@ -25722,9 +27496,9 @@ var ts; case 130 /* GetAccessor */: case 131 /* SetAccessor */: case 129 /* Constructor */: - case 175 /* WhileStatement */: - case 174 /* DoStatement */: - case 176 /* ForStatement */: + case 176 /* WhileStatement */: + case 175 /* DoStatement */: + case 177 /* ForStatement */: return spanInPreviousNode(node); default: return spanInNode(node.parent); @@ -25744,7 +27518,7 @@ var ts; return spanInNode(node.parent); } function spanInWhileKeyword(node) { - if (node.parent.kind === 174 /* DoStatement */) { + if (node.parent.kind === 175 /* DoStatement */) { return textSpan(node, ts.findNextToken(node.parent.expression, node.parent)); } return spanInNode(node.parent); @@ -25784,7 +27558,7 @@ var ts; return null; } var decoded = JSON.parse(encoded); - return new ts.TextChangeRange(new ts.TextSpan(decoded.span.start, decoded.span.length), decoded.newLength); + return ts.createTextChangeRange(ts.createTextSpan(decoded.span.start, decoded.span.length), decoded.newLength); }; return ScriptSnapshotShimAdapter; })(); @@ -25932,14 +27706,14 @@ var ts; LanguageServiceShimObject.prototype.getSyntacticClassifications = function (fileName, start, length) { var _this = this; return this.forwardJSONCall("getSyntacticClassifications('" + fileName + "', " + start + ", " + length + ")", function () { - var classifications = _this.languageService.getSyntacticClassifications(fileName, new ts.TextSpan(start, length)); + var classifications = _this.languageService.getSyntacticClassifications(fileName, ts.createTextSpan(start, length)); return classifications; }); }; LanguageServiceShimObject.prototype.getSemanticClassifications = function (fileName, start, length) { var _this = this; return this.forwardJSONCall("getSemanticClassifications('" + fileName + "', " + start + ", " + length + ")", function () { - var classifications = _this.languageService.getSemanticClassifications(fileName, new ts.TextSpan(start, length)); + var classifications = _this.languageService.getSemanticClassifications(fileName, ts.createTextSpan(start, length)); return classifications; }); }; diff --git a/bin/typescriptServices_internal.d.ts b/bin/typescriptServices_internal.d.ts index 260c1b1c679..5731d6959de 100644 --- a/bin/typescriptServices_internal.d.ts +++ b/bin/typescriptServices_internal.d.ts @@ -26,7 +26,7 @@ declare module ts { } interface StringSet extends Map { } - function forEach(array: T[], callback: (element: T) => U): U; + function forEach(array: T[], callback: (element: T, index: number) => U): U; function contains(array: T[], value: T): boolean; function indexOf(array: T[], value: T): number; function countWhere(array: T[], predicate: (x: T) => boolean): number; @@ -48,6 +48,7 @@ declare module ts { function forEachKey(map: Map, callback: (key: string) => U): U; function lookUp(map: Map, key: string): T; function mapToArray(map: Map): T[]; + function copyMap(source: Map, target: Map): void; /** * Creates a map from the elements of an array. * @@ -142,6 +143,14 @@ declare module ts { interface StringSymbolWriter extends SymbolWriter { string(): string; } + interface EmitHost extends ScriptReferenceHost { + getSourceFiles(): SourceFile[]; + isEmitBlocked(sourceFile?: SourceFile): boolean; + getCommonSourceDirectory(): string; + getCanonicalFileName(fileName: string): string; + getNewLine(): string; + writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; + } function getSingleLineStringWriter(): StringSymbolWriter; function releaseStringWriter(writer: StringSymbolWriter): void; function getFullWidth(node: Node): number; @@ -149,7 +158,8 @@ declare module ts { function getSourceFileOfNode(node: Node): SourceFile; function nodePosToString(node: Node): string; function getStartPosOfNode(node: Node): number; - function isMissingNode(node: Node): boolean; + function nodeIsMissing(node: Node): boolean; + function nodeIsPresent(node: Node): boolean; function getTokenPosOfNode(node: Node, sourceFile?: SourceFile): number; function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node): string; function getTextOfNodeFromSourceText(sourceText: string, node: Node): string; @@ -163,6 +173,7 @@ declare module ts { function isExternalModule(file: SourceFile): boolean; function isDeclarationFile(file: SourceFile): boolean; function isConstEnumDeclaration(node: Node): boolean; + function getCombinedNodeFlags(node: Node): NodeFlags; function isConst(node: Node): boolean; function isLet(node: Node): boolean; function isPrologueDirective(node: Node): boolean; @@ -178,6 +189,7 @@ declare module ts { function getSuperContainer(node: Node): Node; function getInvokedExpression(node: CallLikeExpression): Expression; function isExpression(node: Node): boolean; + function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean): boolean; function isExternalModuleImportDeclaration(node: Node): boolean; function getExternalModuleImportDeclarationExpression(node: Node): Expression; function isInternalModuleImportDeclaration(node: Node): boolean; @@ -196,12 +208,42 @@ declare module ts { function getClassImplementedTypeNodes(node: ClassDeclaration): NodeArray; function getInterfaceBaseTypeNodes(node: InterfaceDeclaration): NodeArray; function getHeritageClause(clauses: NodeArray, kind: SyntaxKind): HeritageClause; - function tryResolveScriptReference(program: Program, sourceFile: SourceFile, reference: FileReference): SourceFile; + function tryResolveScriptReference(host: ScriptReferenceHost, sourceFile: SourceFile, reference: FileReference): SourceFile; function getAncestor(node: Node, kind: SyntaxKind): Node; function getFileReferenceFromReferencePath(comment: string, commentRange: CommentRange): ReferencePathMatchResult; function isKeyword(token: SyntaxKind): boolean; function isTrivia(token: SyntaxKind): boolean; function isModifier(token: SyntaxKind): boolean; + function createEmitHostFromProgram(program: Program): EmitHost; + function textSpanEnd(span: TextSpan): number; + function textSpanIsEmpty(span: TextSpan): boolean; + function textSpanContainsPosition(span: TextSpan, position: number): boolean; + function textSpanContainsTextSpan(span: TextSpan, other: TextSpan): boolean; + function textSpanOverlapsWith(span: TextSpan, other: TextSpan): boolean; + function textSpanOverlap(span1: TextSpan, span2: TextSpan): TextSpan; + function textSpanIntersectsWithTextSpan(span: TextSpan, other: TextSpan): boolean; + function textSpanIntersectsWith(span: TextSpan, start: number, length: number): boolean; + function textSpanIntersectsWithPosition(span: TextSpan, position: number): boolean; + function textSpanIntersection(span1: TextSpan, span2: TextSpan): TextSpan; + function createTextSpan(start: number, length: number): TextSpan; + function createTextSpanFromBounds(start: number, end: number): TextSpan; + function textChangeRangeNewSpan(range: TextChangeRange): TextSpan; + function textChangeRangeIsUnchanged(range: TextChangeRange): boolean; + function createTextChangeRange(span: TextSpan, newLength: number): TextChangeRange; + var unchangedTextChangeRange: TextChangeRange; + /** + * Called to merge all the changes that occurred across several versions of a script snapshot + * into a single change. i.e. if a user keeps making successive edits to a script we will + * have a text change from V1 to V2, V2 to V3, ..., Vn. + * + * This function will then merge those changes into a single change range valid between V1 and + * Vn. + */ + function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; +} +declare module ts { + var optionDeclarations: CommandLineOption[]; + function parseCommandLine(commandLine: string[]): ParsedCommandLine; } declare module ts { interface ListItemInfo { diff --git a/bin/typescript_internal.d.ts b/bin/typescript_internal.d.ts index 37ab4b4da64..e9bff0d37f9 100644 --- a/bin/typescript_internal.d.ts +++ b/bin/typescript_internal.d.ts @@ -26,7 +26,7 @@ declare module "typescript" { } interface StringSet extends Map { } - function forEach(array: T[], callback: (element: T) => U): U; + function forEach(array: T[], callback: (element: T, index: number) => U): U; function contains(array: T[], value: T): boolean; function indexOf(array: T[], value: T): number; function countWhere(array: T[], predicate: (x: T) => boolean): number; @@ -48,6 +48,7 @@ declare module "typescript" { function forEachKey(map: Map, callback: (key: string) => U): U; function lookUp(map: Map, key: string): T; function mapToArray(map: Map): T[]; + function copyMap(source: Map, target: Map): void; /** * Creates a map from the elements of an array. * @@ -142,6 +143,14 @@ declare module "typescript" { interface StringSymbolWriter extends SymbolWriter { string(): string; } + interface EmitHost extends ScriptReferenceHost { + getSourceFiles(): SourceFile[]; + isEmitBlocked(sourceFile?: SourceFile): boolean; + getCommonSourceDirectory(): string; + getCanonicalFileName(fileName: string): string; + getNewLine(): string; + writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; + } function getSingleLineStringWriter(): StringSymbolWriter; function releaseStringWriter(writer: StringSymbolWriter): void; function getFullWidth(node: Node): number; @@ -149,7 +158,8 @@ declare module "typescript" { function getSourceFileOfNode(node: Node): SourceFile; function nodePosToString(node: Node): string; function getStartPosOfNode(node: Node): number; - function isMissingNode(node: Node): boolean; + function nodeIsMissing(node: Node): boolean; + function nodeIsPresent(node: Node): boolean; function getTokenPosOfNode(node: Node, sourceFile?: SourceFile): number; function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node): string; function getTextOfNodeFromSourceText(sourceText: string, node: Node): string; @@ -163,6 +173,7 @@ declare module "typescript" { function isExternalModule(file: SourceFile): boolean; function isDeclarationFile(file: SourceFile): boolean; function isConstEnumDeclaration(node: Node): boolean; + function getCombinedNodeFlags(node: Node): NodeFlags; function isConst(node: Node): boolean; function isLet(node: Node): boolean; function isPrologueDirective(node: Node): boolean; @@ -178,6 +189,7 @@ declare module "typescript" { function getSuperContainer(node: Node): Node; function getInvokedExpression(node: CallLikeExpression): Expression; function isExpression(node: Node): boolean; + function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean): boolean; function isExternalModuleImportDeclaration(node: Node): boolean; function getExternalModuleImportDeclarationExpression(node: Node): Expression; function isInternalModuleImportDeclaration(node: Node): boolean; @@ -196,12 +208,42 @@ declare module "typescript" { function getClassImplementedTypeNodes(node: ClassDeclaration): NodeArray; function getInterfaceBaseTypeNodes(node: InterfaceDeclaration): NodeArray; function getHeritageClause(clauses: NodeArray, kind: SyntaxKind): HeritageClause; - function tryResolveScriptReference(program: Program, sourceFile: SourceFile, reference: FileReference): SourceFile; + function tryResolveScriptReference(host: ScriptReferenceHost, sourceFile: SourceFile, reference: FileReference): SourceFile; function getAncestor(node: Node, kind: SyntaxKind): Node; function getFileReferenceFromReferencePath(comment: string, commentRange: CommentRange): ReferencePathMatchResult; function isKeyword(token: SyntaxKind): boolean; function isTrivia(token: SyntaxKind): boolean; function isModifier(token: SyntaxKind): boolean; + function createEmitHostFromProgram(program: Program): EmitHost; + function textSpanEnd(span: TextSpan): number; + function textSpanIsEmpty(span: TextSpan): boolean; + function textSpanContainsPosition(span: TextSpan, position: number): boolean; + function textSpanContainsTextSpan(span: TextSpan, other: TextSpan): boolean; + function textSpanOverlapsWith(span: TextSpan, other: TextSpan): boolean; + function textSpanOverlap(span1: TextSpan, span2: TextSpan): TextSpan; + function textSpanIntersectsWithTextSpan(span: TextSpan, other: TextSpan): boolean; + function textSpanIntersectsWith(span: TextSpan, start: number, length: number): boolean; + function textSpanIntersectsWithPosition(span: TextSpan, position: number): boolean; + function textSpanIntersection(span1: TextSpan, span2: TextSpan): TextSpan; + function createTextSpan(start: number, length: number): TextSpan; + function createTextSpanFromBounds(start: number, end: number): TextSpan; + function textChangeRangeNewSpan(range: TextChangeRange): TextSpan; + function textChangeRangeIsUnchanged(range: TextChangeRange): boolean; + function createTextChangeRange(span: TextSpan, newLength: number): TextChangeRange; + var unchangedTextChangeRange: TextChangeRange; + /** + * Called to merge all the changes that occurred across several versions of a script snapshot + * into a single change. i.e. if a user keeps making successive edits to a script we will + * have a text change from V1 to V2, V2 to V3, ..., Vn. + * + * This function will then merge those changes into a single change range valid between V1 and + * Vn. + */ + function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; +} +declare module "typescript" { + var optionDeclarations: CommandLineOption[]; + function parseCommandLine(commandLine: string[]): ParsedCommandLine; } declare module "typescript" { interface ListItemInfo { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7a4d808e023..f3f90b633ab 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16,6 +16,8 @@ module ts { var emptySymbols: SymbolTable = {}; var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || ScriptTarget.ES3; + var emitResolver = createResolver(); var checker: TypeChecker = { @@ -1575,7 +1577,6 @@ module ts { case SyntaxKind.IndexSignature: case SyntaxKind.Parameter: case SyntaxKind.ModuleBlock: - case SyntaxKind.TypeParameter: case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.TypeLiteral: @@ -1585,7 +1586,9 @@ module ts { case SyntaxKind.UnionType: case SyntaxKind.ParenthesizedType: return isDeclarationVisible(node.parent); - + + // Type parameters are always visible + case SyntaxKind.TypeParameter: // Source file is always visible case SyntaxKind.SourceFile: return true; @@ -3336,6 +3339,8 @@ module ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: return isContextSensitiveFunctionLikeDeclaration(node); + case SyntaxKind.ParenthesizedExpression: + return isContextSensitive((node).expression); } return false; @@ -3651,9 +3656,7 @@ module ts { var maybeCache = maybeStack[depth]; // If result is definitely true, copy assumptions to global cache, else copy to next level up var destinationCache = result === Ternary.True || depth === 0 ? relation : maybeStack[depth - 1]; - for (var p in maybeCache) { - destinationCache[p] = maybeCache[p]; - } + copyMap(/*source*/maybeCache, /*target*/destinationCache); } else { // A false result goes straight into global cache (when something is false under assumptions it @@ -4591,8 +4594,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 an object, union, or type parameter type - if (node && symbol.flags & SymbolFlags.Variable && type.flags & (TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter)) { + // Only narrow when symbol is variable of type any or an object, union, or type parameter type + if (node && symbol.flags & SymbolFlags.Variable && type.flags & (TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter)) { loop: while (node.parent) { var child = node; node = node.parent; @@ -4648,21 +4651,16 @@ module ts { if (expr.left.kind !== SyntaxKind.TypeOfExpression || expr.right.kind !== SyntaxKind.StringLiteral) { return type; } - var left = expr.left; var right = expr.right; - if (left.expression.kind !== SyntaxKind.Identifier || - getResolvedSymbol(left.expression) !== symbol) { - + if (left.expression.kind !== SyntaxKind.Identifier || getResolvedSymbol(left.expression) !== symbol) { return type; } - var t = right.text; var checkType: Type = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType; if (expr.operator === SyntaxKind.ExclamationEqualsEqualsToken) { assumeTrue = !assumeTrue; } - if (assumeTrue) { // The assumed result is true. If check was for a primitive type, that type is the narrowed type. Otherwise we can // remove the primitive types from the narrowed type. @@ -4706,8 +4704,8 @@ module ts { } function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { - // Check that assumed result is true and we have variable symbol on the left - if (!assumeTrue || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { + // Check that type is not any, assumed result is true, and we have variable symbol on the left + if (type.flags & TypeFlags.Any || !assumeTrue || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property @@ -4715,13 +4713,21 @@ module ts { if (!isTypeSubtypeOf(rightType, globalFunctionType)) { return type; } + // Target type is type of prototype property var prototypeProperty = getPropertyOfType(rightType, "prototype"); if (!prototypeProperty) { return type; } - var prototypeType = getTypeOfSymbol(prototypeProperty); - // Narrow to type of prototype property if it is a subtype of current type - return isTypeSubtypeOf(prototypeType, type) ? prototypeType : type; + var targetType = getTypeOfSymbol(prototypeProperty); + // Narrow to target type if it is a subtype of current type + if (isTypeSubtypeOf(targetType, type)) { + return targetType; + } + // If current type is a union type, remove all constituents that aren't subtypes of target type + if (type.flags & TypeFlags.Union) { + return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, targetType))); + } + return type; } // Narrow the given type based on the given expression having the assumed boolean value @@ -5061,17 +5067,25 @@ module ts { return undefined; } - // In a typed function call, an argument expression is contextually typed by the type of the corresponding parameter. - function getContextualTypeForArgument(node: Expression): Type { - var callExpression = node.parent; - var argIndex = indexOf(callExpression.arguments, node); + // In a typed function call, an argument or substitution expression is contextually typed by the type of the corresponding parameter. + function getContextualTypeForArgument(callTarget: CallLikeExpression, arg: Expression): Type { + var args = getEffectiveCallArguments(callTarget); + var argIndex = indexOf(args, arg); if (argIndex >= 0) { - var signature = getResolvedSignature(callExpression); + var signature = getResolvedSignature(callTarget); return getTypeAtPosition(signature, argIndex); } return undefined; } + function getContextualTypeForSubstitutionExpression(template: TemplateExpression, substitutionExpression: Expression) { + if (template.parent.kind === SyntaxKind.TaggedTemplateExpression) { + return getContextualTypeForArgument(template.parent, substitutionExpression); + } + + return undefined; + } + function getContextualTypeForBinaryOperand(node: Expression): Type { var binaryExpression = node.parent; var operator = binaryExpression.operator; @@ -5209,7 +5223,7 @@ module ts { return getContextualTypeForReturnExpression(node); case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: - return getContextualTypeForArgument(node); + return getContextualTypeForArgument(parent, node); case SyntaxKind.TypeAssertionExpression: return getTypeFromTypeNode((parent).type); case SyntaxKind.BinaryExpression: @@ -5220,6 +5234,11 @@ module ts { return getContextualTypeForElementExpression(node); case SyntaxKind.ConditionalExpression: return getContextualTypeForConditionalOperand(node); + case SyntaxKind.TemplateSpan: + Debug.assert(parent.parent.kind === SyntaxKind.TemplateExpression); + return getContextualTypeForSubstitutionExpression(parent.parent, node); + case SyntaxKind.ParenthesizedExpression: + return getContextualType(parent); } return undefined; } @@ -5604,8 +5623,11 @@ module ts { return unknownType; } - if (isConstEnumObjectType(objectType) && node.argumentExpression && node.argumentExpression.kind !== SyntaxKind.StringLiteral) { - error(node.argumentExpression, Diagnostics.Index_expression_arguments_in_const_enums_must_be_of_type_string); + var isConstEnum = isConstEnumObjectType(objectType); + if (isConstEnum && + (!node.argumentExpression || node.argumentExpression.kind !== SyntaxKind.StringLiteral)) { + error(node.argumentExpression, Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal); + return unknownType; } // TypeScript 1.0 spec (April 2014): 4.10 Property Access @@ -5626,6 +5648,10 @@ module ts { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } + else if (isConstEnum) { + error(node.argumentExpression, Diagnostics.Property_0_does_not_exist_on_const_enum_1, name, symbolToString(objectType.symbol)); + return unknownType; + } } } @@ -5880,7 +5906,7 @@ module ts { } /** - * Returns the effective arguments for an expression that works like a function invokation. + * Returns the effective arguments for an expression that works like a function invocation. * * If 'node' is a CallExpression or a NewExpression, then its argument list is returned. * If 'node' is a TaggedTemplateExpression, a new argument list is constructed from the substitution @@ -6114,8 +6140,10 @@ module ts { var result = candidates; var lastParent: Node; var lastSymbol: Symbol; - var cutoffPos: number = 0; - var pos: number; + var cutoffIndex: number = 0; + var index: number; + var specializedIndex: number = -1; + var spliceIndex: number; Debug.assert(!result.length); for (var i = 0; i < signatures.length; i++) { var signature = signatures[i]; @@ -6123,25 +6151,36 @@ module ts { var parent = signature.declaration && signature.declaration.parent; if (!lastSymbol || symbol === lastSymbol) { if (lastParent && parent === lastParent) { - pos++; + index++; } else { lastParent = parent; - pos = cutoffPos; + index = cutoffIndex; } } else { // current declaration belongs to a different symbol - // set cutoffPos so re-orderings in the future won't change result set from 0 to cutoffPos - pos = cutoffPos = result.length; + // set cutoffIndex so re-orderings in the future won't change result set from 0 to cutoffIndex + index = cutoffIndex = result.length; lastParent = parent; } lastSymbol = symbol; - for (var j = result.length; j > pos; j--) { - result[j] = result[j - 1]; + // specialized signatures always need to be placed before non-specialized signatures regardless + // of the cutoff position; see GH#1133 + if (signature.hasStringLiterals) { + specializedIndex++; + spliceIndex = specializedIndex; + // The cutoff index always needs to be greater than or equal to the specialized signature index + // in order to prevent non-specialized signatures from being added before a specialized + // signature. + cutoffIndex++; } - result[pos] = signature; + else { + spliceIndex = index; + } + + result.splice(spliceIndex, 0, signature); } } } @@ -6324,7 +6363,7 @@ module ts { function checkTaggedTemplateExpression(node: TaggedTemplateExpression): Type { // Grammar checking - if (compilerOptions.target < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { grammarErrorOnFirstToken(node.template, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); } @@ -7173,12 +7212,15 @@ module ts { checkVariableLikeDeclaration(node); var func = getContainingFunction(node); - if (node.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) { + if (node.flags & NodeFlags.AccessibilityModifier) { func = getContainingFunction(node); if (!(func.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) { error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } + if (node.questionToken && isBindingPattern(node.name) && func.body) { + error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature); + } if (node.dotDotDotToken) { if (!isArrayType(getTypeOfSymbol(node.symbol))) { error(node, Diagnostics.A_rest_parameter_must_be_of_an_array_type); @@ -7192,17 +7234,20 @@ module ts { checkGrammarIndexSignature(node); } // TODO (yuisu): Remove this check in else-if when SyntaxKind.Construct is moved and ambient context is handled - else if (node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.ConstructorType || + else if (node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.ConstructorType || node.kind === SyntaxKind.CallSignature || node.kind === SyntaxKind.Constructor || node.kind === SyntaxKind.ConstructSignature){ checkGrammarFunctionLikeDeclaration(node); } checkTypeParameters(node.typeParameters); + forEach(node.parameters, checkParameter); + if (node.type) { checkSourceElement(node.type); } + if (produceDiagnostics) { checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { @@ -8993,7 +9038,12 @@ module ts { checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - if (symbol.flags & SymbolFlags.ValueModule && symbol.declarations.length > 1 && !isInAmbientContext(node)) { + + // The following checks only apply on a non-ambient instantiated module declaration. + if (symbol.flags & SymbolFlags.ValueModule + && symbol.declarations.length > 1 + && !isInAmbientContext(node) + && isInstantiatedModule(node, compilerOptions.preserveConstEnums)) { var classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (classOrFunc) { if (getSourceFileOfNode(node) !== getSourceFileOfNode(classOrFunc)) { @@ -9004,6 +9054,8 @@ module ts { } } } + + // Checks for ambient external modules. if (node.name.kind === SyntaxKind.StringLiteral) { if (!isGlobalSourceFile(node.parent)) { error(node.name, Diagnostics.Ambient_external_modules_cannot_be_nested_in_other_modules); @@ -9251,6 +9303,8 @@ module ts { case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: case SyntaxKind.TaggedTemplateExpression: + case SyntaxKind.TemplateExpression: + case SyntaxKind.TemplateSpan: case SyntaxKind.TypeAssertionExpression: case SyntaxKind.ParenthesizedExpression: case SyntaxKind.TypeOfExpression: @@ -9794,8 +9848,20 @@ module ts { function isUniqueLocalName(name: string, container: Node): boolean { for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { - if (node.locals && hasProperty(node.locals, name) && node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue)) { - return false; + if (node.locals && hasProperty(node.locals, name)) { + var symbolWithRelevantName = node.locals[name]; + if (symbolWithRelevantName.flags & (SymbolFlags.Value | SymbolFlags.ExportValue)) { + return false; + } + + // An import can be emitted too, if it is referenced as a value. + // Make sure the name in question does not collide with an import. + if (symbolWithRelevantName.flags & SymbolFlags.Import) { + var importDeclarationWithRelevantName = getDeclarationOfKind(symbolWithRelevantName, SyntaxKind.ImportDeclaration); + if (isReferencedImportDeclaration(importDeclarationWithRelevantName)) { + return false; + } + } } } return true; @@ -9995,7 +10061,7 @@ module ts { globalRegExpType = getGlobalType("RegExp"); // If we're in ES6 mode, load the TemplateStringsArray. // Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios. - globalTemplateStringsArrayType = compilerOptions.target >= ScriptTarget.ES6 + globalTemplateStringsArrayType = languageVersion >= ScriptTarget.ES6 ? getGlobalType("TemplateStringsArray") : unknownType; anyArrayType = createArrayType(anyType); @@ -10132,6 +10198,9 @@ module ts { else if (node.kind === SyntaxKind.InterfaceDeclaration && flags & NodeFlags.Ambient) { return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); } + else if (node.kind === SyntaxKind.Parameter && (flags & NodeFlags.AccessibilityModifier) && isBindingPattern((node).name)) { + return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); + } } function checkGrammarForDisallowedTrailingComma(list: NodeArray): boolean { @@ -10364,7 +10433,7 @@ module ts { return; var computedPropertyName = node; - if (compilerOptions.target < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); } else if (computedPropertyName.expression.kind === SyntaxKind.BinaryExpression && (computedPropertyName.expression).operator === SyntaxKind.CommaToken) { @@ -10464,7 +10533,7 @@ module ts { function checkGrammarAccessor(accessor: MethodDeclaration): boolean { var kind = accessor.kind; - if (compilerOptions.target < ScriptTarget.ES5) { + if (languageVersion < ScriptTarget.ES5) { return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); } else if (isInAmbientContext(accessor)) { @@ -10669,7 +10738,7 @@ module ts { return grammarErrorAtPos(getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty); } - if (compilerOptions.target < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { if (isLet(declarationList)) { return grammarErrorOnFirstToken(declarationList, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } @@ -10771,7 +10840,7 @@ module ts { function grammarErrorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { var sourceFile = getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = createScanner(compilerOptions.target, /*skipTrivia*/ true, sourceFile.text); + var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text); var start = scanToken(scanner, node.pos); diagnostics.push(createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2)); return true; @@ -10913,7 +10982,7 @@ module ts { if (node.parserContextFlags & ParserContextFlags.StrictMode) { return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); } - else if (compilerOptions.target >= ScriptTarget.ES5) { + else if (languageVersion >= ScriptTarget.ES5) { return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); } } @@ -10922,7 +10991,7 @@ module ts { function grammarErrorAfterFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { var sourceFile = getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = createScanner(compilerOptions.target, /*skipTrivia*/ true, sourceFile.text); + var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text); scanToken(scanner, node.pos); diagnostics.push(createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2)); return true; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 9fe59b1ba27..23bbba5c6ca 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -33,6 +33,10 @@ module ts { type: "boolean", description: Diagnostics.Print_this_message, }, + { + name: "listFiles", + type: "boolean", + }, { name: "locale", type: "string", @@ -40,6 +44,7 @@ module ts { { name: "mapRoot", type: "string", + isFilePath: true, description: Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations, paramType: Diagnostics.LOCATION, }, @@ -67,7 +72,7 @@ module ts { { name: "noImplicitAny", type: "boolean", - description: Diagnostics.Warn_on_expressions_and_declarations_with_an_implied_any_type, + description: Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type, }, { name: "noLib", @@ -90,6 +95,7 @@ module ts { { name: "outDir", type: "string", + isFilePath: true, description: Diagnostics.Redirect_output_structure_to_the_directory, paramType: Diagnostics.DIRECTORY, }, @@ -98,6 +104,14 @@ module ts { type: "boolean", description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code }, + { + name: "project", + shortName: "p", + type: "string", + isFilePath: true, + description: Diagnostics.Compile_the_project_in_the_given_directory, + paramType: Diagnostics.DIRECTORY + }, { name: "removeComments", type: "boolean", @@ -111,6 +125,7 @@ module ts { { name: "sourceRoot", type: "string", + isFilePath: true, description: Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations, paramType: Diagnostics.LOCATION, }, @@ -141,26 +156,19 @@ module ts { } ]; - var shortOptionNames: Map = {}; - var optionNameMap: Map = {}; - - forEach(optionDeclarations, option => { - optionNameMap[option.name.toLowerCase()] = option; - - if (option.shortName) { - shortOptionNames[option.shortName] = option.name; - } - }); - export function parseCommandLine(commandLine: string[]): ParsedCommandLine { - // Set default compiler option values - var options: CompilerOptions = { - target: ScriptTarget.ES3, - module: ModuleKind.None - }; + var options: CompilerOptions = {}; var filenames: string[] = []; var errors: Diagnostic[] = []; + var shortOptionNames: Map = {}; + var optionNameMap: Map = {}; + forEach(optionDeclarations, option => { + optionNameMap[option.name.toLowerCase()] = option; + if (option.shortName) { + shortOptionNames[option.shortName] = option.name; + } + }); parseStrings(commandLine); return { options, @@ -256,4 +264,84 @@ module ts { parseStrings(args); } } + + export function readConfigFile(filename: string): any { + try { + var text = sys.readFile(filename); + return /\S/.test(text) ? JSON.parse(text) : {}; + } + catch (e) { + } + } + + export function parseConfigFile(json: any, basePath?: string): ParsedCommandLine { + var errors: Diagnostic[] = []; + + return { + options: getCompilerOptions(), + filenames: getFiles(), + errors + }; + + function getCompilerOptions(): CompilerOptions { + var options: CompilerOptions = {}; + var optionNameMap: Map = {}; + forEach(optionDeclarations, option => { + optionNameMap[option.name] = option; + }); + var jsonOptions = json["compilerOptions"]; + if (jsonOptions) { + for (var id in jsonOptions) { + if (hasProperty(optionNameMap, id)) { + var opt = optionNameMap[id]; + var optType = opt.type; + var value = jsonOptions[id]; + var expectedType = typeof optType === "string" ? optType : "string"; + if (typeof value === expectedType) { + if (typeof optType !== "string") { + var key = value.toLowerCase(); + if (hasProperty(optType, key)) { + value = optType[key]; + } + else { + errors.push(createCompilerDiagnostic(opt.error)); + value = 0; + } + } + if (opt.isFilePath) { + value = normalizePath(combinePaths(basePath, value)); + } + options[opt.name] = value; + } + else { + errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType)); + } + } + else { + errors.push(createCompilerDiagnostic(Diagnostics.Unknown_compiler_option_0, id)); + } + } + } + return options; + } + + function getFiles(): string[] { + var files: string[] = []; + if (hasProperty(json, "files")) { + if (json["files"] instanceof Array) { + var files = map(json["files"], s => combinePaths(basePath, s)); + } + } + else { + var sysFiles = sys.readDirectory(basePath, ".ts"); + for (var i = 0; i < sysFiles.length; i++) { + var name = sysFiles[i]; + if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { + files.push(name); + } + } + } + return files; + } + } } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 4ba93729c36..4a710c035ba 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -178,6 +178,19 @@ module ts { return result; } + export function extend(first: Map, second: Map): Map { + var result: Map = {}; + for (var id in first) { + result[id] = first[id]; + } + for (var id in second) { + if (!hasProperty(result, id)) { + result[id] = second[id]; + } + } + return result; + } + export function forEachValue(map: Map, callback: (value: T) => U): U { var result: U; for (var id in map) { @@ -208,6 +221,12 @@ module ts { return result; } + export function copyMap(source: Map, target: Map): void { + for (var p in source) { + target[p] = source[p]; + } + } + /** * Creates a map from the elements of an array. * @@ -562,7 +581,7 @@ module ts { export function combinePaths(path1: string, path2: string) { if (!(path1 && path1.length)) return path2; if (!(path2 && path2.length)) return path1; - if (path2.charAt(0) === directorySeparator) return path2; + if (getRootLength(path2) !== 0) return path2; if (path1.charAt(path1.length - 1) === directorySeparator) return path1 + path2; return path1 + directorySeparator + path2; } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 99d8d0b72fb..64511ad8072 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -146,6 +146,7 @@ module ts { Modifiers_cannot_appear_here: { code: 1184, category: DiagnosticCategory.Error, key: "Modifiers cannot appear here." }, Merge_conflict_marker_encountered: { code: 1185, category: DiagnosticCategory.Error, key: "Merge conflict marker encountered." }, A_rest_element_cannot_have_an_initializer: { code: 1186, category: DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, + A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." }, 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." }, @@ -297,6 +298,7 @@ module ts { Type_0_has_no_property_1: { code: 2460, category: DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}'." }, Type_0_is_not_an_array_type: { code: 2461, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type." }, A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: DiagnosticCategory.Error, key: "A rest element must be last in an array destructuring pattern" }, + A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: { code: 2463, category: DiagnosticCategory.Error, key: "A binding pattern parameter cannot be optional in an implementation signature." }, 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_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -369,19 +371,22 @@ module ts { Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." }, In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 4083, category: DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression.", isEarly: true }, const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 4084, category: DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." }, - Index_expression_arguments_in_const_enums_must_be_of_type_string: { code: 4085, category: DiagnosticCategory.Error, key: "Index expression arguments in 'const' enums must be of type 'string'." }, + A_const_enum_member_can_only_be_accessed_using_a_string_literal: { code: 4085, category: DiagnosticCategory.Error, key: "A const enum member can only be accessed using a string literal.", isEarly: true }, const_enum_member_initializer_was_evaluated_to_a_non_finite_value: { code: 4086, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to a non-finite value." }, const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 4087, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." }, + Property_0_does_not_exist_on_const_enum_1: { code: 4088, category: DiagnosticCategory.Error, key: "Property '{0}' does not exist on 'const' enum '{1}'.", isEarly: true }, The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." }, Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" }, Unsupported_file_encoding: { code: 5013, category: DiagnosticCategory.Error, key: "Unsupported file encoding." }, Unknown_compiler_option_0: { code: 5023, category: DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." }, + Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." }, Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" }, - Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option mapRoot cannot be specified without specifying sourcemap option." }, - Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option sourceRoot cannot be specified without specifying sourcemap option." }, - Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option noEmit cannot be specified with option out or outDir." }, - Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option noEmit cannot be specified with option declaration." }, + Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option." }, + Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option." }, + Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, + Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, + Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, @@ -396,6 +401,7 @@ module ts { 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." }, + Compile_the_project_in_the_given_directory: { code: 6020, category: DiagnosticCategory.Message, key: "Compile the project in the given directory." }, Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" }, options: { code: 6024, category: DiagnosticCategory.Message, key: "options" }, file: { code: 6025, category: DiagnosticCategory.Message, key: "file" }, @@ -403,7 +409,7 @@ module ts { Options_Colon: { code: 6027, category: DiagnosticCategory.Message, key: "Options:" }, Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" }, Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." }, - File_change_detected_Compiling: { code: 6032, category: DiagnosticCategory.Message, key: "File change detected. Compiling..." }, + File_change_detected_Starting_incremental_compilation: { code: 6032, category: DiagnosticCategory.Message, key: "File change detected. Starting incremental compilation..." }, KIND: { code: 6034, category: DiagnosticCategory.Message, key: "KIND" }, FILE: { code: 6035, category: DiagnosticCategory.Message, key: "FILE" }, VERSION: { code: 6036, category: DiagnosticCategory.Message, key: "VERSION" }, @@ -419,7 +425,7 @@ module ts { 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}'." }, Corrupted_locale_file_0: { code: 6051, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." }, - Warn_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: DiagnosticCategory.Message, key: "Warn on expressions and declarations with an implied 'any' type." }, + Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." }, File_0_not_found: { code: 6053, category: DiagnosticCategory.Error, key: "File '{0}' not found." }, File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5bec5301721..6c33fa42013 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -224,7 +224,7 @@ "A 'declare' modifier cannot be used with an import declaration.": { "category": "Error", "code": 1079, - "isEarly": true + "isEarly": true }, "Invalid 'reference' directive syntax.": { "category": "Error", @@ -659,7 +659,7 @@ "An implementation cannot be declared in ambient contexts.": { "category": "Error", "code": 1184, - "isEarly": true + "isEarly": true }, "Modifiers cannot appear here.": { "category": "Error", @@ -673,6 +673,10 @@ "category": "Error", "code": 1186 }, + "A parameter property may not be a binding pattern.": { + "category": "Error", + "code": 1187 + }, "Duplicate identifier '{0}'.": { "category": "Error", @@ -1282,6 +1286,10 @@ "category": "Error", "code": 2462 }, + "A binding pattern parameter cannot be optional in an implementation signature.": { + "category": "Error", + "code": 2463 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -1572,9 +1580,10 @@ "category": "Error", "code": 4084 }, - "Index expression arguments in 'const' enums must be of type 'string'.": { + "A const enum member can only be accessed using a string literal.": { "category": "Error", - "code": 4085 + "code": 4085, + "isEarly": true }, "'const' enum member initializer was evaluated to a non-finite value.": { "category": "Error", @@ -1584,6 +1593,11 @@ "category": "Error", "code": 4087 }, + "Property '{0}' does not exist on 'const' enum '{1}'.": { + "category": "Error", + "code": 4088, + "isEarly": true + }, "The current host does not support the '{0}' option.": { "category": "Error", "code": 5001 @@ -1604,26 +1618,34 @@ "category": "Error", "code": 5023 }, + "Compiler option '{0}' requires a value of type {1}.": { + "category": "Error", + "code": 5024 + }, "Could not write file '{0}': {1}": { "category": "Error", "code": 5033 }, - "Option mapRoot cannot be specified without specifying sourcemap option.": { + "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.": { "category": "Error", "code": 5038 }, - "Option sourceRoot cannot be specified without specifying sourcemap option.": { + "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.": { "category": "Error", "code": 5039 }, - "Option noEmit cannot be specified with option out or outDir.": { + "Option 'noEmit' cannot be specified with option 'out' or 'outDir'.": { "category": "Error", "code": 5040 }, - "Option noEmit cannot be specified with option declaration.": { + "Option 'noEmit' cannot be specified with option 'declaration'.": { "category": "Error", "code": 5041 }, + "Option 'project' cannot be mixed with source files on a command line.": { + "category": "Error", + "code": 5042 + }, "Concatenate and emit output to single file.": { "category": "Message", "code": 6001 @@ -1680,6 +1702,10 @@ "category": "Message", "code": 6019 }, + "Compile the project in the given directory.": { + "category": "Message", + "code": 6020 + }, "Syntax: {0}": { "category": "Message", "code": 6023 @@ -1708,7 +1734,7 @@ "category": "Message", "code": 6030 }, - "File change detected. Compiling...": { + "File change detected. Starting incremental compilation...": { "category": "Message", "code": 6032 }, @@ -1772,7 +1798,7 @@ "category": "Error", "code": 6051 }, - "Warn on expressions and declarations with an implied 'any' type.": { + "Raise error on expressions and declarations with an implied 'any' type.": { "category": "Message", "code": 6052 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9670b62af1b..61d60aebf3a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -170,9 +170,10 @@ module ts { function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string){ if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos); + var lastLine = currentSourceFile.getLineStarts().length; var firstCommentLineIndent: number; for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, /*character*/1); + var nextLineStart = currentLine === lastLine ? (comment.end + 1) : currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, /*character*/1); if (pos !== comment.pos) { // If we are not emitting first line, we need to write the spaces to adjust the alignment @@ -339,6 +340,7 @@ module ts { function emitDeclarations(host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[], jsFilePath: string, root?: SourceFile): DeclarationEmit { var newLine = host.getNewLine(); var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || ScriptTarget.ES3; var write: (s: string) => void; var writeLine: () => void; @@ -1461,18 +1463,7 @@ module ts { referencePathsOutput, } } - - export interface EmitHost extends ScriptReferenceHost { - getSourceFiles(): SourceFile[]; - isEmitBlocked(sourceFile?: SourceFile): boolean; - - getCommonSourceDirectory(): string; - getCanonicalFileName(fileName: string): string; - getNewLine(): string; - - writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; - } - + export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { var diagnostics: Diagnostic[] = []; var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); @@ -1484,6 +1475,7 @@ module ts { export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile?: SourceFile): EmitResult { // var program = resolver.getProgram(); var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || ScriptTarget.ES3; var sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined; var diagnostics: Diagnostic[] = []; var newLine = host.getNewLine(); @@ -2032,14 +2024,14 @@ module ts { } function emitLiteral(node: LiteralExpression) { - var text = compilerOptions.target < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : + var text = languageVersion < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } // For version below ES6, emit binary integer literal and octal integer literal in canonical form - else if (compilerOptions.target < ScriptTarget.ES6 && node.kind === SyntaxKind.NumericLiteral && isBinaryOrOctalIntegerLiteral(text)) { + else if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.NumericLiteral && isBinaryOrOctalIntegerLiteral(text)) { write(node.text); } else { @@ -2054,7 +2046,7 @@ module ts { function emitTemplateExpression(node: TemplateExpression): void { // In ES6 mode and above, we can simply emit each portion of a template in order, but in // ES3 & ES5 we must convert the template expression into a series of string concatenations. - if (compilerOptions.target >= ScriptTarget.ES6) { + if (languageVersion >= ScriptTarget.ES6) { forEachChild(node, emit); return; } @@ -2068,9 +2060,15 @@ module ts { write("("); } - emitLiteral(node.head); + var headEmitted = false; + if (shouldEmitTemplateHead()) { + emitLiteral(node.head); + headEmitted = true; + } + + for (var i = 0; i < node.templateSpans.length; i++) { + var templateSpan = node.templateSpans[i]; - forEach(node.templateSpans, templateSpan => { // Check if the expression has operands and binds its operands less closely than binary '+'. // If it does, we need to wrap the expression in parentheses. Otherwise, something like // `abc${ 1 << 2 }` @@ -2082,7 +2080,14 @@ module ts { // "abc" + (1 << 2) + "" var needsParens = templateSpan.expression.kind !== SyntaxKind.ParenthesizedExpression && comparePrecedenceToBinaryPlus(templateSpan.expression) !== Comparison.GreaterThan; - write(" + "); + + if (i > 0 || headEmitted) { + // If this is the first span and the head was not emitted, then this templateSpan's + // expression will be the first to be emitted. Don't emit the preceding ' + ' in that + // case. + write(" + "); + } + emitParenthesized(templateSpan.expression, needsParens); // Only emit if the literal is non-empty. // The binary '+' operator is left-associative, so the first string concatenation @@ -2092,12 +2097,34 @@ module ts { write(" + ") emitLiteral(templateSpan.literal); } - }); + } if (emitOuterParens) { write(")"); } + function shouldEmitTemplateHead() { + // If this expression has an empty head literal and the first template span has a non-empty + // literal, then emitting the empty head literal is not necessary. + // `${ foo } and ${ bar }` + // can be emitted as + // foo + " and " + bar + // This is because it is only required that one of the first two operands in the emit + // output must be a string literal, so that the other operand and all following operands + // are forced into strings. + // + // If the first template span has an empty literal, then the head must still be emitted. + // `${ foo }${ bar }` + // must still be emitted as + // "" + foo + bar + + // There is always atleast one templateSpan in this code path, since + // NoSubstitutionTemplateLiterals are directly emitted via emitLiteral() + Debug.assert(node.templateSpans.length !== 0); + + return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; + } + function templateNeedsParens(template: TemplateExpression, parent: Expression) { switch (parent.kind) { case SyntaxKind.CallExpression: @@ -2117,7 +2144,8 @@ module ts { * or equal precedence to the binary '+' operator */ function comparePrecedenceToBinaryPlus(expression: Expression): Comparison { - // All binary expressions have lower precedence than '+' apart from '*', '/', and '%'. + // All binary expressions have lower precedence than '+' apart from '*', '/', and '%' + // which have greater precedence and '-' which has equal precedence. // All unary operators have a higher precedence apart from yield. // Arrow functions and conditionals have a lower precedence, // although we convert the former into regular function expressions in ES5 mode, @@ -2125,7 +2153,7 @@ module ts { // // TODO (drosen): Note that we need to account for the upcoming 'yield' and // spread ('...') unary operators that are anticipated for ES6. - Debug.assert(compilerOptions.target <= ScriptTarget.ES5); + Debug.assert(languageVersion < ScriptTarget.ES6); switch (expression.kind) { case SyntaxKind.BinaryExpression: switch ((expression).operator) { @@ -2134,6 +2162,7 @@ module ts { case SyntaxKind.PercentToken: return Comparison.GreaterThan; case SyntaxKind.PlusToken: + case SyntaxKind.MinusToken: return Comparison.EqualTo; default: return Comparison.LessThan; @@ -2309,7 +2338,7 @@ module ts { write("[]"); return; } - if (compilerOptions.target >= ScriptTarget.ES6) { + if (languageVersion >= ScriptTarget.ES6) { write("["); emitList(elements, 0, elements.length, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, /*trailingComma*/ elements.hasTrailingComma); @@ -2359,7 +2388,7 @@ module ts { write(" "); } emitList(properties, 0, properties.length, /*multiLine*/ multiLine, - /*trailingComma*/ properties.hasTrailingComma && compilerOptions.target >= ScriptTarget.ES5); + /*trailingComma*/ properties.hasTrailingComma && languageVersion >= ScriptTarget.ES5); if (!multiLine) { write(" "); } @@ -2379,7 +2408,7 @@ module ts { } emitLeadingComments(node); emit(node.name); - if (compilerOptions.target < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { write(": function "); } emitSignatureAndBody(node); @@ -2405,7 +2434,7 @@ module ts { // export var obj = { y }; // } // The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version - if (compilerOptions.target < ScriptTarget.ES6 || resolver.getExpressionNamePrefix(node.name)) { + if (languageVersion < ScriptTarget.ES6 || resolver.getExpressionNamePrefix(node.name)) { // Emit identifier as an identifier write(": "); // Even though this is stored as identifier treat it as an expression @@ -2487,7 +2516,7 @@ module ts { } function emitTaggedTemplateExpression(node: TaggedTemplateExpression): void { - Debug.assert(compilerOptions.target >= ScriptTarget.ES6, "Trying to emit a tagged template in pre-ES6 mode."); + Debug.assert(languageVersion >= ScriptTarget.ES6, "Trying to emit a tagged template in pre-ES6 mode."); emit(node.tag); write(" "); emit(node.template); @@ -2579,7 +2608,7 @@ module ts { function emitBinaryExpression(node: BinaryExpression) { - if (compilerOptions.target < ScriptTarget.ES6 && node.operator === SyntaxKind.EqualsToken && + if (languageVersion < ScriptTarget.ES6 && node.operator === SyntaxKind.EqualsToken && (node.left.kind === SyntaxKind.ObjectLiteralExpression || node.left.kind === SyntaxKind.ArrayLiteralExpression)) { emitDestructuring(node); } @@ -3075,7 +3104,7 @@ module ts { function emitVariableDeclaration(node: VariableDeclaration) { emitLeadingComments(node); if (isBindingPattern(node.name)) { - if (compilerOptions.target < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { emitDestructuring(node); } else { @@ -3110,7 +3139,7 @@ module ts { function emitParameter(node: ParameterDeclaration) { emitLeadingComments(node); - if (compilerOptions.target < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { if (isBindingPattern(node.name)) { var name = createTempVariable(node); if (!tempParameters) { @@ -3134,7 +3163,7 @@ module ts { } function emitDefaultValueAssignments(node: FunctionLikeDeclaration) { - if (compilerOptions.target < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { var tempIndex = 0; forEach(node.parameters, p => { if (isBindingPattern(p.name)) { @@ -3164,7 +3193,7 @@ module ts { } function emitRestParameter(node: FunctionLikeDeclaration) { - if (compilerOptions.target < ScriptTarget.ES6 && hasRestParameters(node)) { + if (languageVersion < ScriptTarget.ES6 && hasRestParameters(node)) { var restIndex = node.parameters.length - 1; var restParam = node.parameters[restIndex]; var tempName = createTempVariable(node, /*forLoopVariable*/ true).text; @@ -3253,7 +3282,7 @@ module ts { write("("); if (node) { var parameters = node.parameters; - var omitCount = compilerOptions.target < ScriptTarget.ES6 && hasRestParameters(node) ? 1 : 0; + var omitCount = languageVersion < ScriptTarget.ES6 && hasRestParameters(node) ? 1 : 0; emitList(parameters, 0, parameters.length - omitCount, /*multiLine*/ false, /*trailingComma*/ false); } write(")"); @@ -3701,8 +3730,8 @@ module ts { } function emitModuleDeclaration(node: ModuleDeclaration) { - var shouldEmit = getModuleInstanceState(node) === ModuleInstanceState.Instantiated || - (getModuleInstanceState(node) === ModuleInstanceState.ConstEnumOnly && compilerOptions.preserveConstEnums); + // Emit only if this module is non-ambient. + var shouldEmit = isInstantiatedModule(node, compilerOptions.preserveConstEnums); if (!shouldEmit) { return emitPinnedOrTripleSlashComments(node); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b9b08087692..5ae44e5ff39 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -12,43 +12,50 @@ module ts { return new (getNodeConstructor(kind))(); } + function visitNode(cbNode: (node: Node) => T, node: Node): T { + if (node) { + return cbNode(node); + } + } + + function visitNodeArray(cbNodes: (nodes: Node[]) => T, nodes: Node[]) { + if (nodes) { + return cbNodes(nodes); + } + } + + function visitEachNode(cbNode: (node: Node) => T, nodes: Node[]) { + if (nodes) { + for (var i = 0, len = nodes.length; i < len; i++) { + var result = cbNode(nodes[i]); + if (result) { + return result; + } + } + } + } + // Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes // stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, // embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns // a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. - export function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodes?: (nodes: Node[]) => T): T { - function child(node: Node): T { - if (node) { - return cbNode(node); - } - } - function children(nodes: Node[]) { - if (nodes) { - if (cbNodes) { - return cbNodes(nodes); - } - - for (var i = 0, len = nodes.length; i < len; i++) { - var result = cbNode(nodes[i]) - if (result) { - return result; - } - } - - return undefined; - } - } + export function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T { if (!node) { return; } + // The visitXXX functions could be written as local functions that close over the cbNode and cbNodeArray + // callback parameters, but that causes a closure allocation for each invocation with noticeable effects + // on performance. + var visitNodes: (cb: (node: Node | Node[]) => T, nodes: Node[]) => T = cbNodeArray ? visitNodeArray : visitEachNode; + var cbNodes = cbNodeArray || cbNode; switch (node.kind) { case SyntaxKind.QualifiedName: - return child((node).left) || - child((node).right); + return visitNode(cbNode, (node).left) || + visitNode(cbNode, (node).right); case SyntaxKind.TypeParameter: - return child((node).name) || - child((node).constraint) || - child((node).expression); + return visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).constraint) || + visitNode(cbNode, (node).expression); case SyntaxKind.Parameter: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -56,22 +63,22 @@ module ts { case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: - return children(node.modifiers) || - child((node).propertyName) || - child((node).dotDotDotToken) || - child((node).name) || - child((node).questionToken) || - child((node).type) || - child((node).initializer); + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).propertyName) || + visitNode(cbNode, (node).dotDotDotToken) || + visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).questionToken) || + visitNode(cbNode, (node).type) || + visitNode(cbNode, (node).initializer); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: - return children(node.modifiers) || - children((node).typeParameters) || - children((node).parameters) || - child((node).type); + return visitNodes(cbNodes, node.modifiers) || + visitNodes(cbNodes, (node).typeParameters) || + visitNodes(cbNodes, (node).parameters) || + visitNode(cbNode, (node).type); case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -80,182 +87,182 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: - return children(node.modifiers) || - child((node).asteriskToken) || - child((node).name) || - child((node).questionToken) || - children((node).typeParameters) || - children((node).parameters) || - child((node).type) || - child((node).body); + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).asteriskToken) || + visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).questionToken) || + visitNodes(cbNodes, (node).typeParameters) || + visitNodes(cbNodes, (node).parameters) || + visitNode(cbNode, (node).type) || + visitNode(cbNode, (node).body); case SyntaxKind.TypeReference: - return child((node).typeName) || - children((node).typeArguments); + return visitNode(cbNode, (node).typeName) || + visitNodes(cbNodes, (node).typeArguments); case SyntaxKind.TypeQuery: - return child((node).exprName); + return visitNode(cbNode, (node).exprName); case SyntaxKind.TypeLiteral: - return children((node).members); + return visitNodes(cbNodes, (node).members); case SyntaxKind.ArrayType: - return child((node).elementType); + return visitNode(cbNode, (node).elementType); case SyntaxKind.TupleType: - return children((node).elementTypes); + return visitNodes(cbNodes, (node).elementTypes); case SyntaxKind.UnionType: - return children((node).types); + return visitNodes(cbNodes, (node).types); case SyntaxKind.ParenthesizedType: - return child((node).type); + return visitNode(cbNode, (node).type); case SyntaxKind.ObjectBindingPattern: case SyntaxKind.ArrayBindingPattern: - return children((node).elements); + return visitNodes(cbNodes, (node).elements); case SyntaxKind.ArrayLiteralExpression: - return children((node).elements); + return visitNodes(cbNodes, (node).elements); case SyntaxKind.ObjectLiteralExpression: - return children((node).properties); + return visitNodes(cbNodes, (node).properties); case SyntaxKind.PropertyAccessExpression: - return child((node).expression) || - child((node).name); + return visitNode(cbNode, (node).expression) || + visitNode(cbNode, (node).name); case SyntaxKind.ElementAccessExpression: - return child((node).expression) || - child((node).argumentExpression); + return visitNode(cbNode, (node).expression) || + visitNode(cbNode, (node).argumentExpression); case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: - return child((node).expression) || - children((node).typeArguments) || - children((node).arguments); + return visitNode(cbNode, (node).expression) || + visitNodes(cbNodes, (node).typeArguments) || + visitNodes(cbNodes, (node).arguments); case SyntaxKind.TaggedTemplateExpression: - return child((node).tag) || - child((node).template); + return visitNode(cbNode, (node).tag) || + visitNode(cbNode, (node).template); case SyntaxKind.TypeAssertionExpression: - return child((node).type) || - child((node).expression); + return visitNode(cbNode, (node).type) || + visitNode(cbNode, (node).expression); case SyntaxKind.ParenthesizedExpression: - return child((node).expression); + return visitNode(cbNode, (node).expression); case SyntaxKind.DeleteExpression: - return child((node).expression); + return visitNode(cbNode, (node).expression); case SyntaxKind.TypeOfExpression: - return child((node).expression); + return visitNode(cbNode, (node).expression); case SyntaxKind.VoidExpression: - return child((node).expression); + return visitNode(cbNode, (node).expression); case SyntaxKind.PrefixUnaryExpression: - return child((node).operand); + return visitNode(cbNode, (node).operand); case SyntaxKind.YieldExpression: - return child((node).asteriskToken) || - child((node).expression); + return visitNode(cbNode, (node).asteriskToken) || + visitNode(cbNode, (node).expression); case SyntaxKind.PostfixUnaryExpression: - return child((node).operand); + return visitNode(cbNode, (node).operand); case SyntaxKind.BinaryExpression: - return child((node).left) || - child((node).right); + return visitNode(cbNode, (node).left) || + visitNode(cbNode, (node).right); case SyntaxKind.ConditionalExpression: - return child((node).condition) || - child((node).whenTrue) || - child((node).whenFalse); + return visitNode(cbNode, (node).condition) || + visitNode(cbNode, (node).whenTrue) || + visitNode(cbNode, (node).whenFalse); case SyntaxKind.SpreadElementExpression: - return child((node).expression); + return visitNode(cbNode, (node).expression); case SyntaxKind.Block: case SyntaxKind.ModuleBlock: - return children((node).statements); + return visitNodes(cbNodes, (node).statements); case SyntaxKind.SourceFile: - return children((node).statements) || - child((node).endOfFileToken); + return visitNodes(cbNodes, (node).statements) || + visitNode(cbNode, (node).endOfFileToken); case SyntaxKind.VariableStatement: - return children(node.modifiers) || - child((node).declarationList); + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).declarationList); case SyntaxKind.VariableDeclarationList: - return children((node).declarations); + return visitNodes(cbNodes, (node).declarations); case SyntaxKind.ExpressionStatement: - return child((node).expression); + return visitNode(cbNode, (node).expression); case SyntaxKind.IfStatement: - return child((node).expression) || - child((node).thenStatement) || - child((node).elseStatement); + return visitNode(cbNode, (node).expression) || + visitNode(cbNode, (node).thenStatement) || + visitNode(cbNode, (node).elseStatement); case SyntaxKind.DoStatement: - return child((node).statement) || - child((node).expression); + return visitNode(cbNode, (node).statement) || + visitNode(cbNode, (node).expression); case SyntaxKind.WhileStatement: - return child((node).expression) || - child((node).statement); + return visitNode(cbNode, (node).expression) || + visitNode(cbNode, (node).statement); case SyntaxKind.ForStatement: - return child((node).initializer) || - child((node).condition) || - child((node).iterator) || - child((node).statement); + return visitNode(cbNode, (node).initializer) || + visitNode(cbNode, (node).condition) || + visitNode(cbNode, (node).iterator) || + visitNode(cbNode, (node).statement); case SyntaxKind.ForInStatement: - return child((node).initializer) || - child((node).expression) || - child((node).statement); + return visitNode(cbNode, (node).initializer) || + visitNode(cbNode, (node).expression) || + visitNode(cbNode, (node).statement); case SyntaxKind.ContinueStatement: case SyntaxKind.BreakStatement: - return child((node).label); + return visitNode(cbNode, (node).label); case SyntaxKind.ReturnStatement: - return child((node).expression); + return visitNode(cbNode, (node).expression); case SyntaxKind.WithStatement: - return child((node).expression) || - child((node).statement); + return visitNode(cbNode, (node).expression) || + visitNode(cbNode, (node).statement); case SyntaxKind.SwitchStatement: - return child((node).expression) || - children((node).clauses); + return visitNode(cbNode, (node).expression) || + visitNodes(cbNodes, (node).clauses); case SyntaxKind.CaseClause: - return child((node).expression) || - children((node).statements); + return visitNode(cbNode, (node).expression) || + visitNodes(cbNodes, (node).statements); case SyntaxKind.DefaultClause: - return children((node).statements); + return visitNodes(cbNodes, (node).statements); case SyntaxKind.LabeledStatement: - return child((node).label) || - child((node).statement); + return visitNode(cbNode, (node).label) || + visitNode(cbNode, (node).statement); case SyntaxKind.ThrowStatement: - return child((node).expression); + return visitNode(cbNode, (node).expression); case SyntaxKind.TryStatement: - return child((node).tryBlock) || - child((node).catchClause) || - child((node).finallyBlock); + return visitNode(cbNode, (node).tryBlock) || + visitNode(cbNode, (node).catchClause) || + visitNode(cbNode, (node).finallyBlock); case SyntaxKind.CatchClause: - return child((node).name) || - child((node).type) || - child((node).block); + return visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).type) || + visitNode(cbNode, (node).block); case SyntaxKind.ClassDeclaration: - return children(node.modifiers) || - child((node).name) || - children((node).typeParameters) || - children((node).heritageClauses) || - children((node).members); + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).name) || + visitNodes(cbNodes, (node).typeParameters) || + visitNodes(cbNodes, (node).heritageClauses) || + visitNodes(cbNodes, (node).members); case SyntaxKind.InterfaceDeclaration: - return children(node.modifiers) || - child((node).name) || - children((node).typeParameters) || - children((node).heritageClauses) || - children((node).members); + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).name) || + visitNodes(cbNodes, (node).typeParameters) || + visitNodes(cbNodes, (node).heritageClauses) || + visitNodes(cbNodes, (node).members); case SyntaxKind.TypeAliasDeclaration: - return children(node.modifiers) || - child((node).name) || - child((node).type); + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).type); case SyntaxKind.EnumDeclaration: - return children(node.modifiers) || - child((node).name) || - children((node).members); + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).name) || + visitNodes(cbNodes, (node).members); case SyntaxKind.EnumMember: - return child((node).name) || - child((node).initializer); + return visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).initializer); case SyntaxKind.ModuleDeclaration: - return children(node.modifiers) || - child((node).name) || - child((node).body); + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).body); case SyntaxKind.ImportDeclaration: - return children(node.modifiers) || - child((node).name) || - child((node).moduleReference); + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).moduleReference); case SyntaxKind.ExportAssignment: - return children(node.modifiers) || - child((node).exportName); + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).exportName); case SyntaxKind.TemplateExpression: - return child((node).head) || children((node).templateSpans); + return visitNode(cbNode, (node).head) || visitNodes(cbNodes, (node).templateSpans); case SyntaxKind.TemplateSpan: - return child((node).expression) || child((node).literal); + return visitNode(cbNode, (node).expression) || visitNode(cbNode, (node).literal); case SyntaxKind.ComputedPropertyName: - return child((node).expression); + return visitNode(cbNode, (node).expression); case SyntaxKind.HeritageClause: - return children((node).types); + return visitNodes(cbNodes, (node).types); case SyntaxKind.ExternalModuleReference: - return child((node).expression); + return visitNode(cbNode, (node).expression); } } @@ -1388,7 +1395,10 @@ module ts { } function canFollowModifier(): boolean { - return token === SyntaxKind.OpenBracketToken || token === SyntaxKind.AsteriskToken || isLiteralPropertyName(); + return token === SyntaxKind.OpenBracketToken + || token === SyntaxKind.OpenBraceToken + || token === SyntaxKind.AsteriskToken + || isLiteralPropertyName(); } // True if positioned at the start of a list element @@ -3480,16 +3490,16 @@ module ts { function parsePrimaryExpression(): PrimaryExpression { switch (token) { + case SyntaxKind.NumericLiteral: + case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + return parseLiteralNode(); case SyntaxKind.ThisKeyword: case SyntaxKind.SuperKeyword: case SyntaxKind.NullKeyword: case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: return parseTokenNode(); - case SyntaxKind.NumericLiteral: - case SyntaxKind.StringLiteral: - case SyntaxKind.NoSubstitutionTemplateLiteral: - return parseLiteralNode(); case SyntaxKind.OpenParenToken: return parseParenthesizedExpression(); case SyntaxKind.OpenBracketToken: diff --git a/src/compiler/program.ts b/src/compiler/program.ts index b506a86786b..06e63635232 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -146,7 +146,9 @@ module ts { function invokeEmitter(targetSourceFile?: SourceFile) { var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(); return emitFiles(resolver, getEmitHost(), targetSourceFile); - } function getSourceFile(filename: string) { + } + + function getSourceFile(filename: string) { filename = host.getCanonicalFileName(filename); return hasProperty(filesByName, filename) ? filesByName[filename] : undefined; } @@ -185,7 +187,10 @@ module ts { } } else { - if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) { + if (options.allowNonTsExtensions && !findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) { + diagnostic = Diagnostics.File_0_not_found; + } + else if (!findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) { diagnostic = Diagnostics.File_0_not_found; filename += ".ts"; } @@ -337,7 +342,7 @@ module ts { } var firstExternalModule = forEach(files, f => isExternalModule(f) ? f : undefined); - if (firstExternalModule && options.module === ModuleKind.None) { + if (firstExternalModule && !options.module) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet var externalModuleErrorSpan = getErrorSpanForNode(firstExternalModule.externalModuleIndicator); var errorStart = skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos); diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 427bc0012d6..4aef773004b 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -224,15 +224,15 @@ module ts { } function isUnicodeIdentifierStart(code: number, languageVersion: ScriptTarget) { - return languageVersion === ScriptTarget.ES3 ? - lookupInUnicodeMap(code, unicodeES3IdentifierStart) : - lookupInUnicodeMap(code, unicodeES5IdentifierStart); + return languageVersion >= ScriptTarget.ES5 ? + lookupInUnicodeMap(code, unicodeES5IdentifierStart) : + lookupInUnicodeMap(code, unicodeES3IdentifierStart); } function isUnicodeIdentifierPart(code: number, languageVersion: ScriptTarget) { - return languageVersion === ScriptTarget.ES3 ? - lookupInUnicodeMap(code, unicodeES3IdentifierPart) : - lookupInUnicodeMap(code, unicodeES5IdentifierPart); + return languageVersion >= ScriptTarget.ES5 ? + lookupInUnicodeMap(code, unicodeES5IdentifierPart) : + lookupInUnicodeMap(code, unicodeES3IdentifierPart); } function makeReverseMap(source: Map): string[] { @@ -279,7 +279,7 @@ module ts { } export function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number { - Debug.assert(line > 0); + Debug.assert(line > 0 && line <= lineStarts.length ); return lineStarts[line - 1] + character - 1; } @@ -1039,7 +1039,7 @@ module ts { value = 0; } tokenValue = "" + value; - return SyntaxKind.NumericLiteral; + return token = SyntaxKind.NumericLiteral; } else if (pos + 2 < len && (text.charCodeAt(pos + 1) === CharacterCodes.O || text.charCodeAt(pos + 1) === CharacterCodes.o)) { pos += 2; @@ -1049,7 +1049,7 @@ module ts { value = 0; } tokenValue = "" + value; - return SyntaxKind.NumericLiteral; + return token = SyntaxKind.NumericLiteral; } // Try to parse as an octal if (pos + 1 < len && isOctalDigit(text.charCodeAt(pos + 1))) { diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 27a8c305c4b..5f10a747d42 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -1,3 +1,4 @@ +/// module ts { export interface System { @@ -14,6 +15,7 @@ module ts { createDirectory(directoryName: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; + readDirectory(path: string, extension?: string): string[]; getMemoryUsage? (): number; exit(exitCode?: number): void; } @@ -28,6 +30,13 @@ module ts { declare var global: any; declare var __filename: string; + declare class Enumerator { + public atEnd(): boolean; + public moveNext(): boolean; + public item(): any; + constructor(o: any); + } + export var sys: System = (function () { function getWScriptSystem(): System { @@ -100,6 +109,34 @@ module ts { } } + function getNames(collection: any): string[] { + var result: string[] = []; + for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { + result.push(e.item().Name); + } + return result.sort(); + } + + function readDirectory(path: string, extension?: string): string[] { + var result: string[] = []; + visitDirectory(path); + return result; + function visitDirectory(path: string) { + var folder = fso.GetFolder(path || "."); + var files = getNames(folder.files); + for (var i = 0; i < files.length; i++) { + var name = files[i]; + if (!extension || fileExtensionIs(name, extension)) { + result.push(combinePaths(path, name)); + } + } + var subfolders = getNames(folder.subfolders); + for (var i = 0; i < subfolders.length; i++) { + visitDirectory(combinePaths(path, subfolders[i])); + } + } + } + return { args, newLine: "\r\n", @@ -129,6 +166,7 @@ module ts { getCurrentDirectory() { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + readDirectory, exit(exitCode?: number): void { try { WScript.Quit(exitCode); @@ -185,6 +223,31 @@ module ts { _fs.writeFileSync(fileName, data, "utf8"); } + function readDirectory(path: string, extension?: string): string[] { + var result: string[] = []; + visitDirectory(path); + return result; + function visitDirectory(path: string) { + var files = _fs.readdirSync(path || ".").sort(); + var directories: string[] = []; + for (var i = 0; i < files.length; i++) { + var name = combinePaths(path, files[i]); + var stat = _fs.lstatSync(name); + if (stat.isFile()) { + if (!extension || fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); + } + } + for (var i = 0; i < directories.length; i++) { + visitDirectory(directories[i]); + } + } + } + return { args: process.argv.slice(2), newLine: _os.EOL, @@ -231,6 +294,7 @@ module ts { getCurrentDirectory() { return process.cwd(); }, + readDirectory, getMemoryUsage() { if (global.gc) { global.gc(); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 9d038920693..ee5dc5104ff 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -4,6 +4,10 @@ module ts { var version = "1.4.0.0"; + export interface SourceFile { + fileWatcher: FileWatcher; + } + /** * Checks to see if the locale is in the appropriate format, * and if it is, attempts to set the appropriate language. @@ -126,16 +130,43 @@ module ts { reportStatisticalValue(name, (time / 1000).toFixed(2) + "s"); } + function isJSONSupported() { + return typeof JSON === "object" && typeof JSON.parse === "function"; + } + + function findConfigFile(): string { + var searchPath = normalizePath(sys.getCurrentDirectory()); + var filename = "tsconfig.json"; + while (true) { + if (sys.fileExists(filename)) { + return filename; + } + var parentPath = getDirectoryPath(searchPath); + if (parentPath === searchPath) { + break; + } + searchPath = parentPath; + filename = "../" + filename; + } + return undefined; + } + export function executeCommandLine(args: string[]): void { var commandLine = parseCommandLine(args); - var compilerOptions = commandLine.options; + var configFilename: string; // Configuration file name (if any) + var configFileWatcher: FileWatcher; // Configuration file watcher + var cachedProgram: Program; // Program cached from last compilation + var rootFilenames: string[]; // Root filenames for compilation + var compilerOptions: CompilerOptions; // Compiler options for compilation + var compilerHost: CompilerHost; // Compiler host + var hostGetSourceFile: typeof compilerHost.getSourceFile; // getSourceFile method from default host + var timerHandle: number; // Handle for 0.25s wait timer - if (compilerOptions.locale) { - if (typeof JSON === "undefined") { + if (commandLine.options.locale) { + if (!isJSONSupported()) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale")); - return sys.exit(1); + return sys.exit(EmitReturnStatus.CompilerOptionsErrors); } - validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); } @@ -146,131 +177,153 @@ module ts { return sys.exit(EmitReturnStatus.CompilerOptionsErrors); } - if (compilerOptions.version) { + if (commandLine.options.version) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); return sys.exit(EmitReturnStatus.Succeeded); } - if (compilerOptions.help) { + if (commandLine.options.help) { printVersion(); printHelp(); return sys.exit(EmitReturnStatus.Succeeded); } - if (commandLine.filenames.length === 0) { + if (commandLine.options.project) { + if (!isJSONSupported()) { + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project")); + return sys.exit(EmitReturnStatus.CompilerOptionsErrors); + } + configFilename = normalizePath(combinePaths(commandLine.options.project, "tsconfig.json")); + if (commandLine.filenames.length !== 0) { + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line)); + return sys.exit(EmitReturnStatus.CompilerOptionsErrors); + } + } + else if (commandLine.filenames.length === 0 && isJSONSupported()) { + configFilename = findConfigFile(); + } + + if (commandLine.filenames.length === 0 && !configFilename) { printVersion(); printHelp(); return sys.exit(EmitReturnStatus.CompilerOptionsErrors); } - var defaultCompilerHost = createCompilerHost(compilerOptions); - - if (compilerOptions.watch) { + if (commandLine.options.watch) { if (!sys.watchFile) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); return sys.exit(EmitReturnStatus.CompilerOptionsErrors); } - - watchProgram(commandLine, defaultCompilerHost); - } - else { - var result = compile(commandLine, defaultCompilerHost).exitStatus - return sys.exit(result); - } - } - - /** - * Compiles the program once, and then watches all given and referenced files for changes. - * Upon detecting a file change, watchProgram will queue up file modification events for the next - * 250ms and then perform a recompilation. The reasoning is that in some cases, an editor can - * save all files at once, and we'd like to just perform a single recompilation. - */ - function watchProgram(commandLine: ParsedCommandLine, compilerHost: CompilerHost): void { - var watchers: Map = {}; - var updatedFiles: Map = {}; - - // Compile the program the first time and watch all given/referenced files. - var program = compile(commandLine, compilerHost).program; - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes)); - addWatchers(program); - return; - - function addWatchers(program: Program) { - forEach(program.getSourceFiles(), f => { - var filename = getCanonicalName(f.filename); - watchers[filename] = sys.watchFile(filename, fileUpdated); - }); - } - - function removeWatchers(program: Program) { - forEach(program.getSourceFiles(), f => { - var filename = getCanonicalName(f.filename); - if (hasProperty(watchers, filename)) { - watchers[filename].close(); - } - }); - - watchers = {}; - } - - // Fired off whenever a file is changed. - function fileUpdated(filename: string) { - var firstNotification = isEmpty(updatedFiles); - updatedFiles[getCanonicalName(filename)] = true; - - // Only start this off when the first file change comes in, - // so that we can batch up all further changes. - if (firstNotification) { - setTimeout(() => { - var changedFiles = updatedFiles; - updatedFiles = {}; - - recompile(changedFiles); - }, 250); + if (configFilename) { + configFileWatcher = sys.watchFile(configFilename, configFileChanged); } } - function recompile(changedFiles: Map) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.File_change_detected_Compiling)); - // Remove all the watchers, as we may not be watching every file - // specified since the last compilation cycle. - removeWatchers(program); + performCompilation(); - // Reuse source files from the last compilation so long as they weren't changed. - var oldSourceFiles = arrayToMap( - filter(program.getSourceFiles(), file => !hasProperty(changedFiles, getCanonicalName(file.filename))), - file => getCanonicalName(file.filename)); + // Invoked to perform initial compilation or re-compilation in watch mode + function performCompilation() { - // We create a new compiler host for this compilation cycle. - // This new host is effectively the same except that 'getSourceFile' - // will try to reuse the SourceFiles from the last compilation cycle - // so long as they were not modified. - var newCompilerHost = clone(compilerHost); - newCompilerHost.getSourceFile = (fileName, languageVersion, onError) => { - fileName = getCanonicalName(fileName); - - var sourceFile = lookUp(oldSourceFiles, fileName); - if (sourceFile) { - return sourceFile; + if (!cachedProgram) { + if (configFilename) { + var configObject = readConfigFile(configFilename); + if (!configObject) { + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, configFilename)); + return sys.exit(EmitReturnStatus.CompilerOptionsErrors); + } + var configParseResult = parseConfigFile(configObject, getDirectoryPath(configFilename)); + if (configParseResult.errors.length > 0) { + reportDiagnostics(configParseResult.errors); + return sys.exit(EmitReturnStatus.CompilerOptionsErrors); + } + rootFilenames = configParseResult.filenames; + compilerOptions = extend(commandLine.options, configParseResult.options); } + else { + rootFilenames = commandLine.filenames; + compilerOptions = commandLine.options; + } + compilerHost = createCompilerHost(compilerOptions); + hostGetSourceFile = compilerHost.getSourceFile; + compilerHost.getSourceFile = getSourceFile; + } - return compilerHost.getSourceFile(fileName, languageVersion, onError); - }; + var compileResult = compile(rootFilenames, compilerOptions, compilerHost); - program = compile(commandLine, newCompilerHost).program; + if (!commandLine.options.watch) { + return sys.exit(compileResult.exitStatus); + } + + setCachedProgram(compileResult.program); reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes)); - addWatchers(program); } - function getCanonicalName(fileName: string) { - return compilerHost.getCanonicalFileName(fileName); + function getSourceFile(filename: string, languageVersion: ScriptTarget, onError ?: (message: string) => void) { + // Return existing SourceFile object if one is available + if (cachedProgram) { + var sourceFile = cachedProgram.getSourceFile(filename); + // A modified source file has no watcher and should not be reused + if (sourceFile && sourceFile.fileWatcher) { + return sourceFile; + } + } + // Use default host function + var sourceFile = hostGetSourceFile(filename, languageVersion, onError); + if (sourceFile && commandLine.options.watch) { + // Attach a file watcher + sourceFile.fileWatcher = sys.watchFile(sourceFile.filename, () => sourceFileChanged(sourceFile)); + } + return sourceFile; + } + + // Change cached program to the given program + function setCachedProgram(program: Program) { + if (cachedProgram) { + var newSourceFiles = program ? program.getSourceFiles() : undefined; + forEach(cachedProgram.getSourceFiles(), sourceFile => { + if (!(newSourceFiles && contains(newSourceFiles, sourceFile))) { + if (sourceFile.fileWatcher) { + sourceFile.fileWatcher.close(); + sourceFile.fileWatcher = undefined; + } + } + }); + } + cachedProgram = program; + } + + // If a source file changes, mark it as unwatched and start the recompilation timer + function sourceFileChanged(sourceFile: SourceFile) { + sourceFile.fileWatcher = undefined; + startTimer(); + } + + // If the configuration file changes, forget cached program and start the recompilation timer + function configFileChanged() { + setCachedProgram(undefined); + startTimer(); + } + + // Upon detecting a file change, wait for 250ms and then perform a recompilation. This gives batch + // operations (such as saving all modified files in an editor) a chance to complete before we kick + // off a new compilation. + function startTimer() { + if (timerHandle) { + clearTimeout(timerHandle); + } + timerHandle = setTimeout(recompile, 250); + } + + function recompile() { + timerHandle = undefined; + reportDiagnostic(createCompilerDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation)); + performCompilation(); } } - function compile(commandLine: ParsedCommandLine, compilerHost: CompilerHost) { + function compile(filenames: string[], compilerOptions: CompilerOptions, compilerHost: CompilerHost) { var parseStart = new Date().getTime(); - var compilerOptions = commandLine.options; - var program = createProgram(commandLine.filenames, compilerOptions, compilerHost); + var program = createProgram(filenames, compilerOptions, compilerHost); var bindStart = new Date().getTime(); var errors: Diagnostic[] = program.getDiagnostics(); @@ -303,7 +356,14 @@ module ts { } reportDiagnostics(errors); - if (commandLine.options.diagnostics) { + + if (compilerOptions.listFiles) { + forEach(program.getSourceFiles(), file => { + sys.write(file.filename + sys.newLine); + }); + } + + if (compilerOptions.diagnostics) { var memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1; reportCountStatistic("Files", program.getSourceFiles().length); reportCountStatistic("Lines", countLines(program)); diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json new file mode 100644 index 00000000000..fd541a8ca80 --- /dev/null +++ b/src/compiler/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": true, + "removeComments": true, + "preserveConstEnums": true, + "out": "../../built/local/tsc.js", + "sourceMap": true + }, + "files": [ + "core.ts", + "sys.ts", + "types.ts", + "scanner.ts", + "parser.ts", + "utilities.ts", + "binder.ts", + "checker.ts", + "emitter.ts", + "program.ts", + "commandLineParser.ts", + "tsc.ts", + "diagnosticInformationMap.generated.ts" + ] +} diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 60ed8352b9a..b8c842641d7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1331,8 +1331,6 @@ module ts { // Generic class and interface types export interface GenericType extends InterfaceType, TypeReference { instantiations: Map; // Generic instantiation cache - openReferenceTargets: GenericType[]; // Open type reference targets - openReferenceChecks: Map; // Open type reference check cache } export interface TupleType extends ObjectType { @@ -1450,6 +1448,7 @@ module ts { diagnostics?: boolean; emitBOM?: boolean; help?: boolean; + listFiles?: boolean; locale?: string; mapRoot?: string; module?: ModuleKind; @@ -1463,6 +1462,7 @@ module ts { out?: string; outDir?: string; preserveConstEnums?: boolean; + project?: string; removeComments?: boolean; sourceMap?: boolean; sourceRoot?: string; @@ -1503,10 +1503,11 @@ module ts { export interface CommandLineOption { name: string; type: string | Map; // "string", "number", "boolean", or an object literal mapping named values to actual values - shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'. + isFilePath?: boolean; // True if option value is a path or filename + shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help' description?: DiagnosticMessage; // The message describing what the command line switch does - paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter. - error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'. + paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter + error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type' } export const enum CharacterCodes { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index edd8bf156cf..7494ec9f6cb 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -23,6 +23,17 @@ module ts { string(): string; } + export interface EmitHost extends ScriptReferenceHost { + getSourceFiles(): SourceFile[]; + isEmitBlocked(sourceFile?: SourceFile): boolean; + + getCommonSourceDirectory(): string; + getCanonicalFileName(fileName: string): string; + getNewLine(): string; + + writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; + } + // Pool writers to avoid needing to allocate them for every symbol we write. var stringWriters: StringSymbolWriter[] = []; export function getSingleLineStringWriter(): StringSymbolWriter { @@ -525,6 +536,12 @@ module ts { return false; } + export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) { + var moduleState = getModuleInstanceState(node) + return moduleState === ModuleInstanceState.Instantiated || + (preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly); + } + export function isExternalModuleImportDeclaration(node: Node) { return node.kind === SyntaxKind.ImportDeclaration && (node).moduleReference.kind === SyntaxKind.ExternalModuleReference; } diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 29861d3e556..a88620c4e6c 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -61,12 +61,6 @@ class CompilerBaselineRunner extends RunnerBase { var otherFiles: { unitName: string; content: string }[]; var harnessCompiler: Harness.Compiler.HarnessCompiler; - var declFileCompilationResult: { - declInputFiles: { unitName: string; content: string }[]; - declOtherFiles: { unitName: string; content: string }[]; - declResult: Harness.Compiler.CompilerResult; - }; - var createNewInstance = false; before(() => { @@ -143,7 +137,6 @@ class CompilerBaselineRunner extends RunnerBase { toBeCompiled = undefined; otherFiles = undefined; harnessCompiler = undefined; - declFileCompilationResult = undefined; }); function getByteOrderMarkText(file: Harness.Compiler.GeneratedFile): string { @@ -179,13 +172,6 @@ class CompilerBaselineRunner extends RunnerBase { } }); - // Compile .d.ts files - it('Correct compiler generated.d.ts for ' + fileName, () => { - declFileCompilationResult = harnessCompiler.compileDeclarationFiles(toBeCompiled, otherFiles, result, function (settings) { - harnessCompiler.setCompilerSettings(tcSettings); - }, options); - }); - it('Correct JS output for ' + fileName, () => { if (!ts.fileExtensionIs(lastUnit.name, '.d.ts') && this.emit) { @@ -223,6 +209,10 @@ class CompilerBaselineRunner extends RunnerBase { } } + var declFileCompilationResult = harnessCompiler.compileDeclarationFiles(toBeCompiled, otherFiles, result, function (settings) { + harnessCompiler.setCompilerSettings(tcSettings); + }, options); + if (declFileCompilationResult && declFileCompilationResult.declResult.errors.length) { jsCode += '\r\n\r\n//// [DtsFileErrors]\r\n'; jsCode += '\r\n\r\n'; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index d0c2db1e8a7..df73e52a605 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -22,6 +22,7 @@ declare var require: any; declare var process: any; +var Buffer = require('buffer').Buffer; // this will work in the browser via browserify var _chai: typeof chai = require('chai'); @@ -810,7 +811,9 @@ module Harness { export function createCompilerHost(inputFiles: { unitName: string; content: string; }[], writeFile: (fn: string, contents: string, writeByteOrderMark: boolean) => void, scriptTarget: ts.ScriptTarget, - useCaseSensitiveFileNames: boolean): ts.CompilerHost { + useCaseSensitiveFileNames: boolean, + // the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host + currentDirectory?: string): ts.CompilerHost { // Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames function getCanonicalFileName(fileName: string): string { @@ -818,6 +821,8 @@ module Harness { } var filemap: { [filename: string]: ts.SourceFile; } = {}; + var getCurrentDirectory = currentDirectory === undefined ? ts.sys.getCurrentDirectory : () => currentDirectory; + // Register input files function register(file: { unitName: string; content: string; }) { if (file.content !== undefined) { @@ -828,11 +833,15 @@ module Harness { inputFiles.forEach(register); return { - getCurrentDirectory: ts.sys.getCurrentDirectory, + getCurrentDirectory, getSourceFile: (fn, languageVersion) => { if (Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(fn))) { return filemap[getCanonicalFileName(fn)]; } + else if (currentDirectory) { + var canonicalAbsolutePath = getCanonicalFileName(ts.getNormalizedAbsolutePath(fn, currentDirectory)); + return Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(canonicalAbsolutePath)) ? filemap[canonicalAbsolutePath] : undefined; + } else if (fn === fourslashFilename) { var tsFn = 'tests/cases/fourslash/' + fourslashFilename; fourslashSourceFile = fourslashSourceFile || ts.createSourceFile(tsFn, Harness.IO.readFile(tsFn), scriptTarget); @@ -909,7 +918,9 @@ module Harness { otherFiles: { unitName: string; content: string }[], onComplete: (result: CompilerResult, program: ts.Program) => void, settingsCallback?: (settings: ts.CompilerOptions) => void, - options?: ts.CompilerOptions) { + options?: ts.CompilerOptions, + // Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file + currentDirectory?: string) { options = options || { noResolve: false }; options.target = options.target || ts.ScriptTarget.ES3; @@ -1063,8 +1074,7 @@ module Harness { var programFiles = inputFiles.map(file => file.unitName); var program = ts.createProgram(programFiles, options, createCompilerHost(inputFiles.concat(otherFiles), (fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }), - options.target, - useCaseSensitiveFileNames)); + options.target, useCaseSensitiveFileNames, currentDirectory)); var checker = program.getTypeChecker(/*produceDiagnostics*/ true); @@ -1095,7 +1105,9 @@ module Harness { otherFiles: { unitName: string; content: string; }[], result: CompilerResult, settingsCallback?: (settings: ts.CompilerOptions) => void, - options?: ts.CompilerOptions) { + options?: ts.CompilerOptions, + // Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file + currentDirectory?: string) { 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'); } @@ -1108,9 +1120,8 @@ module Harness { ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles)); ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles)); - this.compileFiles(declInputFiles, declOtherFiles, function (compileResult) { - declResult = compileResult; - }, settingsCallback, options); + this.compileFiles(declInputFiles, declOtherFiles, function (compileResult) { declResult = compileResult; }, + settingsCallback, options, currentDirectory); return { declInputFiles, declOtherFiles, declResult }; } @@ -1127,29 +1138,27 @@ module Harness { } 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.getNormalizedAbsolutePath(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"; + var sourceFile = result.program.getSourceFile(fileName); + assert(sourceFile, "Program has no source file with name '" + fileName + "'"); + // Is this file going to be emitted separately + var sourceFileName: string; + if (ts.isExternalModule(sourceFile) || !options.out) { + if (options.outDir) { + var sourceFilePath = ts.getNormalizedAbsolutePath(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; + } + var dTsFileName = ts.removeFileExtension(sourceFileName) + ".d.ts"; + return ts.forEach(result.declFilesCode, declFile => declFile.fileName === dTsFileName ? declFile : undefined); } @@ -1199,7 +1208,6 @@ module Harness { export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: HarnessDiagnostic[]) { diagnostics.sort(compareDiagnostics); - var outputLines: string[] = []; // Count up all the errors we find so we don't miss any var totalErrorsReported = 0; @@ -1290,8 +1298,13 @@ module Harness { return diagnostic.filename && isLibraryFile(diagnostic.filename); }); + var numTest262HarnessDiagnostics = ts.countWhere(diagnostics, diagnostic => { + // Count an error generated from tests262-harness folder.This should only apply for test262 + return diagnostic.filename && diagnostic.filename.indexOf("test262-harness") >= 0; + }); + // Verify we didn't miss any errors in total - assert.equal(totalErrorsReported + numLibraryDiagnostics, diagnostics.length, 'total number of errors'); + assert.equal(totalErrorsReported + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length, 'total number of errors'); return minimalDiagnosticsToString(diagnostics) + ts.sys.newLine + ts.sys.newLine + outputLines.join('\r\n'); @@ -1634,7 +1647,8 @@ module Harness { } function writeComparison(expected: string, actual: string, relativeFilename: string, actualFilename: string, descriptionForDescribe: string) { - if (expected != actual) { + var encoded_actual = (new Buffer(actual)).toString('utf8') + if (expected != encoded_actual) { // Overwrite & issue error var errMsg = 'The baseline file ' + relativeFilename + ' has changed'; throw new Error(errMsg); diff --git a/src/harness/instrumenter.ts b/src/harness/instrumenter.ts index 61f6a8f2ec3..1c9b9af78d2 100644 --- a/src/harness/instrumenter.ts +++ b/src/harness/instrumenter.ts @@ -3,11 +3,11 @@ var fs: any = require('fs'); var path: any = require('path'); function instrumentForRecording(fn: string, tscPath: string) { - instrument(tscPath, 'sys = Playback.wrapSystem(sys); sys.startRecord("' + fn + '");', 'sys.endRecord();'); + instrument(tscPath, 'ts.sys = Playback.wrapSystem(ts.sys); ts.sys.startRecord("' + fn + '");', 'ts.sys.endRecord();'); } function instrumentForReplay(logFilename: string, tscPath: string) { - instrument(tscPath, 'sys = Playback.wrapSystem(sys); sys.startReplay("' + logFilename + '");'); + instrument(tscPath, 'ts.sys = Playback.wrapSystem(ts.sys); ts.sys.startReplay("' + logFilename + '");'); } function instrument(tscPath: string, prepareCode: string, cleanupCode: string = '') { @@ -27,8 +27,12 @@ function instrument(tscPath: string, prepareCode: string, cleanupCode: string = fs.readFile(path.resolve(path.dirname(tscPath) + '/loggedIO.js'), 'utf-8', (err: any, loggerContent: string) => { if (err) throw err; - var invocationLine = 'ts.executeCommandLine(sys.args);'; + var invocationLine = 'ts.executeCommandLine(ts.sys.args);'; var index1 = tscContent.indexOf(invocationLine); + if (index1 < 0) { + throw new Error("Could not find " + invocationLine); + } + var index2 = index1 + invocationLine.length; var newContent = tscContent.substr(0, index1) + loggerContent + prepareCode + invocationLine + cleanupCode + tscContent.substr(index2) + '\r\n'; fs.writeFile(tscPath, newContent); diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 8d22b1da1d8..b506cdd66b6 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -28,12 +28,7 @@ module RWC { var compilerOptions: ts.CompilerOptions; var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' }; var baseName = /(.*)\/(.*).json/.exec(ts.normalizeSlashes(jsonPath))[2]; - // Compile .d.ts files - var declFileCompilationResult: { - declInputFiles: { unitName: string; content: string }[]; - declOtherFiles: { unitName: string; content: string }[]; - declResult: Harness.Compiler.CompilerResult; - }; + var currentDirectory: string; after(() => { // Mocha holds onto the closure environment of the describe callback even after the test is done. @@ -44,7 +39,7 @@ module RWC { compilerOptions = undefined; baselineOpts = undefined; baseName = undefined; - declFileCompilationResult = undefined; + currentDirectory = undefined; }); it('can compile', () => { @@ -52,6 +47,7 @@ module RWC { var opts: ts.ParsedCommandLine; var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath)); + currentDirectory = ioLog.currentDirectory; runWithIOLog(ioLog, () => { opts = ts.parseCommandLine(ioLog.arguments); assert.equal(opts.errors.length, 0); @@ -59,7 +55,6 @@ module RWC { runWithIOLog(ioLog, () => { harnessCompiler.reset(); - // Load the files ts.forEach(opts.filenames, fileName => { inputFiles.push(getHarnessCompilerInputUnit(fileName)); @@ -88,7 +83,11 @@ module RWC { // Emit the results compilerOptions = harnessCompiler.compileFiles(inputFiles, otherFiles, compileResult => { compilerResult = compileResult; - }, /*settingsCallback*/ undefined, opts.options); + }, + /*settingsCallback*/ undefined, opts.options, + // Since all Rwc json file specified current directory in its json file, we need to pass this information to compilerHost + // so that when the host is asked for current directory, it should give the value from json rather than from process + currentDirectory); }); function getHarnessCompilerInputUnit(fileName: string) { @@ -103,11 +102,6 @@ module RWC { } }); - // 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', () => { @@ -152,9 +146,13 @@ module RWC { }, false, baselineOpts); }); - it('has no errors in generated declaration files', () => { + // Ideally, a generated declaration file will have no errors. But we allow generated + // declaration file errors as part of the baseline. + it('has the expected 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', () => { + Harness.Baseline.runBaseline('has the expected errors in generated declaration files', baseName + '.dts.errors.txt', () => { + var declFileCompilationResult = Harness.Compiler.getCompiler().compileDeclarationFiles(inputFiles, otherFiles, compilerResult, + /*settingscallback*/ undefined, compilerOptions, currentDirectory); if (declFileCompilationResult.declResult.errors.length === 0) { return null; } diff --git a/src/services/compiler/tsc.ts b/src/services/compiler/tsc.ts index e77ea9467ca..acd4fb40e6a 100644 --- a/src/services/compiler/tsc.ts +++ b/src/services/compiler/tsc.ts @@ -413,7 +413,7 @@ module TypeScript { opts.flag('noImplicitAny', { usage: { - locCode: DiagnosticCode.Warn_on_expressions_and_declarations_with_an_implied_any_type, + locCode: DiagnosticCode.Raise_error_on_expressions_and_declarations_with_an_implied_any_type, args: null }, set: () => { diff --git a/src/services/core/timer.ts b/src/services/core/timer.ts deleted file mode 100644 index 7d6e3b0784e..00000000000 --- a/src/services/core/timer.ts +++ /dev/null @@ -1,52 +0,0 @@ -/// - -var global: any = Function("return this").call(null); - -module TypeScript { - module Clock { - export var now: () => number; - export var resolution: number; - - declare module WScript { - export function InitializeProjection(): void; - } - - declare module TestUtilities { - export function QueryPerformanceCounter(): number; - export function QueryPerformanceFrequency(): number; - } - - if (typeof WScript !== "undefined" && typeof global['WScript'].InitializeProjection !== "undefined") { - // Running in JSHost. - global['WScript'].InitializeProjection(); - - now = function () { - return TestUtilities.QueryPerformanceCounter(); - }; - - resolution = TestUtilities.QueryPerformanceFrequency(); - } - else { - now = function () { - return Date.now(); - }; - - resolution = 1000; - } - } - - export class Timer { - public startTime: number; - public time = 0; - - public start() { - this.time = 0; - this.startTime = Clock.now(); - } - - public end() { - // Set time to MS. - this.time = (Clock.now() - this.startTime); - } - } -} \ No newline at end of file diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index b5edf776d58..cab7547557c 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -68,7 +68,9 @@ module ts.formatting { export function formatOnEnter(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeOptions): TextChange[] { var line = sourceFile.getLineAndCharacterFromPosition(position).line; - Debug.assert(line >= 2); + if (line === 1) { + return []; + } // get the span for the previous\current line var span = { // get start position for the previous line @@ -241,8 +243,18 @@ module ts.formatting { } var precedingToken = findPrecedingToken(originalRange.pos, sourceFile); - // no preceding token found - start from the beginning of enclosing node - return precedingToken ? precedingToken.end : enclosingNode.pos; + if (!precedingToken) { + // no preceding token found - start from the beginning of enclosing node + return enclosingNode.pos; + } + + // preceding token ends after the start of original range (i.e when originaRange.pos falls in the middle of literal) + // start from the beginning of enclosingNode to handle the entire 'originalRange' + if (precedingToken.end >= originalRange.pos) { + return enclosingNode.pos; + } + + return precedingToken.end; } /* @@ -597,7 +609,11 @@ module ts.formatting { if (listEndToken !== SyntaxKind.Unknown) { if (formattingScanner.isOnToken()) { var tokenInfo = formattingScanner.readTokenInfo(parent); - if (tokenInfo.token.kind === listEndToken) { + // consume the list end token only if it is still belong to the parent + // there might be the case when current token matches end token but does not considered as one + // function (x: function) <-- + // without this check close paren will be interpreted as list end token for function expression which is wrong + if (tokenInfo.token.kind === listEndToken && rangeContainsRange(parent, tokenInfo.token)) { // consume list end token consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation); } diff --git a/src/services/formatting/formattingScanner.ts b/src/services/formatting/formattingScanner.ts index 7ddfecc17f2..e9485158aba 100644 --- a/src/services/formatting/formattingScanner.ts +++ b/src/services/formatting/formattingScanner.ts @@ -187,6 +187,9 @@ module ts.formatting { } // consume trailing trivia + if (trailingTrivia) { + trailingTrivia = undefined; + } while(scanner.getStartPos() < endPos) { currentToken = scanner.scan(); if (!isTrivia(currentToken)) { diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index ce240a95168..3aa97fe6ae6 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -12,10 +12,15 @@ module ts.formatting { return 0; } - // no indentation in string \regex literals - if ((precedingToken.kind === SyntaxKind.StringLiteral || precedingToken.kind === SyntaxKind.RegularExpressionLiteral) && - precedingToken.getStart(sourceFile) <= position && - precedingToken.end > position) { + // no indentation in string \regex\template literals + var precedingTokenIsLiteral = + precedingToken.kind === SyntaxKind.StringLiteral || + precedingToken.kind === SyntaxKind.RegularExpressionLiteral || + precedingToken.kind === SyntaxKind.NoSubstitutionTemplateLiteral || + precedingToken.kind === SyntaxKind.TemplateHead || + precedingToken.kind === SyntaxKind.TemplateMiddle || + precedingToken.kind === SyntaxKind.TemplateTail; + if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { return 0; } diff --git a/src/services/resources/diagnosticCode.generated.ts b/src/services/resources/diagnosticCode.generated.ts index 03c4efea480..86509fdd63b 100644 --- a/src/services/resources/diagnosticCode.generated.ts +++ b/src/services/resources/diagnosticCode.generated.ts @@ -436,7 +436,7 @@ module TypeScript { This_version_of_the_Javascript_runtime_does_not_support_the_0_function: "This version of the Javascript runtime does not support the '{0}' function.", Unknown_rule: "Unknown rule.", Invalid_line_number_0: "Invalid line number ({0})", - Warn_on_expressions_and_declarations_with_an_implied_any_type: "Warn on expressions and declarations with an implied 'any' type.", + Raise_error_on_expressions_and_declarations_with_an_implied_any_type: "Raise error on expressions and declarations with an implied 'any' type.", Variable_0_implicitly_has_an_any_type: "Variable '{0}' implicitly has an 'any' type.", Parameter_0_of_1_implicitly_has_an_any_type: "Parameter '{0}' of '{1}' implicitly has an 'any' type.", Parameter_0_of_function_type_implicitly_has_an_any_type: "Parameter '{0}' of function type implicitly has an 'any' type.", diff --git a/src/services/resources/diagnosticMessages.json b/src/services/resources/diagnosticMessages.json index 54ecbb75370..60a0bb48df9 100644 --- a/src/services/resources/diagnosticMessages.json +++ b/src/services/resources/diagnosticMessages.json @@ -1743,7 +1743,7 @@ "category": "Error", "code": 7003 }, - "Warn on expressions and declarations with an implied 'any' type.": { + "Raise error on expressions and declarations with an implied 'any' type.": { "category": "Message", "code": 7004 }, diff --git a/src/services/services.ts b/src/services/services.ts index 1618fb6e276..84e5e7fefa5 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -852,6 +852,7 @@ module ts { // export interface LanguageServiceHost extends Logger { getCompilationSettings(): CompilerOptions; + getNewLine?(): string; getScriptFileNames(): string[]; getScriptVersion(fileName: string): string; getScriptIsOpen(fileName: string): boolean; @@ -1962,7 +1963,9 @@ module ts { getCancellationToken: () => cancellationToken, getCanonicalFileName: (filename) => useCaseSensitivefilenames ? filename : filename.toLowerCase(), useCaseSensitiveFileNames: () => useCaseSensitivefilenames, - getNewLine: () => "\r\n", + getNewLine: () => { + return host.getNewLine ? host.getNewLine() : "\r\n"; + }, getDefaultLibFilename: (options): string => { return host.getDefaultLibFilename(options); }, diff --git a/src/services/syntax/SyntaxGenerator.d.ts b/src/services/syntax/SyntaxGenerator.d.ts index 4a833f07587..d01d227b786 100644 --- a/src/services/syntax/SyntaxGenerator.d.ts +++ b/src/services/syntax/SyntaxGenerator.d.ts @@ -417,7 +417,7 @@ declare module TypeScript { This_version_of_the_Javascript_runtime_does_not_support_the_0_function: string; Unknown_rule: string; Invalid_line_number_0: string; - Warn_on_expressions_and_declarations_with_an_implied_any_type: string; + Raise_error_on_expressions_and_declarations_with_an_implied_any_type: string; Variable_0_implicitly_has_an_any_type: string; Parameter_0_of_1_implicitly_has_an_any_type: string; Parameter_0_of_function_type_implicitly_has_an_any_type: string; diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json new file mode 100644 index 00000000000..296e65965d5 --- /dev/null +++ b/src/services/tsconfig.json @@ -0,0 +1,47 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": true, + "removeComments": true, + "preserveConstEnums": true, + "out": "../../built/local/typescriptServices.js", + "sourceMap": true + }, + "files": [ + "../compiler/core.ts", + "../compiler/sys.ts", + "../compiler/types.ts", + "../compiler/scanner.ts", + "../compiler/parser.ts", + "../compiler/utilities.ts", + "../compiler/binder.ts", + "../compiler/checker.ts", + "../compiler/emitter.ts", + "../compiler/program.ts", + "../compiler/commandLineParser.ts", + "../compiler/diagnosticInformationMap.generated.ts", + "breakpoints.ts", + "navigationBar.ts", + "outliningElementsCollector.ts", + "services.ts", + "shims.ts", + "signatureHelp.ts", + "utilities.ts", + "formatting/formatting.ts", + "formatting/formattingContext.ts", + "formatting/formattingRequestKind.ts", + "formatting/formattingScanner.ts", + "formatting/references.ts", + "formatting/rule.ts", + "formatting/ruleAction.ts", + "formatting/ruleDescriptor.ts", + "formatting/ruleFlag.ts", + "formatting/ruleOperation.ts", + "formatting/ruleOperationContext.ts", + "formatting/rules.ts", + "formatting/rulesMap.ts", + "formatting/rulesProvider.ts", + "formatting/smartIndenter.ts", + "formatting/tokenRange.ts" + ] +} diff --git a/tests/baselines/reference/TypeGuardWithArrayUnion.js b/tests/baselines/reference/TypeGuardWithArrayUnion.js new file mode 100644 index 00000000000..cf98d2c2453 --- /dev/null +++ b/tests/baselines/reference/TypeGuardWithArrayUnion.js @@ -0,0 +1,23 @@ +//// [TypeGuardWithArrayUnion.ts] +class Message { + value: string; +} + +function saySize(message: Message | Message[]) { + if (message instanceof Array) { + return message.length; // Should have type Message[] here + } +} + + +//// [TypeGuardWithArrayUnion.js] +var Message = (function () { + function Message() { + } + return Message; +})(); +function saySize(message) { + if (message instanceof Array) { + return message.length; // Should have type Message[] here + } +} diff --git a/tests/baselines/reference/TypeGuardWithArrayUnion.types b/tests/baselines/reference/TypeGuardWithArrayUnion.types new file mode 100644 index 00000000000..557e305ef74 --- /dev/null +++ b/tests/baselines/reference/TypeGuardWithArrayUnion.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/expressions/typeGuards/TypeGuardWithArrayUnion.ts === +class Message { +>Message : Message + + value: string; +>value : string +} + +function saySize(message: Message | Message[]) { +>saySize : (message: Message | Message[]) => number +>message : Message | Message[] +>Message : Message +>Message : Message + + if (message instanceof Array) { +>message instanceof Array : boolean +>message : Message | Message[] +>Array : ArrayConstructor + + return message.length; // Should have type Message[] here +>message.length : number +>message : Message[] +>length : number + } +} + diff --git a/tests/baselines/reference/baseIndexSignatureResolution.js b/tests/baselines/reference/baseIndexSignatureResolution.js index 4c2d63bf2c9..4720e92b969 100644 --- a/tests/baselines/reference/baseIndexSignatureResolution.js +++ b/tests/baselines/reference/baseIndexSignatureResolution.js @@ -55,27 +55,4 @@ interface B extends A { } var b: B = null; var z: Derived = b.foo(); -class Base { private a: string; } -class Derived extends Base { private b: string; } - -// Note - commmenting "extends Foo" prevents the error -interface Foo { - [i: number]: Base; -} -interface FooOf extends Foo { - [i: number]: TBase; -} -var x: FooOf = null; -var y: Derived = x[0]; - -/* -// Note - the equivalent for normal interface methods works fine: -interface A { - foo(): Base; -} -interface B extends A { - foo(): TBase; -} -var b: B = null; -var z: Derived = b.foo(); - +*/ diff --git a/tests/baselines/reference/castTest.types b/tests/baselines/reference/castTest.types index 501ff5a3cbe..8250bec362d 100644 --- a/tests/baselines/reference/castTest.types +++ b/tests/baselines/reference/castTest.types @@ -65,8 +65,8 @@ var p_cast = ({ >p_cast : Point > ({ x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }, mult: function(p) { return p; }}) : Point >Point : Point ->({ x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }, mult: function(p) { return p; }}) : { x: number; y: number; add: (dx: any, dy: any) => Point; mult: (p: any) => any; } ->{ x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }, mult: function(p) { return p; }} : { x: number; y: number; add: (dx: any, dy: any) => Point; mult: (p: any) => any; } +>({ x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }, mult: function(p) { return p; }}) : { x: number; y: number; add: (dx: number, dy: number) => Point; mult: (p: Point) => Point; } +>{ x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }, mult: function(p) { return p; }} : { x: number; y: number; add: (dx: number, dy: number) => Point; mult: (p: Point) => Point; } x: 0, >x : number @@ -75,10 +75,10 @@ var p_cast = ({ >y : number add: function(dx, dy) { ->add : (dx: any, dy: any) => Point ->function(dx, dy) { return new Point(this.x + dx, this.y + dy); } : (dx: any, dy: any) => Point ->dx : any ->dy : any +>add : (dx: number, dy: number) => Point +>function(dx, dy) { return new Point(this.x + dx, this.y + dy); } : (dx: number, dy: number) => Point +>dx : number +>dy : number return new Point(this.x + dx, this.y + dy); >new Point(this.x + dx, this.y + dy) : Point @@ -87,19 +87,19 @@ var p_cast = ({ >this.x : any >this : any >x : any ->dx : any +>dx : number >this.y + dy : any >this.y : any >this : any >y : any ->dy : any +>dy : number }, mult: function(p) { return p; } ->mult : (p: any) => any ->function(p) { return p; } : (p: any) => any ->p : any ->p : any +>mult : (p: Point) => Point +>function(p) { return p; } : (p: Point) => Point +>p : Point +>p : Point }) diff --git a/tests/baselines/reference/cloduleWithPriorInstantiatedModule.errors.txt b/tests/baselines/reference/cloduleWithPriorInstantiatedModule.errors.txt new file mode 100644 index 00000000000..1b0d9cf13ca --- /dev/null +++ b/tests/baselines/reference/cloduleWithPriorInstantiatedModule.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/cloduleWithPriorInstantiatedModule.ts(2,8): error TS2434: A module declaration cannot be located prior to a class or function with which it is merged + + +==== tests/cases/compiler/cloduleWithPriorInstantiatedModule.ts (1 errors) ==== + // Non-ambient & instantiated module. + module Moclodule { + ~~~~~~~~~ +!!! error TS2434: A module declaration cannot be located prior to a class or function with which it is merged + export interface Someinterface { + foo(): void; + } + var x = 10; + } + + class Moclodule { + } + + // Instantiated module. + module Moclodule { + export class Manager { + } + } \ No newline at end of file diff --git a/tests/baselines/reference/cloduleWithPriorInstantiatedModule.js b/tests/baselines/reference/cloduleWithPriorInstantiatedModule.js new file mode 100644 index 00000000000..601ab0a7536 --- /dev/null +++ b/tests/baselines/reference/cloduleWithPriorInstantiatedModule.js @@ -0,0 +1,39 @@ +//// [cloduleWithPriorInstantiatedModule.ts] +// Non-ambient & instantiated module. +module Moclodule { + export interface Someinterface { + foo(): void; + } + var x = 10; +} + +class Moclodule { +} + +// Instantiated module. +module Moclodule { + export class Manager { + } +} + +//// [cloduleWithPriorInstantiatedModule.js] +// Non-ambient & instantiated module. +var Moclodule; +(function (Moclodule) { + var x = 10; +})(Moclodule || (Moclodule = {})); +var Moclodule = (function () { + function Moclodule() { + } + return Moclodule; +})(); +// Instantiated module. +var Moclodule; +(function (Moclodule) { + var Manager = (function () { + function Manager() { + } + return Manager; + })(); + Moclodule.Manager = Manager; +})(Moclodule || (Moclodule = {})); diff --git a/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.js b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.js new file mode 100644 index 00000000000..cf06f1134fb --- /dev/null +++ b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.js @@ -0,0 +1,33 @@ +//// [cloduleWithPriorUninstantiatedModule.ts] +// Non-ambient & uninstantiated module. +module Moclodule { + export interface Someinterface { + foo(): void; + } +} + +class Moclodule { +} + +// Instantiated module. +module Moclodule { + export class Manager { + } +} + +//// [cloduleWithPriorUninstantiatedModule.js] +var Moclodule = (function () { + function Moclodule() { + } + return Moclodule; +})(); +// Instantiated module. +var Moclodule; +(function (Moclodule) { + var Manager = (function () { + function Manager() { + } + return Manager; + })(); + Moclodule.Manager = Manager; +})(Moclodule || (Moclodule = {})); diff --git a/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.types b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.types new file mode 100644 index 00000000000..8dc14646a6b --- /dev/null +++ b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts === +// Non-ambient & uninstantiated module. +module Moclodule { +>Moclodule : typeof Moclodule + + export interface Someinterface { +>Someinterface : Someinterface + + foo(): void; +>foo : () => void + } +} + +class Moclodule { +>Moclodule : Moclodule +} + +// Instantiated module. +module Moclodule { +>Moclodule : typeof Moclodule + + export class Manager { +>Manager : Manager + } +} diff --git a/tests/baselines/reference/commentEmitWithCommentOnLastLine.js b/tests/baselines/reference/commentEmitWithCommentOnLastLine.js new file mode 100644 index 00000000000..ffd4addb264 --- /dev/null +++ b/tests/baselines/reference/commentEmitWithCommentOnLastLine.js @@ -0,0 +1,11 @@ +//// [commentEmitWithCommentOnLastLine.ts] +var x: any; +/* +var bar; +*/ + +//// [commentEmitWithCommentOnLastLine.js] +var x; +/* +var bar; +*/ diff --git a/tests/baselines/reference/commentEmitWithCommentOnLastLine.types b/tests/baselines/reference/commentEmitWithCommentOnLastLine.types new file mode 100644 index 00000000000..d59c42d3795 --- /dev/null +++ b/tests/baselines/reference/commentEmitWithCommentOnLastLine.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/commentEmitWithCommentOnLastLine.ts === +var x: any; +>x : any + +/* +var bar; +*/ diff --git a/tests/baselines/reference/concatError.js b/tests/baselines/reference/concatError.js index 04c0a16b836..dee3d8a30e3 100644 --- a/tests/baselines/reference/concatError.js +++ b/tests/baselines/reference/concatError.js @@ -57,34 +57,4 @@ var c: C; var cc: C>; c = c.m(cc); -var n1: number[]; -/* -interface Array { - concat(...items: T[][]): T[]; // Note: This overload needs to be picked for arrays of arrays, even though both are applicable - concat(...items: T[]): T[]; -} -*/ -var fa: number[]; - -fa = fa.concat([0]); -fa = fa.concat(0); - - - - - -/* - - - - -declare class C { - public m(p1: C>): C; - //public p: T; -} - -var c: C; -var cc: C>; - -c = c.m(cc); - +*/ diff --git a/tests/baselines/reference/constEnumBadPropertyNames.errors.txt b/tests/baselines/reference/constEnumBadPropertyNames.errors.txt new file mode 100644 index 00000000000..7cccf86b1c8 --- /dev/null +++ b/tests/baselines/reference/constEnumBadPropertyNames.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/constEnumBadPropertyNames.ts(2,11): error TS4088: Property 'B' does not exist on 'const' enum 'E'. + + +==== tests/cases/compiler/constEnumBadPropertyNames.ts (1 errors) ==== + const enum E { A } + var x = E["B"] + ~~~ +!!! error TS4088: Property 'B' does not exist on 'const' enum 'E'. \ No newline at end of file diff --git a/tests/baselines/reference/constEnumErrors.errors.txt b/tests/baselines/reference/constEnumErrors.errors.txt index 541f814af98..53fed12f382 100644 --- a/tests/baselines/reference/constEnumErrors.errors.txt +++ b/tests/baselines/reference/constEnumErrors.errors.txt @@ -3,8 +3,8 @@ tests/cases/compiler/constEnumErrors.ts(5,8): error TS2300: Duplicate identifier tests/cases/compiler/constEnumErrors.ts(12,9): error TS4083: In 'const' enum declarations member initializer must be constant expression. tests/cases/compiler/constEnumErrors.ts(14,9): error TS4083: In 'const' enum declarations member initializer must be constant expression. tests/cases/compiler/constEnumErrors.ts(15,10): error TS4083: In 'const' enum declarations member initializer must be constant expression. -tests/cases/compiler/constEnumErrors.ts(22,13): error TS4085: Index expression arguments in 'const' enums must be of type 'string'. -tests/cases/compiler/constEnumErrors.ts(24,13): error TS4085: Index expression arguments in 'const' enums must be of type 'string'. +tests/cases/compiler/constEnumErrors.ts(22,13): error TS4085: A const enum member can only be accessed using a string literal. +tests/cases/compiler/constEnumErrors.ts(24,13): error TS4085: A const enum member can only be accessed using a string literal. tests/cases/compiler/constEnumErrors.ts(26,9): error TS4084: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. tests/cases/compiler/constEnumErrors.ts(27,10): error TS4084: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. tests/cases/compiler/constEnumErrors.ts(32,5): error TS4084: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. @@ -47,11 +47,11 @@ tests/cases/compiler/constEnumErrors.ts(42,9): error TS4087: 'const' enum member var y0 = E2[1] ~ -!!! error TS4085: Index expression arguments in 'const' enums must be of type 'string'. +!!! error TS4085: A const enum member can only be accessed using a string literal. var name = "A"; var y1 = E2[name]; ~~~~ -!!! error TS4085: Index expression arguments in 'const' enums must be of type 'string'. +!!! error TS4085: A const enum member can only be accessed using a string literal. var x = E2; ~~ diff --git a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt index 972b4bb9188..adfb1c68b7a 100644 --- a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt +++ b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt @@ -1,9 +1,17 @@ tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(2,22): error TS2339: Property 'foo' does not exist on type 'string'. +tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'T'. +tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,32): error TS2339: Property 'foo' does not exist on type 'T'. -==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (1 errors) ==== +==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (3 errors) ==== var f10: (x: T, b: () => (a: T) => void, y: T) => T; f10('', () => a => a.foo, ''); // a is string ~~~ !!! error TS2339: Property 'foo' does not exist on type 'string'. - var r9 = f10('', () => (a => a.foo), 1); // error \ No newline at end of file + var r9 = f10('', () => (a => a.foo), 1); // error + ~~~ +!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'T'. + ~~~ +!!! error TS2339: Property 'foo' does not exist on type 'T'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterProperties1.errors.txt b/tests/baselines/reference/destructuringParameterProperties1.errors.txt new file mode 100644 index 00000000000..b8f3a22b4c5 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterProperties1.errors.txt @@ -0,0 +1,71 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(9,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(16,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,26): error TS2339: Property 'x' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,35): error TS2339: Property 'y' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,43): error TS2339: Property 'y' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,52): error TS2339: Property 'z' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(25,30): error TS2339: Property 'x' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(25,36): error TS2339: Property 'y' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(25,42): error TS2339: Property 'z' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(29,30): error TS2339: Property 'x' does not exist on type 'C3'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(29,36): error TS2339: Property 'y' does not exist on type 'C3'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(29,42): error TS2339: Property 'z' does not exist on type 'C3'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts (13 errors) ==== + class C1 { + constructor(public [x, y, z]: string[]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } + + type TupleType1 = [string, number, boolean]; + + class C2 { + constructor(public [x, y, z]: TupleType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } + + type ObjType1 = { x: number; y: string; z: boolean } + + class C3 { + constructor(public { x, y, z }: ObjType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } + + var c1 = new C1([]); + c1 = new C1(["larry", "{curly}", "moe"]); + var useC1Properties = c1.x === c1.y && c1.y === c1.z; + ~ +!!! error TS2339: Property 'x' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'z' does not exist on type 'C1'. + + var c2 = new C2(["10", 10, !!10]); + var [c2_x, c2_y, c2_z] = [c2.x, c2.y, c2.z]; + ~ +!!! error TS2339: Property 'x' does not exist on type 'C2'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C2'. + ~ +!!! error TS2339: Property 'z' does not exist on type 'C2'. + + var c3 = new C3({x: 0, y: "", z: false}); + c3 = new C3({x: 0, "y": "y", z: true}); + var [c3_x, c3_y, c3_z] = [c3.x, c3.y, c3.z]; + ~ +!!! error TS2339: Property 'x' does not exist on type 'C3'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C3'. + ~ +!!! error TS2339: Property 'z' does not exist on type 'C3'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterProperties1.js b/tests/baselines/reference/destructuringParameterProperties1.js new file mode 100644 index 00000000000..cc16cc78de5 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterProperties1.js @@ -0,0 +1,61 @@ +//// [destructuringParameterProperties1.ts] +class C1 { + constructor(public [x, y, z]: string[]) { + } +} + +type TupleType1 = [string, number, boolean]; + +class C2 { + constructor(public [x, y, z]: TupleType1) { + } +} + +type ObjType1 = { x: number; y: string; z: boolean } + +class C3 { + constructor(public { x, y, z }: ObjType1) { + } +} + +var c1 = new C1([]); +c1 = new C1(["larry", "{curly}", "moe"]); +var useC1Properties = c1.x === c1.y && c1.y === c1.z; + +var c2 = new C2(["10", 10, !!10]); +var [c2_x, c2_y, c2_z] = [c2.x, c2.y, c2.z]; + +var c3 = new C3({x: 0, y: "", z: false}); +c3 = new C3({x: 0, "y": "y", z: true}); +var [c3_x, c3_y, c3_z] = [c3.x, c3.y, c3.z]; + +//// [destructuringParameterProperties1.js] +var C1 = (function () { + function C1(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C1; +})(); +var C2 = (function () { + function C2(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C2; +})(); +var C3 = (function () { + function C3(_a) { + var x = _a.x, y = _a.y, z = _a.z; + this.{ x, y, z } = { x, y, z }; + } + return C3; +})(); +var c1 = new C1([]); +c1 = new C1(["larry", "{curly}", "moe"]); +var useC1Properties = c1.x === c1.y && c1.y === c1.z; +var c2 = new C2(["10", 10, !!10]); +var _a = [c2.x, c2.y, c2.z], c2_x = _a[0], c2_y = _a[1], c2_z = _a[2]; +var c3 = new C3({ x: 0, y: "", z: false }); +c3 = new C3({ x: 0, "y": "y", z: true }); +var _b = [c3.x, c3.y, c3.z], c3_x = _b[0], c3_y = _b[1], c3_z = _b[2]; diff --git a/tests/baselines/reference/destructuringParameterProperties2.errors.txt b/tests/baselines/reference/destructuringParameterProperties2.errors.txt new file mode 100644 index 00000000000..61c0e61611a --- /dev/null +++ b/tests/baselines/reference/destructuringParameterProperties2.errors.txt @@ -0,0 +1,56 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(2,36): error TS1187: A parameter property may not be a binding pattern. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(9,21): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(13,21): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(17,21): error TS2339: Property 'c' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(21,27): error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts (8 errors) ==== + class C1 { + constructor(private k: number, private [a, b, c]: [number, string, boolean]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + this.a = a || k; + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + } + + public getA() { + return this.a + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + + public getB() { + return this.b + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + } + + public getC() { + return this.c; + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + } + } + + var x = new C1(undefined, [0, undefined, ""]); + ~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'. + var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + + var y = new C1(10, [0, "", true]); + var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + + var z = new C1(10, [undefined, "", null]); + var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterProperties2.js b/tests/baselines/reference/destructuringParameterProperties2.js new file mode 100644 index 00000000000..27e190af62f --- /dev/null +++ b/tests/baselines/reference/destructuringParameterProperties2.js @@ -0,0 +1,58 @@ +//// [destructuringParameterProperties2.ts] +class C1 { + constructor(private k: number, private [a, b, c]: [number, string, boolean]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +var x = new C1(undefined, [0, undefined, ""]); +var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + +var y = new C1(10, [0, "", true]); +var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + +var z = new C1(10, [undefined, "", null]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + + +//// [destructuringParameterProperties2.js] +var C1 = (function () { + function C1(k, _a) { + var a = _a[0], b = _a[1], c = _a[2]; + this.k = k; + this.[a, b, c] = [a, b, c]; + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + C1.prototype.getA = function () { + return this.a; + }; + C1.prototype.getB = function () { + return this.b; + }; + C1.prototype.getC = function () { + return this.c; + }; + return C1; +})(); +var x = new C1(undefined, [0, undefined, ""]); +var _a = [x.getA(), x.getB(), x.getC()], x_a = _a[0], x_b = _a[1], x_c = _a[2]; +var y = new C1(10, [0, "", true]); +var _b = [y.getA(), y.getB(), y.getC()], y_a = _b[0], y_b = _b[1], y_c = _b[2]; +var z = new C1(10, [undefined, "", null]); +var _c = [z.getA(), z.getB(), z.getC()], z_a = _c[0], z_b = _c[1], z_c = _c[2]; diff --git a/tests/baselines/reference/destructuringParameterProperties3.errors.txt b/tests/baselines/reference/destructuringParameterProperties3.errors.txt new file mode 100644 index 00000000000..73d7dab2a38 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterProperties3.errors.txt @@ -0,0 +1,56 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(2,31): error TS1187: A parameter property may not be a binding pattern. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(9,21): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(13,21): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(17,21): error TS2339: Property 'c' does not exist on type 'C1'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts (7 errors) ==== + class C1 { + constructor(private k: T, private [a, b, c]: [T,U,V]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + this.a = a || k; + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + } + + public getA() { + return this.a + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + + public getB() { + return this.b + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + } + + public getC() { + return this.c; + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + } + } + + var x = new C1(undefined, [0, true, ""]); + var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + + var y = new C1(10, [0, true, true]); + var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + + var z = new C1(10, [undefined, "", ""]); + var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + + var w = new C1(10, [undefined, undefined, undefined]); + var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterProperties3.js b/tests/baselines/reference/destructuringParameterProperties3.js new file mode 100644 index 00000000000..fe9e69d7e5b --- /dev/null +++ b/tests/baselines/reference/destructuringParameterProperties3.js @@ -0,0 +1,63 @@ +//// [destructuringParameterProperties3.ts] +class C1 { + constructor(private k: T, private [a, b, c]: [T,U,V]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +var x = new C1(undefined, [0, true, ""]); +var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + +var y = new C1(10, [0, true, true]); +var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + +var z = new C1(10, [undefined, "", ""]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + +var w = new C1(10, [undefined, undefined, undefined]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + + +//// [destructuringParameterProperties3.js] +var C1 = (function () { + function C1(k, _a) { + var a = _a[0], b = _a[1], c = _a[2]; + this.k = k; + this.[a, b, c] = [a, b, c]; + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + C1.prototype.getA = function () { + return this.a; + }; + C1.prototype.getB = function () { + return this.b; + }; + C1.prototype.getC = function () { + return this.c; + }; + return C1; +})(); +var x = new C1(undefined, [0, true, ""]); +var _a = [x.getA(), x.getB(), x.getC()], x_a = _a[0], x_b = _a[1], x_c = _a[2]; +var y = new C1(10, [0, true, true]); +var _b = [y.getA(), y.getB(), y.getC()], y_a = _b[0], y_b = _b[1], y_c = _b[2]; +var z = new C1(10, [undefined, "", ""]); +var _c = [z.getA(), z.getB(), z.getC()], z_a = _c[0], z_b = _c[1], z_c = _c[2]; +var w = new C1(10, [undefined, undefined, undefined]); +var _d = [z.getA(), z.getB(), z.getC()], z_a = _d[0], z_b = _d[1], z_c = _d[2]; diff --git a/tests/baselines/reference/destructuringParameterProperties4.errors.txt b/tests/baselines/reference/destructuringParameterProperties4.errors.txt new file mode 100644 index 00000000000..04f6f82b5df --- /dev/null +++ b/tests/baselines/reference/destructuringParameterProperties4.errors.txt @@ -0,0 +1,60 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(3,31): error TS1187: A parameter property may not be a binding pattern. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(4,59): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(4,83): error TS2339: Property 'c' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(5,18): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(10,21): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(14,21): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(18,21): error TS2339: Property 'c' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(24,24): error TS2339: Property 'a' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(24,34): error TS2339: Property 'b' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(24,44): error TS2339: Property 'c' does not exist on type 'C2'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts (10 errors) ==== + + class C1 { + constructor(private k: T, protected [a, b, c]: [T,U,V]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + this.a = a || k; + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + } + + public getA() { + return this.a + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + + public getB() { + return this.b + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + } + + public getC() { + return this.c; + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + } + } + + class C2 extends C1 { + public doSomethingWithSuperProperties() { + return `${this.a} ${this.b} ${this.c}`; + ~ +!!! error TS2339: Property 'a' does not exist on type 'C2'. + ~ +!!! error TS2339: Property 'b' does not exist on type 'C2'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'C2'. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterProperties4.js b/tests/baselines/reference/destructuringParameterProperties4.js new file mode 100644 index 00000000000..6da6f53a4fe --- /dev/null +++ b/tests/baselines/reference/destructuringParameterProperties4.js @@ -0,0 +1,65 @@ +//// [destructuringParameterProperties4.ts] + +class C1 { + constructor(private k: T, protected [a, b, c]: [T,U,V]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +class C2 extends C1 { + public doSomethingWithSuperProperties() { + return `${this.a} ${this.b} ${this.c}`; + } +} + + +//// [destructuringParameterProperties4.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var C1 = (function () { + function C1(k, [a, b, c]) { + this.k = k; + this.[a, b, c] = [a, b, c]; + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + C1.prototype.getA = function () { + return this.a; + }; + C1.prototype.getB = function () { + return this.b; + }; + C1.prototype.getC = function () { + return this.c; + }; + return C1; +})(); +var C2 = (function (_super) { + __extends(C2, _super); + function C2() { + _super.apply(this, arguments); + } + C2.prototype.doSomethingWithSuperProperties = function () { + return `${this.a} ${this.b} ${this.c}`; + }; + return C2; +})(C1); diff --git a/tests/baselines/reference/destructuringParameterProperties5.errors.txt b/tests/baselines/reference/destructuringParameterProperties5.errors.txt new file mode 100644 index 00000000000..dca02a9a84e --- /dev/null +++ b/tests/baselines/reference/destructuringParameterProperties5.errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,27): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,31): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x2' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,35): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(7,29): error TS2339: Property 'x1' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(7,40): error TS2339: Property 'x2' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(7,51): error TS2339: Property 'x3' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(7,62): error TS2339: Property 'y' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(7,72): error TS2339: Property 'z' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(11,16): error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'. + Types of property '0' are incompatible. + Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'. + Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts (10 errors) ==== + type ObjType1 = { x: number; y: string; z: boolean } + type TupleType1 = [ObjType1, number, string] + + class C1 { + constructor(public [{ x1, x2, x3 }, y, z]: TupleType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + ~~ +!!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature. + ~~ +!!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x2' and no string index signature. + ~~ +!!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature. + var foo: any = x1 || x2 || x3 || y || z; + var bar: any = this.x1 || this.x2 || this.x3 || this.y || this.z; + ~~ +!!! error TS2339: Property 'x1' does not exist on type 'C1'. + ~~ +!!! error TS2339: Property 'x2' does not exist on type 'C1'. + ~~ +!!! error TS2339: Property 'x3' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'z' does not exist on type 'C1'. + } + } + + var a = new C1([{ x1: 10, x2: "", x3: true }, "", false]); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'. +!!! error TS2345: Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'. + var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z]; \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterProperties5.js b/tests/baselines/reference/destructuringParameterProperties5.js new file mode 100644 index 00000000000..d9b1710ae89 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterProperties5.js @@ -0,0 +1,26 @@ +//// [destructuringParameterProperties5.ts] +type ObjType1 = { x: number; y: string; z: boolean } +type TupleType1 = [ObjType1, number, string] + +class C1 { + constructor(public [{ x1, x2, x3 }, y, z]: TupleType1) { + var foo: any = x1 || x2 || x3 || y || z; + var bar: any = this.x1 || this.x2 || this.x3 || this.y || this.z; + } +} + +var a = new C1([{ x1: 10, x2: "", x3: true }, "", false]); +var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z]; + +//// [destructuringParameterProperties5.js] +var C1 = (function () { + function C1(_a) { + var _b = _a[0], x1 = _b.x1, x2 = _b.x2, x3 = _b.x3, y = _a[1], z = _a[2]; + this.[{ x1, x2, x3 }, y, z] = [{ x1, x2, x3 }, y, z]; + var foo = x1 || x2 || x3 || y || z; + var bar = this.x1 || this.x2 || this.x3 || this.y || this.z; + } + return C1; +})(); +var a = new C1([{ x1: 10, x2: "", x3: true }, "", false]); +var _a = [a.x1, a.x2, a.x3, a.y, a.z], a_x1 = _a[0], a_x2 = _a[1], a_x3 = _a[2], a_y = _a[3], a_z = _a[4]; diff --git a/tests/baselines/reference/emitDefaultParametersFunction.js b/tests/baselines/reference/emitDefaultParametersFunction.js new file mode 100644 index 00000000000..6be7ae9dbfe --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunction.js @@ -0,0 +1,27 @@ +//// [emitDefaultParametersFunction.ts] +function foo(x: string, y = 10) { } +function baz(x: string, y = 5, ...rest) { } +function bar(y = 10) { } +function bar1(y = 10, ...rest) { } + +//// [emitDefaultParametersFunction.js] +function foo(x, y) { + if (y === void 0) { y = 10; } +} +function baz(x, y) { + if (y === void 0) { y = 5; } + var rest = []; + for (var _i = 2; _i < arguments.length; _i++) { + rest[_i - 2] = arguments[_i]; + } +} +function bar(y) { + if (y === void 0) { y = 10; } +} +function bar1(y) { + if (y === void 0) { y = 10; } + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } +} diff --git a/tests/baselines/reference/emitDefaultParametersFunction.types b/tests/baselines/reference/emitDefaultParametersFunction.types new file mode 100644 index 00000000000..a8dec6335a9 --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunction.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunction.ts === +function foo(x: string, y = 10) { } +>foo : (x: string, y?: number) => void +>x : string +>y : number + +function baz(x: string, y = 5, ...rest) { } +>baz : (x: string, y?: number, ...rest: any[]) => void +>x : string +>y : number +>rest : any[] + +function bar(y = 10) { } +>bar : (y?: number) => void +>y : number + +function bar1(y = 10, ...rest) { } +>bar1 : (y?: number, ...rest: any[]) => void +>y : number +>rest : any[] + diff --git a/tests/baselines/reference/emitDefaultParametersFunctionES6.js b/tests/baselines/reference/emitDefaultParametersFunctionES6.js new file mode 100644 index 00000000000..f4084a16f6f --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunctionES6.js @@ -0,0 +1,15 @@ +//// [emitDefaultParametersFunctionES6.ts] +function foo(x: string, y = 10) { } +function baz(x: string, y = 5, ...rest) { } +function bar(y = 10) { } +function bar1(y = 10, ...rest) { } + +//// [emitDefaultParametersFunctionES6.js] +function foo(x, y = 10) { +} +function baz(x, y = 5, ...rest) { +} +function bar(y = 10) { +} +function bar1(y = 10, ...rest) { +} diff --git a/tests/baselines/reference/emitDefaultParametersFunctionES6.types b/tests/baselines/reference/emitDefaultParametersFunctionES6.types new file mode 100644 index 00000000000..1c67032264f --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunctionES6.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionES6.ts === +function foo(x: string, y = 10) { } +>foo : (x: string, y?: number) => void +>x : string +>y : number + +function baz(x: string, y = 5, ...rest) { } +>baz : (x: string, y?: number, ...rest: any[]) => void +>x : string +>y : number +>rest : any[] + +function bar(y = 10) { } +>bar : (y?: number) => void +>y : number + +function bar1(y = 10, ...rest) { } +>bar1 : (y?: number, ...rest: any[]) => void +>y : number +>rest : any[] + diff --git a/tests/baselines/reference/emitDefaultParametersFunctionExpression.js b/tests/baselines/reference/emitDefaultParametersFunctionExpression.js new file mode 100644 index 00000000000..bcfe5b240f2 --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunctionExpression.js @@ -0,0 +1,54 @@ +//// [emitDefaultParametersFunctionExpression.ts] +var lambda1 = (y = "hello") => { } +var lambda2 = (x: number, y = "hello") => { } +var lambda3 = (x: number, y = "hello", ...rest) => { } +var lambda4 = (y = "hello", ...rest) => { } + +var x = function (str = "hello", ...rest) { } +var y = (function (num = 10, boo = false, ...rest) { })() +var z = (function (num: number, boo = false, ...rest) { })(10) + + +//// [emitDefaultParametersFunctionExpression.js] +var lambda1 = function (y) { + if (y === void 0) { y = "hello"; } +}; +var lambda2 = function (x, y) { + if (y === void 0) { y = "hello"; } +}; +var lambda3 = function (x, y) { + if (y === void 0) { y = "hello"; } + var rest = []; + for (var _i = 2; _i < arguments.length; _i++) { + rest[_i - 2] = arguments[_i]; + } +}; +var lambda4 = function (y) { + if (y === void 0) { y = "hello"; } + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } +}; +var x = function (str) { + if (str === void 0) { str = "hello"; } + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } +}; +var y = (function (num, boo) { + if (num === void 0) { num = 10; } + if (boo === void 0) { boo = false; } + var rest = []; + for (var _i = 2; _i < arguments.length; _i++) { + rest[_i - 2] = arguments[_i]; + } +})(); +var z = (function (num, boo) { + if (boo === void 0) { boo = false; } + var rest = []; + for (var _i = 2; _i < arguments.length; _i++) { + rest[_i - 2] = arguments[_i]; + } +})(10); diff --git a/tests/baselines/reference/emitDefaultParametersFunctionExpression.types b/tests/baselines/reference/emitDefaultParametersFunctionExpression.types new file mode 100644 index 00000000000..5c223ff1344 --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunctionExpression.types @@ -0,0 +1,49 @@ +=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionExpression.ts === +var lambda1 = (y = "hello") => { } +>lambda1 : (y?: string) => void +>(y = "hello") => { } : (y?: string) => void +>y : string + +var lambda2 = (x: number, y = "hello") => { } +>lambda2 : (x: number, y?: string) => void +>(x: number, y = "hello") => { } : (x: number, y?: string) => void +>x : number +>y : string + +var lambda3 = (x: number, y = "hello", ...rest) => { } +>lambda3 : (x: number, y?: string, ...rest: any[]) => void +>(x: number, y = "hello", ...rest) => { } : (x: number, y?: string, ...rest: any[]) => void +>x : number +>y : string +>rest : any[] + +var lambda4 = (y = "hello", ...rest) => { } +>lambda4 : (y?: string, ...rest: any[]) => void +>(y = "hello", ...rest) => { } : (y?: string, ...rest: any[]) => void +>y : string +>rest : any[] + +var x = function (str = "hello", ...rest) { } +>x : (str?: string, ...rest: any[]) => void +>function (str = "hello", ...rest) { } : (str?: string, ...rest: any[]) => void +>str : string +>rest : any[] + +var y = (function (num = 10, boo = false, ...rest) { })() +>y : void +>(function (num = 10, boo = false, ...rest) { })() : void +>(function (num = 10, boo = false, ...rest) { }) : (num?: number, boo?: boolean, ...rest: any[]) => void +>function (num = 10, boo = false, ...rest) { } : (num?: number, boo?: boolean, ...rest: any[]) => void +>num : number +>boo : boolean +>rest : any[] + +var z = (function (num: number, boo = false, ...rest) { })(10) +>z : void +>(function (num: number, boo = false, ...rest) { })(10) : void +>(function (num: number, boo = false, ...rest) { }) : (num: number, boo?: boolean, ...rest: any[]) => void +>function (num: number, boo = false, ...rest) { } : (num: number, boo?: boolean, ...rest: any[]) => void +>num : number +>boo : boolean +>rest : any[] + diff --git a/tests/baselines/reference/emitDefaultParametersFunctionExpressionES6.js b/tests/baselines/reference/emitDefaultParametersFunctionExpressionES6.js new file mode 100644 index 00000000000..eabb0e1e344 --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunctionExpressionES6.js @@ -0,0 +1,25 @@ +//// [emitDefaultParametersFunctionExpressionES6.ts] +var lambda1 = (y = "hello") => { } +var lambda2 = (x: number, y = "hello") => { } +var lambda3 = (x: number, y = "hello", ...rest) => { } +var lambda4 = (y = "hello", ...rest) => { } + +var x = function (str = "hello", ...rest) { } +var y = (function (num = 10, boo = false, ...rest) { })() +var z = (function (num: number, boo = false, ...rest) { })(10) + +//// [emitDefaultParametersFunctionExpressionES6.js] +var lambda1 = function (y = "hello") { +}; +var lambda2 = function (x, y = "hello") { +}; +var lambda3 = function (x, y = "hello", ...rest) { +}; +var lambda4 = function (y = "hello", ...rest) { +}; +var x = function (str = "hello", ...rest) { +}; +var y = (function (num = 10, boo = false, ...rest) { +})(); +var z = (function (num, boo = false, ...rest) { +})(10); diff --git a/tests/baselines/reference/emitDefaultParametersFunctionExpressionES6.types b/tests/baselines/reference/emitDefaultParametersFunctionExpressionES6.types new file mode 100644 index 00000000000..9b8805dfa2b --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunctionExpressionES6.types @@ -0,0 +1,49 @@ +=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionExpressionES6.ts === +var lambda1 = (y = "hello") => { } +>lambda1 : (y?: string) => void +>(y = "hello") => { } : (y?: string) => void +>y : string + +var lambda2 = (x: number, y = "hello") => { } +>lambda2 : (x: number, y?: string) => void +>(x: number, y = "hello") => { } : (x: number, y?: string) => void +>x : number +>y : string + +var lambda3 = (x: number, y = "hello", ...rest) => { } +>lambda3 : (x: number, y?: string, ...rest: any[]) => void +>(x: number, y = "hello", ...rest) => { } : (x: number, y?: string, ...rest: any[]) => void +>x : number +>y : string +>rest : any[] + +var lambda4 = (y = "hello", ...rest) => { } +>lambda4 : (y?: string, ...rest: any[]) => void +>(y = "hello", ...rest) => { } : (y?: string, ...rest: any[]) => void +>y : string +>rest : any[] + +var x = function (str = "hello", ...rest) { } +>x : (str?: string, ...rest: any[]) => void +>function (str = "hello", ...rest) { } : (str?: string, ...rest: any[]) => void +>str : string +>rest : any[] + +var y = (function (num = 10, boo = false, ...rest) { })() +>y : void +>(function (num = 10, boo = false, ...rest) { })() : void +>(function (num = 10, boo = false, ...rest) { }) : (num?: number, boo?: boolean, ...rest: any[]) => void +>function (num = 10, boo = false, ...rest) { } : (num?: number, boo?: boolean, ...rest: any[]) => void +>num : number +>boo : boolean +>rest : any[] + +var z = (function (num: number, boo = false, ...rest) { })(10) +>z : void +>(function (num: number, boo = false, ...rest) { })(10) : void +>(function (num: number, boo = false, ...rest) { }) : (num: number, boo?: boolean, ...rest: any[]) => void +>function (num: number, boo = false, ...rest) { } : (num: number, boo?: boolean, ...rest: any[]) => void +>num : number +>boo : boolean +>rest : any[] + diff --git a/tests/baselines/reference/emitDefaultParametersFunctionProperty.js b/tests/baselines/reference/emitDefaultParametersFunctionProperty.js new file mode 100644 index 00000000000..16cac41a4ce --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunctionProperty.js @@ -0,0 +1,32 @@ +//// [emitDefaultParametersFunctionProperty.ts] +var obj2 = { + func1(y = 10, ...rest) { }, + func2(x = "hello") { }, + func3(x: string, z: number, y = "hello") { }, + func4(x: string, z: number, y = "hello", ...rest) { }, +} + + +//// [emitDefaultParametersFunctionProperty.js] +var obj2 = { + func1: function (y) { + if (y === void 0) { y = 10; } + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } + }, + func2: function (x) { + if (x === void 0) { x = "hello"; } + }, + func3: function (x, z, y) { + if (y === void 0) { y = "hello"; } + }, + func4: function (x, z, y) { + if (y === void 0) { y = "hello"; } + var rest = []; + for (var _i = 3; _i < arguments.length; _i++) { + rest[_i - 3] = arguments[_i]; + } + }, +}; diff --git a/tests/baselines/reference/emitDefaultParametersFunctionProperty.types b/tests/baselines/reference/emitDefaultParametersFunctionProperty.types new file mode 100644 index 00000000000..7c1ea6a5da3 --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunctionProperty.types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionProperty.ts === +var obj2 = { +>obj2 : { func1(y?: number, ...rest: any[]): void; func2(x?: string): void; func3(x: string, z: number, y?: string): void; func4(x: string, z: number, y?: string, ...rest: any[]): void; } +>{ func1(y = 10, ...rest) { }, func2(x = "hello") { }, func3(x: string, z: number, y = "hello") { }, func4(x: string, z: number, y = "hello", ...rest) { },} : { func1(y?: number, ...rest: any[]): void; func2(x?: string): void; func3(x: string, z: number, y?: string): void; func4(x: string, z: number, y?: string, ...rest: any[]): void; } + + func1(y = 10, ...rest) { }, +>func1 : (y?: number, ...rest: any[]) => void +>y : number +>rest : any[] + + func2(x = "hello") { }, +>func2 : (x?: string) => void +>x : string + + func3(x: string, z: number, y = "hello") { }, +>func3 : (x: string, z: number, y?: string) => void +>x : string +>z : number +>y : string + + func4(x: string, z: number, y = "hello", ...rest) { }, +>func4 : (x: string, z: number, y?: string, ...rest: any[]) => void +>x : string +>z : number +>y : string +>rest : any[] +} + diff --git a/tests/baselines/reference/emitDefaultParametersFunctionPropertyES6.js b/tests/baselines/reference/emitDefaultParametersFunctionPropertyES6.js new file mode 100644 index 00000000000..fce694a453a --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunctionPropertyES6.js @@ -0,0 +1,19 @@ +//// [emitDefaultParametersFunctionPropertyES6.ts] +var obj2 = { + func1(y = 10, ...rest) { }, + func2(x = "hello") { }, + func3(x: string, z: number, y = "hello") { }, + func4(x: string, z: number, y = "hello", ...rest) { }, +} + +//// [emitDefaultParametersFunctionPropertyES6.js] +var obj2 = { + func1(y = 10, ...rest) { + }, + func2(x = "hello") { + }, + func3(x, z, y = "hello") { + }, + func4(x, z, y = "hello", ...rest) { + }, +}; diff --git a/tests/baselines/reference/emitDefaultParametersFunctionPropertyES6.types b/tests/baselines/reference/emitDefaultParametersFunctionPropertyES6.types new file mode 100644 index 00000000000..ed80158ffd1 --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersFunctionPropertyES6.types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionPropertyES6.ts === +var obj2 = { +>obj2 : { func1(y?: number, ...rest: any[]): void; func2(x?: string): void; func3(x: string, z: number, y?: string): void; func4(x: string, z: number, y?: string, ...rest: any[]): void; } +>{ func1(y = 10, ...rest) { }, func2(x = "hello") { }, func3(x: string, z: number, y = "hello") { }, func4(x: string, z: number, y = "hello", ...rest) { },} : { func1(y?: number, ...rest: any[]): void; func2(x?: string): void; func3(x: string, z: number, y?: string): void; func4(x: string, z: number, y?: string, ...rest: any[]): void; } + + func1(y = 10, ...rest) { }, +>func1 : (y?: number, ...rest: any[]) => void +>y : number +>rest : any[] + + func2(x = "hello") { }, +>func2 : (x?: string) => void +>x : string + + func3(x: string, z: number, y = "hello") { }, +>func3 : (x: string, z: number, y?: string) => void +>x : string +>z : number +>y : string + + func4(x: string, z: number, y = "hello", ...rest) { }, +>func4 : (x: string, z: number, y?: string, ...rest: any[]) => void +>x : string +>z : number +>y : string +>rest : any[] +} diff --git a/tests/baselines/reference/emitDefaultParametersMethod.js b/tests/baselines/reference/emitDefaultParametersMethod.js new file mode 100644 index 00000000000..126c19305b3 --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersMethod.js @@ -0,0 +1,62 @@ +//// [emitDefaultParametersMethod.ts] +class C { + constructor(t: boolean, z: string, x: number, y = "hello") { } + + public foo(x: string, t = false) { } + public foo1(x: string, t = false, ...rest) { } + public bar(t = false) { } + public boo(t = false, ...rest) { } +} + +class D { + constructor(y = "hello") { } +} + +class E { + constructor(y = "hello", ...rest) { } +} + + +//// [emitDefaultParametersMethod.js] +var C = (function () { + function C(t, z, x, y) { + if (y === void 0) { y = "hello"; } + } + C.prototype.foo = function (x, t) { + if (t === void 0) { t = false; } + }; + C.prototype.foo1 = function (x, t) { + if (t === void 0) { t = false; } + var rest = []; + for (var _i = 2; _i < arguments.length; _i++) { + rest[_i - 2] = arguments[_i]; + } + }; + C.prototype.bar = function (t) { + if (t === void 0) { t = false; } + }; + C.prototype.boo = function (t) { + if (t === void 0) { t = false; } + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } + }; + return C; +})(); +var D = (function () { + function D(y) { + if (y === void 0) { y = "hello"; } + } + return D; +})(); +var E = (function () { + function E(y) { + if (y === void 0) { y = "hello"; } + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } + } + return E; +})(); diff --git a/tests/baselines/reference/emitDefaultParametersMethod.types b/tests/baselines/reference/emitDefaultParametersMethod.types new file mode 100644 index 00000000000..5b2f08d4f70 --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersMethod.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersMethod.ts === +class C { +>C : C + + constructor(t: boolean, z: string, x: number, y = "hello") { } +>t : boolean +>z : string +>x : number +>y : string + + public foo(x: string, t = false) { } +>foo : (x: string, t?: boolean) => void +>x : string +>t : boolean + + public foo1(x: string, t = false, ...rest) { } +>foo1 : (x: string, t?: boolean, ...rest: any[]) => void +>x : string +>t : boolean +>rest : any[] + + public bar(t = false) { } +>bar : (t?: boolean) => void +>t : boolean + + public boo(t = false, ...rest) { } +>boo : (t?: boolean, ...rest: any[]) => void +>t : boolean +>rest : any[] +} + +class D { +>D : D + + constructor(y = "hello") { } +>y : string +} + +class E { +>E : E + + constructor(y = "hello", ...rest) { } +>y : string +>rest : any[] +} + diff --git a/tests/baselines/reference/emitDefaultParametersMethodES6.js b/tests/baselines/reference/emitDefaultParametersMethodES6.js new file mode 100644 index 00000000000..bf96e00e375 --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersMethodES6.js @@ -0,0 +1,42 @@ +//// [emitDefaultParametersMethodES6.ts] +class C { + constructor(t: boolean, z: string, x: number, y = "hello") { } + + public foo(x: string, t = false) { } + public foo1(x: string, t = false, ...rest) { } + public bar(t = false) { } + public boo(t = false, ...rest) { } +} + +class D { + constructor(y = "hello") { } +} + +class E { + constructor(y = "hello", ...rest) { } +} + +//// [emitDefaultParametersMethodES6.js] +var C = (function () { + function C(t, z, x, y = "hello") { + } + C.prototype.foo = function (x, t = false) { + }; + C.prototype.foo1 = function (x, t = false, ...rest) { + }; + C.prototype.bar = function (t = false) { + }; + C.prototype.boo = function (t = false, ...rest) { + }; + return C; +})(); +var D = (function () { + function D(y = "hello") { + } + return D; +})(); +var E = (function () { + function E(y = "hello", ...rest) { + } + return E; +})(); diff --git a/tests/baselines/reference/emitDefaultParametersMethodES6.types b/tests/baselines/reference/emitDefaultParametersMethodES6.types new file mode 100644 index 00000000000..54312714b1d --- /dev/null +++ b/tests/baselines/reference/emitDefaultParametersMethodES6.types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersMethodES6.ts === +class C { +>C : C + + constructor(t: boolean, z: string, x: number, y = "hello") { } +>t : boolean +>z : string +>x : number +>y : string + + public foo(x: string, t = false) { } +>foo : (x: string, t?: boolean) => void +>x : string +>t : boolean + + public foo1(x: string, t = false, ...rest) { } +>foo1 : (x: string, t?: boolean, ...rest: any[]) => void +>x : string +>t : boolean +>rest : any[] + + public bar(t = false) { } +>bar : (t?: boolean) => void +>t : boolean + + public boo(t = false, ...rest) { } +>boo : (t?: boolean, ...rest: any[]) => void +>t : boolean +>rest : any[] +} + +class D { +>D : D + + constructor(y = "hello") { } +>y : string +} + +class E { +>E : E + + constructor(y = "hello", ...rest) { } +>y : string +>rest : any[] +} diff --git a/tests/baselines/reference/emitRestParametersFunction.js b/tests/baselines/reference/emitRestParametersFunction.js new file mode 100644 index 00000000000..01116f2ac92 --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunction.js @@ -0,0 +1,17 @@ +//// [emitRestParametersFunction.ts] +function bar(...rest) { } +function foo(x: number, y: string, ...rest) { } + +//// [emitRestParametersFunction.js] +function bar() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +} +function foo(x, y) { + var rest = []; + for (var _i = 2; _i < arguments.length; _i++) { + rest[_i - 2] = arguments[_i]; + } +} diff --git a/tests/baselines/reference/emitRestParametersFunction.types b/tests/baselines/reference/emitRestParametersFunction.types new file mode 100644 index 00000000000..a65adb57702 --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunction.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/restParameters/emitRestParametersFunction.ts === +function bar(...rest) { } +>bar : (...rest: any[]) => void +>rest : any[] + +function foo(x: number, y: string, ...rest) { } +>foo : (x: number, y: string, ...rest: any[]) => void +>x : number +>y : string +>rest : any[] + diff --git a/tests/baselines/reference/emitRestParametersFunctionES6.js b/tests/baselines/reference/emitRestParametersFunctionES6.js new file mode 100644 index 00000000000..242c40f252d --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunctionES6.js @@ -0,0 +1,9 @@ +//// [emitRestParametersFunctionES6.ts] +function bar(...rest) { } +function foo(x: number, y: string, ...rest) { } + +//// [emitRestParametersFunctionES6.js] +function bar(...rest) { +} +function foo(x, y, ...rest) { +} diff --git a/tests/baselines/reference/emitRestParametersFunctionES6.types b/tests/baselines/reference/emitRestParametersFunctionES6.types new file mode 100644 index 00000000000..5689d64c4df --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunctionES6.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/restParameters/emitRestParametersFunctionES6.ts === +function bar(...rest) { } +>bar : (...rest: any[]) => void +>rest : any[] + +function foo(x: number, y: string, ...rest) { } +>foo : (x: number, y: string, ...rest: any[]) => void +>x : number +>y : string +>rest : any[] + diff --git a/tests/baselines/reference/emitRestParametersFunctionExpression.js b/tests/baselines/reference/emitRestParametersFunctionExpression.js new file mode 100644 index 00000000000..da87cc79f2d --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunctionExpression.js @@ -0,0 +1,32 @@ +//// [emitRestParametersFunctionExpression.ts] +var funcExp = (...rest) => { } +var funcExp1 = (X: number, ...rest) => { } +var funcExp2 = function (...rest) { } +var funcExp3 = (function (...rest) { })() + + +//// [emitRestParametersFunctionExpression.js] +var funcExp = function () { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +}; +var funcExp1 = function (X) { + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } +}; +var funcExp2 = function () { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +}; +var funcExp3 = (function () { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +})(); diff --git a/tests/baselines/reference/emitRestParametersFunctionExpression.types b/tests/baselines/reference/emitRestParametersFunctionExpression.types new file mode 100644 index 00000000000..9f08b9d9d83 --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunctionExpression.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/es6/restParameters/emitRestParametersFunctionExpression.ts === +var funcExp = (...rest) => { } +>funcExp : (...rest: any[]) => void +>(...rest) => { } : (...rest: any[]) => void +>rest : any[] + +var funcExp1 = (X: number, ...rest) => { } +>funcExp1 : (X: number, ...rest: any[]) => void +>(X: number, ...rest) => { } : (X: number, ...rest: any[]) => void +>X : number +>rest : any[] + +var funcExp2 = function (...rest) { } +>funcExp2 : (...rest: any[]) => void +>function (...rest) { } : (...rest: any[]) => void +>rest : any[] + +var funcExp3 = (function (...rest) { })() +>funcExp3 : void +>(function (...rest) { })() : void +>(function (...rest) { }) : (...rest: any[]) => void +>function (...rest) { } : (...rest: any[]) => void +>rest : any[] + diff --git a/tests/baselines/reference/emitRestParametersFunctionExpressionES6.js b/tests/baselines/reference/emitRestParametersFunctionExpressionES6.js new file mode 100644 index 00000000000..6c79e4956ae --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunctionExpressionES6.js @@ -0,0 +1,15 @@ +//// [emitRestParametersFunctionExpressionES6.ts] +var funcExp = (...rest) => { } +var funcExp1 = (X: number, ...rest) => { } +var funcExp2 = function (...rest) { } +var funcExp3 = (function (...rest) { })() + +//// [emitRestParametersFunctionExpressionES6.js] +var funcExp = function (...rest) { +}; +var funcExp1 = function (X, ...rest) { +}; +var funcExp2 = function (...rest) { +}; +var funcExp3 = (function (...rest) { +})(); diff --git a/tests/baselines/reference/emitRestParametersFunctionExpressionES6.types b/tests/baselines/reference/emitRestParametersFunctionExpressionES6.types new file mode 100644 index 00000000000..224cb37367a --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunctionExpressionES6.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/es6/restParameters/emitRestParametersFunctionExpressionES6.ts === +var funcExp = (...rest) => { } +>funcExp : (...rest: any[]) => void +>(...rest) => { } : (...rest: any[]) => void +>rest : any[] + +var funcExp1 = (X: number, ...rest) => { } +>funcExp1 : (X: number, ...rest: any[]) => void +>(X: number, ...rest) => { } : (X: number, ...rest: any[]) => void +>X : number +>rest : any[] + +var funcExp2 = function (...rest) { } +>funcExp2 : (...rest: any[]) => void +>function (...rest) { } : (...rest: any[]) => void +>rest : any[] + +var funcExp3 = (function (...rest) { })() +>funcExp3 : void +>(function (...rest) { })() : void +>(function (...rest) { }) : (...rest: any[]) => void +>function (...rest) { } : (...rest: any[]) => void +>rest : any[] + diff --git a/tests/baselines/reference/emitRestParametersFunctionProperty.js b/tests/baselines/reference/emitRestParametersFunctionProperty.js new file mode 100644 index 00000000000..4fd60a9269d --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunctionProperty.js @@ -0,0 +1,19 @@ +//// [emitRestParametersFunctionProperty.ts] +var obj: { + func1: (...rest) => void +} + +var obj2 = { + func(...rest) { } +} + +//// [emitRestParametersFunctionProperty.js] +var obj; +var obj2 = { + func: function () { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } + } +}; diff --git a/tests/baselines/reference/emitRestParametersFunctionProperty.types b/tests/baselines/reference/emitRestParametersFunctionProperty.types new file mode 100644 index 00000000000..8242e742ee0 --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunctionProperty.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/es6/restParameters/emitRestParametersFunctionProperty.ts === +var obj: { +>obj : { func1: (...rest: any[]) => void; } + + func1: (...rest) => void +>func1 : (...rest: any[]) => void +>rest : any[] +} + +var obj2 = { +>obj2 : { func(...rest: any[]): void; } +>{ func(...rest) { }} : { func(...rest: any[]): void; } + + func(...rest) { } +>func : (...rest: any[]) => void +>rest : any[] +} diff --git a/tests/baselines/reference/emitRestParametersFunctionPropertyES6.js b/tests/baselines/reference/emitRestParametersFunctionPropertyES6.js new file mode 100644 index 00000000000..87aa489ecf3 --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunctionPropertyES6.js @@ -0,0 +1,15 @@ +//// [emitRestParametersFunctionPropertyES6.ts] +var obj: { + func1: (...rest) => void +} + +var obj2 = { + func(...rest) { } +} + +//// [emitRestParametersFunctionPropertyES6.js] +var obj; +var obj2 = { + func(...rest) { + } +}; diff --git a/tests/baselines/reference/emitRestParametersFunctionPropertyES6.types b/tests/baselines/reference/emitRestParametersFunctionPropertyES6.types new file mode 100644 index 00000000000..07a008cd4c0 --- /dev/null +++ b/tests/baselines/reference/emitRestParametersFunctionPropertyES6.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/es6/restParameters/emitRestParametersFunctionPropertyES6.ts === +var obj: { +>obj : { func1: (...rest: any[]) => void; } + + func1: (...rest) => void +>func1 : (...rest: any[]) => void +>rest : any[] +} + +var obj2 = { +>obj2 : { func(...rest: any[]): void; } +>{ func(...rest) { }} : { func(...rest: any[]): void; } + + func(...rest) { } +>func : (...rest: any[]) => void +>rest : any[] +} diff --git a/tests/baselines/reference/emitRestParametersMethod.js b/tests/baselines/reference/emitRestParametersMethod.js new file mode 100644 index 00000000000..5ceb6d768f8 --- /dev/null +++ b/tests/baselines/reference/emitRestParametersMethod.js @@ -0,0 +1,58 @@ +//// [emitRestParametersMethod.ts] +class C { + constructor(name: string, ...rest) { } + + public bar(...rest) { } + public foo(x: number, ...rest) { } +} + +class D { + constructor(...rest) { } + + public bar(...rest) { } + public foo(x: number, ...rest) { } +} + +//// [emitRestParametersMethod.js] +var C = (function () { + function C(name) { + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } + } + C.prototype.bar = function () { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } + }; + C.prototype.foo = function (x) { + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } + }; + return C; +})(); +var D = (function () { + function D() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } + } + D.prototype.bar = function () { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } + }; + D.prototype.foo = function (x) { + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } + }; + return D; +})(); diff --git a/tests/baselines/reference/emitRestParametersMethod.types b/tests/baselines/reference/emitRestParametersMethod.types new file mode 100644 index 00000000000..c94561ca737 --- /dev/null +++ b/tests/baselines/reference/emitRestParametersMethod.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es6/restParameters/emitRestParametersMethod.ts === +class C { +>C : C + + constructor(name: string, ...rest) { } +>name : string +>rest : any[] + + public bar(...rest) { } +>bar : (...rest: any[]) => void +>rest : any[] + + public foo(x: number, ...rest) { } +>foo : (x: number, ...rest: any[]) => void +>x : number +>rest : any[] +} + +class D { +>D : D + + constructor(...rest) { } +>rest : any[] + + public bar(...rest) { } +>bar : (...rest: any[]) => void +>rest : any[] + + public foo(x: number, ...rest) { } +>foo : (x: number, ...rest: any[]) => void +>x : number +>rest : any[] +} diff --git a/tests/baselines/reference/emitRestParametersMethodES6.js b/tests/baselines/reference/emitRestParametersMethodES6.js new file mode 100644 index 00000000000..d0a0e2a120c --- /dev/null +++ b/tests/baselines/reference/emitRestParametersMethodES6.js @@ -0,0 +1,35 @@ +//// [emitRestParametersMethodES6.ts] +class C { + constructor(name: string, ...rest) { } + + public bar(...rest) { } + public foo(x: number, ...rest) { } +} + +class D { + constructor(...rest) { } + + public bar(...rest) { } + public foo(x: number, ...rest) { } +} + + +//// [emitRestParametersMethodES6.js] +var C = (function () { + function C(name, ...rest) { + } + C.prototype.bar = function (...rest) { + }; + C.prototype.foo = function (x, ...rest) { + }; + return C; +})(); +var D = (function () { + function D(...rest) { + } + D.prototype.bar = function (...rest) { + }; + D.prototype.foo = function (x, ...rest) { + }; + return D; +})(); diff --git a/tests/baselines/reference/emitRestParametersMethodES6.types b/tests/baselines/reference/emitRestParametersMethodES6.types new file mode 100644 index 00000000000..4555a5c666d --- /dev/null +++ b/tests/baselines/reference/emitRestParametersMethodES6.types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es6/restParameters/emitRestParametersMethodES6.ts === +class C { +>C : C + + constructor(name: string, ...rest) { } +>name : string +>rest : any[] + + public bar(...rest) { } +>bar : (...rest: any[]) => void +>rest : any[] + + public foo(x: number, ...rest) { } +>foo : (x: number, ...rest: any[]) => void +>x : number +>rest : any[] +} + +class D { +>D : D + + constructor(...rest) { } +>rest : any[] + + public bar(...rest) { } +>bar : (...rest: any[]) => void +>rest : any[] + + public foo(x: number, ...rest) { } +>foo : (x: number, ...rest: any[]) => void +>x : number +>rest : any[] +} + diff --git a/tests/baselines/reference/inheritedOverloadedSpecializedSignatures.js b/tests/baselines/reference/inheritedOverloadedSpecializedSignatures.js index 792c9232fa2..da16ad0d0e5 100644 --- a/tests/baselines/reference/inheritedOverloadedSpecializedSignatures.js +++ b/tests/baselines/reference/inheritedOverloadedSpecializedSignatures.js @@ -28,22 +28,43 @@ interface B { (x: 'B2'): string[]; } -var b: B; -// non of these lines should error -var x1: string[] = b('B2'); -var x2: number = b('B1'); -var x3: boolean = b('A2'); -var x4: string = b('A1'); -var x5: void = b('A0'); +interface C1 extends B { + (x: 'C1'): number[]; +} + +interface C2 extends B { + (x: 'C2'): boolean[]; +} + +interface C extends C1, C2 { + (x: 'C'): string; +} + +var c: C; +// none of these lines should error +var x1: string[] = c('B2'); +var x2: number = c('B1'); +var x3: boolean = c('A2'); +var x4: string = c('A1'); +var x5: void = c('A0'); +var x6: number[] = c('C1'); +var x7: boolean[] = c('C2'); +var x8: string = c('C'); +var x9: void = c('generic'); + //// [inheritedOverloadedSpecializedSignatures.js] var b; // Should not error b('foo').charAt(0); -var b; -// non of these lines should error -var x1 = b('B2'); -var x2 = b('B1'); -var x3 = b('A2'); -var x4 = b('A1'); -var x5 = b('A0'); +var c; +// none of these lines should error +var x1 = c('B2'); +var x2 = c('B1'); +var x3 = c('A2'); +var x4 = c('A1'); +var x5 = c('A0'); +var x6 = c('C1'); +var x7 = c('C2'); +var x8 = c('C'); +var x9 = c('generic'); diff --git a/tests/baselines/reference/inheritedOverloadedSpecializedSignatures.types b/tests/baselines/reference/inheritedOverloadedSpecializedSignatures.types index 0284fa4bc43..dcbab74b681 100644 --- a/tests/baselines/reference/inheritedOverloadedSpecializedSignatures.types +++ b/tests/baselines/reference/inheritedOverloadedSpecializedSignatures.types @@ -58,33 +58,78 @@ interface B { >x : 'B2' } -var b: B; ->b : B +interface C1 extends B { +>C1 : C1 >B : B -// non of these lines should error -var x1: string[] = b('B2'); + (x: 'C1'): number[]; +>x : 'C1' +} + +interface C2 extends B { +>C2 : C2 +>B : B + + (x: 'C2'): boolean[]; +>x : 'C2' +} + +interface C extends C1, C2 { +>C : C +>C1 : C1 +>C2 : C2 + + (x: 'C'): string; +>x : 'C' +} + +var c: C; +>c : C +>C : C + +// none of these lines should error +var x1: string[] = c('B2'); >x1 : string[] ->b('B2') : string[] ->b : B +>c('B2') : string[] +>c : C -var x2: number = b('B1'); +var x2: number = c('B1'); >x2 : number ->b('B1') : number ->b : B +>c('B1') : number +>c : C -var x3: boolean = b('A2'); +var x3: boolean = c('A2'); >x3 : boolean ->b('A2') : boolean ->b : B +>c('A2') : boolean +>c : C -var x4: string = b('A1'); +var x4: string = c('A1'); >x4 : string ->b('A1') : string ->b : B +>c('A1') : string +>c : C -var x5: void = b('A0'); +var x5: void = c('A0'); >x5 : void ->b('A0') : void ->b : B +>c('A0') : void +>c : C + +var x6: number[] = c('C1'); +>x6 : number[] +>c('C1') : number[] +>c : C + +var x7: boolean[] = c('C2'); +>x7 : boolean[] +>c('C2') : boolean[] +>c : C + +var x8: string = c('C'); +>x8 : string +>c('C') : string +>c : C + +var x9: void = c('generic'); +>x9 : void +>c('generic') : void +>c : C diff --git a/tests/baselines/reference/logicalOrExpressionIsNotContextuallyTyped.types b/tests/baselines/reference/logicalOrExpressionIsNotContextuallyTyped.types index f450307758d..72fd6281ba9 100644 --- a/tests/baselines/reference/logicalOrExpressionIsNotContextuallyTyped.types +++ b/tests/baselines/reference/logicalOrExpressionIsNotContextuallyTyped.types @@ -11,14 +11,14 @@ var a: (a: string) => string; // bug 786110 var r = a || ((a) => a.toLowerCase()); ->r : (a: any) => any ->a || ((a) => a.toLowerCase()) : (a: any) => any +>r : (a: string) => string +>a || ((a) => a.toLowerCase()) : (a: string) => string >a : (a: string) => string ->((a) => a.toLowerCase()) : (a: any) => any ->(a) => a.toLowerCase() : (a: any) => any ->a : any ->a.toLowerCase() : any ->a.toLowerCase : any ->a : any ->toLowerCase : any +>((a) => a.toLowerCase()) : (a: string) => string +>(a) => a.toLowerCase() : (a: string) => string +>a : string +>a.toLowerCase() : string +>a.toLowerCase : () => string +>a : string +>toLowerCase : () => string diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.js new file mode 100644 index 00000000000..983dc004acf --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.js @@ -0,0 +1,35 @@ +//// [moduleSharesNameWithImportDeclarationInsideIt.ts] +module Z.M { + export function bar() { + return ""; + } +} +module A.M { + import M = Z.M; + export function bar() { + } + M.bar(); // Should call Z.M.bar +} + +//// [moduleSharesNameWithImportDeclarationInsideIt.js] +var Z; +(function (Z) { + var M; + (function (M) { + function bar() { + return ""; + } + M.bar = bar; + })(M = Z.M || (Z.M = {})); +})(Z || (Z = {})); +var A; +(function (A) { + var M; + (function (_M) { + var M = Z.M; + function bar() { + } + _M.bar = bar; + M.bar(); // Should call Z.M.bar + })(M = A.M || (A.M = {})); +})(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.types b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.types new file mode 100644 index 00000000000..5a29a01cec7 --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.types @@ -0,0 +1,29 @@ +=== tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt.ts === +module Z.M { +>Z : typeof Z +>M : typeof M + + export function bar() { +>bar : () => string + + return ""; + } +} +module A.M { +>A : typeof A +>M : typeof A.M + + import M = Z.M; +>M : typeof M +>Z : typeof Z +>M : typeof M + + export function bar() { +>bar : () => void + } + M.bar(); // Should call Z.M.bar +>M.bar() : string +>M.bar : () => string +>M : typeof M +>bar : () => string +} diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt2.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt2.js new file mode 100644 index 00000000000..1366f52e7f8 --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt2.js @@ -0,0 +1,35 @@ +//// [moduleSharesNameWithImportDeclarationInsideIt2.ts] +module Z.M { + export function bar() { + return ""; + } +} +module A.M { + export import M = Z.M; + export function bar() { + } + M.bar(); // Should call Z.M.bar +} + +//// [moduleSharesNameWithImportDeclarationInsideIt2.js] +var Z; +(function (Z) { + var M; + (function (M) { + function bar() { + return ""; + } + M.bar = bar; + })(M = Z.M || (Z.M = {})); +})(Z || (Z = {})); +var A; +(function (A) { + var M; + (function (M) { + M.M = Z.M; + function bar() { + } + M.bar = bar; + M.M.bar(); // Should call Z.M.bar + })(M = A.M || (A.M = {})); +})(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt2.types b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt2.types new file mode 100644 index 00000000000..75aba0e2d0e --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt2.types @@ -0,0 +1,29 @@ +=== tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt2.ts === +module Z.M { +>Z : typeof Z +>M : typeof M + + export function bar() { +>bar : () => string + + return ""; + } +} +module A.M { +>A : typeof A +>M : typeof A.M + + export import M = Z.M; +>M : typeof M +>Z : typeof Z +>M : typeof M + + export function bar() { +>bar : () => void + } + M.bar(); // Should call Z.M.bar +>M.bar() : string +>M.bar : () => string +>M : typeof M +>bar : () => string +} diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.errors.txt b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.errors.txt new file mode 100644 index 00000000000..f8fa117c024 --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt3.ts(10,12): error TS2300: Duplicate identifier 'M'. +tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt3.ts(11,12): error TS2300: Duplicate identifier 'M'. + + +==== tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt3.ts (2 errors) ==== + module Z { + export module M { + export function bar() { + return ""; + } + } + export interface I { } + } + module A.M { + import M = Z.M; + ~ +!!! error TS2300: Duplicate identifier 'M'. + import M = Z.I; + ~ +!!! error TS2300: Duplicate identifier 'M'. + + export function bar() { + } + M.bar(); // Should call Z.M.bar + } \ No newline at end of file diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.js new file mode 100644 index 00000000000..c11b36f643a --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.js @@ -0,0 +1,40 @@ +//// [moduleSharesNameWithImportDeclarationInsideIt3.ts] +module Z { + export module M { + export function bar() { + return ""; + } + } + export interface I { } +} +module A.M { + import M = Z.M; + import M = Z.I; + + export function bar() { + } + M.bar(); // Should call Z.M.bar +} + +//// [moduleSharesNameWithImportDeclarationInsideIt3.js] +var Z; +(function (Z) { + var M; + (function (M) { + function bar() { + return ""; + } + M.bar = bar; + })(M = Z.M || (Z.M = {})); +})(Z || (Z = {})); +var A; +(function (A) { + var M; + (function (_M) { + var M = Z.M; + function bar() { + } + _M.bar = bar; + M.bar(); // Should call Z.M.bar + })(M = A.M || (A.M = {})); +})(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.js new file mode 100644 index 00000000000..c61f3d4dd9d --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.js @@ -0,0 +1,36 @@ +//// [moduleSharesNameWithImportDeclarationInsideIt4.ts] +module Z.M { + export function bar() { + return ""; + } +} +module A.M { + interface M { } + import M = Z.M; + export function bar() { + } + M.bar(); // Should call Z.M.bar +} + +//// [moduleSharesNameWithImportDeclarationInsideIt4.js] +var Z; +(function (Z) { + var M; + (function (M) { + function bar() { + return ""; + } + M.bar = bar; + })(M = Z.M || (Z.M = {})); +})(Z || (Z = {})); +var A; +(function (A) { + var M; + (function (_M) { + var M = Z.M; + function bar() { + } + _M.bar = bar; + M.bar(); // Should call Z.M.bar + })(M = A.M || (A.M = {})); +})(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.types b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.types new file mode 100644 index 00000000000..b4df2e0ae08 --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt4.ts === +module Z.M { +>Z : typeof Z +>M : typeof M + + export function bar() { +>bar : () => string + + return ""; + } +} +module A.M { +>A : typeof A +>M : typeof A.M + + interface M { } +>M : M + + import M = Z.M; +>M : typeof M +>Z : typeof Z +>M : typeof M + + export function bar() { +>bar : () => void + } + M.bar(); // Should call Z.M.bar +>M.bar() : string +>M.bar : () => string +>M : typeof M +>bar : () => string +} diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.errors.txt b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.errors.txt new file mode 100644 index 00000000000..5e548809e9c --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt5.ts(10,12): error TS2300: Duplicate identifier 'M'. +tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt5.ts(11,12): error TS2300: Duplicate identifier 'M'. + + +==== tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt5.ts (2 errors) ==== + module Z { + export module M { + export function bar() { + return ""; + } + } + export interface I { } + } + module A.M { + import M = Z.I; + ~ +!!! error TS2300: Duplicate identifier 'M'. + import M = Z.M; + ~ +!!! error TS2300: Duplicate identifier 'M'. + + export function bar() { + } + M.bar(); // Should call Z.M.bar + } \ No newline at end of file diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js new file mode 100644 index 00000000000..0995dcbb9c0 --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js @@ -0,0 +1,39 @@ +//// [moduleSharesNameWithImportDeclarationInsideIt5.ts] +module Z { + export module M { + export function bar() { + return ""; + } + } + export interface I { } +} +module A.M { + import M = Z.I; + import M = Z.M; + + export function bar() { + } + M.bar(); // Should call Z.M.bar +} + +//// [moduleSharesNameWithImportDeclarationInsideIt5.js] +var Z; +(function (Z) { + var M; + (function (M) { + function bar() { + return ""; + } + M.bar = bar; + })(M = Z.M || (Z.M = {})); +})(Z || (Z = {})); +var A; +(function (A) { + var M; + (function (M) { + function bar() { + } + M.bar = bar; + M.bar(); // Should call Z.M.bar + })(M = A.M || (A.M = {})); +})(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.js new file mode 100644 index 00000000000..51b2d4f89f9 --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.js @@ -0,0 +1,32 @@ +//// [moduleSharesNameWithImportDeclarationInsideIt6.ts] +module Z.M { + export function bar() { + return ""; + } +} +module A.M { + import M = Z.M; + export function bar() { + } +} + +//// [moduleSharesNameWithImportDeclarationInsideIt6.js] +var Z; +(function (Z) { + var M; + (function (M) { + function bar() { + return ""; + } + M.bar = bar; + })(M = Z.M || (Z.M = {})); +})(Z || (Z = {})); +var A; +(function (A) { + var M; + (function (M) { + function bar() { + } + M.bar = bar; + })(M = A.M || (A.M = {})); +})(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.types b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.types new file mode 100644 index 00000000000..01879d2db11 --- /dev/null +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt6.ts === +module Z.M { +>Z : typeof Z +>M : typeof M + + export function bar() { +>bar : () => string + + return ""; + } +} +module A.M { +>A : typeof A +>M : typeof A.M + + import M = Z.M; +>M : typeof M +>Z : typeof Z +>M : typeof M + + export function bar() { +>bar : () => void + } +} diff --git a/tests/baselines/reference/optionalBindingParameters1.errors.txt b/tests/baselines/reference/optionalBindingParameters1.errors.txt new file mode 100644 index 00000000000..a2961fb9651 --- /dev/null +++ b/tests/baselines/reference/optionalBindingParameters1.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts(2,14): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts(8,5): error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'. + + +==== tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts (2 errors) ==== + + function foo([x,y,z]?: [string, number, boolean]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + + } + + foo(["", 0, false]); + + foo([false, 0, ""]); + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'. \ No newline at end of file diff --git a/tests/baselines/reference/optionalBindingParameters1.js b/tests/baselines/reference/optionalBindingParameters1.js new file mode 100644 index 00000000000..536cb1e567a --- /dev/null +++ b/tests/baselines/reference/optionalBindingParameters1.js @@ -0,0 +1,16 @@ +//// [optionalBindingParameters1.ts] + +function foo([x,y,z]?: [string, number, boolean]) { + +} + +foo(["", 0, false]); + +foo([false, 0, ""]); + +//// [optionalBindingParameters1.js] +function foo(_a) { + var x = _a[0], y = _a[1], z = _a[2]; +} +foo(["", 0, false]); +foo([false, 0, ""]); diff --git a/tests/baselines/reference/optionalBindingParameters2.errors.txt b/tests/baselines/reference/optionalBindingParameters2.errors.txt new file mode 100644 index 00000000000..e67687722d0 --- /dev/null +++ b/tests/baselines/reference/optionalBindingParameters2.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/es6/destructuring/optionalBindingParameters2.ts(2,14): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/optionalBindingParameters2.ts(8,5): error TS2345: Argument of type '{ x: boolean; y: number; z: string; }' is not assignable to parameter of type '{ x: string; y: number; z: boolean; }'. + Types of property 'x' are incompatible. + Type 'boolean' is not assignable to type 'string'. + + +==== tests/cases/conformance/es6/destructuring/optionalBindingParameters2.ts (2 errors) ==== + + function foo({ x, y, z }?: { x: string; y: number; z: boolean }) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + + } + + foo({ x: "", y: 0, z: false }); + + foo({ x: false, y: 0, z: "" }); + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ x: boolean; y: number; z: string; }' is not assignable to parameter of type '{ x: string; y: number; z: boolean; }'. +!!! error TS2345: Types of property 'x' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/optionalBindingParameters2.js b/tests/baselines/reference/optionalBindingParameters2.js new file mode 100644 index 00000000000..04e1138561a --- /dev/null +++ b/tests/baselines/reference/optionalBindingParameters2.js @@ -0,0 +1,16 @@ +//// [optionalBindingParameters2.ts] + +function foo({ x, y, z }?: { x: string; y: number; z: boolean }) { + +} + +foo({ x: "", y: 0, z: false }); + +foo({ x: false, y: 0, z: "" }); + +//// [optionalBindingParameters2.js] +function foo(_a) { + var x = _a.x, y = _a.y, z = _a.z; +} +foo({ x: "", y: 0, z: false }); +foo({ x: false, y: 0, z: "" }); diff --git a/tests/baselines/reference/optionalBindingParametersInOverloads1.errors.txt b/tests/baselines/reference/optionalBindingParametersInOverloads1.errors.txt new file mode 100644 index 00000000000..5999ec514b0 --- /dev/null +++ b/tests/baselines/reference/optionalBindingParametersInOverloads1.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads1.ts(9,5): error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'. + + +==== tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads1.ts (1 errors) ==== + + function foo([x, y, z] ?: [string, number, boolean]); + function foo(...rest: any[]) { + + } + + foo(["", 0, false]); + + foo([false, 0, ""]); + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'. \ No newline at end of file diff --git a/tests/baselines/reference/optionalBindingParametersInOverloads1.js b/tests/baselines/reference/optionalBindingParametersInOverloads1.js new file mode 100644 index 00000000000..3658efa72c6 --- /dev/null +++ b/tests/baselines/reference/optionalBindingParametersInOverloads1.js @@ -0,0 +1,20 @@ +//// [optionalBindingParametersInOverloads1.ts] + +function foo([x, y, z] ?: [string, number, boolean]); +function foo(...rest: any[]) { + +} + +foo(["", 0, false]); + +foo([false, 0, ""]); + +//// [optionalBindingParametersInOverloads1.js] +function foo() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +} +foo(["", 0, false]); +foo([false, 0, ""]); diff --git a/tests/baselines/reference/optionalBindingParametersInOverloads2.errors.txt b/tests/baselines/reference/optionalBindingParametersInOverloads2.errors.txt new file mode 100644 index 00000000000..765fd5e3de6 --- /dev/null +++ b/tests/baselines/reference/optionalBindingParametersInOverloads2.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads2.ts(9,5): error TS2345: Argument of type '{ x: boolean; y: number; z: string; }' is not assignable to parameter of type '{ x: string; y: number; z: boolean; }'. + Types of property 'x' are incompatible. + Type 'boolean' is not assignable to type 'string'. + + +==== tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads2.ts (1 errors) ==== + + function foo({ x, y, z }?: { x: string; y: number; z: boolean }); + function foo(...rest: any[]) { + + } + + foo({ x: "", y: 0, z: false }); + + foo({ x: false, y: 0, z: "" }); + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ x: boolean; y: number; z: string; }' is not assignable to parameter of type '{ x: string; y: number; z: boolean; }'. +!!! error TS2345: Types of property 'x' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/optionalBindingParametersInOverloads2.js b/tests/baselines/reference/optionalBindingParametersInOverloads2.js new file mode 100644 index 00000000000..1ddfdae4f07 --- /dev/null +++ b/tests/baselines/reference/optionalBindingParametersInOverloads2.js @@ -0,0 +1,20 @@ +//// [optionalBindingParametersInOverloads2.ts] + +function foo({ x, y, z }?: { x: string; y: number; z: boolean }); +function foo(...rest: any[]) { + +} + +foo({ x: "", y: 0, z: false }); + +foo({ x: false, y: 0, z: "" }); + +//// [optionalBindingParametersInOverloads2.js] +function foo() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +} +foo({ x: "", y: 0, z: false }); +foo({ x: false, y: 0, z: "" }); diff --git a/tests/baselines/reference/parenthesizedContexualTyping1.js b/tests/baselines/reference/parenthesizedContexualTyping1.js new file mode 100644 index 00000000000..2f1e9ff62fc --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping1.js @@ -0,0 +1,52 @@ +//// [parenthesizedContexualTyping1.ts] + +function fun(g: (x: T) => T, x: T): T; +function fun(g: (x: T) => T, h: (y: T) => T, x: T): T; +function fun(g: (x: T) => T, x: T): T { + return g(x); +} + +var a = fun(x => x, 10); +var b = fun((x => x), 10); +var c = fun(((x => x)), 10); +var d = fun((((x => x))), 10); + +var e = fun(x => x, x => x, 10); +var f = fun((x => x), (x => x), 10); +var g = fun(((x => x)), ((x => x)), 10); +var h = fun((((x => x))), ((x => x)), 10); + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10); +var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); +var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); +var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10); + +var lambda1: (x: number) => number = x => x; +var lambda2: (x: number) => number = (x => x); + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); + +//// [parenthesizedContexualTyping1.js] +function fun(g, x) { + return g(x); +} +var a = fun(function (x) { return x; }, 10); +var b = fun((function (x) { return x; }), 10); +var c = fun(((function (x) { return x; })), 10); +var d = fun((((function (x) { return x; }))), 10); +var e = fun(function (x) { return x; }, function (x) { return x; }, 10); +var f = fun((function (x) { return x; }), (function (x) { return x; }), 10); +var g = fun(((function (x) { return x; })), ((function (x) { return x; })), 10); +var h = fun((((function (x) { return x; }))), ((function (x) { return x; })), 10); +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? function (x) { return x; } : function (x) { return undefined; }), 10); +var j = fun((Math.random() < 0.5 ? (function (x) { return x; }) : (function (x) { return undefined; })), 10); +var k = fun((Math.random() < 0.5 ? (function (x) { return x; }) : (function (x) { return undefined; })), function (x) { return x; }, 10); +var l = fun(((Math.random() < 0.5 ? ((function (x) { return x; })) : ((function (x) { return undefined; })))), ((function (x) { return x; })), 10); +var lambda1 = function (x) { return x; }; +var lambda2 = (function (x) { return x; }); +var obj1 = { x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } }; +var obj2 = ({ x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } }); diff --git a/tests/baselines/reference/parenthesizedContexualTyping1.types b/tests/baselines/reference/parenthesizedContexualTyping1.types new file mode 100644 index 00000000000..60020fd8eb2 --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping1.types @@ -0,0 +1,289 @@ +=== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping1.ts === + +function fun(g: (x: T) => T, x: T): T; +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>g : (x: T) => T +>x : T +>T : T +>T : T +>x : T +>T : T +>T : T + +function fun(g: (x: T) => T, h: (y: T) => T, x: T): T; +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>g : (x: T) => T +>x : T +>T : T +>T : T +>h : (y: T) => T +>y : T +>T : T +>T : T +>x : T +>T : T +>T : T + +function fun(g: (x: T) => T, x: T): T { +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>g : (x: T) => T +>x : T +>T : T +>T : T +>x : T +>T : T +>T : T + + return g(x); +>g(x) : T +>g : (x: T) => T +>x : T +} + +var a = fun(x => x, 10); +>a : number +>fun(x => x, 10) : number +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: number) => number +>x : number +>x : number + +var b = fun((x => x), 10); +>b : number +>fun((x => x), 10) : number +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +var c = fun(((x => x)), 10); +>c : number +>fun(((x => x)), 10) : number +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +var d = fun((((x => x))), 10); +>d : number +>fun((((x => x))), 10) : number +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(((x => x))) : (x: number) => number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +var e = fun(x => x, x => x, 10); +>e : number +>fun(x => x, x => x, 10) : number +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: number) => number +>x : number +>x : number +>x => x : (x: number) => number +>x : number +>x : number + +var f = fun((x => x), (x => x), 10); +>f : number +>fun((x => x), (x => x), 10) : number +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +var g = fun(((x => x)), ((x => x)), 10); +>g : number +>fun(((x => x)), ((x => x)), 10) : number +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +var h = fun((((x => x))), ((x => x)), 10); +>h : number +>fun((((x => x))), ((x => x)), 10) : number +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(((x => x))) : (x: number) => number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10); +>i : any +>fun((Math.random() < 0.5 ? x => x : x => undefined), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(Math.random() < 0.5 ? x => x : x => undefined) : (x: number) => any +>Math.random() < 0.5 ? x => x : x => undefined : (x: number) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>x => x : (x: number) => number +>x : number +>x : number +>x => undefined : (x: number) => any +>x : number +>undefined : undefined + +var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); +>j : any +>fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: number) => any +>Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: number) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>(x => undefined) : (x: number) => any +>x => undefined : (x: number) => any +>x : number +>undefined : undefined + +var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); +>k : any +>fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: number) => any +>Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: number) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>(x => undefined) : (x: number) => any +>x => undefined : (x: number) => any +>x : number +>undefined : undefined +>x => x : (x: any) => any +>x : any +>x : any + +var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10); +>l : any +>fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))) : (x: number) => any +>(Math.random() < 0.5 ? ((x => x)) : ((x => undefined))) : (x: number) => any +>Math.random() < 0.5 ? ((x => x)) : ((x => undefined)) : (x: number) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>((x => undefined)) : (x: number) => any +>(x => undefined) : (x: number) => any +>x => undefined : (x: number) => any +>x : number +>undefined : undefined +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +var lambda1: (x: number) => number = x => x; +>lambda1 : (x: number) => number +>x : number +>x => x : (x: number) => number +>x : number +>x : number + +var lambda2: (x: number) => number = (x => x); +>lambda2 : (x: number) => number +>x : number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>x : (p: number) => string +>p : number +>y : (p: string) => number +>p : string + +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +>obj1 : { x: (p: number) => string; y: (p: string) => number; } +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: number) => any; y: (y: string) => any; } +>x : (x: number) => any +>x => (x, undefined) : (x: number) => any +>x : number +>(x, undefined) : undefined +>x, undefined : undefined +>x : number +>undefined : undefined +>y : (y: string) => any +>y => (y, undefined) : (y: string) => any +>y : string +>(y, undefined) : undefined +>y, undefined : undefined +>y : string +>undefined : undefined + +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); +>obj2 : { x: (p: number) => string; y: (p: string) => number; } +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>({ x: x => (x, undefined), y: y => (y, undefined) }) : { x: (x: number) => any; y: (y: string) => any; } +>{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: number) => any; y: (y: string) => any; } +>x : (x: number) => any +>x => (x, undefined) : (x: number) => any +>x : number +>(x, undefined) : undefined +>x, undefined : undefined +>x : number +>undefined : undefined +>y : (y: string) => any +>y => (y, undefined) : (y: string) => any +>y : string +>(y, undefined) : undefined +>y, undefined : undefined +>y : string +>undefined : undefined + diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.js b/tests/baselines/reference/parenthesizedContexualTyping2.js new file mode 100644 index 00000000000..d5e4e0ebe8f --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping2.js @@ -0,0 +1,128 @@ +//// [parenthesizedContexualTyping2.ts] +// These tests ensure that in cases where it may *appear* that a value has a type, +// they actually are properly being contextually typed. The way we test this is +// that we invoke contextually typed arguments with type arguments. +// Since 'any' cannot be invoked with type arguments, we should get errors +// back if contextual typing is not taking effect. + +type FuncType = (x: (p: T) => T) => typeof x; + +function fun(f: FuncType, x: T): T; +function fun(f: FuncType, g: FuncType, x: T): T; +function fun(...rest: any[]): T { + return undefined; +} + +var a = fun(x => { x(undefined); return x; }, 10); +var b = fun((x => { x(undefined); return x; }), 10); +var c = fun(((x => { x(undefined); return x; })), 10); +var d = fun((((x => { x(undefined); return x; }))), 10); + +var e = fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10); +var f = fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10); +var g = fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10); +var h = fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10); + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10); +var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10); +var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10); +var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10); + +var lambda1: FuncType = x => { x(undefined); return x; }; +var lambda2: FuncType = (x => { x(undefined); return x; }); + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); + +//// [parenthesizedContexualTyping2.js] +// These tests ensure that in cases where it may *appear* that a value has a type, +// they actually are properly being contextually typed. The way we test this is +// that we invoke contextually typed arguments with type arguments. +// Since 'any' cannot be invoked with type arguments, we should get errors +// back if contextual typing is not taking effect. +function fun() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } + return undefined; +} +var a = fun(function (x) { + x(undefined); + return x; +}, 10); +var b = fun((function (x) { + x(undefined); + return x; +}), 10); +var c = fun(((function (x) { + x(undefined); + return x; +})), 10); +var d = fun((((function (x) { + x(undefined); + return x; +}))), 10); +var e = fun(function (x) { + x(undefined); + return x; +}, function (x) { + x(undefined); + return x; +}, 10); +var f = fun((function (x) { + x(undefined); + return x; +}), (function (x) { + x(undefined); + return x; +}), 10); +var g = fun(((function (x) { + x(undefined); + return x; +})), ((function (x) { + x(undefined); + return x; +})), 10); +var h = fun((((function (x) { + x(undefined); + return x; +}))), ((function (x) { + x(undefined); + return x; +})), 10); +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? function (x) { + x(undefined); + return x; +} : function (x) { return undefined; }), 10); +var j = fun((Math.random() < 0.5 ? (function (x) { + x(undefined); + return x; +}) : (function (x) { return undefined; })), 10); +var k = fun((Math.random() < 0.5 ? (function (x) { + x(undefined); + return x; +}) : (function (x) { return undefined; })), function (x) { + x(undefined); + return x; +}, 10); +var l = fun(((Math.random() < 0.5 ? ((function (x) { + x(undefined); + return x; +})) : ((function (x) { return undefined; })))), ((function (x) { + x(undefined); + return x; +})), 10); +var lambda1 = function (x) { + x(undefined); + return x; +}; +var lambda2 = (function (x) { + x(undefined); + return x; +}); +var obj1 = { x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } }; +var obj2 = ({ x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } }); diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.types b/tests/baselines/reference/parenthesizedContexualTyping2.types new file mode 100644 index 00000000000..6824cc0f6e9 --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping2.types @@ -0,0 +1,350 @@ +=== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts === +// These tests ensure that in cases where it may *appear* that a value has a type, +// they actually are properly being contextually typed. The way we test this is +// that we invoke contextually typed arguments with type arguments. +// Since 'any' cannot be invoked with type arguments, we should get errors +// back if contextual typing is not taking effect. + +type FuncType = (x: (p: T) => T) => typeof x; +>FuncType : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>T : T +>p : T +>T : T +>T : T +>x : (p: T) => T + +function fun(f: FuncType, x: T): T; +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>T : T +>f : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>x : T +>T : T +>T : T + +function fun(f: FuncType, g: FuncType, x: T): T; +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>T : T +>f : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>g : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>x : T +>T : T +>T : T + +function fun(...rest: any[]): T { +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>T : T +>rest : any[] +>T : T + + return undefined; +>undefined : undefined +} + +var a = fun(x => { x(undefined); return x; }, 10); +>a : number +>fun(x => { x(undefined); return x; }, 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var b = fun((x => { x(undefined); return x; }), 10); +>b : number +>fun((x => { x(undefined); return x; }), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var c = fun(((x => { x(undefined); return x; })), 10); +>c : number +>fun(((x => { x(undefined); return x; })), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var d = fun((((x => { x(undefined); return x; }))), 10); +>d : number +>fun((((x => { x(undefined); return x; }))), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(((x => { x(undefined); return x; }))) : (x: (p: T) => T) => (p: T) => T +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var e = fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10); +>e : number +>fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var f = fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10); +>f : number +>fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var g = fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10); +>g : number +>fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var h = fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10); +>h : number +>fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(((x => { x(undefined); return x; }))) : (x: (p: T) => T) => (p: T) => T +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10); +>i : number +>fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined) : (x: (p: T) => T) => any +>Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined : (x: (p: T) => T) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>x => undefined : (x: (p: T) => T) => any +>x : (p: T) => T +>undefined : undefined + +var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10); +>j : number +>fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)) : (x: (p: T) => T) => any +>Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined) : (x: (p: T) => T) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>(x => undefined) : (x: (p: T) => T) => any +>x => undefined : (x: (p: T) => T) => any +>x : (p: T) => T +>undefined : undefined + +var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10); +>k : number +>fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)) : (x: (p: T) => T) => any +>Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined) : (x: (p: T) => T) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>(x => undefined) : (x: (p: T) => T) => any +>x => undefined : (x: (p: T) => T) => any +>x : (p: T) => T +>undefined : undefined +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10); +>l : number +>fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))) : (x: (p: T) => T) => any +>(Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined))) : (x: (p: T) => T) => any +>Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)) : (x: (p: T) => T) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>((x => undefined)) : (x: (p: T) => T) => any +>(x => undefined) : (x: (p: T) => T) => any +>x => undefined : (x: (p: T) => T) => any +>x : (p: T) => T +>undefined : undefined +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var lambda1: FuncType = x => { x(undefined); return x; }; +>lambda1 : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var lambda2: FuncType = (x => { x(undefined); return x; }); +>lambda2 : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>x : (p: number) => string +>p : number +>y : (p: string) => number +>p : string + +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +>obj1 : { x: (p: number) => string; y: (p: string) => number; } +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: number) => any; y: (y: string) => any; } +>x : (x: number) => any +>x => (x, undefined) : (x: number) => any +>x : number +>(x, undefined) : undefined +>x, undefined : undefined +>x : number +>undefined : undefined +>y : (y: string) => any +>y => (y, undefined) : (y: string) => any +>y : string +>(y, undefined) : undefined +>y, undefined : undefined +>y : string +>undefined : undefined + +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); +>obj2 : { x: (p: number) => string; y: (p: string) => number; } +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>({ x: x => (x, undefined), y: y => (y, undefined) }) : { x: (x: number) => any; y: (y: string) => any; } +>{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: number) => any; y: (y: string) => any; } +>x : (x: number) => any +>x => (x, undefined) : (x: number) => any +>x : number +>(x, undefined) : undefined +>x, undefined : undefined +>x : number +>undefined : undefined +>y : (y: string) => any +>y => (y, undefined) : (y: string) => any +>y : string +>(y, undefined) : undefined +>y, undefined : undefined +>y : string +>undefined : undefined + diff --git a/tests/baselines/reference/parenthesizedContexualTyping3.js b/tests/baselines/reference/parenthesizedContexualTyping3.js new file mode 100644 index 00000000000..69784d14ce4 --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping3.js @@ -0,0 +1,35 @@ +//// [parenthesizedContexualTyping3.ts] + +// Contextual typing for parenthesized substitution expressions in tagged templates. + +/** + * tempFun - Can't have fun for too long. + */ +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T { + return g(x); +} + +var a = tempFun `${ x => x } ${ 10 }` +var b = tempFun `${ (x => x) } ${ 10 }` +var c = tempFun `${ ((x => x)) } ${ 10 }` +var d = tempFun `${ x => x } ${ x => x } ${ 10 }` +var e = tempFun `${ x => x } ${ (x => x) } ${ 10 }` +var f = tempFun `${ x => x } ${ ((x => x)) } ${ 10 }` +var g = tempFun `${ (x => x) } ${ (((x => x))) } ${ 10 }` +var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }` + +//// [parenthesizedContexualTyping3.js] +// Contextual typing for parenthesized substitution expressions in tagged templates. +function tempFun(tempStrs, g, x) { + return g(x); +} +var a = tempFun `${function (x) { return x; }} ${10}`; +var b = tempFun `${(function (x) { return x; })} ${10}`; +var c = tempFun `${((function (x) { return x; }))} ${10}`; +var d = tempFun `${function (x) { return x; }} ${function (x) { return x; }} ${10}`; +var e = tempFun `${function (x) { return x; }} ${(function (x) { return x; })} ${10}`; +var f = tempFun `${function (x) { return x; }} ${((function (x) { return x; }))} ${10}`; +var g = tempFun `${(function (x) { return x; })} ${(((function (x) { return x; })))} ${10}`; +var h = tempFun `${(function (x) { return x; })} ${(((function (x) { return x; })))} ${undefined}`; diff --git a/tests/baselines/reference/parenthesizedContexualTyping3.types b/tests/baselines/reference/parenthesizedContexualTyping3.types new file mode 100644 index 00000000000..26c0207e523 --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping3.types @@ -0,0 +1,142 @@ +=== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping3.ts === + +// Contextual typing for parenthesized substitution expressions in tagged templates. + +/** + * tempFun - Can't have fun for too long. + */ +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>tempStrs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>g : (x: T) => T +>x : T +>T : T +>T : T +>x : T +>T : T +>T : T + +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>tempStrs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>g : (x: T) => T +>x : T +>T : T +>T : T +>h : (y: T) => T +>y : T +>T : T +>T : T +>x : T +>T : T +>T : T + +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T { +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>tempStrs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>g : (x: T) => T +>x : T +>T : T +>T : T +>x : T +>T : T +>T : T + + return g(x); +>g(x) : T +>g : (x: T) => T +>x : T +} + +var a = tempFun `${ x => x } ${ 10 }` +>a : number +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: number) => number +>x : number +>x : number + +var b = tempFun `${ (x => x) } ${ 10 }` +>b : number +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +var c = tempFun `${ ((x => x)) } ${ 10 }` +>c : number +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +var d = tempFun `${ x => x } ${ x => x } ${ 10 }` +>d : number +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: number) => number +>x : number +>x : number +>x => x : (x: number) => number +>x : number +>x : number + +var e = tempFun `${ x => x } ${ (x => x) } ${ 10 }` +>e : number +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: number) => number +>x : number +>x : number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +var f = tempFun `${ x => x } ${ ((x => x)) } ${ 10 }` +>f : number +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: number) => number +>x : number +>x : number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +var g = tempFun `${ (x => x) } ${ (((x => x))) } ${ 10 }` +>g : number +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>(((x => x))) : (x: number) => number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + +var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }` +>h : any +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any +>(((x => x))) : (x: any) => any +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any +>undefined : undefined + diff --git a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt index 4f41f7523d7..0d3528b6dc3 100644 --- a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt @@ -1,9 +1,9 @@ -error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option. -error TS5038: Option mapRoot cannot be specified without specifying sourcemap option. +error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. +error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. -!!! error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option. -!!! error TS5038: Option mapRoot cannot be specified without specifying sourcemap option. +!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. +!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt index 4f41f7523d7..0d3528b6dc3 100644 --- a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt @@ -1,9 +1,9 @@ -error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option. -error TS5038: Option mapRoot cannot be specified without specifying sourcemap option. +error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. +error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. -!!! error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option. -!!! error TS5038: Option mapRoot cannot be specified without specifying sourcemap option. +!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. +!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt index de6de5ecfc6..01a3526196c 100644 --- a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt @@ -1,7 +1,7 @@ -error TS5038: Option mapRoot cannot be specified without specifying sourcemap option. +error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. -!!! error TS5038: Option mapRoot cannot be specified without specifying sourcemap option. +!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt index de6de5ecfc6..01a3526196c 100644 --- a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt @@ -1,7 +1,7 @@ -error TS5038: Option mapRoot cannot be specified without specifying sourcemap option. +error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. -!!! error TS5038: Option mapRoot cannot be specified without specifying sourcemap option. +!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.errors.txt index 93a57bb27f5..b7abc0c2d52 100644 --- a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.errors.txt @@ -1,7 +1,7 @@ -error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option. +error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. -!!! error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option. +!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.errors.txt index 93a57bb27f5..b7abc0c2d52 100644 --- a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.errors.txt @@ -1,7 +1,7 @@ -error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option. +error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. -!!! error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option. +!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/recursivelySpecializedConstructorDeclaration.js b/tests/baselines/reference/recursivelySpecializedConstructorDeclaration.js index dd8028b086a..c0abe985dbc 100644 --- a/tests/baselines/reference/recursivelySpecializedConstructorDeclaration.js +++ b/tests/baselines/reference/recursivelySpecializedConstructorDeclaration.js @@ -74,32 +74,4 @@ declare module MsPortal.Controls.Base.ItemList { class ViewModel extends ItemValue { } } -module MsPortal.Controls.Base.ItemList { - - export interface Interface { - // Removing this line fixes the constructor of ItemValue - options: ViewModel; - } - - export class ItemValue { - constructor(value: T) { - } - } - - export class ViewModel extends ItemValue { - } -} - -// Generates: -/* -declare module MsPortal.Controls.Base.ItemList { - interface Interface { - options: ViewModel; - } - class ItemValue { - constructor(value: T); - } - class ViewModel extends ItemValue { - } -} - +*/ diff --git a/tests/baselines/reference/taggedTemplateContextualTyping1.js b/tests/baselines/reference/taggedTemplateContextualTyping1.js new file mode 100644 index 00000000000..c1ae5c384e4 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateContextualTyping1.js @@ -0,0 +1,53 @@ +//// [taggedTemplateContextualTyping1.ts] + +type FuncType = (x: (p: T) => T) => typeof x; + +function tempTag1(templateStrs: TemplateStringsArray, f: FuncType, x: T): T; +function tempTag1(templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T; +function tempTag1(...rest: any[]): T { + return undefined; +} + +// If contextual typing takes place, these functions should work. +// Otherwise, the arrow functions' parameters will be typed as 'any', +// and it is an error to invoke an any-typed value with type arguments, +// so this test will error. +tempTag1 `${ x => { x(undefined); return x; } }${ 10 }`; +tempTag1 `${ x => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ 10 }`; +tempTag1 `${ x => { x(undefined); return x; } }${ (y: (p: T) => T) => { y(undefined); return y } }${ undefined }`; +tempTag1 `${ (x: (p: T) => T) => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ undefined }`; + + +//// [taggedTemplateContextualTyping1.js] +function tempTag1(...rest) { + return undefined; +} +// If contextual typing takes place, these functions should work. +// Otherwise, the arrow functions' parameters will be typed as 'any', +// and it is an error to invoke an any-typed value with type arguments, +// so this test will error. +tempTag1 `${function (x) { + x(undefined); + return x; +}}${10}`; +tempTag1 `${function (x) { + x(undefined); + return x; +}}${function (y) { + y(undefined); + return y; +}}${10}`; +tempTag1 `${function (x) { + x(undefined); + return x; +}}${function (y) { + y(undefined); + return y; +}}${undefined}`; +tempTag1 `${function (x) { + x(undefined); + return x; +}}${function (y) { + y(undefined); + return y; +}}${undefined}`; diff --git a/tests/baselines/reference/taggedTemplateContextualTyping1.types b/tests/baselines/reference/taggedTemplateContextualTyping1.types new file mode 100644 index 00000000000..a6432d34f81 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateContextualTyping1.types @@ -0,0 +1,113 @@ +=== tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping1.ts === + +type FuncType = (x: (p: T) => T) => typeof x; +>FuncType : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>T : T +>p : T +>T : T +>T : T +>x : (p: T) => T + +function tempTag1(templateStrs: TemplateStringsArray, f: FuncType, x: T): T; +>tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>T : T +>templateStrs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>f : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>x : T +>T : T +>T : T + +function tempTag1(templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T; +>tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>T : T +>templateStrs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>f : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>h : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>x : T +>T : T +>T : T + +function tempTag1(...rest: any[]): T { +>tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>T : T +>rest : any[] +>T : T + + return undefined; +>undefined : undefined +} + +// If contextual typing takes place, these functions should work. +// Otherwise, the arrow functions' parameters will be typed as 'any', +// and it is an error to invoke an any-typed value with type arguments, +// so this test will error. +tempTag1 `${ x => { x(undefined); return x; } }${ 10 }`; +>tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +tempTag1 `${ x => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ 10 }`; +>tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>y => { y(undefined); return y; } : (y: (p: T) => T) => (p: T) => T +>y : (p: T) => T +>y(undefined) : number +>y : (p: T) => T +>undefined : undefined +>y : (p: T) => T + +tempTag1 `${ x => { x(undefined); return x; } }${ (y: (p: T) => T) => { y(undefined); return y } }${ undefined }`; +>tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>(y: (p: T) => T) => { y(undefined); return y } : (y: (p: T) => T) => (p: T) => T +>y : (p: T) => T +>T : T +>p : T +>T : T +>T : T +>y(undefined) : number +>y : (p: T) => T +>undefined : undefined +>y : (p: T) => T +>undefined : undefined + +tempTag1 `${ (x: (p: T) => T) => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ undefined }`; +>tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(x: (p: T) => T) => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>T : T +>p : T +>T : T +>T : T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>y => { y(undefined); return y; } : (y: (p: T) => T) => (p: T) => T +>y : (p: T) => T +>y(undefined) : number +>y : (p: T) => T +>undefined : undefined +>y : (p: T) => T +>undefined : undefined + diff --git a/tests/baselines/reference/taggedTemplateContextualTyping2.js b/tests/baselines/reference/taggedTemplateContextualTyping2.js new file mode 100644 index 00000000000..a24de8224f3 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateContextualTyping2.js @@ -0,0 +1,42 @@ +//// [taggedTemplateContextualTyping2.ts] + +type FuncType1 = (x: (p: T) => T) => typeof x; +type FuncType2 = (x: (p: T) => T) => typeof x; + +function tempTag2(templateStrs: TemplateStringsArray, f: FuncType1, x: number): number; +function tempTag2(templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string; +function tempTag2(...rest: any[]): any { + return undefined; +} + +// If contextual typing takes place, these functions should work. +// Otherwise, the arrow functions' parameters will be typed as 'any', +// and it is an error to invoke an any-typed value with type arguments, +// so this test will error. +tempTag2 `${ x => { x(undefined); return x; } }${ 0 }`; +tempTag2 `${ x => { x(undefined); return x; } }${ y => { y(null); return y; } }${ "hello" }`; +tempTag2 `${ x => { x(undefined); return x; } }${ undefined }${ "hello" }`; + +//// [taggedTemplateContextualTyping2.js] +function tempTag2(...rest) { + return undefined; +} +// If contextual typing takes place, these functions should work. +// Otherwise, the arrow functions' parameters will be typed as 'any', +// and it is an error to invoke an any-typed value with type arguments, +// so this test will error. +tempTag2 `${function (x) { + x(undefined); + return x; +}}${0}`; +tempTag2 `${function (x) { + x(undefined); + return x; +}}${function (y) { + y(null); + return y; +}}${"hello"}`; +tempTag2 `${function (x) { + x(undefined); + return x; +}}${undefined}${"hello"}`; diff --git a/tests/baselines/reference/taggedTemplateContextualTyping2.types b/tests/baselines/reference/taggedTemplateContextualTyping2.types new file mode 100644 index 00000000000..9ca7386dc34 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateContextualTyping2.types @@ -0,0 +1,84 @@ +=== tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping2.ts === + +type FuncType1 = (x: (p: T) => T) => typeof x; +>FuncType1 : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>T : T +>p : T +>T : T +>T : T +>x : (p: T) => T + +type FuncType2 = (x: (p: T) => T) => typeof x; +>FuncType2 : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>S : S +>T : T +>p : T +>T : T +>T : T +>x : (p: T) => T + +function tempTag2(templateStrs: TemplateStringsArray, f: FuncType1, x: number): number; +>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>templateStrs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>f : (x: (p: T) => T) => (p: T) => T +>FuncType1 : (x: (p: T) => T) => (p: T) => T +>x : number + +function tempTag2(templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string; +>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>templateStrs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>f : (x: (p: T) => T) => (p: T) => T +>FuncType2 : (x: (p: T) => T) => (p: T) => T +>h : (x: (p: T) => T) => (p: T) => T +>FuncType2 : (x: (p: T) => T) => (p: T) => T +>x : string + +function tempTag2(...rest: any[]): any { +>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>rest : any[] + + return undefined; +>undefined : undefined +} + +// If contextual typing takes place, these functions should work. +// Otherwise, the arrow functions' parameters will be typed as 'any', +// and it is an error to invoke an any-typed value with type arguments, +// so this test will error. +tempTag2 `${ x => { x(undefined); return x; } }${ 0 }`; +>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +tempTag2 `${ x => { x(undefined); return x; } }${ y => { y(null); return y; } }${ "hello" }`; +>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : string +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>y => { y(null); return y; } : (y: (p: T) => T) => (p: T) => T +>y : (p: T) => T +>y(null) : number +>y : (p: T) => T +>y : (p: T) => T + +tempTag2 `${ x => { x(undefined); return x; } }${ undefined }${ "hello" }`; +>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : string +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>undefined : undefined + diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.errors.txt new file mode 100644 index 00000000000..b38a70ca18b --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts(6,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts(6,31): error TS2322: Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts (2 errors) ==== + + + function foo(...rest: any[]) { + } + + foo `${function (x: number) { x = "bad"; } }`; + ~~~ +!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. + ~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.errors.txt new file mode 100644 index 00000000000..6b0f4b642ff --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts(5,31): error TS2322: Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts (1 errors) ==== + + function foo(...rest: any[]) { + } + + foo `${function (x: number) { x = "bad"; } }`; + ~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js new file mode 100644 index 00000000000..bc18a600458 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js @@ -0,0 +1,13 @@ +//// [taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts] + +function foo(...rest: any[]) { +} + +foo `${function (x: number) { x = "bad"; } }`; + +//// [taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js] +function foo(...rest) { +} +foo `${function (x) { + x = "bad"; +}}`; diff --git a/tests/baselines/reference/templateStringBinaryOperations.js b/tests/baselines/reference/templateStringBinaryOperations.js new file mode 100644 index 00000000000..691dad41f77 --- /dev/null +++ b/tests/baselines/reference/templateStringBinaryOperations.js @@ -0,0 +1,103 @@ +//// [templateStringBinaryOperations.ts] +var a = 1 + `${ 3 }`; +var b = 1 + `2${ 3 }`; +var c = 1 + `${ 3 }4`; +var d = 1 + `2${ 3 }4`; +var e = `${ 3 }` + 5; +var f = `2${ 3 }` + 5; +var g = `${ 3 }4` + 5; +var h = `2${ 3 }4` + 5; +var i = 1 + `${ 3 }` + 5; +var j = 1 + `2${ 3 }` + 5; +var k = 1 + `${ 3 }4` + 5; +var l = 1 + `2${ 3 }4` + 5; + +var a2 = 1 + `${ 3 - 4 }`; +var b2 = 1 + `2${ 3 - 4 }`; +var c2 = 1 + `${ 3 - 4 }5`; +var d2 = 1 + `2${ 3 - 4 }5`; +var e2 = `${ 3 - 4 }` + 6; +var f2 = `2${ 3 - 4 }` + 6; +var g2 = `${ 3 - 4 }5` + 6; +var h2 = `2${ 3 - 4 }5` + 6; +var i2 = 1 + `${ 3 - 4 }` + 6; +var j2 = 1 + `2${ 3 - 4 }` + 6; +var k2 = 1 + `${ 3 - 4 }5` + 6; +var l2 = 1 + `2${ 3 - 4 }5` + 6; + +var a3 = 1 + `${ 3 * 4 }`; +var b3 = 1 + `2${ 3 * 4 }`; +var c3 = 1 + `${ 3 * 4 }5`; +var d3 = 1 + `2${ 3 * 4 }5`; +var e3 = `${ 3 * 4 }` + 6; +var f3 = `2${ 3 * 4 }` + 6; +var g3 = `${ 3 * 4 }5` + 6; +var h3 = `2${ 3 * 4 }5` + 6; +var i3 = 1 + `${ 3 * 4 }` + 6; +var j3 = 1 + `2${ 3 * 4 }` + 6; +var k3 = 1 + `${ 3 * 4 }5` + 6; +var l3 = 1 + `2${ 3 * 4 }5` + 6; + +var a4 = 1 + `${ 3 & 4 }`; +var b4 = 1 + `2${ 3 & 4 }`; +var c4 = 1 + `${ 3 & 4 }5`; +var d4 = 1 + `2${ 3 & 4 }5`; +var e4 = `${ 3 & 4 }` + 6; +var f4 = `2${ 3 & 4 }` + 6; +var g4 = `${ 3 & 4 }5` + 6; +var h4 = `2${ 3 & 4 }5` + 6; +var i4 = 1 + `${ 3 & 4 }` + 6; +var j4 = 1 + `2${ 3 & 4 }` + 6; +var k4 = 1 + `${ 3 & 4 }5` + 6; +var l4 = 1 + `2${ 3 & 4 }5` + 6; + + +//// [templateStringBinaryOperations.js] +var a = 1 + ("" + 3); +var b = 1 + ("2" + 3); +var c = 1 + (3 + "4"); +var d = 1 + ("2" + 3 + "4"); +var e = ("" + 3) + 5; +var f = ("2" + 3) + 5; +var g = (3 + "4") + 5; +var h = ("2" + 3 + "4") + 5; +var i = 1 + ("" + 3) + 5; +var j = 1 + ("2" + 3) + 5; +var k = 1 + (3 + "4") + 5; +var l = 1 + ("2" + 3 + "4") + 5; +var a2 = 1 + ("" + (3 - 4)); +var b2 = 1 + ("2" + (3 - 4)); +var c2 = 1 + ((3 - 4) + "5"); +var d2 = 1 + ("2" + (3 - 4) + "5"); +var e2 = ("" + (3 - 4)) + 6; +var f2 = ("2" + (3 - 4)) + 6; +var g2 = ((3 - 4) + "5") + 6; +var h2 = ("2" + (3 - 4) + "5") + 6; +var i2 = 1 + ("" + (3 - 4)) + 6; +var j2 = 1 + ("2" + (3 - 4)) + 6; +var k2 = 1 + ((3 - 4) + "5") + 6; +var l2 = 1 + ("2" + (3 - 4) + "5") + 6; +var a3 = 1 + ("" + 3 * 4); +var b3 = 1 + ("2" + 3 * 4); +var c3 = 1 + (3 * 4 + "5"); +var d3 = 1 + ("2" + 3 * 4 + "5"); +var e3 = ("" + 3 * 4) + 6; +var f3 = ("2" + 3 * 4) + 6; +var g3 = (3 * 4 + "5") + 6; +var h3 = ("2" + 3 * 4 + "5") + 6; +var i3 = 1 + ("" + 3 * 4) + 6; +var j3 = 1 + ("2" + 3 * 4) + 6; +var k3 = 1 + (3 * 4 + "5") + 6; +var l3 = 1 + ("2" + 3 * 4 + "5") + 6; +var a4 = 1 + ("" + (3 & 4)); +var b4 = 1 + ("2" + (3 & 4)); +var c4 = 1 + ((3 & 4) + "5"); +var d4 = 1 + ("2" + (3 & 4) + "5"); +var e4 = ("" + (3 & 4)) + 6; +var f4 = ("2" + (3 & 4)) + 6; +var g4 = ((3 & 4) + "5") + 6; +var h4 = ("2" + (3 & 4) + "5") + 6; +var i4 = 1 + ("" + (3 & 4)) + 6; +var j4 = 1 + ("2" + (3 & 4)) + 6; +var k4 = 1 + ((3 & 4) + "5") + 6; +var l4 = 1 + ("2" + (3 & 4) + "5") + 6; diff --git a/tests/baselines/reference/templateStringBinaryOperations.types b/tests/baselines/reference/templateStringBinaryOperations.types new file mode 100644 index 00000000000..094c82f3678 --- /dev/null +++ b/tests/baselines/reference/templateStringBinaryOperations.types @@ -0,0 +1,245 @@ +=== tests/cases/conformance/es6/templates/templateStringBinaryOperations.ts === +var a = 1 + `${ 3 }`; +>a : string +>1 + `${ 3 }` : string + +var b = 1 + `2${ 3 }`; +>b : string +>1 + `2${ 3 }` : string + +var c = 1 + `${ 3 }4`; +>c : string +>1 + `${ 3 }4` : string + +var d = 1 + `2${ 3 }4`; +>d : string +>1 + `2${ 3 }4` : string + +var e = `${ 3 }` + 5; +>e : string +>`${ 3 }` + 5 : string + +var f = `2${ 3 }` + 5; +>f : string +>`2${ 3 }` + 5 : string + +var g = `${ 3 }4` + 5; +>g : string +>`${ 3 }4` + 5 : string + +var h = `2${ 3 }4` + 5; +>h : string +>`2${ 3 }4` + 5 : string + +var i = 1 + `${ 3 }` + 5; +>i : string +>1 + `${ 3 }` + 5 : string +>1 + `${ 3 }` : string + +var j = 1 + `2${ 3 }` + 5; +>j : string +>1 + `2${ 3 }` + 5 : string +>1 + `2${ 3 }` : string + +var k = 1 + `${ 3 }4` + 5; +>k : string +>1 + `${ 3 }4` + 5 : string +>1 + `${ 3 }4` : string + +var l = 1 + `2${ 3 }4` + 5; +>l : string +>1 + `2${ 3 }4` + 5 : string +>1 + `2${ 3 }4` : string + +var a2 = 1 + `${ 3 - 4 }`; +>a2 : string +>1 + `${ 3 - 4 }` : string +>3 - 4 : number + +var b2 = 1 + `2${ 3 - 4 }`; +>b2 : string +>1 + `2${ 3 - 4 }` : string +>3 - 4 : number + +var c2 = 1 + `${ 3 - 4 }5`; +>c2 : string +>1 + `${ 3 - 4 }5` : string +>3 - 4 : number + +var d2 = 1 + `2${ 3 - 4 }5`; +>d2 : string +>1 + `2${ 3 - 4 }5` : string +>3 - 4 : number + +var e2 = `${ 3 - 4 }` + 6; +>e2 : string +>`${ 3 - 4 }` + 6 : string +>3 - 4 : number + +var f2 = `2${ 3 - 4 }` + 6; +>f2 : string +>`2${ 3 - 4 }` + 6 : string +>3 - 4 : number + +var g2 = `${ 3 - 4 }5` + 6; +>g2 : string +>`${ 3 - 4 }5` + 6 : string +>3 - 4 : number + +var h2 = `2${ 3 - 4 }5` + 6; +>h2 : string +>`2${ 3 - 4 }5` + 6 : string +>3 - 4 : number + +var i2 = 1 + `${ 3 - 4 }` + 6; +>i2 : string +>1 + `${ 3 - 4 }` + 6 : string +>1 + `${ 3 - 4 }` : string +>3 - 4 : number + +var j2 = 1 + `2${ 3 - 4 }` + 6; +>j2 : string +>1 + `2${ 3 - 4 }` + 6 : string +>1 + `2${ 3 - 4 }` : string +>3 - 4 : number + +var k2 = 1 + `${ 3 - 4 }5` + 6; +>k2 : string +>1 + `${ 3 - 4 }5` + 6 : string +>1 + `${ 3 - 4 }5` : string +>3 - 4 : number + +var l2 = 1 + `2${ 3 - 4 }5` + 6; +>l2 : string +>1 + `2${ 3 - 4 }5` + 6 : string +>1 + `2${ 3 - 4 }5` : string +>3 - 4 : number + +var a3 = 1 + `${ 3 * 4 }`; +>a3 : string +>1 + `${ 3 * 4 }` : string +>3 * 4 : number + +var b3 = 1 + `2${ 3 * 4 }`; +>b3 : string +>1 + `2${ 3 * 4 }` : string +>3 * 4 : number + +var c3 = 1 + `${ 3 * 4 }5`; +>c3 : string +>1 + `${ 3 * 4 }5` : string +>3 * 4 : number + +var d3 = 1 + `2${ 3 * 4 }5`; +>d3 : string +>1 + `2${ 3 * 4 }5` : string +>3 * 4 : number + +var e3 = `${ 3 * 4 }` + 6; +>e3 : string +>`${ 3 * 4 }` + 6 : string +>3 * 4 : number + +var f3 = `2${ 3 * 4 }` + 6; +>f3 : string +>`2${ 3 * 4 }` + 6 : string +>3 * 4 : number + +var g3 = `${ 3 * 4 }5` + 6; +>g3 : string +>`${ 3 * 4 }5` + 6 : string +>3 * 4 : number + +var h3 = `2${ 3 * 4 }5` + 6; +>h3 : string +>`2${ 3 * 4 }5` + 6 : string +>3 * 4 : number + +var i3 = 1 + `${ 3 * 4 }` + 6; +>i3 : string +>1 + `${ 3 * 4 }` + 6 : string +>1 + `${ 3 * 4 }` : string +>3 * 4 : number + +var j3 = 1 + `2${ 3 * 4 }` + 6; +>j3 : string +>1 + `2${ 3 * 4 }` + 6 : string +>1 + `2${ 3 * 4 }` : string +>3 * 4 : number + +var k3 = 1 + `${ 3 * 4 }5` + 6; +>k3 : string +>1 + `${ 3 * 4 }5` + 6 : string +>1 + `${ 3 * 4 }5` : string +>3 * 4 : number + +var l3 = 1 + `2${ 3 * 4 }5` + 6; +>l3 : string +>1 + `2${ 3 * 4 }5` + 6 : string +>1 + `2${ 3 * 4 }5` : string +>3 * 4 : number + +var a4 = 1 + `${ 3 & 4 }`; +>a4 : string +>1 + `${ 3 & 4 }` : string +>3 & 4 : number + +var b4 = 1 + `2${ 3 & 4 }`; +>b4 : string +>1 + `2${ 3 & 4 }` : string +>3 & 4 : number + +var c4 = 1 + `${ 3 & 4 }5`; +>c4 : string +>1 + `${ 3 & 4 }5` : string +>3 & 4 : number + +var d4 = 1 + `2${ 3 & 4 }5`; +>d4 : string +>1 + `2${ 3 & 4 }5` : string +>3 & 4 : number + +var e4 = `${ 3 & 4 }` + 6; +>e4 : string +>`${ 3 & 4 }` + 6 : string +>3 & 4 : number + +var f4 = `2${ 3 & 4 }` + 6; +>f4 : string +>`2${ 3 & 4 }` + 6 : string +>3 & 4 : number + +var g4 = `${ 3 & 4 }5` + 6; +>g4 : string +>`${ 3 & 4 }5` + 6 : string +>3 & 4 : number + +var h4 = `2${ 3 & 4 }5` + 6; +>h4 : string +>`2${ 3 & 4 }5` + 6 : string +>3 & 4 : number + +var i4 = 1 + `${ 3 & 4 }` + 6; +>i4 : string +>1 + `${ 3 & 4 }` + 6 : string +>1 + `${ 3 & 4 }` : string +>3 & 4 : number + +var j4 = 1 + `2${ 3 & 4 }` + 6; +>j4 : string +>1 + `2${ 3 & 4 }` + 6 : string +>1 + `2${ 3 & 4 }` : string +>3 & 4 : number + +var k4 = 1 + `${ 3 & 4 }5` + 6; +>k4 : string +>1 + `${ 3 & 4 }5` + 6 : string +>1 + `${ 3 & 4 }5` : string +>3 & 4 : number + +var l4 = 1 + `2${ 3 & 4 }5` + 6; +>l4 : string +>1 + `2${ 3 & 4 }5` + 6 : string +>1 + `2${ 3 & 4 }5` : string +>3 & 4 : number + diff --git a/tests/baselines/reference/templateStringBinaryOperationsES6.js b/tests/baselines/reference/templateStringBinaryOperationsES6.js new file mode 100644 index 00000000000..8dcdd8a2aa7 --- /dev/null +++ b/tests/baselines/reference/templateStringBinaryOperationsES6.js @@ -0,0 +1,103 @@ +//// [templateStringBinaryOperationsES6.ts] +var a = 1 + `${ 3 }`; +var b = 1 + `2${ 3 }`; +var c = 1 + `${ 3 }4`; +var d = 1 + `2${ 3 }4`; +var e = `${ 3 }` + 5; +var f = `2${ 3 }` + 5; +var g = `${ 3 }4` + 5; +var h = `2${ 3 }4` + 5; +var i = 1 + `${ 3 }` + 5; +var j = 1 + `2${ 3 }` + 5; +var k = 1 + `${ 3 }4` + 5; +var l = 1 + `2${ 3 }4` + 5; + +var a2 = 1 + `${ 3 - 4 }`; +var b2 = 1 + `2${ 3 - 4 }`; +var c2 = 1 + `${ 3 - 4 }5`; +var d2 = 1 + `2${ 3 - 4 }5`; +var e2 = `${ 3 - 4 }` + 6; +var f2 = `2${ 3 - 4 }` + 6; +var g2 = `${ 3 - 4 }5` + 6; +var h2 = `2${ 3 - 4 }5` + 6; +var i2 = 1 + `${ 3 - 4 }` + 6; +var j2 = 1 + `2${ 3 - 4 }` + 6; +var k2 = 1 + `${ 3 - 4 }5` + 6; +var l2 = 1 + `2${ 3 - 4 }5` + 6; + +var a3 = 1 + `${ 3 * 4 }`; +var b3 = 1 + `2${ 3 * 4 }`; +var c3 = 1 + `${ 3 * 4 }5`; +var d3 = 1 + `2${ 3 * 4 }5`; +var e3 = `${ 3 * 4 }` + 6; +var f3 = `2${ 3 * 4 }` + 6; +var g3 = `${ 3 * 4 }5` + 6; +var h3 = `2${ 3 * 4 }5` + 6; +var i3 = 1 + `${ 3 * 4 }` + 6; +var j3 = 1 + `2${ 3 * 4 }` + 6; +var k3 = 1 + `${ 3 * 4 }5` + 6; +var l3 = 1 + `2${ 3 * 4 }5` + 6; + +var a4 = 1 + `${ 3 & 4 }`; +var b4 = 1 + `2${ 3 & 4 }`; +var c4 = 1 + `${ 3 & 4 }5`; +var d4 = 1 + `2${ 3 & 4 }5`; +var e4 = `${ 3 & 4 }` + 6; +var f4 = `2${ 3 & 4 }` + 6; +var g4 = `${ 3 & 4 }5` + 6; +var h4 = `2${ 3 & 4 }5` + 6; +var i4 = 1 + `${ 3 & 4 }` + 6; +var j4 = 1 + `2${ 3 & 4 }` + 6; +var k4 = 1 + `${ 3 & 4 }5` + 6; +var l4 = 1 + `2${ 3 & 4 }5` + 6; + + +//// [templateStringBinaryOperationsES6.js] +var a = 1 + `${3}`; +var b = 1 + `2${3}`; +var c = 1 + `${3}4`; +var d = 1 + `2${3}4`; +var e = `${3}` + 5; +var f = `2${3}` + 5; +var g = `${3}4` + 5; +var h = `2${3}4` + 5; +var i = 1 + `${3}` + 5; +var j = 1 + `2${3}` + 5; +var k = 1 + `${3}4` + 5; +var l = 1 + `2${3}4` + 5; +var a2 = 1 + `${3 - 4}`; +var b2 = 1 + `2${3 - 4}`; +var c2 = 1 + `${3 - 4}5`; +var d2 = 1 + `2${3 - 4}5`; +var e2 = `${3 - 4}` + 6; +var f2 = `2${3 - 4}` + 6; +var g2 = `${3 - 4}5` + 6; +var h2 = `2${3 - 4}5` + 6; +var i2 = 1 + `${3 - 4}` + 6; +var j2 = 1 + `2${3 - 4}` + 6; +var k2 = 1 + `${3 - 4}5` + 6; +var l2 = 1 + `2${3 - 4}5` + 6; +var a3 = 1 + `${3 * 4}`; +var b3 = 1 + `2${3 * 4}`; +var c3 = 1 + `${3 * 4}5`; +var d3 = 1 + `2${3 * 4}5`; +var e3 = `${3 * 4}` + 6; +var f3 = `2${3 * 4}` + 6; +var g3 = `${3 * 4}5` + 6; +var h3 = `2${3 * 4}5` + 6; +var i3 = 1 + `${3 * 4}` + 6; +var j3 = 1 + `2${3 * 4}` + 6; +var k3 = 1 + `${3 * 4}5` + 6; +var l3 = 1 + `2${3 * 4}5` + 6; +var a4 = 1 + `${3 & 4}`; +var b4 = 1 + `2${3 & 4}`; +var c4 = 1 + `${3 & 4}5`; +var d4 = 1 + `2${3 & 4}5`; +var e4 = `${3 & 4}` + 6; +var f4 = `2${3 & 4}` + 6; +var g4 = `${3 & 4}5` + 6; +var h4 = `2${3 & 4}5` + 6; +var i4 = 1 + `${3 & 4}` + 6; +var j4 = 1 + `2${3 & 4}` + 6; +var k4 = 1 + `${3 & 4}5` + 6; +var l4 = 1 + `2${3 & 4}5` + 6; diff --git a/tests/baselines/reference/templateStringBinaryOperationsES6.types b/tests/baselines/reference/templateStringBinaryOperationsES6.types new file mode 100644 index 00000000000..a79885904e2 --- /dev/null +++ b/tests/baselines/reference/templateStringBinaryOperationsES6.types @@ -0,0 +1,245 @@ +=== tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6.ts === +var a = 1 + `${ 3 }`; +>a : string +>1 + `${ 3 }` : string + +var b = 1 + `2${ 3 }`; +>b : string +>1 + `2${ 3 }` : string + +var c = 1 + `${ 3 }4`; +>c : string +>1 + `${ 3 }4` : string + +var d = 1 + `2${ 3 }4`; +>d : string +>1 + `2${ 3 }4` : string + +var e = `${ 3 }` + 5; +>e : string +>`${ 3 }` + 5 : string + +var f = `2${ 3 }` + 5; +>f : string +>`2${ 3 }` + 5 : string + +var g = `${ 3 }4` + 5; +>g : string +>`${ 3 }4` + 5 : string + +var h = `2${ 3 }4` + 5; +>h : string +>`2${ 3 }4` + 5 : string + +var i = 1 + `${ 3 }` + 5; +>i : string +>1 + `${ 3 }` + 5 : string +>1 + `${ 3 }` : string + +var j = 1 + `2${ 3 }` + 5; +>j : string +>1 + `2${ 3 }` + 5 : string +>1 + `2${ 3 }` : string + +var k = 1 + `${ 3 }4` + 5; +>k : string +>1 + `${ 3 }4` + 5 : string +>1 + `${ 3 }4` : string + +var l = 1 + `2${ 3 }4` + 5; +>l : string +>1 + `2${ 3 }4` + 5 : string +>1 + `2${ 3 }4` : string + +var a2 = 1 + `${ 3 - 4 }`; +>a2 : string +>1 + `${ 3 - 4 }` : string +>3 - 4 : number + +var b2 = 1 + `2${ 3 - 4 }`; +>b2 : string +>1 + `2${ 3 - 4 }` : string +>3 - 4 : number + +var c2 = 1 + `${ 3 - 4 }5`; +>c2 : string +>1 + `${ 3 - 4 }5` : string +>3 - 4 : number + +var d2 = 1 + `2${ 3 - 4 }5`; +>d2 : string +>1 + `2${ 3 - 4 }5` : string +>3 - 4 : number + +var e2 = `${ 3 - 4 }` + 6; +>e2 : string +>`${ 3 - 4 }` + 6 : string +>3 - 4 : number + +var f2 = `2${ 3 - 4 }` + 6; +>f2 : string +>`2${ 3 - 4 }` + 6 : string +>3 - 4 : number + +var g2 = `${ 3 - 4 }5` + 6; +>g2 : string +>`${ 3 - 4 }5` + 6 : string +>3 - 4 : number + +var h2 = `2${ 3 - 4 }5` + 6; +>h2 : string +>`2${ 3 - 4 }5` + 6 : string +>3 - 4 : number + +var i2 = 1 + `${ 3 - 4 }` + 6; +>i2 : string +>1 + `${ 3 - 4 }` + 6 : string +>1 + `${ 3 - 4 }` : string +>3 - 4 : number + +var j2 = 1 + `2${ 3 - 4 }` + 6; +>j2 : string +>1 + `2${ 3 - 4 }` + 6 : string +>1 + `2${ 3 - 4 }` : string +>3 - 4 : number + +var k2 = 1 + `${ 3 - 4 }5` + 6; +>k2 : string +>1 + `${ 3 - 4 }5` + 6 : string +>1 + `${ 3 - 4 }5` : string +>3 - 4 : number + +var l2 = 1 + `2${ 3 - 4 }5` + 6; +>l2 : string +>1 + `2${ 3 - 4 }5` + 6 : string +>1 + `2${ 3 - 4 }5` : string +>3 - 4 : number + +var a3 = 1 + `${ 3 * 4 }`; +>a3 : string +>1 + `${ 3 * 4 }` : string +>3 * 4 : number + +var b3 = 1 + `2${ 3 * 4 }`; +>b3 : string +>1 + `2${ 3 * 4 }` : string +>3 * 4 : number + +var c3 = 1 + `${ 3 * 4 }5`; +>c3 : string +>1 + `${ 3 * 4 }5` : string +>3 * 4 : number + +var d3 = 1 + `2${ 3 * 4 }5`; +>d3 : string +>1 + `2${ 3 * 4 }5` : string +>3 * 4 : number + +var e3 = `${ 3 * 4 }` + 6; +>e3 : string +>`${ 3 * 4 }` + 6 : string +>3 * 4 : number + +var f3 = `2${ 3 * 4 }` + 6; +>f3 : string +>`2${ 3 * 4 }` + 6 : string +>3 * 4 : number + +var g3 = `${ 3 * 4 }5` + 6; +>g3 : string +>`${ 3 * 4 }5` + 6 : string +>3 * 4 : number + +var h3 = `2${ 3 * 4 }5` + 6; +>h3 : string +>`2${ 3 * 4 }5` + 6 : string +>3 * 4 : number + +var i3 = 1 + `${ 3 * 4 }` + 6; +>i3 : string +>1 + `${ 3 * 4 }` + 6 : string +>1 + `${ 3 * 4 }` : string +>3 * 4 : number + +var j3 = 1 + `2${ 3 * 4 }` + 6; +>j3 : string +>1 + `2${ 3 * 4 }` + 6 : string +>1 + `2${ 3 * 4 }` : string +>3 * 4 : number + +var k3 = 1 + `${ 3 * 4 }5` + 6; +>k3 : string +>1 + `${ 3 * 4 }5` + 6 : string +>1 + `${ 3 * 4 }5` : string +>3 * 4 : number + +var l3 = 1 + `2${ 3 * 4 }5` + 6; +>l3 : string +>1 + `2${ 3 * 4 }5` + 6 : string +>1 + `2${ 3 * 4 }5` : string +>3 * 4 : number + +var a4 = 1 + `${ 3 & 4 }`; +>a4 : string +>1 + `${ 3 & 4 }` : string +>3 & 4 : number + +var b4 = 1 + `2${ 3 & 4 }`; +>b4 : string +>1 + `2${ 3 & 4 }` : string +>3 & 4 : number + +var c4 = 1 + `${ 3 & 4 }5`; +>c4 : string +>1 + `${ 3 & 4 }5` : string +>3 & 4 : number + +var d4 = 1 + `2${ 3 & 4 }5`; +>d4 : string +>1 + `2${ 3 & 4 }5` : string +>3 & 4 : number + +var e4 = `${ 3 & 4 }` + 6; +>e4 : string +>`${ 3 & 4 }` + 6 : string +>3 & 4 : number + +var f4 = `2${ 3 & 4 }` + 6; +>f4 : string +>`2${ 3 & 4 }` + 6 : string +>3 & 4 : number + +var g4 = `${ 3 & 4 }5` + 6; +>g4 : string +>`${ 3 & 4 }5` + 6 : string +>3 & 4 : number + +var h4 = `2${ 3 & 4 }5` + 6; +>h4 : string +>`2${ 3 & 4 }5` + 6 : string +>3 & 4 : number + +var i4 = 1 + `${ 3 & 4 }` + 6; +>i4 : string +>1 + `${ 3 & 4 }` + 6 : string +>1 + `${ 3 & 4 }` : string +>3 & 4 : number + +var j4 = 1 + `2${ 3 & 4 }` + 6; +>j4 : string +>1 + `2${ 3 & 4 }` + 6 : string +>1 + `2${ 3 & 4 }` : string +>3 & 4 : number + +var k4 = 1 + `${ 3 & 4 }5` + 6; +>k4 : string +>1 + `${ 3 & 4 }5` + 6 : string +>1 + `${ 3 & 4 }5` : string +>3 & 4 : number + +var l4 = 1 + `2${ 3 & 4 }5` + 6; +>l4 : string +>1 + `2${ 3 & 4 }5` + 6 : string +>1 + `2${ 3 & 4 }5` : string +>3 & 4 : number + diff --git a/tests/baselines/reference/templateStringBinaryOperationsES6Invalid.errors.txt b/tests/baselines/reference/templateStringBinaryOperationsES6Invalid.errors.txt new file mode 100644 index 00000000000..261eb6bd558 --- /dev/null +++ b/tests/baselines/reference/templateStringBinaryOperationsES6Invalid.errors.txt @@ -0,0 +1,399 @@ +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(1,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(2,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(3,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(4,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(5,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(6,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(7,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(8,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(10,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(11,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(12,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(13,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(14,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(15,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(16,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(17,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(19,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(20,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(21,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(22,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(23,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(24,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(25,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(26,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(28,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(29,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(30,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(31,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(32,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(33,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(34,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(35,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(37,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(38,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(39,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(40,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(41,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(42,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(43,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(44,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(46,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(47,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(48,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(49,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(50,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(51,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(52,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(53,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(55,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(56,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(57,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(58,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(59,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(60,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(61,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(62,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(64,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(65,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(66,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(67,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(68,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(69,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(70,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(71,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(73,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(74,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(75,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(76,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(77,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(78,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(79,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(80,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(82,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(83,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(84,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(85,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(86,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(87,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(88,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(89,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(91,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(92,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(93,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(94,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(95,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(96,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(97,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(98,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(100,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(101,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(102,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(103,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(104,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(105,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(106,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts(107,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + +==== tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts (96 errors) ==== + var a = 1 - `${ 3 }`; + ~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b = 1 - `2${ 3 }`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c = 1 - `${ 3 }4`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d = 1 - `2${ 3 }4`; + ~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e = `${ 3 }` - 5; + ~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f = `2${ 3 }` - 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g = `${ 3 }4` - 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h = `2${ 3 }4` - 5; + ~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a2 = 1 * `${ 3 }`; + ~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b2 = 1 * `2${ 3 }`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c2 = 1 * `${ 3 }4`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d2 = 1 * `2${ 3 }4`; + ~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e2 = `${ 3 }` * 5; + ~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f2 = `2${ 3 }` * 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g2 = `${ 3 }4` * 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h2 = `2${ 3 }4` * 5; + ~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a3 = 1 & `${ 3 }`; + ~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b3 = 1 & `2${ 3 }`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c3 = 1 & `${ 3 }4`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d3 = 1 & `2${ 3 }4`; + ~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e3 = `${ 3 }` & 5; + ~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f3 = `2${ 3 }` & 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g3 = `${ 3 }4` & 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h3 = `2${ 3 }4` & 5; + ~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a4 = 1 - `${ 3 - 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b4 = 1 - `2${ 3 - 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c4 = 1 - `${ 3 - 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d4 = 1 - `2${ 3 - 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e4 = `${ 3 - 4 }` - 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f4 = `2${ 3 - 4 }` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g4 = `${ 3 - 4 }5` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h4 = `2${ 3 - 4 }5` - 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a5 = 1 - `${ 3 * 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b5 = 1 - `2${ 3 * 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c5 = 1 - `${ 3 * 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d5 = 1 - `2${ 3 * 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e5 = `${ 3 * 4 }` - 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f5 = `2${ 3 * 4 }` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g5 = `${ 3 * 4 }5` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h5 = `2${ 3 * 4 }5` - 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a6 = 1 - `${ 3 & 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b6 = 1 - `2${ 3 & 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c6 = 1 - `${ 3 & 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d6 = 1 - `2${ 3 & 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e6 = `${ 3 & 4 }` - 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f6 = `2${ 3 & 4 }` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g6 = `${ 3 & 4 }5` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h6 = `2${ 3 & 4 }5` - 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a7 = 1 * `${ 3 - 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b7 = 1 * `2${ 3 - 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c7 = 1 * `${ 3 - 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d7 = 1 * `2${ 3 - 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e7 = `${ 3 - 4 }` * 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f7 = `2${ 3 - 4 }` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g7 = `${ 3 - 4 }5` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h7 = `2${ 3 - 4 }5` * 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a8 = 1 * `${ 3 * 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b8 = 1 * `2${ 3 * 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c8 = 1 * `${ 3 * 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d8 = 1 * `2${ 3 * 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e8 = `${ 3 * 4 }` * 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f8 = `2${ 3 * 4 }` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g8 = `${ 3 * 4 }5` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h8 = `2${ 3 * 4 }5` * 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a9 = 1 * `${ 3 & 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b9 = 1 * `2${ 3 & 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c9 = 1 * `${ 3 & 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d9 = 1 * `2${ 3 & 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e9 = `${ 3 & 4 }` * 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f9 = `2${ 3 & 4 }` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g9 = `${ 3 & 4 }5` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h9 = `2${ 3 & 4 }5` * 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var aa = 1 & `${ 3 - 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ba = 1 & `2${ 3 - 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ca = 1 & `${ 3 - 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var da = 1 & `2${ 3 - 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ea = `${ 3 - 4 }` & 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var fa = `2${ 3 - 4 }` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ga = `${ 3 - 4 }5` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ha = `2${ 3 - 4 }5` & 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var ab = 1 & `${ 3 * 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var bb = 1 & `2${ 3 * 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var cb = 1 & `${ 3 * 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var db = 1 & `2${ 3 * 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var eb = `${ 3 * 4 }` & 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var fb = `2${ 3 * 4 }` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var gb = `${ 3 * 4 }5` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var hb = `2${ 3 * 4 }5` & 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var ac = 1 & `${ 3 & 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var bc = 1 & `2${ 3 & 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var cc = 1 & `${ 3 & 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var dc = 1 & `2${ 3 & 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ec = `${ 3 & 4 }` & 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var fc = `2${ 3 & 4 }` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var gc = `${ 3 & 4 }5` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var hc = `2${ 3 & 4 }5` & 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + \ No newline at end of file diff --git a/tests/baselines/reference/templateStringBinaryOperationsES6Invalid.js b/tests/baselines/reference/templateStringBinaryOperationsES6Invalid.js new file mode 100644 index 00000000000..4408fd1ffe9 --- /dev/null +++ b/tests/baselines/reference/templateStringBinaryOperationsES6Invalid.js @@ -0,0 +1,207 @@ +//// [templateStringBinaryOperationsES6Invalid.ts] +var a = 1 - `${ 3 }`; +var b = 1 - `2${ 3 }`; +var c = 1 - `${ 3 }4`; +var d = 1 - `2${ 3 }4`; +var e = `${ 3 }` - 5; +var f = `2${ 3 }` - 5; +var g = `${ 3 }4` - 5; +var h = `2${ 3 }4` - 5; + +var a2 = 1 * `${ 3 }`; +var b2 = 1 * `2${ 3 }`; +var c2 = 1 * `${ 3 }4`; +var d2 = 1 * `2${ 3 }4`; +var e2 = `${ 3 }` * 5; +var f2 = `2${ 3 }` * 5; +var g2 = `${ 3 }4` * 5; +var h2 = `2${ 3 }4` * 5; + +var a3 = 1 & `${ 3 }`; +var b3 = 1 & `2${ 3 }`; +var c3 = 1 & `${ 3 }4`; +var d3 = 1 & `2${ 3 }4`; +var e3 = `${ 3 }` & 5; +var f3 = `2${ 3 }` & 5; +var g3 = `${ 3 }4` & 5; +var h3 = `2${ 3 }4` & 5; + +var a4 = 1 - `${ 3 - 4 }`; +var b4 = 1 - `2${ 3 - 4 }`; +var c4 = 1 - `${ 3 - 4 }5`; +var d4 = 1 - `2${ 3 - 4 }5`; +var e4 = `${ 3 - 4 }` - 6; +var f4 = `2${ 3 - 4 }` - 6; +var g4 = `${ 3 - 4 }5` - 6; +var h4 = `2${ 3 - 4 }5` - 6; + +var a5 = 1 - `${ 3 * 4 }`; +var b5 = 1 - `2${ 3 * 4 }`; +var c5 = 1 - `${ 3 * 4 }5`; +var d5 = 1 - `2${ 3 * 4 }5`; +var e5 = `${ 3 * 4 }` - 6; +var f5 = `2${ 3 * 4 }` - 6; +var g5 = `${ 3 * 4 }5` - 6; +var h5 = `2${ 3 * 4 }5` - 6; + +var a6 = 1 - `${ 3 & 4 }`; +var b6 = 1 - `2${ 3 & 4 }`; +var c6 = 1 - `${ 3 & 4 }5`; +var d6 = 1 - `2${ 3 & 4 }5`; +var e6 = `${ 3 & 4 }` - 6; +var f6 = `2${ 3 & 4 }` - 6; +var g6 = `${ 3 & 4 }5` - 6; +var h6 = `2${ 3 & 4 }5` - 6; + +var a7 = 1 * `${ 3 - 4 }`; +var b7 = 1 * `2${ 3 - 4 }`; +var c7 = 1 * `${ 3 - 4 }5`; +var d7 = 1 * `2${ 3 - 4 }5`; +var e7 = `${ 3 - 4 }` * 6; +var f7 = `2${ 3 - 4 }` * 6; +var g7 = `${ 3 - 4 }5` * 6; +var h7 = `2${ 3 - 4 }5` * 6; + +var a8 = 1 * `${ 3 * 4 }`; +var b8 = 1 * `2${ 3 * 4 }`; +var c8 = 1 * `${ 3 * 4 }5`; +var d8 = 1 * `2${ 3 * 4 }5`; +var e8 = `${ 3 * 4 }` * 6; +var f8 = `2${ 3 * 4 }` * 6; +var g8 = `${ 3 * 4 }5` * 6; +var h8 = `2${ 3 * 4 }5` * 6; + +var a9 = 1 * `${ 3 & 4 }`; +var b9 = 1 * `2${ 3 & 4 }`; +var c9 = 1 * `${ 3 & 4 }5`; +var d9 = 1 * `2${ 3 & 4 }5`; +var e9 = `${ 3 & 4 }` * 6; +var f9 = `2${ 3 & 4 }` * 6; +var g9 = `${ 3 & 4 }5` * 6; +var h9 = `2${ 3 & 4 }5` * 6; + +var aa = 1 & `${ 3 - 4 }`; +var ba = 1 & `2${ 3 - 4 }`; +var ca = 1 & `${ 3 - 4 }5`; +var da = 1 & `2${ 3 - 4 }5`; +var ea = `${ 3 - 4 }` & 6; +var fa = `2${ 3 - 4 }` & 6; +var ga = `${ 3 - 4 }5` & 6; +var ha = `2${ 3 - 4 }5` & 6; + +var ab = 1 & `${ 3 * 4 }`; +var bb = 1 & `2${ 3 * 4 }`; +var cb = 1 & `${ 3 * 4 }5`; +var db = 1 & `2${ 3 * 4 }5`; +var eb = `${ 3 * 4 }` & 6; +var fb = `2${ 3 * 4 }` & 6; +var gb = `${ 3 * 4 }5` & 6; +var hb = `2${ 3 * 4 }5` & 6; + +var ac = 1 & `${ 3 & 4 }`; +var bc = 1 & `2${ 3 & 4 }`; +var cc = 1 & `${ 3 & 4 }5`; +var dc = 1 & `2${ 3 & 4 }5`; +var ec = `${ 3 & 4 }` & 6; +var fc = `2${ 3 & 4 }` & 6; +var gc = `${ 3 & 4 }5` & 6; +var hc = `2${ 3 & 4 }5` & 6; + + +//// [templateStringBinaryOperationsES6Invalid.js] +var a = 1 - `${3}`; +var b = 1 - `2${3}`; +var c = 1 - `${3}4`; +var d = 1 - `2${3}4`; +var e = `${3}` - 5; +var f = `2${3}` - 5; +var g = `${3}4` - 5; +var h = `2${3}4` - 5; +var a2 = 1 * `${3}`; +var b2 = 1 * `2${3}`; +var c2 = 1 * `${3}4`; +var d2 = 1 * `2${3}4`; +var e2 = `${3}` * 5; +var f2 = `2${3}` * 5; +var g2 = `${3}4` * 5; +var h2 = `2${3}4` * 5; +var a3 = 1 & `${3}`; +var b3 = 1 & `2${3}`; +var c3 = 1 & `${3}4`; +var d3 = 1 & `2${3}4`; +var e3 = `${3}` & 5; +var f3 = `2${3}` & 5; +var g3 = `${3}4` & 5; +var h3 = `2${3}4` & 5; +var a4 = 1 - `${3 - 4}`; +var b4 = 1 - `2${3 - 4}`; +var c4 = 1 - `${3 - 4}5`; +var d4 = 1 - `2${3 - 4}5`; +var e4 = `${3 - 4}` - 6; +var f4 = `2${3 - 4}` - 6; +var g4 = `${3 - 4}5` - 6; +var h4 = `2${3 - 4}5` - 6; +var a5 = 1 - `${3 * 4}`; +var b5 = 1 - `2${3 * 4}`; +var c5 = 1 - `${3 * 4}5`; +var d5 = 1 - `2${3 * 4}5`; +var e5 = `${3 * 4}` - 6; +var f5 = `2${3 * 4}` - 6; +var g5 = `${3 * 4}5` - 6; +var h5 = `2${3 * 4}5` - 6; +var a6 = 1 - `${3 & 4}`; +var b6 = 1 - `2${3 & 4}`; +var c6 = 1 - `${3 & 4}5`; +var d6 = 1 - `2${3 & 4}5`; +var e6 = `${3 & 4}` - 6; +var f6 = `2${3 & 4}` - 6; +var g6 = `${3 & 4}5` - 6; +var h6 = `2${3 & 4}5` - 6; +var a7 = 1 * `${3 - 4}`; +var b7 = 1 * `2${3 - 4}`; +var c7 = 1 * `${3 - 4}5`; +var d7 = 1 * `2${3 - 4}5`; +var e7 = `${3 - 4}` * 6; +var f7 = `2${3 - 4}` * 6; +var g7 = `${3 - 4}5` * 6; +var h7 = `2${3 - 4}5` * 6; +var a8 = 1 * `${3 * 4}`; +var b8 = 1 * `2${3 * 4}`; +var c8 = 1 * `${3 * 4}5`; +var d8 = 1 * `2${3 * 4}5`; +var e8 = `${3 * 4}` * 6; +var f8 = `2${3 * 4}` * 6; +var g8 = `${3 * 4}5` * 6; +var h8 = `2${3 * 4}5` * 6; +var a9 = 1 * `${3 & 4}`; +var b9 = 1 * `2${3 & 4}`; +var c9 = 1 * `${3 & 4}5`; +var d9 = 1 * `2${3 & 4}5`; +var e9 = `${3 & 4}` * 6; +var f9 = `2${3 & 4}` * 6; +var g9 = `${3 & 4}5` * 6; +var h9 = `2${3 & 4}5` * 6; +var aa = 1 & `${3 - 4}`; +var ba = 1 & `2${3 - 4}`; +var ca = 1 & `${3 - 4}5`; +var da = 1 & `2${3 - 4}5`; +var ea = `${3 - 4}` & 6; +var fa = `2${3 - 4}` & 6; +var ga = `${3 - 4}5` & 6; +var ha = `2${3 - 4}5` & 6; +var ab = 1 & `${3 * 4}`; +var bb = 1 & `2${3 * 4}`; +var cb = 1 & `${3 * 4}5`; +var db = 1 & `2${3 * 4}5`; +var eb = `${3 * 4}` & 6; +var fb = `2${3 * 4}` & 6; +var gb = `${3 * 4}5` & 6; +var hb = `2${3 * 4}5` & 6; +var ac = 1 & `${3 & 4}`; +var bc = 1 & `2${3 & 4}`; +var cc = 1 & `${3 & 4}5`; +var dc = 1 & `2${3 & 4}5`; +var ec = `${3 & 4}` & 6; +var fc = `2${3 & 4}` & 6; +var gc = `${3 & 4}5` & 6; +var hc = `2${3 & 4}5` & 6; diff --git a/tests/baselines/reference/templateStringBinaryOperationsInvalid.errors.txt b/tests/baselines/reference/templateStringBinaryOperationsInvalid.errors.txt new file mode 100644 index 00000000000..8a6a9719a57 --- /dev/null +++ b/tests/baselines/reference/templateStringBinaryOperationsInvalid.errors.txt @@ -0,0 +1,399 @@ +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(1,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(2,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(3,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(4,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(5,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(6,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(7,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(8,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(10,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(11,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(12,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(13,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(14,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(15,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(16,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(17,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(19,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(20,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(21,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(22,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(23,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(24,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(25,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(26,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(28,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(29,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(30,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(31,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(32,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(33,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(34,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(35,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(37,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(38,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(39,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(40,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(41,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(42,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(43,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(44,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(46,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(47,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(48,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(49,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(50,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(51,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(52,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(53,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(55,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(56,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(57,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(58,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(59,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(60,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(61,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(62,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(64,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(65,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(66,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(67,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(68,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(69,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(70,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(71,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(73,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(74,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(75,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(76,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(77,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(78,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(79,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(80,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(82,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(83,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(84,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(85,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(86,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(87,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(88,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(89,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(91,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(92,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(93,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(94,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(95,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(96,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(97,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(98,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(100,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(101,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(102,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(103,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(104,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(105,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(106,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts(107,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + +==== tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts (96 errors) ==== + var a = 1 - `${ 3 }`; + ~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b = 1 - `2${ 3 }`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c = 1 - `${ 3 }4`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d = 1 - `2${ 3 }4`; + ~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e = `${ 3 }` - 5; + ~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f = `2${ 3 }` - 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g = `${ 3 }4` - 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h = `2${ 3 }4` - 5; + ~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a2 = 1 * `${ 3 }`; + ~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b2 = 1 * `2${ 3 }`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c2 = 1 * `${ 3 }4`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d2 = 1 * `2${ 3 }4`; + ~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e2 = `${ 3 }` * 5; + ~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f2 = `2${ 3 }` * 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g2 = `${ 3 }4` * 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h2 = `2${ 3 }4` * 5; + ~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a3 = 1 & `${ 3 }`; + ~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b3 = 1 & `2${ 3 }`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c3 = 1 & `${ 3 }4`; + ~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d3 = 1 & `2${ 3 }4`; + ~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e3 = `${ 3 }` & 5; + ~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f3 = `2${ 3 }` & 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g3 = `${ 3 }4` & 5; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h3 = `2${ 3 }4` & 5; + ~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a4 = 1 - `${ 3 - 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b4 = 1 - `2${ 3 - 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c4 = 1 - `${ 3 - 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d4 = 1 - `2${ 3 - 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e4 = `${ 3 - 4 }` - 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f4 = `2${ 3 - 4 }` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g4 = `${ 3 - 4 }5` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h4 = `2${ 3 - 4 }5` - 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a5 = 1 - `${ 3 * 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b5 = 1 - `2${ 3 * 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c5 = 1 - `${ 3 * 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d5 = 1 - `2${ 3 * 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e5 = `${ 3 * 4 }` - 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f5 = `2${ 3 * 4 }` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g5 = `${ 3 * 4 }5` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h5 = `2${ 3 * 4 }5` - 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a6 = 1 - `${ 3 & 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b6 = 1 - `2${ 3 & 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c6 = 1 - `${ 3 & 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d6 = 1 - `2${ 3 & 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e6 = `${ 3 & 4 }` - 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f6 = `2${ 3 & 4 }` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g6 = `${ 3 & 4 }5` - 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h6 = `2${ 3 & 4 }5` - 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a7 = 1 * `${ 3 - 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b7 = 1 * `2${ 3 - 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c7 = 1 * `${ 3 - 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d7 = 1 * `2${ 3 - 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e7 = `${ 3 - 4 }` * 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f7 = `2${ 3 - 4 }` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g7 = `${ 3 - 4 }5` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h7 = `2${ 3 - 4 }5` * 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a8 = 1 * `${ 3 * 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b8 = 1 * `2${ 3 * 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c8 = 1 * `${ 3 * 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d8 = 1 * `2${ 3 * 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e8 = `${ 3 * 4 }` * 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f8 = `2${ 3 * 4 }` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g8 = `${ 3 * 4 }5` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h8 = `2${ 3 * 4 }5` * 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var a9 = 1 * `${ 3 & 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var b9 = 1 * `2${ 3 & 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var c9 = 1 * `${ 3 & 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var d9 = 1 * `2${ 3 & 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var e9 = `${ 3 & 4 }` * 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var f9 = `2${ 3 & 4 }` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var g9 = `${ 3 & 4 }5` * 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var h9 = `2${ 3 & 4 }5` * 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var aa = 1 & `${ 3 - 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ba = 1 & `2${ 3 - 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ca = 1 & `${ 3 - 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var da = 1 & `2${ 3 - 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ea = `${ 3 - 4 }` & 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var fa = `2${ 3 - 4 }` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ga = `${ 3 - 4 }5` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ha = `2${ 3 - 4 }5` & 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var ab = 1 & `${ 3 * 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var bb = 1 & `2${ 3 * 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var cb = 1 & `${ 3 * 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var db = 1 & `2${ 3 * 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var eb = `${ 3 * 4 }` & 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var fb = `2${ 3 * 4 }` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var gb = `${ 3 * 4 }5` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var hb = `2${ 3 * 4 }5` & 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var ac = 1 & `${ 3 & 4 }`; + ~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var bc = 1 & `2${ 3 & 4 }`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var cc = 1 & `${ 3 & 4 }5`; + ~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var dc = 1 & `2${ 3 & 4 }5`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var ec = `${ 3 & 4 }` & 6; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var fc = `2${ 3 & 4 }` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var gc = `${ 3 & 4 }5` & 6; + ~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + var hc = `2${ 3 & 4 }5` & 6; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + \ No newline at end of file diff --git a/tests/baselines/reference/templateStringBinaryOperationsInvalid.js b/tests/baselines/reference/templateStringBinaryOperationsInvalid.js new file mode 100644 index 00000000000..f8c0344f44b --- /dev/null +++ b/tests/baselines/reference/templateStringBinaryOperationsInvalid.js @@ -0,0 +1,207 @@ +//// [templateStringBinaryOperationsInvalid.ts] +var a = 1 - `${ 3 }`; +var b = 1 - `2${ 3 }`; +var c = 1 - `${ 3 }4`; +var d = 1 - `2${ 3 }4`; +var e = `${ 3 }` - 5; +var f = `2${ 3 }` - 5; +var g = `${ 3 }4` - 5; +var h = `2${ 3 }4` - 5; + +var a2 = 1 * `${ 3 }`; +var b2 = 1 * `2${ 3 }`; +var c2 = 1 * `${ 3 }4`; +var d2 = 1 * `2${ 3 }4`; +var e2 = `${ 3 }` * 5; +var f2 = `2${ 3 }` * 5; +var g2 = `${ 3 }4` * 5; +var h2 = `2${ 3 }4` * 5; + +var a3 = 1 & `${ 3 }`; +var b3 = 1 & `2${ 3 }`; +var c3 = 1 & `${ 3 }4`; +var d3 = 1 & `2${ 3 }4`; +var e3 = `${ 3 }` & 5; +var f3 = `2${ 3 }` & 5; +var g3 = `${ 3 }4` & 5; +var h3 = `2${ 3 }4` & 5; + +var a4 = 1 - `${ 3 - 4 }`; +var b4 = 1 - `2${ 3 - 4 }`; +var c4 = 1 - `${ 3 - 4 }5`; +var d4 = 1 - `2${ 3 - 4 }5`; +var e4 = `${ 3 - 4 }` - 6; +var f4 = `2${ 3 - 4 }` - 6; +var g4 = `${ 3 - 4 }5` - 6; +var h4 = `2${ 3 - 4 }5` - 6; + +var a5 = 1 - `${ 3 * 4 }`; +var b5 = 1 - `2${ 3 * 4 }`; +var c5 = 1 - `${ 3 * 4 }5`; +var d5 = 1 - `2${ 3 * 4 }5`; +var e5 = `${ 3 * 4 }` - 6; +var f5 = `2${ 3 * 4 }` - 6; +var g5 = `${ 3 * 4 }5` - 6; +var h5 = `2${ 3 * 4 }5` - 6; + +var a6 = 1 - `${ 3 & 4 }`; +var b6 = 1 - `2${ 3 & 4 }`; +var c6 = 1 - `${ 3 & 4 }5`; +var d6 = 1 - `2${ 3 & 4 }5`; +var e6 = `${ 3 & 4 }` - 6; +var f6 = `2${ 3 & 4 }` - 6; +var g6 = `${ 3 & 4 }5` - 6; +var h6 = `2${ 3 & 4 }5` - 6; + +var a7 = 1 * `${ 3 - 4 }`; +var b7 = 1 * `2${ 3 - 4 }`; +var c7 = 1 * `${ 3 - 4 }5`; +var d7 = 1 * `2${ 3 - 4 }5`; +var e7 = `${ 3 - 4 }` * 6; +var f7 = `2${ 3 - 4 }` * 6; +var g7 = `${ 3 - 4 }5` * 6; +var h7 = `2${ 3 - 4 }5` * 6; + +var a8 = 1 * `${ 3 * 4 }`; +var b8 = 1 * `2${ 3 * 4 }`; +var c8 = 1 * `${ 3 * 4 }5`; +var d8 = 1 * `2${ 3 * 4 }5`; +var e8 = `${ 3 * 4 }` * 6; +var f8 = `2${ 3 * 4 }` * 6; +var g8 = `${ 3 * 4 }5` * 6; +var h8 = `2${ 3 * 4 }5` * 6; + +var a9 = 1 * `${ 3 & 4 }`; +var b9 = 1 * `2${ 3 & 4 }`; +var c9 = 1 * `${ 3 & 4 }5`; +var d9 = 1 * `2${ 3 & 4 }5`; +var e9 = `${ 3 & 4 }` * 6; +var f9 = `2${ 3 & 4 }` * 6; +var g9 = `${ 3 & 4 }5` * 6; +var h9 = `2${ 3 & 4 }5` * 6; + +var aa = 1 & `${ 3 - 4 }`; +var ba = 1 & `2${ 3 - 4 }`; +var ca = 1 & `${ 3 - 4 }5`; +var da = 1 & `2${ 3 - 4 }5`; +var ea = `${ 3 - 4 }` & 6; +var fa = `2${ 3 - 4 }` & 6; +var ga = `${ 3 - 4 }5` & 6; +var ha = `2${ 3 - 4 }5` & 6; + +var ab = 1 & `${ 3 * 4 }`; +var bb = 1 & `2${ 3 * 4 }`; +var cb = 1 & `${ 3 * 4 }5`; +var db = 1 & `2${ 3 * 4 }5`; +var eb = `${ 3 * 4 }` & 6; +var fb = `2${ 3 * 4 }` & 6; +var gb = `${ 3 * 4 }5` & 6; +var hb = `2${ 3 * 4 }5` & 6; + +var ac = 1 & `${ 3 & 4 }`; +var bc = 1 & `2${ 3 & 4 }`; +var cc = 1 & `${ 3 & 4 }5`; +var dc = 1 & `2${ 3 & 4 }5`; +var ec = `${ 3 & 4 }` & 6; +var fc = `2${ 3 & 4 }` & 6; +var gc = `${ 3 & 4 }5` & 6; +var hc = `2${ 3 & 4 }5` & 6; + + +//// [templateStringBinaryOperationsInvalid.js] +var a = 1 - ("" + 3); +var b = 1 - ("2" + 3); +var c = 1 - (3 + "4"); +var d = 1 - ("2" + 3 + "4"); +var e = ("" + 3) - 5; +var f = ("2" + 3) - 5; +var g = (3 + "4") - 5; +var h = ("2" + 3 + "4") - 5; +var a2 = 1 * ("" + 3); +var b2 = 1 * ("2" + 3); +var c2 = 1 * (3 + "4"); +var d2 = 1 * ("2" + 3 + "4"); +var e2 = ("" + 3) * 5; +var f2 = ("2" + 3) * 5; +var g2 = (3 + "4") * 5; +var h2 = ("2" + 3 + "4") * 5; +var a3 = 1 & "" + 3; +var b3 = 1 & "2" + 3; +var c3 = 1 & 3 + "4"; +var d3 = 1 & "2" + 3 + "4"; +var e3 = "" + 3 & 5; +var f3 = "2" + 3 & 5; +var g3 = 3 + "4" & 5; +var h3 = "2" + 3 + "4" & 5; +var a4 = 1 - ("" + (3 - 4)); +var b4 = 1 - ("2" + (3 - 4)); +var c4 = 1 - ((3 - 4) + "5"); +var d4 = 1 - ("2" + (3 - 4) + "5"); +var e4 = ("" + (3 - 4)) - 6; +var f4 = ("2" + (3 - 4)) - 6; +var g4 = ((3 - 4) + "5") - 6; +var h4 = ("2" + (3 - 4) + "5") - 6; +var a5 = 1 - ("" + 3 * 4); +var b5 = 1 - ("2" + 3 * 4); +var c5 = 1 - (3 * 4 + "5"); +var d5 = 1 - ("2" + 3 * 4 + "5"); +var e5 = ("" + 3 * 4) - 6; +var f5 = ("2" + 3 * 4) - 6; +var g5 = (3 * 4 + "5") - 6; +var h5 = ("2" + 3 * 4 + "5") - 6; +var a6 = 1 - ("" + (3 & 4)); +var b6 = 1 - ("2" + (3 & 4)); +var c6 = 1 - ((3 & 4) + "5"); +var d6 = 1 - ("2" + (3 & 4) + "5"); +var e6 = ("" + (3 & 4)) - 6; +var f6 = ("2" + (3 & 4)) - 6; +var g6 = ((3 & 4) + "5") - 6; +var h6 = ("2" + (3 & 4) + "5") - 6; +var a7 = 1 * ("" + (3 - 4)); +var b7 = 1 * ("2" + (3 - 4)); +var c7 = 1 * ((3 - 4) + "5"); +var d7 = 1 * ("2" + (3 - 4) + "5"); +var e7 = ("" + (3 - 4)) * 6; +var f7 = ("2" + (3 - 4)) * 6; +var g7 = ((3 - 4) + "5") * 6; +var h7 = ("2" + (3 - 4) + "5") * 6; +var a8 = 1 * ("" + 3 * 4); +var b8 = 1 * ("2" + 3 * 4); +var c8 = 1 * (3 * 4 + "5"); +var d8 = 1 * ("2" + 3 * 4 + "5"); +var e8 = ("" + 3 * 4) * 6; +var f8 = ("2" + 3 * 4) * 6; +var g8 = (3 * 4 + "5") * 6; +var h8 = ("2" + 3 * 4 + "5") * 6; +var a9 = 1 * ("" + (3 & 4)); +var b9 = 1 * ("2" + (3 & 4)); +var c9 = 1 * ((3 & 4) + "5"); +var d9 = 1 * ("2" + (3 & 4) + "5"); +var e9 = ("" + (3 & 4)) * 6; +var f9 = ("2" + (3 & 4)) * 6; +var g9 = ((3 & 4) + "5") * 6; +var h9 = ("2" + (3 & 4) + "5") * 6; +var aa = 1 & "" + (3 - 4); +var ba = 1 & "2" + (3 - 4); +var ca = 1 & (3 - 4) + "5"; +var da = 1 & "2" + (3 - 4) + "5"; +var ea = "" + (3 - 4) & 6; +var fa = "2" + (3 - 4) & 6; +var ga = (3 - 4) + "5" & 6; +var ha = "2" + (3 - 4) + "5" & 6; +var ab = 1 & "" + 3 * 4; +var bb = 1 & "2" + 3 * 4; +var cb = 1 & 3 * 4 + "5"; +var db = 1 & "2" + 3 * 4 + "5"; +var eb = "" + 3 * 4 & 6; +var fb = "2" + 3 * 4 & 6; +var gb = 3 * 4 + "5" & 6; +var hb = "2" + 3 * 4 + "5" & 6; +var ac = 1 & "" + (3 & 4); +var bc = 1 & "2" + (3 & 4); +var cc = 1 & (3 & 4) + "5"; +var dc = 1 & "2" + (3 & 4) + "5"; +var ec = "" + (3 & 4) & 6; +var fc = "2" + (3 & 4) & 6; +var gc = (3 & 4) + "5" & 6; +var hc = "2" + (3 & 4) + "5" & 6; diff --git a/tests/baselines/reference/templateStringInBinaryAddition.js b/tests/baselines/reference/templateStringInBinaryAddition.js deleted file mode 100644 index 0e1f728005c..00000000000 --- a/tests/baselines/reference/templateStringInBinaryAddition.js +++ /dev/null @@ -1,5 +0,0 @@ -//// [templateStringInBinaryAddition.ts] -var x = 10 + `abc${ 10 }def`; - -//// [templateStringInBinaryAddition.js] -var x = 10 + ("abc" + 10 + "def"); diff --git a/tests/baselines/reference/templateStringInBinaryAddition.types b/tests/baselines/reference/templateStringInBinaryAddition.types deleted file mode 100644 index f722ff696f4..00000000000 --- a/tests/baselines/reference/templateStringInBinaryAddition.types +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/conformance/es6/templates/templateStringInBinaryAddition.ts === -var x = 10 + `abc${ 10 }def`; ->x : string ->10 + `abc${ 10 }def` : string - diff --git a/tests/baselines/reference/templateStringInBinaryAdditionES6.js b/tests/baselines/reference/templateStringInBinaryAdditionES6.js deleted file mode 100644 index 7a40d4cc54f..00000000000 --- a/tests/baselines/reference/templateStringInBinaryAdditionES6.js +++ /dev/null @@ -1,5 +0,0 @@ -//// [templateStringInBinaryAdditionES6.ts] -var x = 10 + `abc${ 10 }def`; - -//// [templateStringInBinaryAdditionES6.js] -var x = 10 + `abc${10}def`; diff --git a/tests/baselines/reference/templateStringInBinaryAdditionES6.types b/tests/baselines/reference/templateStringInBinaryAdditionES6.types deleted file mode 100644 index b421d7dc70e..00000000000 --- a/tests/baselines/reference/templateStringInBinaryAdditionES6.types +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/conformance/es6/templates/templateStringInBinaryAdditionES6.ts === -var x = 10 + `abc${ 10 }def`; ->x : string ->10 + `abc${ 10 }def` : string - diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortions.js b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.js index 8bc6e2c4206..e7a35d76f45 100644 --- a/tests/baselines/reference/templateStringWithEmptyLiteralPortions.js +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.js @@ -21,18 +21,22 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; -var l = `1${ 0 }2${ 0 }3`; +var l = `${ 0 }2${ 0 }3`; + +var m = `1${ 0 }2${ 0 }3`; + //// [templateStringWithEmptyLiteralPortions.js] var a = ""; var b = "" + 0; var c = "1" + 0; -var d = "" + 0 + "2"; +var d = 0 + "2"; var e = "1" + 0 + "2"; var f = "" + 0 + 0; var g = "1" + 0 + 0; -var h = "" + 0 + "2" + 0; +var h = 0 + "2" + 0; var i = "1" + 0 + "2" + 0; var j = "" + 0 + 0 + "3"; var k = "1" + 0 + 0 + "3"; -var l = "1" + 0 + "2" + 0 + "3"; +var l = 0 + "2" + 0 + "3"; +var m = "1" + 0 + "2" + 0 + "3"; diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortions.types b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.types index a44bab8fe44..c901d674306 100644 --- a/tests/baselines/reference/templateStringWithEmptyLiteralPortions.types +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.types @@ -32,6 +32,9 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; >k : string -var l = `1${ 0 }2${ 0 }3`; +var l = `${ 0 }2${ 0 }3`; >l : string +var m = `1${ 0 }2${ 0 }3`; +>m : string + diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js index f0e827cde63..fe1bce291f0 100644 --- a/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js @@ -21,7 +21,10 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; -var l = `1${ 0 }2${ 0 }3`; +var l = `${ 0 }2${ 0 }3`; + +var m = `1${ 0 }2${ 0 }3`; + //// [templateStringWithEmptyLiteralPortionsES6.js] var a = ``; @@ -35,4 +38,5 @@ var h = `${0}2${0}`; var i = `1${0}2${0}`; var j = `${0}${0}3`; var k = `1${0}${0}3`; -var l = `1${0}2${0}3`; +var l = `${0}2${0}3`; +var m = `1${0}2${0}3`; diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types index 4074831d410..d70dd29e4da 100644 --- a/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types @@ -32,6 +32,9 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; >k : string -var l = `1${ 0 }2${ 0 }3`; +var l = `${ 0 }2${ 0 }3`; >l : string +var m = `1${ 0 }2${ 0 }3`; +>m : string + diff --git a/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.errors.txt b/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.errors.txt new file mode 100644 index 00000000000..7204f32dba2 --- /dev/null +++ b/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts(3,27): error TS2322: Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts (1 errors) ==== + + + `${function (x: number) { x = "bad"; } }`; + ~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js b/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js new file mode 100644 index 00000000000..ef113312060 --- /dev/null +++ b/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js @@ -0,0 +1,9 @@ +//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts] + + +`${function (x: number) { x = "bad"; } }`; + +//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js] +"" + function (x) { + x = "bad"; +}; diff --git a/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.errors.txt b/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.errors.txt new file mode 100644 index 00000000000..9fece57ef5e --- /dev/null +++ b/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts(2,27): error TS2322: Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts (1 errors) ==== + + `${function (x: number) { x = "bad"; } }`; + ~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js b/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js new file mode 100644 index 00000000000..9ce47348dc1 --- /dev/null +++ b/tests/baselines/reference/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js @@ -0,0 +1,8 @@ +//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts] + +`${function (x: number) { x = "bad"; } }`; + +//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js] +`${function (x) { + x = "bad"; +}}`; diff --git a/tests/baselines/reference/typeGuardOfFormInstanceOf.types b/tests/baselines/reference/typeGuardOfFormInstanceOf.types index fb44482c86e..891e8c1bea2 100644 --- a/tests/baselines/reference/typeGuardOfFormInstanceOf.types +++ b/tests/baselines/reference/typeGuardOfFormInstanceOf.types @@ -124,9 +124,9 @@ var r2: D1 | C2 = c2Ord1 instanceof C1 && c2Ord1; // C2 | D1 >r2 : C2 | D1 >D1 : D1 >C2 : C2 ->c2Ord1 instanceof C1 && c2Ord1 : C2 | D1 +>c2Ord1 instanceof C1 && c2Ord1 : D1 >c2Ord1 instanceof C1 : boolean >c2Ord1 : C2 | D1 >C1 : typeof C1 ->c2Ord1 : C2 | D1 +>c2Ord1 : D1 diff --git a/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types b/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types index 7bf67da1500..fe23d6d303e 100644 --- a/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types +++ b/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types @@ -154,9 +154,9 @@ var r2: D1 | C2 = c2Ord1 instanceof c1 && c2Ord1; // C2 | D1 >r2 : C2 | D1 >D1 : D1 >C2 : C2 ->c2Ord1 instanceof c1 && c2Ord1 : C2 | D1 +>c2Ord1 instanceof c1 && c2Ord1 : D1 >c2Ord1 instanceof c1 : boolean >c2Ord1 : C2 | D1 >c1 : C1 ->c2Ord1 : C2 | D1 +>c2Ord1 : D1 diff --git a/tests/baselines/reference/typeGuardsWithAny.errors.txt b/tests/baselines/reference/typeGuardsWithAny.errors.txt new file mode 100644 index 00000000000..653c89c7554 --- /dev/null +++ b/tests/baselines/reference/typeGuardsWithAny.errors.txt @@ -0,0 +1,49 @@ +tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(11,7): error TS2339: Property 'p' does not exist on type 'string'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(18,7): error TS2339: Property 'p' does not exist on type 'number'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(25,7): error TS2339: Property 'p' does not exist on type 'boolean'. + + +==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts (3 errors) ==== + var x: any = { p: 0 }; + + if (x instanceof Object) { + x.p; // No error, type any unaffected by instanceof type guard + } + else { + x.p; // No error, type any unaffected by instanceof type guard + } + + if (typeof x === "string") { + x.p; // Error, type any narrowed by primitive type check + ~ +!!! error TS2339: Property 'p' does not exist on type 'string'. + } + else { + x.p; // No error, type unaffected in this branch + } + + if (typeof x === "number") { + x.p; // Error, type any narrowed by primitive type check + ~ +!!! error TS2339: Property 'p' does not exist on type 'number'. + } + else { + x.p; // No error, type unaffected in this branch + } + + if (typeof x === "boolean") { + x.p; // Error, type any narrowed by primitive type check + ~ +!!! error TS2339: Property 'p' does not exist on type 'boolean'. + } + else { + x.p; // No error, type unaffected in this branch + } + + if (typeof x === "object") { + x.p; // No error, type any only affected by primitive type check + } + else { + x.p; // No error, type unaffected in this branch + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsWithAny.js b/tests/baselines/reference/typeGuardsWithAny.js index 56676fb6d68..be3d64b806f 100644 --- a/tests/baselines/reference/typeGuardsWithAny.js +++ b/tests/baselines/reference/typeGuardsWithAny.js @@ -1,18 +1,71 @@ //// [typeGuardsWithAny.ts] var x: any = { p: 0 }; + if (x instanceof Object) { - x.p; // No error, type any unaffected by type guard + x.p; // No error, type any unaffected by instanceof type guard } else { - x.p; // No error, type any unaffected by type guard + x.p; // No error, type any unaffected by instanceof type guard +} + +if (typeof x === "string") { + x.p; // Error, type any narrowed by primitive type check +} +else { + x.p; // No error, type unaffected in this branch +} + +if (typeof x === "number") { + x.p; // Error, type any narrowed by primitive type check +} +else { + x.p; // No error, type unaffected in this branch +} + +if (typeof x === "boolean") { + x.p; // Error, type any narrowed by primitive type check +} +else { + x.p; // No error, type unaffected in this branch +} + +if (typeof x === "object") { + x.p; // No error, type any only affected by primitive type check +} +else { + x.p; // No error, type unaffected in this branch } //// [typeGuardsWithAny.js] var x = { p: 0 }; if (x instanceof Object) { - x.p; // No error, type any unaffected by type guard + x.p; // No error, type any unaffected by instanceof type guard } else { - x.p; // No error, type any unaffected by type guard + x.p; // No error, type any unaffected by instanceof type guard +} +if (typeof x === "string") { + x.p; // Error, type any narrowed by primitive type check +} +else { + x.p; // No error, type unaffected in this branch +} +if (typeof x === "number") { + x.p; // Error, type any narrowed by primitive type check +} +else { + x.p; // No error, type unaffected in this branch +} +if (typeof x === "boolean") { + x.p; // Error, type any narrowed by primitive type check +} +else { + x.p; // No error, type unaffected in this branch +} +if (typeof x === "object") { + x.p; // No error, type any only affected by primitive type check +} +else { + x.p; // No error, type unaffected in this branch } diff --git a/tests/baselines/reference/typeGuardsWithAny.types b/tests/baselines/reference/typeGuardsWithAny.types deleted file mode 100644 index ee628c9c249..00000000000 --- a/tests/baselines/reference/typeGuardsWithAny.types +++ /dev/null @@ -1,23 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts === -var x: any = { p: 0 }; ->x : any ->{ p: 0 } : { p: number; } ->p : number - -if (x instanceof Object) { ->x instanceof Object : boolean ->x : any ->Object : ObjectConstructor - - x.p; // No error, type any unaffected by type guard ->x.p : any ->x : any ->p : any -} -else { - x.p; // No error, type any unaffected by type guard ->x.p : any ->x : any ->p : any -} - diff --git a/tests/baselines/reference/typeGuardsWithInstanceOf.js b/tests/baselines/reference/typeGuardsWithInstanceOf.js new file mode 100644 index 00000000000..34af7037f0b --- /dev/null +++ b/tests/baselines/reference/typeGuardsWithInstanceOf.js @@ -0,0 +1,18 @@ +//// [typeGuardsWithInstanceOf.ts] +interface I { global: string; } +var result: I; +var result2: I; + +if (!(result instanceof RegExp)) { + result = result2; +} else if (!result.global) { +} + +//// [typeGuardsWithInstanceOf.js] +var result; +var result2; +if (!(result instanceof RegExp)) { + result = result2; +} +else if (!result.global) { +} diff --git a/tests/baselines/reference/typeGuardsWithInstanceOf.types b/tests/baselines/reference/typeGuardsWithInstanceOf.types new file mode 100644 index 00000000000..0d7b477faed --- /dev/null +++ b/tests/baselines/reference/typeGuardsWithInstanceOf.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts === +interface I { global: string; } +>I : I +>global : string + +var result: I; +>result : I +>I : I + +var result2: I; +>result2 : I +>I : I + +if (!(result instanceof RegExp)) { +>!(result instanceof RegExp) : boolean +>(result instanceof RegExp) : boolean +>result instanceof RegExp : boolean +>result : I +>RegExp : RegExpConstructor + + result = result2; +>result = result2 : I +>result : I +>result2 : I + +} else if (!result.global) { +>!result.global : boolean +>result.global : string +>result : I +>global : string +} diff --git a/tests/baselines/reference/visibilityOfTypeParameters.js b/tests/baselines/reference/visibilityOfTypeParameters.js new file mode 100644 index 00000000000..2cb006737b2 --- /dev/null +++ b/tests/baselines/reference/visibilityOfTypeParameters.js @@ -0,0 +1,24 @@ +//// [visibilityOfTypeParameters.ts] + +export class MyClass { + protected myMethod(val: T): T { + return val; + } +} + +//// [visibilityOfTypeParameters.js] +var MyClass = (function () { + function MyClass() { + } + MyClass.prototype.myMethod = function (val) { + return val; + }; + return MyClass; +})(); +exports.MyClass = MyClass; + + +//// [visibilityOfTypeParameters.d.ts] +export declare class MyClass { + protected myMethod(val: T): T; +} diff --git a/tests/baselines/reference/visibilityOfTypeParameters.types b/tests/baselines/reference/visibilityOfTypeParameters.types new file mode 100644 index 00000000000..60a9330eb7e --- /dev/null +++ b/tests/baselines/reference/visibilityOfTypeParameters.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/visibilityOfTypeParameters.ts === + +export class MyClass { +>MyClass : MyClass + + protected myMethod(val: T): T { +>myMethod : (val: T) => T +>T : T +>val : T +>T : T +>T : T + + return val; +>val : T + } +} diff --git a/tests/cases/compiler/cloduleWithPriorInstantiatedModule.ts b/tests/cases/compiler/cloduleWithPriorInstantiatedModule.ts new file mode 100644 index 00000000000..c6423ce41a7 --- /dev/null +++ b/tests/cases/compiler/cloduleWithPriorInstantiatedModule.ts @@ -0,0 +1,16 @@ +// Non-ambient & instantiated module. +module Moclodule { + export interface Someinterface { + foo(): void; + } + var x = 10; +} + +class Moclodule { +} + +// Instantiated module. +module Moclodule { + export class Manager { + } +} \ No newline at end of file diff --git a/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts b/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts new file mode 100644 index 00000000000..0c603b71a4d --- /dev/null +++ b/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts @@ -0,0 +1,15 @@ +// Non-ambient & uninstantiated module. +module Moclodule { + export interface Someinterface { + foo(): void; + } +} + +class Moclodule { +} + +// Instantiated module. +module Moclodule { + export class Manager { + } +} \ No newline at end of file diff --git a/tests/cases/compiler/commentEmitWithCommentOnLastLine.ts b/tests/cases/compiler/commentEmitWithCommentOnLastLine.ts new file mode 100644 index 00000000000..d148fbda6fa --- /dev/null +++ b/tests/cases/compiler/commentEmitWithCommentOnLastLine.ts @@ -0,0 +1,4 @@ +var x: any; +/* +var bar; +*/ \ No newline at end of file diff --git a/tests/cases/compiler/constEnumBadPropertyNames.ts b/tests/cases/compiler/constEnumBadPropertyNames.ts new file mode 100644 index 00000000000..89fc5d421ff --- /dev/null +++ b/tests/cases/compiler/constEnumBadPropertyNames.ts @@ -0,0 +1,2 @@ +const enum E { A } +var x = E["B"] \ No newline at end of file diff --git a/tests/cases/compiler/inheritedOverloadedSpecializedSignatures.ts b/tests/cases/compiler/inheritedOverloadedSpecializedSignatures.ts index c513cecb2cb..03a433382ce 100644 --- a/tests/cases/compiler/inheritedOverloadedSpecializedSignatures.ts +++ b/tests/cases/compiler/inheritedOverloadedSpecializedSignatures.ts @@ -27,10 +27,26 @@ interface B { (x: 'B2'): string[]; } -var b: B; -// non of these lines should error -var x1: string[] = b('B2'); -var x2: number = b('B1'); -var x3: boolean = b('A2'); -var x4: string = b('A1'); -var x5: void = b('A0'); \ No newline at end of file +interface C1 extends B { + (x: 'C1'): number[]; +} + +interface C2 extends B { + (x: 'C2'): boolean[]; +} + +interface C extends C1, C2 { + (x: 'C'): string; +} + +var c: C; +// none of these lines should error +var x1: string[] = c('B2'); +var x2: number = c('B1'); +var x3: boolean = c('A2'); +var x4: string = c('A1'); +var x5: void = c('A0'); +var x6: number[] = c('C1'); +var x7: boolean[] = c('C2'); +var x8: string = c('C'); +var x9: void = c('generic'); diff --git a/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt.ts b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt.ts new file mode 100644 index 00000000000..dfb21cccbe7 --- /dev/null +++ b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt.ts @@ -0,0 +1,11 @@ +module Z.M { + export function bar() { + return ""; + } +} +module A.M { + import M = Z.M; + export function bar() { + } + M.bar(); // Should call Z.M.bar +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt2.ts b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt2.ts new file mode 100644 index 00000000000..f81fe17a624 --- /dev/null +++ b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt2.ts @@ -0,0 +1,11 @@ +module Z.M { + export function bar() { + return ""; + } +} +module A.M { + export import M = Z.M; + export function bar() { + } + M.bar(); // Should call Z.M.bar +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt3.ts b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt3.ts new file mode 100644 index 00000000000..417d6aad8fd --- /dev/null +++ b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt3.ts @@ -0,0 +1,16 @@ +module Z { + export module M { + export function bar() { + return ""; + } + } + export interface I { } +} +module A.M { + import M = Z.M; + import M = Z.I; + + export function bar() { + } + M.bar(); // Should call Z.M.bar +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt4.ts b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt4.ts new file mode 100644 index 00000000000..1c7993c596e --- /dev/null +++ b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt4.ts @@ -0,0 +1,12 @@ +module Z.M { + export function bar() { + return ""; + } +} +module A.M { + interface M { } + import M = Z.M; + export function bar() { + } + M.bar(); // Should call Z.M.bar +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt5.ts b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt5.ts new file mode 100644 index 00000000000..fa224b1b7f9 --- /dev/null +++ b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt5.ts @@ -0,0 +1,16 @@ +module Z { + export module M { + export function bar() { + return ""; + } + } + export interface I { } +} +module A.M { + import M = Z.I; + import M = Z.M; + + export function bar() { + } + M.bar(); // Should call Z.M.bar +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt6.ts b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt6.ts new file mode 100644 index 00000000000..f488a5de070 --- /dev/null +++ b/tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt6.ts @@ -0,0 +1,10 @@ +module Z.M { + export function bar() { + return ""; + } +} +module A.M { + import M = Z.M; + export function bar() { + } +} \ No newline at end of file diff --git a/tests/cases/compiler/visibilityOfTypeParameters.ts b/tests/cases/compiler/visibilityOfTypeParameters.ts new file mode 100644 index 00000000000..386d0bb9cb4 --- /dev/null +++ b/tests/cases/compiler/visibilityOfTypeParameters.ts @@ -0,0 +1,8 @@ +// @module:commonjs +//@declaration: true + +export class MyClass { + protected myMethod(val: T): T { + return val; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunction.ts b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunction.ts new file mode 100644 index 00000000000..12480939a39 --- /dev/null +++ b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunction.ts @@ -0,0 +1,5 @@ +// @target: es5 +function foo(x: string, y = 10) { } +function baz(x: string, y = 5, ...rest) { } +function bar(y = 10) { } +function bar1(y = 10, ...rest) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionES6.ts b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionES6.ts new file mode 100644 index 00000000000..00afc306546 --- /dev/null +++ b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionES6.ts @@ -0,0 +1,5 @@ +// @target:es6 +function foo(x: string, y = 10) { } +function baz(x: string, y = 5, ...rest) { } +function bar(y = 10) { } +function bar1(y = 10, ...rest) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionExpression.ts b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionExpression.ts new file mode 100644 index 00000000000..f8e10c0ae14 --- /dev/null +++ b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionExpression.ts @@ -0,0 +1,9 @@ +// @target: es5 +var lambda1 = (y = "hello") => { } +var lambda2 = (x: number, y = "hello") => { } +var lambda3 = (x: number, y = "hello", ...rest) => { } +var lambda4 = (y = "hello", ...rest) => { } + +var x = function (str = "hello", ...rest) { } +var y = (function (num = 10, boo = false, ...rest) { })() +var z = (function (num: number, boo = false, ...rest) { })(10) diff --git a/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionExpressionES6.ts b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionExpressionES6.ts new file mode 100644 index 00000000000..aebed249a65 --- /dev/null +++ b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionExpressionES6.ts @@ -0,0 +1,9 @@ +// @target:es6 +var lambda1 = (y = "hello") => { } +var lambda2 = (x: number, y = "hello") => { } +var lambda3 = (x: number, y = "hello", ...rest) => { } +var lambda4 = (y = "hello", ...rest) => { } + +var x = function (str = "hello", ...rest) { } +var y = (function (num = 10, boo = false, ...rest) { })() +var z = (function (num: number, boo = false, ...rest) { })(10) \ No newline at end of file diff --git a/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionProperty.ts b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionProperty.ts new file mode 100644 index 00000000000..8e280894af0 --- /dev/null +++ b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionProperty.ts @@ -0,0 +1,7 @@ +// @target: es5 +var obj2 = { + func1(y = 10, ...rest) { }, + func2(x = "hello") { }, + func3(x: string, z: number, y = "hello") { }, + func4(x: string, z: number, y = "hello", ...rest) { }, +} diff --git a/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionPropertyES6.ts b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionPropertyES6.ts new file mode 100644 index 00000000000..cb1cfb78546 --- /dev/null +++ b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionPropertyES6.ts @@ -0,0 +1,7 @@ +// @target:es6 +var obj2 = { + func1(y = 10, ...rest) { }, + func2(x = "hello") { }, + func3(x: string, z: number, y = "hello") { }, + func4(x: string, z: number, y = "hello", ...rest) { }, +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersMethod.ts b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersMethod.ts new file mode 100644 index 00000000000..be4a563836f --- /dev/null +++ b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersMethod.ts @@ -0,0 +1,17 @@ +// @target: es5 +class C { + constructor(t: boolean, z: string, x: number, y = "hello") { } + + public foo(x: string, t = false) { } + public foo1(x: string, t = false, ...rest) { } + public bar(t = false) { } + public boo(t = false, ...rest) { } +} + +class D { + constructor(y = "hello") { } +} + +class E { + constructor(y = "hello", ...rest) { } +} diff --git a/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersMethodES6.ts b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersMethodES6.ts new file mode 100644 index 00000000000..886b2e9235b --- /dev/null +++ b/tests/cases/conformance/es6/defaultParameters/emitDefaultParametersMethodES6.ts @@ -0,0 +1,17 @@ +// @target:es6 +class C { + constructor(t: boolean, z: string, x: number, y = "hello") { } + + public foo(x: string, t = false) { } + public foo1(x: string, t = false, ...rest) { } + public bar(t = false) { } + public boo(t = false, ...rest) { } +} + +class D { + constructor(y = "hello") { } +} + +class E { + constructor(y = "hello", ...rest) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts new file mode 100644 index 00000000000..ba73adc9fde --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts @@ -0,0 +1,29 @@ +class C1 { + constructor(public [x, y, z]: string[]) { + } +} + +type TupleType1 = [string, number, boolean]; + +class C2 { + constructor(public [x, y, z]: TupleType1) { + } +} + +type ObjType1 = { x: number; y: string; z: boolean } + +class C3 { + constructor(public { x, y, z }: ObjType1) { + } +} + +var c1 = new C1([]); +c1 = new C1(["larry", "{curly}", "moe"]); +var useC1Properties = c1.x === c1.y && c1.y === c1.z; + +var c2 = new C2(["10", 10, !!10]); +var [c2_x, c2_y, c2_z] = [c2.x, c2.y, c2.z]; + +var c3 = new C3({x: 0, y: "", z: false}); +c3 = new C3({x: 0, "y": "y", z: true}); +var [c3_x, c3_y, c3_z] = [c3.x, c3.y, c3.z]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts new file mode 100644 index 00000000000..b7f37809154 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts @@ -0,0 +1,28 @@ +class C1 { + constructor(private k: number, private [a, b, c]: [number, string, boolean]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +var x = new C1(undefined, [0, undefined, ""]); +var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + +var y = new C1(10, [0, "", true]); +var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + +var z = new C1(10, [undefined, "", null]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts new file mode 100644 index 00000000000..6819d024e6a --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts @@ -0,0 +1,31 @@ +class C1 { + constructor(private k: T, private [a, b, c]: [T,U,V]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +var x = new C1(undefined, [0, true, ""]); +var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + +var y = new C1(10, [0, true, true]); +var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + +var z = new C1(10, [undefined, "", ""]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + +var w = new C1(10, [undefined, undefined, undefined]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts new file mode 100644 index 00000000000..7a83e5f4d4b --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts @@ -0,0 +1,27 @@ +// @target: es6 + +class C1 { + constructor(private k: T, protected [a, b, c]: [T,U,V]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +class C2 extends C1 { + public doSomethingWithSuperProperties() { + return `${this.a} ${this.b} ${this.c}`; + } +} diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts new file mode 100644 index 00000000000..02f9b780ad9 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts @@ -0,0 +1,12 @@ +type ObjType1 = { x: number; y: string; z: boolean } +type TupleType1 = [ObjType1, number, string] + +class C1 { + constructor(public [{ x1, x2, x3 }, y, z]: TupleType1) { + var foo: any = x1 || x2 || x3 || y || z; + var bar: any = this.x1 || this.x2 || this.x3 || this.y || this.z; + } +} + +var a = new C1([{ x1: 10, x2: "", x3: true }, "", false]); +var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts b/tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts new file mode 100644 index 00000000000..5bdcb49e5d9 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts @@ -0,0 +1,8 @@ + +function foo([x,y,z]?: [string, number, boolean]) { + +} + +foo(["", 0, false]); + +foo([false, 0, ""]); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/optionalBindingParameters2.ts b/tests/cases/conformance/es6/destructuring/optionalBindingParameters2.ts new file mode 100644 index 00000000000..12338aeb445 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/optionalBindingParameters2.ts @@ -0,0 +1,8 @@ + +function foo({ x, y, z }?: { x: string; y: number; z: boolean }) { + +} + +foo({ x: "", y: 0, z: false }); + +foo({ x: false, y: 0, z: "" }); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads1.ts b/tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads1.ts new file mode 100644 index 00000000000..82aa49d346a --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads1.ts @@ -0,0 +1,9 @@ + +function foo([x, y, z] ?: [string, number, boolean]); +function foo(...rest: any[]) { + +} + +foo(["", 0, false]); + +foo([false, 0, ""]); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads2.ts b/tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads2.ts new file mode 100644 index 00000000000..bbe763b3008 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads2.ts @@ -0,0 +1,9 @@ + +function foo({ x, y, z }?: { x: string; y: number; z: boolean }); +function foo(...rest: any[]) { + +} + +foo({ x: "", y: 0, z: false }); + +foo({ x: false, y: 0, z: "" }); \ No newline at end of file diff --git a/tests/cases/conformance/es6/restParameters/emitRestParametersFunction.ts b/tests/cases/conformance/es6/restParameters/emitRestParametersFunction.ts new file mode 100644 index 00000000000..ee170d2bcb9 --- /dev/null +++ b/tests/cases/conformance/es6/restParameters/emitRestParametersFunction.ts @@ -0,0 +1,3 @@ +// @target: es5 +function bar(...rest) { } +function foo(x: number, y: string, ...rest) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionES6.ts b/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionES6.ts new file mode 100644 index 00000000000..366905d764b --- /dev/null +++ b/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionES6.ts @@ -0,0 +1,3 @@ +// @target: es6 +function bar(...rest) { } +function foo(x: number, y: string, ...rest) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionExpression.ts b/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionExpression.ts new file mode 100644 index 00000000000..a9ddf83c816 --- /dev/null +++ b/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionExpression.ts @@ -0,0 +1,5 @@ +// @target: es5 +var funcExp = (...rest) => { } +var funcExp1 = (X: number, ...rest) => { } +var funcExp2 = function (...rest) { } +var funcExp3 = (function (...rest) { })() diff --git a/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionExpressionES6.ts b/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionExpressionES6.ts new file mode 100644 index 00000000000..310dcfd1557 --- /dev/null +++ b/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionExpressionES6.ts @@ -0,0 +1,5 @@ +// @target: es6 +var funcExp = (...rest) => { } +var funcExp1 = (X: number, ...rest) => { } +var funcExp2 = function (...rest) { } +var funcExp3 = (function (...rest) { })() \ No newline at end of file diff --git a/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionProperty.ts b/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionProperty.ts new file mode 100644 index 00000000000..c8a8ed16e7b --- /dev/null +++ b/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionProperty.ts @@ -0,0 +1,8 @@ +// @target: es5 +var obj: { + func1: (...rest) => void +} + +var obj2 = { + func(...rest) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionPropertyES6.ts b/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionPropertyES6.ts new file mode 100644 index 00000000000..34bb0cae6b7 --- /dev/null +++ b/tests/cases/conformance/es6/restParameters/emitRestParametersFunctionPropertyES6.ts @@ -0,0 +1,8 @@ +// @target: es6 +var obj: { + func1: (...rest) => void +} + +var obj2 = { + func(...rest) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/restParameters/emitRestParametersMethod.ts b/tests/cases/conformance/es6/restParameters/emitRestParametersMethod.ts new file mode 100644 index 00000000000..6b9e70fd196 --- /dev/null +++ b/tests/cases/conformance/es6/restParameters/emitRestParametersMethod.ts @@ -0,0 +1,14 @@ +// @target: es5 +class C { + constructor(name: string, ...rest) { } + + public bar(...rest) { } + public foo(x: number, ...rest) { } +} + +class D { + constructor(...rest) { } + + public bar(...rest) { } + public foo(x: number, ...rest) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/restParameters/emitRestParametersMethodES6.ts b/tests/cases/conformance/es6/restParameters/emitRestParametersMethodES6.ts new file mode 100644 index 00000000000..df2f2293c75 --- /dev/null +++ b/tests/cases/conformance/es6/restParameters/emitRestParametersMethodES6.ts @@ -0,0 +1,14 @@ +// @target: es6 +class C { + constructor(name: string, ...rest) { } + + public bar(...rest) { } + public foo(x: number, ...rest) { } +} + +class D { + constructor(...rest) { } + + public bar(...rest) { } + public foo(x: number, ...rest) { } +} diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts new file mode 100644 index 00000000000..210f3eebbd7 --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts @@ -0,0 +1,6 @@ + + +function foo(...rest: any[]) { +} + +foo `${function (x: number) { x = "bad"; } }`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts new file mode 100644 index 00000000000..0a51fea491f --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts @@ -0,0 +1,6 @@ +//@target: es6 + +function foo(...rest: any[]) { +} + +foo `${function (x: number) { x = "bad"; } }`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringBinaryOperations.ts b/tests/cases/conformance/es6/templates/templateStringBinaryOperations.ts new file mode 100644 index 00000000000..28313595f99 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringBinaryOperations.ts @@ -0,0 +1,51 @@ +var a = 1 + `${ 3 }`; +var b = 1 + `2${ 3 }`; +var c = 1 + `${ 3 }4`; +var d = 1 + `2${ 3 }4`; +var e = `${ 3 }` + 5; +var f = `2${ 3 }` + 5; +var g = `${ 3 }4` + 5; +var h = `2${ 3 }4` + 5; +var i = 1 + `${ 3 }` + 5; +var j = 1 + `2${ 3 }` + 5; +var k = 1 + `${ 3 }4` + 5; +var l = 1 + `2${ 3 }4` + 5; + +var a2 = 1 + `${ 3 - 4 }`; +var b2 = 1 + `2${ 3 - 4 }`; +var c2 = 1 + `${ 3 - 4 }5`; +var d2 = 1 + `2${ 3 - 4 }5`; +var e2 = `${ 3 - 4 }` + 6; +var f2 = `2${ 3 - 4 }` + 6; +var g2 = `${ 3 - 4 }5` + 6; +var h2 = `2${ 3 - 4 }5` + 6; +var i2 = 1 + `${ 3 - 4 }` + 6; +var j2 = 1 + `2${ 3 - 4 }` + 6; +var k2 = 1 + `${ 3 - 4 }5` + 6; +var l2 = 1 + `2${ 3 - 4 }5` + 6; + +var a3 = 1 + `${ 3 * 4 }`; +var b3 = 1 + `2${ 3 * 4 }`; +var c3 = 1 + `${ 3 * 4 }5`; +var d3 = 1 + `2${ 3 * 4 }5`; +var e3 = `${ 3 * 4 }` + 6; +var f3 = `2${ 3 * 4 }` + 6; +var g3 = `${ 3 * 4 }5` + 6; +var h3 = `2${ 3 * 4 }5` + 6; +var i3 = 1 + `${ 3 * 4 }` + 6; +var j3 = 1 + `2${ 3 * 4 }` + 6; +var k3 = 1 + `${ 3 * 4 }5` + 6; +var l3 = 1 + `2${ 3 * 4 }5` + 6; + +var a4 = 1 + `${ 3 & 4 }`; +var b4 = 1 + `2${ 3 & 4 }`; +var c4 = 1 + `${ 3 & 4 }5`; +var d4 = 1 + `2${ 3 & 4 }5`; +var e4 = `${ 3 & 4 }` + 6; +var f4 = `2${ 3 & 4 }` + 6; +var g4 = `${ 3 & 4 }5` + 6; +var h4 = `2${ 3 & 4 }5` + 6; +var i4 = 1 + `${ 3 & 4 }` + 6; +var j4 = 1 + `2${ 3 & 4 }` + 6; +var k4 = 1 + `${ 3 & 4 }5` + 6; +var l4 = 1 + `2${ 3 & 4 }5` + 6; diff --git a/tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6.ts b/tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6.ts new file mode 100644 index 00000000000..d734c9b4cb9 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6.ts @@ -0,0 +1,52 @@ +// @target: ES6 +var a = 1 + `${ 3 }`; +var b = 1 + `2${ 3 }`; +var c = 1 + `${ 3 }4`; +var d = 1 + `2${ 3 }4`; +var e = `${ 3 }` + 5; +var f = `2${ 3 }` + 5; +var g = `${ 3 }4` + 5; +var h = `2${ 3 }4` + 5; +var i = 1 + `${ 3 }` + 5; +var j = 1 + `2${ 3 }` + 5; +var k = 1 + `${ 3 }4` + 5; +var l = 1 + `2${ 3 }4` + 5; + +var a2 = 1 + `${ 3 - 4 }`; +var b2 = 1 + `2${ 3 - 4 }`; +var c2 = 1 + `${ 3 - 4 }5`; +var d2 = 1 + `2${ 3 - 4 }5`; +var e2 = `${ 3 - 4 }` + 6; +var f2 = `2${ 3 - 4 }` + 6; +var g2 = `${ 3 - 4 }5` + 6; +var h2 = `2${ 3 - 4 }5` + 6; +var i2 = 1 + `${ 3 - 4 }` + 6; +var j2 = 1 + `2${ 3 - 4 }` + 6; +var k2 = 1 + `${ 3 - 4 }5` + 6; +var l2 = 1 + `2${ 3 - 4 }5` + 6; + +var a3 = 1 + `${ 3 * 4 }`; +var b3 = 1 + `2${ 3 * 4 }`; +var c3 = 1 + `${ 3 * 4 }5`; +var d3 = 1 + `2${ 3 * 4 }5`; +var e3 = `${ 3 * 4 }` + 6; +var f3 = `2${ 3 * 4 }` + 6; +var g3 = `${ 3 * 4 }5` + 6; +var h3 = `2${ 3 * 4 }5` + 6; +var i3 = 1 + `${ 3 * 4 }` + 6; +var j3 = 1 + `2${ 3 * 4 }` + 6; +var k3 = 1 + `${ 3 * 4 }5` + 6; +var l3 = 1 + `2${ 3 * 4 }5` + 6; + +var a4 = 1 + `${ 3 & 4 }`; +var b4 = 1 + `2${ 3 & 4 }`; +var c4 = 1 + `${ 3 & 4 }5`; +var d4 = 1 + `2${ 3 & 4 }5`; +var e4 = `${ 3 & 4 }` + 6; +var f4 = `2${ 3 & 4 }` + 6; +var g4 = `${ 3 & 4 }5` + 6; +var h4 = `2${ 3 & 4 }5` + 6; +var i4 = 1 + `${ 3 & 4 }` + 6; +var j4 = 1 + `2${ 3 & 4 }` + 6; +var k4 = 1 + `${ 3 & 4 }5` + 6; +var l4 = 1 + `2${ 3 & 4 }5` + 6; diff --git a/tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts b/tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts new file mode 100644 index 00000000000..0bfa84e05a5 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringBinaryOperationsES6Invalid.ts @@ -0,0 +1,108 @@ +// @target: ES6 +var a = 1 - `${ 3 }`; +var b = 1 - `2${ 3 }`; +var c = 1 - `${ 3 }4`; +var d = 1 - `2${ 3 }4`; +var e = `${ 3 }` - 5; +var f = `2${ 3 }` - 5; +var g = `${ 3 }4` - 5; +var h = `2${ 3 }4` - 5; + +var a2 = 1 * `${ 3 }`; +var b2 = 1 * `2${ 3 }`; +var c2 = 1 * `${ 3 }4`; +var d2 = 1 * `2${ 3 }4`; +var e2 = `${ 3 }` * 5; +var f2 = `2${ 3 }` * 5; +var g2 = `${ 3 }4` * 5; +var h2 = `2${ 3 }4` * 5; + +var a3 = 1 & `${ 3 }`; +var b3 = 1 & `2${ 3 }`; +var c3 = 1 & `${ 3 }4`; +var d3 = 1 & `2${ 3 }4`; +var e3 = `${ 3 }` & 5; +var f3 = `2${ 3 }` & 5; +var g3 = `${ 3 }4` & 5; +var h3 = `2${ 3 }4` & 5; + +var a4 = 1 - `${ 3 - 4 }`; +var b4 = 1 - `2${ 3 - 4 }`; +var c4 = 1 - `${ 3 - 4 }5`; +var d4 = 1 - `2${ 3 - 4 }5`; +var e4 = `${ 3 - 4 }` - 6; +var f4 = `2${ 3 - 4 }` - 6; +var g4 = `${ 3 - 4 }5` - 6; +var h4 = `2${ 3 - 4 }5` - 6; + +var a5 = 1 - `${ 3 * 4 }`; +var b5 = 1 - `2${ 3 * 4 }`; +var c5 = 1 - `${ 3 * 4 }5`; +var d5 = 1 - `2${ 3 * 4 }5`; +var e5 = `${ 3 * 4 }` - 6; +var f5 = `2${ 3 * 4 }` - 6; +var g5 = `${ 3 * 4 }5` - 6; +var h5 = `2${ 3 * 4 }5` - 6; + +var a6 = 1 - `${ 3 & 4 }`; +var b6 = 1 - `2${ 3 & 4 }`; +var c6 = 1 - `${ 3 & 4 }5`; +var d6 = 1 - `2${ 3 & 4 }5`; +var e6 = `${ 3 & 4 }` - 6; +var f6 = `2${ 3 & 4 }` - 6; +var g6 = `${ 3 & 4 }5` - 6; +var h6 = `2${ 3 & 4 }5` - 6; + +var a7 = 1 * `${ 3 - 4 }`; +var b7 = 1 * `2${ 3 - 4 }`; +var c7 = 1 * `${ 3 - 4 }5`; +var d7 = 1 * `2${ 3 - 4 }5`; +var e7 = `${ 3 - 4 }` * 6; +var f7 = `2${ 3 - 4 }` * 6; +var g7 = `${ 3 - 4 }5` * 6; +var h7 = `2${ 3 - 4 }5` * 6; + +var a8 = 1 * `${ 3 * 4 }`; +var b8 = 1 * `2${ 3 * 4 }`; +var c8 = 1 * `${ 3 * 4 }5`; +var d8 = 1 * `2${ 3 * 4 }5`; +var e8 = `${ 3 * 4 }` * 6; +var f8 = `2${ 3 * 4 }` * 6; +var g8 = `${ 3 * 4 }5` * 6; +var h8 = `2${ 3 * 4 }5` * 6; + +var a9 = 1 * `${ 3 & 4 }`; +var b9 = 1 * `2${ 3 & 4 }`; +var c9 = 1 * `${ 3 & 4 }5`; +var d9 = 1 * `2${ 3 & 4 }5`; +var e9 = `${ 3 & 4 }` * 6; +var f9 = `2${ 3 & 4 }` * 6; +var g9 = `${ 3 & 4 }5` * 6; +var h9 = `2${ 3 & 4 }5` * 6; + +var aa = 1 & `${ 3 - 4 }`; +var ba = 1 & `2${ 3 - 4 }`; +var ca = 1 & `${ 3 - 4 }5`; +var da = 1 & `2${ 3 - 4 }5`; +var ea = `${ 3 - 4 }` & 6; +var fa = `2${ 3 - 4 }` & 6; +var ga = `${ 3 - 4 }5` & 6; +var ha = `2${ 3 - 4 }5` & 6; + +var ab = 1 & `${ 3 * 4 }`; +var bb = 1 & `2${ 3 * 4 }`; +var cb = 1 & `${ 3 * 4 }5`; +var db = 1 & `2${ 3 * 4 }5`; +var eb = `${ 3 * 4 }` & 6; +var fb = `2${ 3 * 4 }` & 6; +var gb = `${ 3 * 4 }5` & 6; +var hb = `2${ 3 * 4 }5` & 6; + +var ac = 1 & `${ 3 & 4 }`; +var bc = 1 & `2${ 3 & 4 }`; +var cc = 1 & `${ 3 & 4 }5`; +var dc = 1 & `2${ 3 & 4 }5`; +var ec = `${ 3 & 4 }` & 6; +var fc = `2${ 3 & 4 }` & 6; +var gc = `${ 3 & 4 }5` & 6; +var hc = `2${ 3 & 4 }5` & 6; diff --git a/tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts b/tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts new file mode 100644 index 00000000000..8770edcbd37 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringBinaryOperationsInvalid.ts @@ -0,0 +1,107 @@ +var a = 1 - `${ 3 }`; +var b = 1 - `2${ 3 }`; +var c = 1 - `${ 3 }4`; +var d = 1 - `2${ 3 }4`; +var e = `${ 3 }` - 5; +var f = `2${ 3 }` - 5; +var g = `${ 3 }4` - 5; +var h = `2${ 3 }4` - 5; + +var a2 = 1 * `${ 3 }`; +var b2 = 1 * `2${ 3 }`; +var c2 = 1 * `${ 3 }4`; +var d2 = 1 * `2${ 3 }4`; +var e2 = `${ 3 }` * 5; +var f2 = `2${ 3 }` * 5; +var g2 = `${ 3 }4` * 5; +var h2 = `2${ 3 }4` * 5; + +var a3 = 1 & `${ 3 }`; +var b3 = 1 & `2${ 3 }`; +var c3 = 1 & `${ 3 }4`; +var d3 = 1 & `2${ 3 }4`; +var e3 = `${ 3 }` & 5; +var f3 = `2${ 3 }` & 5; +var g3 = `${ 3 }4` & 5; +var h3 = `2${ 3 }4` & 5; + +var a4 = 1 - `${ 3 - 4 }`; +var b4 = 1 - `2${ 3 - 4 }`; +var c4 = 1 - `${ 3 - 4 }5`; +var d4 = 1 - `2${ 3 - 4 }5`; +var e4 = `${ 3 - 4 }` - 6; +var f4 = `2${ 3 - 4 }` - 6; +var g4 = `${ 3 - 4 }5` - 6; +var h4 = `2${ 3 - 4 }5` - 6; + +var a5 = 1 - `${ 3 * 4 }`; +var b5 = 1 - `2${ 3 * 4 }`; +var c5 = 1 - `${ 3 * 4 }5`; +var d5 = 1 - `2${ 3 * 4 }5`; +var e5 = `${ 3 * 4 }` - 6; +var f5 = `2${ 3 * 4 }` - 6; +var g5 = `${ 3 * 4 }5` - 6; +var h5 = `2${ 3 * 4 }5` - 6; + +var a6 = 1 - `${ 3 & 4 }`; +var b6 = 1 - `2${ 3 & 4 }`; +var c6 = 1 - `${ 3 & 4 }5`; +var d6 = 1 - `2${ 3 & 4 }5`; +var e6 = `${ 3 & 4 }` - 6; +var f6 = `2${ 3 & 4 }` - 6; +var g6 = `${ 3 & 4 }5` - 6; +var h6 = `2${ 3 & 4 }5` - 6; + +var a7 = 1 * `${ 3 - 4 }`; +var b7 = 1 * `2${ 3 - 4 }`; +var c7 = 1 * `${ 3 - 4 }5`; +var d7 = 1 * `2${ 3 - 4 }5`; +var e7 = `${ 3 - 4 }` * 6; +var f7 = `2${ 3 - 4 }` * 6; +var g7 = `${ 3 - 4 }5` * 6; +var h7 = `2${ 3 - 4 }5` * 6; + +var a8 = 1 * `${ 3 * 4 }`; +var b8 = 1 * `2${ 3 * 4 }`; +var c8 = 1 * `${ 3 * 4 }5`; +var d8 = 1 * `2${ 3 * 4 }5`; +var e8 = `${ 3 * 4 }` * 6; +var f8 = `2${ 3 * 4 }` * 6; +var g8 = `${ 3 * 4 }5` * 6; +var h8 = `2${ 3 * 4 }5` * 6; + +var a9 = 1 * `${ 3 & 4 }`; +var b9 = 1 * `2${ 3 & 4 }`; +var c9 = 1 * `${ 3 & 4 }5`; +var d9 = 1 * `2${ 3 & 4 }5`; +var e9 = `${ 3 & 4 }` * 6; +var f9 = `2${ 3 & 4 }` * 6; +var g9 = `${ 3 & 4 }5` * 6; +var h9 = `2${ 3 & 4 }5` * 6; + +var aa = 1 & `${ 3 - 4 }`; +var ba = 1 & `2${ 3 - 4 }`; +var ca = 1 & `${ 3 - 4 }5`; +var da = 1 & `2${ 3 - 4 }5`; +var ea = `${ 3 - 4 }` & 6; +var fa = `2${ 3 - 4 }` & 6; +var ga = `${ 3 - 4 }5` & 6; +var ha = `2${ 3 - 4 }5` & 6; + +var ab = 1 & `${ 3 * 4 }`; +var bb = 1 & `2${ 3 * 4 }`; +var cb = 1 & `${ 3 * 4 }5`; +var db = 1 & `2${ 3 * 4 }5`; +var eb = `${ 3 * 4 }` & 6; +var fb = `2${ 3 * 4 }` & 6; +var gb = `${ 3 * 4 }5` & 6; +var hb = `2${ 3 * 4 }5` & 6; + +var ac = 1 & `${ 3 & 4 }`; +var bc = 1 & `2${ 3 & 4 }`; +var cc = 1 & `${ 3 & 4 }5`; +var dc = 1 & `2${ 3 & 4 }5`; +var ec = `${ 3 & 4 }` & 6; +var fc = `2${ 3 & 4 }` & 6; +var gc = `${ 3 & 4 }5` & 6; +var hc = `2${ 3 & 4 }5` & 6; diff --git a/tests/cases/conformance/es6/templates/templateStringInBinaryAddition.ts b/tests/cases/conformance/es6/templates/templateStringInBinaryAddition.ts deleted file mode 100644 index 7f00313ca86..00000000000 --- a/tests/cases/conformance/es6/templates/templateStringInBinaryAddition.ts +++ /dev/null @@ -1 +0,0 @@ -var x = 10 + `abc${ 10 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInBinaryAdditionES6.ts b/tests/cases/conformance/es6/templates/templateStringInBinaryAdditionES6.ts deleted file mode 100644 index 5f44e3cb9d4..00000000000 --- a/tests/cases/conformance/es6/templates/templateStringInBinaryAdditionES6.ts +++ /dev/null @@ -1,2 +0,0 @@ -// @target: ES6 -var x = 10 + `abc${ 10 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts index 11dca4caf77..9191ca1934c 100644 --- a/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts +++ b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts @@ -20,4 +20,6 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; -var l = `1${ 0 }2${ 0 }3`; \ No newline at end of file +var l = `${ 0 }2${ 0 }3`; + +var m = `1${ 0 }2${ 0 }3`; diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts index 183da57dd45..ff178d22432 100644 --- a/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts +++ b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts @@ -21,4 +21,6 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; -var l = `1${ 0 }2${ 0 }3`; \ No newline at end of file +var l = `${ 0 }2${ 0 }3`; + +var m = `1${ 0 }2${ 0 }3`; diff --git a/tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts b/tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts new file mode 100644 index 00000000000..26995f21e58 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts @@ -0,0 +1,3 @@ + + +`${function (x: number) { x = "bad"; } }`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts b/tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts new file mode 100644 index 00000000000..4803285a24a --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts @@ -0,0 +1,3 @@ +//@target: es6 + +`${function (x: number) { x = "bad"; } }`; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping1.ts new file mode 100644 index 00000000000..49dfe75ccc6 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping1.ts @@ -0,0 +1,29 @@ + +function fun(g: (x: T) => T, x: T): T; +function fun(g: (x: T) => T, h: (y: T) => T, x: T): T; +function fun(g: (x: T) => T, x: T): T { + return g(x); +} + +var a = fun(x => x, 10); +var b = fun((x => x), 10); +var c = fun(((x => x)), 10); +var d = fun((((x => x))), 10); + +var e = fun(x => x, x => x, 10); +var f = fun((x => x), (x => x), 10); +var g = fun(((x => x)), ((x => x)), 10); +var h = fun((((x => x))), ((x => x)), 10); + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10); +var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); +var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); +var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10); + +var lambda1: (x: number) => number = x => x; +var lambda2: (x: number) => number = (x => x); + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts new file mode 100644 index 00000000000..15acbf3e134 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts @@ -0,0 +1,36 @@ +// These tests ensure that in cases where it may *appear* that a value has a type, +// they actually are properly being contextually typed. The way we test this is +// that we invoke contextually typed arguments with type arguments. +// Since 'any' cannot be invoked with type arguments, we should get errors +// back if contextual typing is not taking effect. + +type FuncType = (x: (p: T) => T) => typeof x; + +function fun(f: FuncType, x: T): T; +function fun(f: FuncType, g: FuncType, x: T): T; +function fun(...rest: any[]): T { + return undefined; +} + +var a = fun(x => { x(undefined); return x; }, 10); +var b = fun((x => { x(undefined); return x; }), 10); +var c = fun(((x => { x(undefined); return x; })), 10); +var d = fun((((x => { x(undefined); return x; }))), 10); + +var e = fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10); +var f = fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10); +var g = fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10); +var h = fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10); + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10); +var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10); +var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10); +var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10); + +var lambda1: FuncType = x => { x(undefined); return x; }; +var lambda2: FuncType = (x => { x(undefined); return x; }); + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping3.ts b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping3.ts new file mode 100644 index 00000000000..004617c3d81 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping3.ts @@ -0,0 +1,21 @@ +// @target: ES6 + +// Contextual typing for parenthesized substitution expressions in tagged templates. + +/** + * tempFun - Can't have fun for too long. + */ +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T { + return g(x); +} + +var a = tempFun `${ x => x } ${ 10 }` +var b = tempFun `${ (x => x) } ${ 10 }` +var c = tempFun `${ ((x => x)) } ${ 10 }` +var d = tempFun `${ x => x } ${ x => x } ${ 10 }` +var e = tempFun `${ x => x } ${ (x => x) } ${ 10 }` +var f = tempFun `${ x => x } ${ ((x => x)) } ${ 10 }` +var g = tempFun `${ (x => x) } ${ (((x => x))) } ${ 10 }` +var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }` \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping1.ts new file mode 100644 index 00000000000..84562f788f3 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping1.ts @@ -0,0 +1,18 @@ +// @target: ES6 + +type FuncType = (x: (p: T) => T) => typeof x; + +function tempTag1(templateStrs: TemplateStringsArray, f: FuncType, x: T): T; +function tempTag1(templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T; +function tempTag1(...rest: any[]): T { + return undefined; +} + +// If contextual typing takes place, these functions should work. +// Otherwise, the arrow functions' parameters will be typed as 'any', +// and it is an error to invoke an any-typed value with type arguments, +// so this test will error. +tempTag1 `${ x => { x(undefined); return x; } }${ 10 }`; +tempTag1 `${ x => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ 10 }`; +tempTag1 `${ x => { x(undefined); return x; } }${ (y: (p: T) => T) => { y(undefined); return y } }${ undefined }`; +tempTag1 `${ (x: (p: T) => T) => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ undefined }`; diff --git a/tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping2.ts b/tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping2.ts new file mode 100644 index 00000000000..24fcf4a04df --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping2.ts @@ -0,0 +1,18 @@ +// @target: ES6 + +type FuncType1 = (x: (p: T) => T) => typeof x; +type FuncType2 = (x: (p: T) => T) => typeof x; + +function tempTag2(templateStrs: TemplateStringsArray, f: FuncType1, x: number): number; +function tempTag2(templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string; +function tempTag2(...rest: any[]): any { + return undefined; +} + +// If contextual typing takes place, these functions should work. +// Otherwise, the arrow functions' parameters will be typed as 'any', +// and it is an error to invoke an any-typed value with type arguments, +// so this test will error. +tempTag2 `${ x => { x(undefined); return x; } }${ 0 }`; +tempTag2 `${ x => { x(undefined); return x; } }${ y => { y(null); return y; } }${ "hello" }`; +tempTag2 `${ x => { x(undefined); return x; } }${ undefined }${ "hello" }`; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/typeGuards/TypeGuardWithArrayUnion.ts b/tests/cases/conformance/expressions/typeGuards/TypeGuardWithArrayUnion.ts new file mode 100644 index 00000000000..8884754b480 --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/TypeGuardWithArrayUnion.ts @@ -0,0 +1,9 @@ +class Message { + value: string; +} + +function saySize(message: Message | Message[]) { + if (message instanceof Array) { + return message.length; // Should have type Message[] here + } +} diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts index e7e756ea8e0..a6379bf95b0 100644 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts @@ -1,7 +1,36 @@ var x: any = { p: 0 }; + if (x instanceof Object) { - x.p; // No error, type any unaffected by type guard + x.p; // No error, type any unaffected by instanceof type guard } else { - x.p; // No error, type any unaffected by type guard + x.p; // No error, type any unaffected by instanceof type guard +} + +if (typeof x === "string") { + x.p; // Error, type any narrowed by primitive type check +} +else { + x.p; // No error, type unaffected in this branch +} + +if (typeof x === "number") { + x.p; // Error, type any narrowed by primitive type check +} +else { + x.p; // No error, type unaffected in this branch +} + +if (typeof x === "boolean") { + x.p; // Error, type any narrowed by primitive type check +} +else { + x.p; // No error, type unaffected in this branch +} + +if (typeof x === "object") { + x.p; // No error, type any only affected by primitive type check +} +else { + x.p; // No error, type unaffected in this branch } diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts new file mode 100644 index 00000000000..2750eb96ebf --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts @@ -0,0 +1,8 @@ +interface I { global: string; } +var result: I; +var result2: I; + +if (!(result instanceof RegExp)) { + result = result2; +} else if (!result.global) { +} \ No newline at end of file diff --git a/tests/cases/fourslash/assertContextualType.ts b/tests/cases/fourslash/assertContextualType.ts index 36a59583825..6ee8861ee8c 100644 --- a/tests/cases/fourslash/assertContextualType.ts +++ b/tests/cases/fourslash/assertContextualType.ts @@ -2,8 +2,5 @@ ////<(aa: number) =>void >(function myFn(b/**/b) { }); -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker(); -verify.quickInfoIs('(parameter) bb: any'); \ No newline at end of file +verify.quickInfoIs('(parameter) bb: number'); \ No newline at end of file diff --git a/tests/cases/fourslash/contextualTyping.ts b/tests/cases/fourslash/contextualTyping.ts index 13fb4dc2450..c363302f7a1 100644 --- a/tests/cases/fourslash/contextualTyping.ts +++ b/tests/cases/fourslash/contextualTyping.ts @@ -212,9 +212,9 @@ verify.quickInfoIs("(parameter) i: number"); goTo.marker('7'); verify.quickInfoIs("(var) c3t1: (s: string) => string"); goTo.marker('8'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('9'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('10'); verify.quickInfoIs("(var) c3t2: IFoo"); goTo.marker('11'); @@ -254,11 +254,11 @@ verify.quickInfoIs("(property) foo: IFoo"); goTo.marker('29'); verify.quickInfoIs("(var) c3t13: IFoo"); goTo.marker('30'); -verify.quickInfoIs("(property) f: (i: any, s: any) => any"); +verify.quickInfoIs("(property) f: (i: number, s: string) => string"); goTo.marker('31'); -verify.quickInfoIs("(parameter) i: any"); +verify.quickInfoIs("(parameter) i: number"); goTo.marker('32'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('33'); verify.quickInfoIs("(var) c3t14: IFoo"); goTo.marker('34'); @@ -286,7 +286,7 @@ verify.quickInfoIs("(var) c7t2: IFoo[]"); goTo.marker('45'); verify.quickInfoIs("(property) t1: (s: string) => string"); goTo.marker('46'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('47'); verify.quickInfoIs("(property) t2: IFoo"); goTo.marker('48'); @@ -326,11 +326,11 @@ verify.quickInfoIs("(property) foo: IFoo"); goTo.marker('65'); verify.quickInfoIs("(property) t13: IFoo"); goTo.marker('66'); -verify.quickInfoIs("(property) f: (i: any, s: any) => any"); +verify.quickInfoIs("(property) f: (i: number, s: string) => string"); goTo.marker('67'); -verify.quickInfoIs("(parameter) i: any"); +verify.quickInfoIs("(parameter) i: number"); goTo.marker('68'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('69'); verify.quickInfoIs("(property) t14: IFoo"); goTo.marker('70'); @@ -346,7 +346,7 @@ verify.quickInfoIs("(parameter) n: number"); goTo.marker('75'); verify.quickInfoIs("(var) c12t1: (s: string) => string"); goTo.marker('76'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('77'); verify.quickInfoIs("(var) c12t2: IFoo"); goTo.marker('78'); @@ -386,11 +386,11 @@ verify.quickInfoIs("(property) foo: IFoo"); goTo.marker('95'); verify.quickInfoIs("(var) c12t13: IFoo"); goTo.marker('96'); -verify.quickInfoIs("(property) f: (i: any, s: any) => any"); +verify.quickInfoIs("(property) f: (i: number, s: string) => string"); goTo.marker('97'); -verify.quickInfoIs("(parameter) i: any"); +verify.quickInfoIs("(parameter) i: number"); goTo.marker('98'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('99'); verify.quickInfoIs("(var) c12t14: IFoo"); goTo.marker('100'); diff --git a/tests/cases/fourslash/formatEmptyParamList.ts b/tests/cases/fourslash/formatEmptyParamList.ts new file mode 100644 index 00000000000..5b207581d61 --- /dev/null +++ b/tests/cases/fourslash/formatEmptyParamList.ts @@ -0,0 +1,5 @@ +/// +////function f( f: function){/*1*/ +goTo.marker("1"); +edit.insert("}"); +verify.currentLineContentIs("function f(f: function){ }") \ No newline at end of file diff --git a/tests/cases/fourslash/formatTemplateLiteral.ts b/tests/cases/fourslash/formatTemplateLiteral.ts new file mode 100644 index 00000000000..a1f5ef963da --- /dev/null +++ b/tests/cases/fourslash/formatTemplateLiteral.ts @@ -0,0 +1,13 @@ +/// +////var x = `sadasdasdasdasfegsfd +/////*1*/rasdesgeryt35t35y35 e4 ergt er 35t 3535 `; +////var y = `1${2}/*2*/3`; + + +goTo.marker("1"); +edit.insert("\r\n"); // edit will trigger formatting - should succeeed + +goTo.marker("2"); +edit.insert("\r\n"); +verify.indentationIs(0); +verify.currentLineContentIs("3`;") \ No newline at end of file diff --git a/tests/cases/fourslash/getEmitOutputSingleFile2.ts b/tests/cases/fourslash/getEmitOutputSingleFile2.ts index bcb1012a6ea..8bf4f7f4af7 100644 --- a/tests/cases/fourslash/getEmitOutputSingleFile2.ts +++ b/tests/cases/fourslash/getEmitOutputSingleFile2.ts @@ -1,6 +1,7 @@ /// // @BaselineFile: getEmitOutputSingleFile2.baseline +// @module: CommonJS // @declaration: true // @out: declSingleFile.js // @outDir: tests/cases/fourslash/ diff --git a/tests/cases/fourslash/getEmitOutputWithDeclarationFile2.ts b/tests/cases/fourslash/getEmitOutputWithDeclarationFile2.ts index f80fa777296..ac68611246b 100644 --- a/tests/cases/fourslash/getEmitOutputWithDeclarationFile2.ts +++ b/tests/cases/fourslash/getEmitOutputWithDeclarationFile2.ts @@ -1,6 +1,7 @@ /// // @BaselineFile: getEmitOutputWithDeclarationFile2.baseline +// @module: CommonJS // @Filename: decl.d.ts // @emitThisFile: true diff --git a/tests/cases/fourslash/getSemanticDiagnosticForDeclaration.ts b/tests/cases/fourslash/getSemanticDiagnosticForDeclaration.ts index fbd086d191d..6345c464213 100644 --- a/tests/cases/fourslash/getSemanticDiagnosticForDeclaration.ts +++ b/tests/cases/fourslash/getSemanticDiagnosticForDeclaration.ts @@ -1,5 +1,6 @@ /// +// @module: CommonJS // @declaration: true //// interface privateInterface {} //// export class Bar implements /*1*/privateInterface/*2*/{ } diff --git a/tests/cases/fourslash/getSemanticDiagnosticForNoDeclaration.ts b/tests/cases/fourslash/getSemanticDiagnosticForNoDeclaration.ts index 57a490fb31c..dc351a21f2c 100644 --- a/tests/cases/fourslash/getSemanticDiagnosticForNoDeclaration.ts +++ b/tests/cases/fourslash/getSemanticDiagnosticForNoDeclaration.ts @@ -1,5 +1,7 @@ /// +// @module: CommonJS + //// interface privateInterface {} //// export class Bar implements /*1*/privateInterface/*2*/{ } diff --git a/tests/cases/fourslash/overloadOnConstCallSignature.ts b/tests/cases/fourslash/overloadOnConstCallSignature.ts index 52e0f3c02e0..7e8075e3652 100644 --- a/tests/cases/fourslash/overloadOnConstCallSignature.ts +++ b/tests/cases/fourslash/overloadOnConstCallSignature.ts @@ -11,8 +11,8 @@ goTo.marker('1'); verify.signatureHelpCountIs(4); -verify.currentSignatureHelpIs('foo(name: string): string'); +verify.currentSignatureHelpIs('foo(name: \'order\'): string'); edit.insert('"hi"'); goTo.marker('2'); -verify.quickInfoIs('(var) x: string'); \ No newline at end of file +verify.quickInfoIs('(var) x: string'); diff --git a/tests/cases/fourslash/quickInfoForContextuallyTypedFunctionInTaggedTemplateExpression1.ts b/tests/cases/fourslash/quickInfoForContextuallyTypedFunctionInTaggedTemplateExpression1.ts new file mode 100644 index 00000000000..ce6b454843a --- /dev/null +++ b/tests/cases/fourslash/quickInfoForContextuallyTypedFunctionInTaggedTemplateExpression1.ts @@ -0,0 +1,19 @@ +/// + +////function tempTag1(templateStrs: TemplateStringsArray, f: (x: T) => T, x: T): T; +////function tempTag1(templateStrs: TemplateStringsArray, f: (x: T) => T, h: (y: T) => T, x: T): T; +////function tempTag1(...rest: any[]): T { +//// return undefined; +////} +//// +////tempTag1 `${ x => /*0*/x }${ 10 }`; +////tempTag1 `${ x => /*1*/x }${ x => /*2*/x }${ 10 }`; +////tempTag1 `${ x => /*3*/x }${ (x: number) => /*4*/x }${ undefined }`; +////tempTag1 `${ (x: number) => /*5*/x }${ x => /*6*/x }${ undefined }`; + +var markers = test.markers(); + +markers.forEach(marker => { + goTo.position(marker.position); + verify.quickInfoIs("(parameter) x: number"); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForContextuallyTypedFunctionInTaggedTemplateExpression2.ts b/tests/cases/fourslash/quickInfoForContextuallyTypedFunctionInTaggedTemplateExpression2.ts new file mode 100644 index 00000000000..d878d601416 --- /dev/null +++ b/tests/cases/fourslash/quickInfoForContextuallyTypedFunctionInTaggedTemplateExpression2.ts @@ -0,0 +1,31 @@ +/// + +////function tempTag2(templateStrs: TemplateStringsArray, f: (x: number) => number, x: number): number; +////function tempTag2(templateStrs: TemplateStringsArray, f: (x: string) => string, h: (y: string) => string, x: string): string; +////function tempTag2(...rest: any[]): any { +//// return undefined; +////} +//// +////tempTag2 `${ x => /*0*/x }${ 0 }`; +////tempTag2 `${ /*1*/x => /*2*/x }${ undefined }`; +////tempTag2 `${ x => /*3*/x }${ x => /*4*/x }${ "hello" }`; +////tempTag2 `${ x => /*5*/x }${ undefined }${ "hello" }`; + +// The first group of parameters, [0, 2], should all be contextually typed as 'number'. +// The second group, [3, 5], should be typed as 'string'. +var numTypedVariableCount = 3; +var strTypedVariableCount = 3; + +if (numTypedVariableCount + strTypedVariableCount !== test.markers().length) { + throw "Unexpected number of markers in file."; +} + +for (var i = 0; i < numTypedVariableCount; i++) { + goTo.marker("" + i); + verify.quickInfoIs("(parameter) x: number"); +} + +for (var i = 0; i < strTypedVariableCount; i++) { + goTo.marker("" + (i + numTypedVariableCount)); + verify.quickInfoIs("(parameter) x: string"); +} \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentTemplateLiterals.ts b/tests/cases/fourslash/smartIndentTemplateLiterals.ts new file mode 100644 index 00000000000..679978a515c --- /dev/null +++ b/tests/cases/fourslash/smartIndentTemplateLiterals.ts @@ -0,0 +1,17 @@ +/// +////var x0 = `sadasdasdasdas/*1*/fegsfdrasdesgeryt35t35y35 e4 ergt er 35t 3535 `; +////var x1 = `sadasdasdasdas/*2*/fegsfdr${0}asdesgeryt35t35y35 e4 ergt er 35t 3535 `; +////var x2 = `sadasdasdasdasfegsfdra${0}sdesge/*3*/ryt35t35y35 e4 ergt er 35t 3535 `; +////var x3 = `sadasdasdasdasfegsfdra${0}sdesge/*4*/ryt35${1}t35y35 e4 ergt er 35t 3535 `; +////var x2 = `sadasdasdasdasfegsfdra${0}sdesge${1}sf/*5*/ryt35t35y35 e4 ergt er 35t 3535 `; + +function verifyIndentation(marker: string): void { + goTo.marker(marker); + edit.insert("\r\n"); + verify.indentationIs(0); +} +verifyIndentation("1"); +verifyIndentation("2"); +verifyIndentation("3"); +verifyIndentation("4"); +verifyIndentation("5"); diff --git a/tests/cases/fourslash/underscoreTyping1.ts b/tests/cases/fourslash/underscoreTyping1.ts index d4556e07f74..fddafe5e88e 100644 --- a/tests/cases/fourslash/underscoreTyping1.ts +++ b/tests/cases/fourslash/underscoreTyping1.ts @@ -1,4 +1,6 @@ /// + +// @module: CommonJS //// interface Dictionary { //// [x: string]: T; diff --git a/tests/perfsys.ts b/tests/perfsys.ts index d3f7ff2ab02..143d0d637d4 100644 --- a/tests/perfsys.ts +++ b/tests/perfsys.ts @@ -1,4 +1,6 @@ /// +/// + module perftest { interface IOLog { @@ -10,24 +12,24 @@ module perftest { getOut(): string; } - export var readFile = sys.readFile; - var writeFile = sys.writeFile; - export var write = sys.write; - var resolvePath = sys.resolvePath; - export var getExecutingFilePath = sys.getExecutingFilePath; - export var getCurrentDirectory = sys.getCurrentDirectory; - var exit = sys.exit; + export var readFile = ts.sys.readFile; + var writeFile = ts.sys.writeFile; + export var write = ts.sys.write; + var resolvePath = ts.sys.resolvePath; + export var getExecutingFilePath = ts.sys.getExecutingFilePath; + export var getCurrentDirectory = ts.sys.getCurrentDirectory; + var exit = ts.sys.exit; - var args = sys.args; + var args = ts.sys.args; // augment sys so first ts.executeCommandLine call will be finish silently - sys.write = (s: string) => { }; - sys.exit = (code: number) => { }; - sys.args = [] + ts.sys.write = (s: string) => { }; + ts.sys.exit = (code: number) => { }; + ts.sys.args = [] export function restoreSys() { - sys.args = args; - sys.write = write; + ts.sys.args = args; + ts.sys.write = write; } export function hasLogIOFlag() { @@ -45,7 +47,7 @@ module perftest { var resolvePathLog: ts.Map = {}; export function interceptIO() { - sys.resolvePath = (s) => { + ts.sys.resolvePath = (s) => { var result = resolvePath(s); resolvePathLog[s] = result; return result; @@ -68,21 +70,21 @@ module perftest { var files: ts.Map = {}; log.fileNames.forEach(f => { files[f] = readFile(f); }) - sys.createDirectory = (s: string) => { }; - sys.directoryExists = (s: string) => true; - sys.fileExists = (s: string) => true; + ts.sys.createDirectory = (s: string) => { }; + ts.sys.directoryExists = (s: string) => true; + ts.sys.fileExists = (s: string) => true; - var currentDirectory = sys.getCurrentDirectory(); - sys.getCurrentDirectory = () => currentDirectory; + var currentDirectory = ts.sys.getCurrentDirectory(); + ts.sys.getCurrentDirectory = () => currentDirectory; - var executingFilePath = sys.getExecutingFilePath(); - sys.getExecutingFilePath = () => executingFilePath; + var executingFilePath = ts.sys.getExecutingFilePath(); + ts.sys.getExecutingFilePath = () => executingFilePath; - sys.readFile = (s: string) => { + ts.sys.readFile = (s: string) => { return files[s]; } - sys.resolvePath = (s: string) => { + ts.sys.resolvePath = (s: string) => { var path = log.resolvePath[s]; if (!path) { throw new Error("Unexpected path '" + s + "'"); @@ -90,11 +92,11 @@ module perftest { return path } - sys.writeFile = (path: string, data: string) => { }; + ts.sys.writeFile = (path: string, data: string) => { }; var out: string = ""; - sys.write = (s: string) => { out += s; }; + ts.sys.write = (s: string) => { out += s; }; return { getOut: () => out, diff --git a/tests/perftsc.ts b/tests/perftsc.ts index e42a6710be4..e0189896a15 100644 --- a/tests/perftsc.ts +++ b/tests/perftsc.ts @@ -13,9 +13,9 @@ if (perftest.hasLogIOFlag()) { getDefaultLibFilename: () => ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(perftest.getExecutingFilePath())), "lib.d.ts"), writeFile: (f: string, content: string) => { throw new Error("Unexpected operation: writeFile"); }, getCurrentDirectory: () => perftest.getCurrentDirectory(), - getCanonicalFileName: ts.getCanonicalFileName, - useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames, - getNewLine: () => sys.newLine + getCanonicalFileName: (f: string) => ts.sys.useCaseSensitiveFileNames ? f : f.toLowerCase(), + useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames, + getNewLine: () => ts.sys.newLine }; var commandLine = ts.parseCommandLine(perftest.getArgsWithoutLogIOFlag()); diff --git a/tests/webhost/webtsc.ts b/tests/webhost/webtsc.ts index c88d2e8f512..ad3c06c8565 100644 --- a/tests/webhost/webtsc.ts +++ b/tests/webhost/webtsc.ts @@ -4,8 +4,12 @@ module TypeScript.WebTsc { declare var RealActiveXObject: { new (s: string): any }; - function getWScriptSystem(): System { + function getWScriptSystem() { var fso = new RealActiveXObject("Scripting.FileSystemObject"); + + var fileStream = new ActiveXObject("ADODB.Stream"); + fileStream.Type = 2 /*text*/; + var args: string[] = []; for (var i = 0; i < WScript.Arguments.length; i++) { args[i] = WScript.Arguments.Item(i); @@ -19,17 +23,35 @@ module TypeScript.WebTsc { writeErr(s: string): void { WScript.StdErr.Write(s); }, - readFile(fileName: string): string { + readFile(fileName: string, encoding?: string): string { + if (!fso.FileExists(fileName)) { + return undefined; + } + fileStream.Open(); try { - var f = fso.OpenTextFile(fileName, 1); - var s: string = f.ReadAll(); - // TODO: Properly handle byte order marks - if (s.length >= 3 && s.charCodeAt(0) === 0xEF && s.charCodeAt(1) === 0xBB && s.charCodeAt(2) === 0xBF) s = s.slice(3); - f.Close(); + if (encoding) { + fileStream.Charset = encoding; + fileStream.LoadFromFile(fileName); + } + else { + // Load file and read the first two bytes into a string with no interpretation + fileStream.Charset = "x-ansi"; + fileStream.LoadFromFile(fileName); + var bom = fileStream.ReadText(2) || ""; + // Position must be at 0 before encoding can be changed + fileStream.Position = 0; + // [0xFF,0xFE] and [0xFE,0xFF] mean utf-16 (little or big endian), otherwise default to utf-8 + fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8"; + } + // ReadText method always strips byte order mark from resulting string + return fileStream.ReadText(); } catch (e) { + throw e; + } + finally { + fileStream.Close(); } - return s; }, writeFile(fileName: string, data: string): boolean { var f = fso.CreateTextFile(fileName, true);