Update LKG

This commit is contained in:
Cyrus Najmabadi 2015-05-15 10:35:06 -07:00
parent 68a4deed28
commit 8af0cbcef4
8 changed files with 896 additions and 513 deletions

View file

@ -4766,6 +4766,7 @@ interface PromiseLike<T> {
* @returns A Promise for the completion of which ever callback is executed. * @returns A Promise for the completion of which ever callback is executed.
*/ */
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>; then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
} }
/** /**
@ -4779,6 +4780,7 @@ interface Promise<T> {
* @returns A Promise for the completion of which ever callback is executed. * @returns A Promise for the completion of which ever callback is executed.
*/ */
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>; then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): Promise<TResult>;
/** /**
* Attaches a callback for only the rejection of the Promise. * Attaches a callback for only the rejection of the Promise.

2
bin/lib.es6.d.ts vendored
View file

@ -4766,6 +4766,7 @@ interface PromiseLike<T> {
* @returns A Promise for the completion of which ever callback is executed. * @returns A Promise for the completion of which ever callback is executed.
*/ */
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>; then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
} }
/** /**
@ -4779,6 +4780,7 @@ interface Promise<T> {
* @returns A Promise for the completion of which ever callback is executed. * @returns A Promise for the completion of which ever callback is executed.
*/ */
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>; then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): Promise<TResult>;
/** /**
* Attaches a callback for only the rejection of the Promise. * Attaches a callback for only the rejection of the Promise.

View file

@ -431,9 +431,13 @@ var ts;
return 3; return 3;
return 2; return 2;
} }
if (path.lastIndexOf("file:///", 0) === 0) {
return "file:///".length;
}
var idx = path.indexOf('://'); var idx = path.indexOf('://');
if (idx !== -1) if (idx !== -1) {
return idx + 3; return idx + "://".length;
}
return 0; return 0;
} }
ts.getRootLength = getRootLength; ts.getRootLength = getRootLength;
@ -584,10 +588,11 @@ var ts;
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
} }
ts.fileExtensionIs = fileExtensionIs; ts.fileExtensionIs = fileExtensionIs;
var supportedExtensions = [".d.ts", ".ts", ".js"]; ts.supportedExtensions = [".ts", ".d.ts"];
var extensionsToRemove = [".d.ts", ".ts", ".js"];
function removeFileExtension(path) { function removeFileExtension(path) {
for (var _i = 0; _i < supportedExtensions.length; _i++) { for (var _i = 0; _i < extensionsToRemove.length; _i++) {
var ext = supportedExtensions[_i]; var ext = extensionsToRemove[_i];
if (fileExtensionIs(path, ext)) { if (fileExtensionIs(path, ext)) {
return path.substr(0, path.length - ext.length); return path.substr(0, path.length - ext.length);
} }
@ -1358,8 +1363,8 @@ var ts;
Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." }, Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." }, Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." },
Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" }, Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option." }, Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5038, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourceMap' option." },
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: ts.DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option." }, Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5039, category: ts.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: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." },
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.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: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
@ -1379,7 +1384,7 @@ var ts;
Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." }, Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." },
Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: ts.DiagnosticCategory.Message, key: "Do not erase const enum declarations in generated code." }, Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: ts.DiagnosticCategory.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: ts.DiagnosticCategory.Message, key: "Do not emit outputs if any type checking errors were reported." }, Do_not_emit_outputs_if_any_errors_were_reported: { code: 6008, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs if any errors were reported." },
Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." },
Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." },
Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" },
@ -1412,7 +1417,7 @@ var ts;
Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." }, Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: ts.DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." }, Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: ts.DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." },
File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." }, File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." },
File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: ts.DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: ts.DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." },
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." },
Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },
@ -3068,6 +3073,9 @@ var ts;
else if (ts.isBlockOrCatchScoped(node)) { else if (ts.isBlockOrCatchScoped(node)) {
bindBlockScopedVariableDeclaration(node); bindBlockScopedVariableDeclaration(node);
} }
else if (ts.isParameterDeclaration(node)) {
bindDeclaration(node, 1, 107455, false);
}
else { else {
bindDeclaration(node, 1, 107454, false); bindDeclaration(node, 1, 107454, false);
} }
@ -3592,9 +3600,6 @@ var ts;
case 141: case 141:
case 143: case 143:
case 144: case 144:
case 163:
case 164:
case 201:
return true; return true;
} }
} }
@ -4176,6 +4181,18 @@ var ts;
return false; return false;
} }
ts.isModifier = isModifier; ts.isModifier = isModifier;
function isParameterDeclaration(node) {
var root = getRootDeclaration(node);
return root.kind === 130;
}
ts.isParameterDeclaration = isParameterDeclaration;
function getRootDeclaration(node) {
while (node.kind === 153) {
node = node.parent.parent;
}
return node;
}
ts.getRootDeclaration = getRootDeclaration;
function nodeStartsNewLexicalEnvironment(n) { function nodeStartsNewLexicalEnvironment(n) {
return isFunctionLike(n) || n.kind === 206 || n.kind === 228; return isFunctionLike(n) || n.kind === 206 || n.kind === 228;
} }
@ -5498,13 +5515,6 @@ var ts;
return token === t && tryParse(nextTokenCanFollowModifier); return token === t && tryParse(nextTokenCanFollowModifier);
} }
function nextTokenCanFollowModifier() { function nextTokenCanFollowModifier() {
nextToken();
return canFollowModifier();
}
function parseAnyContextualModifier() {
return ts.isModifier(token) && tryParse(nextTokenCanFollowContextualModifier);
}
function nextTokenCanFollowContextualModifier() {
if (token === 70) { if (token === 70) {
return nextToken() === 77; return nextToken() === 77;
} }
@ -5521,6 +5531,9 @@ var ts;
nextToken(); nextToken();
return canFollowModifier(); return canFollowModifier();
} }
function parseAnyContextualModifier() {
return ts.isModifier(token) && tryParse(nextTokenCanFollowModifier);
}
function canFollowModifier() { function canFollowModifier() {
return token === 18 return token === 18
|| token === 14 || token === 14
@ -9209,10 +9222,11 @@ var ts;
return symbol; return symbol;
} }
} }
var fileName;
var sourceFile; var sourceFile;
while (true) { while (true) {
var fileName = ts.normalizePath(ts.combinePaths(searchPath, moduleName)); fileName = ts.normalizePath(ts.combinePaths(searchPath, moduleName));
sourceFile = host.getSourceFile(fileName + ".ts") || host.getSourceFile(fileName + ".d.ts"); sourceFile = ts.forEach(ts.supportedExtensions, function (extension) { return host.getSourceFile(fileName + extension); });
if (sourceFile || isRelative) { if (sourceFile || isRelative) {
break; break;
} }
@ -10157,14 +10171,8 @@ var ts;
resolutionTargets.pop(); resolutionTargets.pop();
return resolutionResults.pop(); return resolutionResults.pop();
} }
function getRootDeclaration(node) {
while (node.kind === 153) {
node = node.parent.parent;
}
return node;
}
function getDeclarationContainer(node) { function getDeclarationContainer(node) {
node = getRootDeclaration(node); node = ts.getRootDeclaration(node);
return node.kind === 199 ? node.parent.parent.parent : node.parent; return node.kind === 199 ? node.parent.parent.parent : node.parent;
} }
function getTypeOfPrototypeProperty(prototype) { function getTypeOfPrototypeProperty(prototype) {
@ -10314,7 +10322,7 @@ var ts;
} }
type = declaration.dotDotDotToken ? anyArrayType : anyType; type = declaration.dotDotDotToken ? anyArrayType : anyType;
if (reportErrors && compilerOptions.noImplicitAny) { if (reportErrors && compilerOptions.noImplicitAny) {
var root = getRootDeclaration(declaration); var root = ts.getRootDeclaration(declaration);
if (!isPrivateWithinAmbient(root) && !(root.kind === 130 && isPrivateWithinAmbient(root.parent))) { if (!isPrivateWithinAmbient(root) && !(root.kind === 130 && isPrivateWithinAmbient(root.parent))) {
reportImplicitAnyError(declaration, type); reportImplicitAnyError(declaration, type);
} }
@ -10427,7 +10435,10 @@ var ts;
function getTypeOfAlias(symbol) { function getTypeOfAlias(symbol) {
var links = getSymbolLinks(symbol); var links = getSymbolLinks(symbol);
if (!links.type) { if (!links.type) {
links.type = getTypeOfSymbol(resolveAlias(symbol)); var targetSymbol = resolveAlias(symbol);
links.type = targetSymbol.flags & 107455
? getTypeOfSymbol(targetSymbol)
: unknownType;
} }
return links.type; return links.type;
} }
@ -11441,7 +11452,13 @@ var ts;
} }
return false; return false;
} }
var removeSubtypesStack = [];
function removeSubtypes(types) { function removeSubtypes(types) {
var typeListId = getTypeListId(types);
if (removeSubtypesStack.lastIndexOf(typeListId) >= 0) {
return;
}
removeSubtypesStack.push(typeListId);
var i = types.length; var i = types.length;
while (i > 0) { while (i > 0) {
i--; i--;
@ -11449,6 +11466,7 @@ var ts;
types.splice(i, 1); types.splice(i, 1);
} }
} }
removeSubtypesStack.pop();
} }
function containsAnyType(types) { function containsAnyType(types) {
for (var _i = 0; _i < types.length; _i++) { for (var _i = 0; _i < types.length; _i++) {
@ -13004,18 +13022,15 @@ var ts;
if (!isTypeSubtypeOf(rightType, globalFunctionType)) { if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
return type; return type;
} }
var targetType;
var prototypeProperty = getPropertyOfType(rightType, "prototype"); var prototypeProperty = getPropertyOfType(rightType, "prototype");
if (prototypeProperty) { if (prototypeProperty) {
var targetType = getTypeOfSymbol(prototypeProperty); var prototypePropertyType = getTypeOfSymbol(prototypeProperty);
if (targetType !== anyType) { if (prototypePropertyType !== anyType) {
if (isTypeSubtypeOf(targetType, type)) { targetType = prototypePropertyType;
return targetType;
}
if (type.flags & 16384) {
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
}
} }
} }
if (!targetType) {
var constructSignatures; var constructSignatures;
if (rightType.flags & 2048) { if (rightType.flags & 2048) {
constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures;
@ -13023,12 +13038,17 @@ var ts;
else if (rightType.flags & 32768) { else if (rightType.flags & 32768) {
constructSignatures = getSignaturesOfType(rightType, 1); constructSignatures = getSignaturesOfType(rightType, 1);
} }
if (constructSignatures && constructSignatures.length !== 0) { if (constructSignatures && constructSignatures.length) {
var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); })); targetType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); }));
if (type.flags & 16384) { }
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); })); }
if (targetType) {
if (isTypeSubtypeOf(targetType, type)) {
return targetType;
}
if (type.flags & 16384) {
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
} }
return instanceType;
} }
return type; return type;
} }
@ -15667,7 +15687,7 @@ var ts;
if (ts.isInAmbientContext(node)) { if (ts.isInAmbientContext(node)) {
return false; return false;
} }
var root = getRootDeclaration(node); var root = ts.getRootDeclaration(node);
if (root.kind === 130 && ts.nodeIsMissing(root.parent.body)) { if (root.kind === 130 && ts.nodeIsMissing(root.parent.body)) {
return false; return false;
} }
@ -15728,7 +15748,7 @@ var ts;
// - ScriptBody : StatementList // - ScriptBody : StatementList
// It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList // It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList
// also occurs in the VarDeclaredNames of StatementList. // also occurs in the VarDeclaredNames of StatementList.
if ((ts.getCombinedNodeFlags(node) & 12288) !== 0 || isParameterDeclaration(node)) { if ((ts.getCombinedNodeFlags(node) & 12288) !== 0 || ts.isParameterDeclaration(node)) {
return; return;
} }
if (node.kind === 199 && !node.initializer) { if (node.kind === 199 && !node.initializer) {
@ -15758,14 +15778,8 @@ var ts;
} }
} }
} }
function isParameterDeclaration(node) {
while (node.kind === 153) {
node = node.parent.parent;
}
return node.kind === 130;
}
function checkParameterInitializer(node) { function checkParameterInitializer(node) {
if (getRootDeclaration(node).kind !== 130) { if (ts.getRootDeclaration(node).kind !== 130) {
return; return;
} }
var func = ts.getContainingFunction(node); var func = ts.getContainingFunction(node);
@ -15804,7 +15818,7 @@ var ts;
if (ts.isBindingPattern(node.name)) { if (ts.isBindingPattern(node.name)) {
ts.forEach(node.name.elements, checkSourceElement); ts.forEach(node.name.elements, checkSourceElement);
} }
if (node.initializer && getRootDeclaration(node).kind === 130 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { if (node.initializer && ts.getRootDeclaration(node).kind === 130 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) {
error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
return; return;
} }
@ -21259,7 +21273,7 @@ var ts;
} }
return true; return true;
} }
function emitListWithSpread(elements, multiLine, trailingComma) { function emitListWithSpread(elements, alwaysCopy, multiLine, trailingComma) {
var pos = 0; var pos = 0;
var group = 0; var group = 0;
var length = elements.length; var length = elements.length;
@ -21275,6 +21289,9 @@ var ts;
e = e.expression; e = e.expression;
emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e));
pos++; pos++;
if (pos === length && group === 0 && alwaysCopy && e.kind !== 154) {
write(".slice()");
}
} }
else { else {
var i = pos; var i = pos;
@ -21312,7 +21329,7 @@ var ts;
write("]"); write("]");
} }
else { else {
emitListWithSpread(elements, (node.flags & 512) !== 0, elements.hasTrailingComma); emitListWithSpread(elements, true, (node.flags & 512) !== 0, elements.hasTrailingComma);
} }
} }
function emitObjectLiteralBody(node, numElements) { function emitObjectLiteralBody(node, numElements) {
@ -21638,7 +21655,7 @@ var ts;
write("void 0"); write("void 0");
} }
write(", "); write(", ");
emitListWithSpread(node.arguments, false, false); emitListWithSpread(node.arguments, false, false, false);
write(")"); write(")");
} }
function emitCallExpression(node) { function emitCallExpression(node) {
@ -22266,7 +22283,7 @@ var ts;
if (node.flags & 1) { if (node.flags & 1) {
writeLine(); writeLine();
emitStart(node); emitStart(node);
if (compilerOptions.module === 4) { if (compilerOptions.module === 4 && node.parent === currentSourceFile) {
write(exportFunctionForFile + "(\""); write(exportFunctionForFile + "(\"");
if (node.flags & 256) { if (node.flags & 256) {
write("default"); write("default");
@ -22604,12 +22621,14 @@ var ts;
node.parent.kind === 228; node.parent.kind === 228;
} }
function emitVariableStatement(node) { function emitVariableStatement(node) {
var startIsEmitted = true; var startIsEmitted = false;
if (!(node.flags & 1)) { if (node.flags & 1) {
if (isES6ExportedDeclaration(node)) {
write("export ");
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
} }
else if (isES6ExportedDeclaration(node)) { }
write("export "); else {
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
} }
if (startIsEmitted) { if (startIsEmitted) {
@ -23628,6 +23647,7 @@ var ts;
if (!shouldEmitEnumDeclaration(node)) { if (!shouldEmitEnumDeclaration(node)) {
return; return;
} }
if (!shouldHoistDeclarationInSystemJsModule(node)) {
if (!(node.flags & 1) || isES6ExportedDeclaration(node)) { if (!(node.flags & 1) || isES6ExportedDeclaration(node)) {
emitStart(node); emitStart(node);
if (isES6ExportedDeclaration(node)) { if (isES6ExportedDeclaration(node)) {
@ -23638,6 +23658,7 @@ var ts;
emitEnd(node); emitEnd(node);
write(";"); write(";");
} }
}
writeLine(); writeLine();
emitStart(node); emitStart(node);
write("(function ("); write("(function (");
@ -23658,7 +23679,7 @@ var ts;
emitModuleMemberName(node); emitModuleMemberName(node);
write(" = {}));"); write(" = {}));");
emitEnd(node); emitEnd(node);
if (!isES6ExportedDeclaration(node) && node.flags & 1) { if (!isES6ExportedDeclaration(node) && node.flags & 1 && !shouldHoistDeclarationInSystemJsModule(node)) {
writeLine(); writeLine();
emitStart(node); emitStart(node);
write("var "); write("var ");
@ -23669,6 +23690,14 @@ var ts;
write(";"); write(";");
} }
if (languageVersion < 2 && node.parent === currentSourceFile) { if (languageVersion < 2 && node.parent === currentSourceFile) {
if (compilerOptions.module === 4 && (node.flags & 1)) {
writeLine();
write(exportFunctionForFile + "(\"");
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
}
emitExportMemberAssignments(node.name); emitExportMemberAssignments(node.name);
} }
} }
@ -24255,12 +24284,25 @@ var ts;
if (hoistedVars) { if (hoistedVars) {
writeLine(); writeLine();
write("var "); write("var ");
var seen = {};
for (var i = 0; i < hoistedVars.length; ++i) { for (var i = 0; i < hoistedVars.length; ++i) {
var local = hoistedVars[i]; var local = hoistedVars[i];
var name_21 = local.kind === 65
? local
: local.name;
if (name_21) {
var text = ts.unescapeIdentifier(name_21.text);
if (ts.hasProperty(seen, text)) {
continue;
}
else {
seen[text] = text;
}
}
if (i !== 0) { if (i !== 0) {
write(", "); write(", ");
} }
if (local.kind === 202 || local.kind === 206) { if (local.kind === 202 || local.kind === 206 || local.kind === 205) {
emitDeclarationName(local); emitDeclarationName(local);
} }
else { else {
@ -24291,6 +24333,9 @@ var ts;
} }
return exportedDeclarations; return exportedDeclarations;
function visit(node) { function visit(node) {
if (node.flags & 2) {
return;
}
if (node.kind === 201) { if (node.kind === 201) {
if (!hoistedFunctionDeclarations) { if (!hoistedFunctionDeclarations) {
hoistedFunctionDeclarations = []; hoistedFunctionDeclarations = [];
@ -24305,24 +24350,35 @@ var ts;
hoistedVars.push(node); hoistedVars.push(node);
return; return;
} }
if (node.kind === 206 && shouldEmitModuleDeclaration(node)) { if (node.kind === 205) {
if (shouldEmitEnumDeclaration(node)) {
if (!hoistedVars) { if (!hoistedVars) {
hoistedVars = []; hoistedVars = [];
} }
hoistedVars.push(node); hoistedVars.push(node);
}
return;
}
if (node.kind === 206) {
if (shouldEmitModuleDeclaration(node)) {
if (!hoistedVars) {
hoistedVars = [];
}
hoistedVars.push(node);
}
return; return;
} }
if (node.kind === 199 || node.kind === 153) { if (node.kind === 199 || node.kind === 153) {
if (shouldHoistVariable(node, false)) { if (shouldHoistVariable(node, false)) {
var name_21 = node.name; var name_22 = node.name;
if (name_21.kind === 65) { if (name_22.kind === 65) {
if (!hoistedVars) { if (!hoistedVars) {
hoistedVars = []; hoistedVars = [];
} }
hoistedVars.push(name_21); hoistedVars.push(name_22);
} }
else { else {
ts.forEachChild(name_21, visit); ts.forEachChild(name_22, visit);
} }
} }
return; return;
@ -25168,14 +25224,14 @@ var ts;
if (options.noEmitOnError && getPreEmitDiagnostics(this).length > 0) { if (options.noEmitOnError && getPreEmitDiagnostics(this).length > 0) {
return { diagnostics: [], sourceMaps: undefined, emitSkipped: true }; return { diagnostics: [], sourceMaps: undefined, emitSkipped: true };
} }
var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile);
var start = new Date().getTime(); var start = new Date().getTime();
var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile); var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile);
ts.emitTime += new Date().getTime() - start; ts.emitTime += new Date().getTime() - start;
return emitResult; return emitResult;
} }
function getSourceFile(fileName) { function getSourceFile(fileName) {
fileName = host.getCanonicalFileName(fileName); fileName = host.getCanonicalFileName(ts.normalizeSlashes(fileName));
return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined;
} }
function getDiagnosticsHelper(sourceFile, getDiagnostics) { function getDiagnosticsHelper(sourceFile, getDiagnostics) {
@ -25231,42 +25287,49 @@ var ts;
function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) {
var start; var start;
var length; var length;
var extensions;
var diagnosticArgument;
if (refEnd !== undefined && refPos !== undefined) { if (refEnd !== undefined && refPos !== undefined) {
start = refPos; start = refPos;
length = refEnd - refPos; length = refEnd - refPos;
} }
var diagnostic; var diagnostic;
if (hasExtension(fileName)) { if (hasExtension(fileName)) {
if (!options.allowNonTsExtensions && !ts.fileExtensionIs(host.getCanonicalFileName(fileName), ".ts")) { if (!options.allowNonTsExtensions && !ts.forEach(ts.supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) {
diagnostic = ts.Diagnostics.File_0_must_have_extension_ts_or_d_ts; diagnostic = ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1;
diagnosticArgument = [fileName, "'" + ts.supportedExtensions.join("', '") + "'"];
} }
else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
diagnosticArgument = [fileName];
} }
else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) { else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) {
diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself; diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself;
diagnosticArgument = [fileName];
} }
} }
else { else {
if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
diagnosticArgument = [fileName];
} }
else if (!findSourceFile(fileName + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(fileName + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) { else if (!ts.forEach(ts.supportedExtensions, function (extension) { return findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd); })) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
fileName += ".ts"; fileName += ".ts";
diagnosticArgument = [fileName];
} }
} }
if (diagnostic) { if (diagnostic) {
if (refFile) { if (refFile) {
diagnostics.add(ts.createFileDiagnostic(refFile, start, length, diagnostic, fileName)); diagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, start, length, diagnostic].concat(diagnosticArgument)));
} }
else { else {
diagnostics.add(ts.createCompilerDiagnostic(diagnostic, fileName)); diagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument)));
} }
} }
} }
function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) { function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) {
var canonicalName = host.getCanonicalFileName(fileName); var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName));
if (ts.hasProperty(filesByName, canonicalName)) { if (ts.hasProperty(filesByName, canonicalName)) {
return getSourceFileFromCache(fileName, canonicalName, false); return getSourceFileFromCache(fileName, canonicalName, false);
} }
@ -25326,9 +25389,10 @@ var ts;
var moduleNameText = moduleNameExpr.text; var moduleNameText = moduleNameExpr.text;
if (moduleNameText) { if (moduleNameText) {
var searchPath = basePath; var searchPath = basePath;
var searchName;
while (true) { while (true) {
var searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleNameText)); searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleNameText));
if (findModuleSourceFile(searchName + ".ts", moduleNameExpr) || findModuleSourceFile(searchName + ".d.ts", moduleNameExpr)) { if (ts.forEach(ts.supportedExtensions, function (extension) { return findModuleSourceFile(searchName + extension, moduleNameExpr); })) {
break; break;
} }
var parentPath = ts.getDirectoryPath(searchPath); var parentPath = ts.getDirectoryPath(searchPath);
@ -25348,10 +25412,7 @@ var ts;
var moduleName = nameLiteral.text; var moduleName = nameLiteral.text;
if (moduleName) { if (moduleName) {
var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName)); var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName));
var tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral); ts.forEach(ts.supportedExtensions, function (extension) { return findModuleSourceFile(searchName + extension, nameLiteral); });
if (!tsFile) {
findModuleSourceFile(searchName + ".d.ts", nameLiteral);
}
} }
} }
}); });
@ -25441,10 +25502,10 @@ var ts;
} }
if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
if (options.mapRoot) { if (options.mapRoot) {
diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option)); diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option));
} }
if (options.sourceRoot) { if (options.sourceRoot) {
diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option)); diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option));
} }
return; return;
} }
@ -25582,7 +25643,7 @@ var ts;
{ {
name: "noEmitOnError", name: "noEmitOnError",
type: "boolean", type: "boolean",
description: ts.Diagnostics.Do_not_emit_outputs_if_any_type_checking_errors_were_reported description: ts.Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported
}, },
{ {
name: "noImplicitAny", name: "noImplicitAny",

View file

@ -431,9 +431,13 @@ var ts;
return 3; return 3;
return 2; return 2;
} }
if (path.lastIndexOf("file:///", 0) === 0) {
return "file:///".length;
}
var idx = path.indexOf('://'); var idx = path.indexOf('://');
if (idx !== -1) if (idx !== -1) {
return idx + 3; return idx + "://".length;
}
return 0; return 0;
} }
ts.getRootLength = getRootLength; ts.getRootLength = getRootLength;
@ -584,10 +588,11 @@ var ts;
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
} }
ts.fileExtensionIs = fileExtensionIs; ts.fileExtensionIs = fileExtensionIs;
var supportedExtensions = [".d.ts", ".ts", ".js"]; ts.supportedExtensions = [".ts", ".d.ts"];
var extensionsToRemove = [".d.ts", ".ts", ".js"];
function removeFileExtension(path) { function removeFileExtension(path) {
for (var _i = 0; _i < supportedExtensions.length; _i++) { for (var _i = 0; _i < extensionsToRemove.length; _i++) {
var ext = supportedExtensions[_i]; var ext = extensionsToRemove[_i];
if (fileExtensionIs(path, ext)) { if (fileExtensionIs(path, ext)) {
return path.substr(0, path.length - ext.length); return path.substr(0, path.length - ext.length);
} }
@ -1358,8 +1363,8 @@ var ts;
Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." }, Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." }, Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." },
Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" }, Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option." }, Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5038, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourceMap' option." },
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: ts.DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option." }, Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5039, category: ts.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: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." },
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.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: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
@ -1379,7 +1384,7 @@ var ts;
Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." }, Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." },
Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: ts.DiagnosticCategory.Message, key: "Do not erase const enum declarations in generated code." }, Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: ts.DiagnosticCategory.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: ts.DiagnosticCategory.Message, key: "Do not emit outputs if any type checking errors were reported." }, Do_not_emit_outputs_if_any_errors_were_reported: { code: 6008, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs if any errors were reported." },
Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." },
Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." },
Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" },
@ -1412,7 +1417,7 @@ var ts;
Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." }, Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: ts.DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." }, Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: ts.DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." },
File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." }, File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." },
File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: ts.DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: ts.DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." },
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." },
Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },
@ -2796,7 +2801,7 @@ var ts;
{ {
name: "noEmitOnError", name: "noEmitOnError",
type: "boolean", type: "boolean",
description: ts.Diagnostics.Do_not_emit_outputs_if_any_type_checking_errors_were_reported description: ts.Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported
}, },
{ {
name: "noImplicitAny", name: "noImplicitAny",
@ -3463,9 +3468,6 @@ var ts;
case 141: case 141:
case 143: case 143:
case 144: case 144:
case 163:
case 164:
case 201:
return true; return true;
} }
} }
@ -4047,6 +4049,18 @@ var ts;
return false; return false;
} }
ts.isModifier = isModifier; ts.isModifier = isModifier;
function isParameterDeclaration(node) {
var root = getRootDeclaration(node);
return root.kind === 130;
}
ts.isParameterDeclaration = isParameterDeclaration;
function getRootDeclaration(node) {
while (node.kind === 153) {
node = node.parent.parent;
}
return node;
}
ts.getRootDeclaration = getRootDeclaration;
function nodeStartsNewLexicalEnvironment(n) { function nodeStartsNewLexicalEnvironment(n) {
return isFunctionLike(n) || n.kind === 206 || n.kind === 228; return isFunctionLike(n) || n.kind === 206 || n.kind === 228;
} }
@ -5369,13 +5383,6 @@ var ts;
return token === t && tryParse(nextTokenCanFollowModifier); return token === t && tryParse(nextTokenCanFollowModifier);
} }
function nextTokenCanFollowModifier() { function nextTokenCanFollowModifier() {
nextToken();
return canFollowModifier();
}
function parseAnyContextualModifier() {
return ts.isModifier(token) && tryParse(nextTokenCanFollowContextualModifier);
}
function nextTokenCanFollowContextualModifier() {
if (token === 70) { if (token === 70) {
return nextToken() === 77; return nextToken() === 77;
} }
@ -5392,6 +5399,9 @@ var ts;
nextToken(); nextToken();
return canFollowModifier(); return canFollowModifier();
} }
function parseAnyContextualModifier() {
return ts.isModifier(token) && tryParse(nextTokenCanFollowModifier);
}
function canFollowModifier() { function canFollowModifier() {
return token === 18 return token === 18
|| token === 14 || token === 14
@ -8737,6 +8747,9 @@ var ts;
else if (ts.isBlockOrCatchScoped(node)) { else if (ts.isBlockOrCatchScoped(node)) {
bindBlockScopedVariableDeclaration(node); bindBlockScopedVariableDeclaration(node);
} }
else if (ts.isParameterDeclaration(node)) {
bindDeclaration(node, 1, 107455, false);
}
else { else {
bindDeclaration(node, 1, 107454, false); bindDeclaration(node, 1, 107454, false);
} }
@ -9593,10 +9606,11 @@ var ts;
return symbol; return symbol;
} }
} }
var fileName;
var sourceFile; var sourceFile;
while (true) { while (true) {
var fileName = ts.normalizePath(ts.combinePaths(searchPath, moduleName)); fileName = ts.normalizePath(ts.combinePaths(searchPath, moduleName));
sourceFile = host.getSourceFile(fileName + ".ts") || host.getSourceFile(fileName + ".d.ts"); sourceFile = ts.forEach(ts.supportedExtensions, function (extension) { return host.getSourceFile(fileName + extension); });
if (sourceFile || isRelative) { if (sourceFile || isRelative) {
break; break;
} }
@ -10541,14 +10555,8 @@ var ts;
resolutionTargets.pop(); resolutionTargets.pop();
return resolutionResults.pop(); return resolutionResults.pop();
} }
function getRootDeclaration(node) {
while (node.kind === 153) {
node = node.parent.parent;
}
return node;
}
function getDeclarationContainer(node) { function getDeclarationContainer(node) {
node = getRootDeclaration(node); node = ts.getRootDeclaration(node);
return node.kind === 199 ? node.parent.parent.parent : node.parent; return node.kind === 199 ? node.parent.parent.parent : node.parent;
} }
function getTypeOfPrototypeProperty(prototype) { function getTypeOfPrototypeProperty(prototype) {
@ -10698,7 +10706,7 @@ var ts;
} }
type = declaration.dotDotDotToken ? anyArrayType : anyType; type = declaration.dotDotDotToken ? anyArrayType : anyType;
if (reportErrors && compilerOptions.noImplicitAny) { if (reportErrors && compilerOptions.noImplicitAny) {
var root = getRootDeclaration(declaration); var root = ts.getRootDeclaration(declaration);
if (!isPrivateWithinAmbient(root) && !(root.kind === 130 && isPrivateWithinAmbient(root.parent))) { if (!isPrivateWithinAmbient(root) && !(root.kind === 130 && isPrivateWithinAmbient(root.parent))) {
reportImplicitAnyError(declaration, type); reportImplicitAnyError(declaration, type);
} }
@ -10811,7 +10819,10 @@ var ts;
function getTypeOfAlias(symbol) { function getTypeOfAlias(symbol) {
var links = getSymbolLinks(symbol); var links = getSymbolLinks(symbol);
if (!links.type) { if (!links.type) {
links.type = getTypeOfSymbol(resolveAlias(symbol)); var targetSymbol = resolveAlias(symbol);
links.type = targetSymbol.flags & 107455
? getTypeOfSymbol(targetSymbol)
: unknownType;
} }
return links.type; return links.type;
} }
@ -11825,7 +11836,13 @@ var ts;
} }
return false; return false;
} }
var removeSubtypesStack = [];
function removeSubtypes(types) { function removeSubtypes(types) {
var typeListId = getTypeListId(types);
if (removeSubtypesStack.lastIndexOf(typeListId) >= 0) {
return;
}
removeSubtypesStack.push(typeListId);
var i = types.length; var i = types.length;
while (i > 0) { while (i > 0) {
i--; i--;
@ -11833,6 +11850,7 @@ var ts;
types.splice(i, 1); types.splice(i, 1);
} }
} }
removeSubtypesStack.pop();
} }
function containsAnyType(types) { function containsAnyType(types) {
for (var _i = 0; _i < types.length; _i++) { for (var _i = 0; _i < types.length; _i++) {
@ -13388,18 +13406,15 @@ var ts;
if (!isTypeSubtypeOf(rightType, globalFunctionType)) { if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
return type; return type;
} }
var targetType;
var prototypeProperty = getPropertyOfType(rightType, "prototype"); var prototypeProperty = getPropertyOfType(rightType, "prototype");
if (prototypeProperty) { if (prototypeProperty) {
var targetType = getTypeOfSymbol(prototypeProperty); var prototypePropertyType = getTypeOfSymbol(prototypeProperty);
if (targetType !== anyType) { if (prototypePropertyType !== anyType) {
if (isTypeSubtypeOf(targetType, type)) { targetType = prototypePropertyType;
return targetType;
}
if (type.flags & 16384) {
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
}
} }
} }
if (!targetType) {
var constructSignatures; var constructSignatures;
if (rightType.flags & 2048) { if (rightType.flags & 2048) {
constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures;
@ -13407,12 +13422,17 @@ var ts;
else if (rightType.flags & 32768) { else if (rightType.flags & 32768) {
constructSignatures = getSignaturesOfType(rightType, 1); constructSignatures = getSignaturesOfType(rightType, 1);
} }
if (constructSignatures && constructSignatures.length !== 0) { if (constructSignatures && constructSignatures.length) {
var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); })); targetType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); }));
if (type.flags & 16384) { }
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); })); }
if (targetType) {
if (isTypeSubtypeOf(targetType, type)) {
return targetType;
}
if (type.flags & 16384) {
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
} }
return instanceType;
} }
return type; return type;
} }
@ -16051,7 +16071,7 @@ var ts;
if (ts.isInAmbientContext(node)) { if (ts.isInAmbientContext(node)) {
return false; return false;
} }
var root = getRootDeclaration(node); var root = ts.getRootDeclaration(node);
if (root.kind === 130 && ts.nodeIsMissing(root.parent.body)) { if (root.kind === 130 && ts.nodeIsMissing(root.parent.body)) {
return false; return false;
} }
@ -16112,7 +16132,7 @@ var ts;
// - ScriptBody : StatementList // - ScriptBody : StatementList
// It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList // It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList
// also occurs in the VarDeclaredNames of StatementList. // also occurs in the VarDeclaredNames of StatementList.
if ((ts.getCombinedNodeFlags(node) & 12288) !== 0 || isParameterDeclaration(node)) { if ((ts.getCombinedNodeFlags(node) & 12288) !== 0 || ts.isParameterDeclaration(node)) {
return; return;
} }
if (node.kind === 199 && !node.initializer) { if (node.kind === 199 && !node.initializer) {
@ -16142,14 +16162,8 @@ var ts;
} }
} }
} }
function isParameterDeclaration(node) {
while (node.kind === 153) {
node = node.parent.parent;
}
return node.kind === 130;
}
function checkParameterInitializer(node) { function checkParameterInitializer(node) {
if (getRootDeclaration(node).kind !== 130) { if (ts.getRootDeclaration(node).kind !== 130) {
return; return;
} }
var func = ts.getContainingFunction(node); var func = ts.getContainingFunction(node);
@ -16188,7 +16202,7 @@ var ts;
if (ts.isBindingPattern(node.name)) { if (ts.isBindingPattern(node.name)) {
ts.forEach(node.name.elements, checkSourceElement); ts.forEach(node.name.elements, checkSourceElement);
} }
if (node.initializer && getRootDeclaration(node).kind === 130 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { if (node.initializer && ts.getRootDeclaration(node).kind === 130 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) {
error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
return; return;
} }
@ -21643,7 +21657,7 @@ var ts;
} }
return true; return true;
} }
function emitListWithSpread(elements, multiLine, trailingComma) { function emitListWithSpread(elements, alwaysCopy, multiLine, trailingComma) {
var pos = 0; var pos = 0;
var group = 0; var group = 0;
var length = elements.length; var length = elements.length;
@ -21659,6 +21673,9 @@ var ts;
e = e.expression; e = e.expression;
emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e));
pos++; pos++;
if (pos === length && group === 0 && alwaysCopy && e.kind !== 154) {
write(".slice()");
}
} }
else { else {
var i = pos; var i = pos;
@ -21696,7 +21713,7 @@ var ts;
write("]"); write("]");
} }
else { else {
emitListWithSpread(elements, (node.flags & 512) !== 0, elements.hasTrailingComma); emitListWithSpread(elements, true, (node.flags & 512) !== 0, elements.hasTrailingComma);
} }
} }
function emitObjectLiteralBody(node, numElements) { function emitObjectLiteralBody(node, numElements) {
@ -22022,7 +22039,7 @@ var ts;
write("void 0"); write("void 0");
} }
write(", "); write(", ");
emitListWithSpread(node.arguments, false, false); emitListWithSpread(node.arguments, false, false, false);
write(")"); write(")");
} }
function emitCallExpression(node) { function emitCallExpression(node) {
@ -22650,7 +22667,7 @@ var ts;
if (node.flags & 1) { if (node.flags & 1) {
writeLine(); writeLine();
emitStart(node); emitStart(node);
if (compilerOptions.module === 4) { if (compilerOptions.module === 4 && node.parent === currentSourceFile) {
write(exportFunctionForFile + "(\""); write(exportFunctionForFile + "(\"");
if (node.flags & 256) { if (node.flags & 256) {
write("default"); write("default");
@ -22988,12 +23005,14 @@ var ts;
node.parent.kind === 228; node.parent.kind === 228;
} }
function emitVariableStatement(node) { function emitVariableStatement(node) {
var startIsEmitted = true; var startIsEmitted = false;
if (!(node.flags & 1)) { if (node.flags & 1) {
if (isES6ExportedDeclaration(node)) {
write("export ");
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
} }
else if (isES6ExportedDeclaration(node)) { }
write("export "); else {
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
} }
if (startIsEmitted) { if (startIsEmitted) {
@ -24012,6 +24031,7 @@ var ts;
if (!shouldEmitEnumDeclaration(node)) { if (!shouldEmitEnumDeclaration(node)) {
return; return;
} }
if (!shouldHoistDeclarationInSystemJsModule(node)) {
if (!(node.flags & 1) || isES6ExportedDeclaration(node)) { if (!(node.flags & 1) || isES6ExportedDeclaration(node)) {
emitStart(node); emitStart(node);
if (isES6ExportedDeclaration(node)) { if (isES6ExportedDeclaration(node)) {
@ -24022,6 +24042,7 @@ var ts;
emitEnd(node); emitEnd(node);
write(";"); write(";");
} }
}
writeLine(); writeLine();
emitStart(node); emitStart(node);
write("(function ("); write("(function (");
@ -24042,7 +24063,7 @@ var ts;
emitModuleMemberName(node); emitModuleMemberName(node);
write(" = {}));"); write(" = {}));");
emitEnd(node); emitEnd(node);
if (!isES6ExportedDeclaration(node) && node.flags & 1) { if (!isES6ExportedDeclaration(node) && node.flags & 1 && !shouldHoistDeclarationInSystemJsModule(node)) {
writeLine(); writeLine();
emitStart(node); emitStart(node);
write("var "); write("var ");
@ -24053,6 +24074,14 @@ var ts;
write(";"); write(";");
} }
if (languageVersion < 2 && node.parent === currentSourceFile) { if (languageVersion < 2 && node.parent === currentSourceFile) {
if (compilerOptions.module === 4 && (node.flags & 1)) {
writeLine();
write(exportFunctionForFile + "(\"");
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
}
emitExportMemberAssignments(node.name); emitExportMemberAssignments(node.name);
} }
} }
@ -24639,12 +24668,25 @@ var ts;
if (hoistedVars) { if (hoistedVars) {
writeLine(); writeLine();
write("var "); write("var ");
var seen = {};
for (var i = 0; i < hoistedVars.length; ++i) { for (var i = 0; i < hoistedVars.length; ++i) {
var local = hoistedVars[i]; var local = hoistedVars[i];
var name_21 = local.kind === 65
? local
: local.name;
if (name_21) {
var text = ts.unescapeIdentifier(name_21.text);
if (ts.hasProperty(seen, text)) {
continue;
}
else {
seen[text] = text;
}
}
if (i !== 0) { if (i !== 0) {
write(", "); write(", ");
} }
if (local.kind === 202 || local.kind === 206) { if (local.kind === 202 || local.kind === 206 || local.kind === 205) {
emitDeclarationName(local); emitDeclarationName(local);
} }
else { else {
@ -24675,6 +24717,9 @@ var ts;
} }
return exportedDeclarations; return exportedDeclarations;
function visit(node) { function visit(node) {
if (node.flags & 2) {
return;
}
if (node.kind === 201) { if (node.kind === 201) {
if (!hoistedFunctionDeclarations) { if (!hoistedFunctionDeclarations) {
hoistedFunctionDeclarations = []; hoistedFunctionDeclarations = [];
@ -24689,24 +24734,35 @@ var ts;
hoistedVars.push(node); hoistedVars.push(node);
return; return;
} }
if (node.kind === 206 && shouldEmitModuleDeclaration(node)) { if (node.kind === 205) {
if (shouldEmitEnumDeclaration(node)) {
if (!hoistedVars) { if (!hoistedVars) {
hoistedVars = []; hoistedVars = [];
} }
hoistedVars.push(node); hoistedVars.push(node);
}
return;
}
if (node.kind === 206) {
if (shouldEmitModuleDeclaration(node)) {
if (!hoistedVars) {
hoistedVars = [];
}
hoistedVars.push(node);
}
return; return;
} }
if (node.kind === 199 || node.kind === 153) { if (node.kind === 199 || node.kind === 153) {
if (shouldHoistVariable(node, false)) { if (shouldHoistVariable(node, false)) {
var name_21 = node.name; var name_22 = node.name;
if (name_21.kind === 65) { if (name_22.kind === 65) {
if (!hoistedVars) { if (!hoistedVars) {
hoistedVars = []; hoistedVars = [];
} }
hoistedVars.push(name_21); hoistedVars.push(name_22);
} }
else { else {
ts.forEachChild(name_21, visit); ts.forEachChild(name_22, visit);
} }
} }
return; return;
@ -25552,14 +25608,14 @@ var ts;
if (options.noEmitOnError && getPreEmitDiagnostics(this).length > 0) { if (options.noEmitOnError && getPreEmitDiagnostics(this).length > 0) {
return { diagnostics: [], sourceMaps: undefined, emitSkipped: true }; return { diagnostics: [], sourceMaps: undefined, emitSkipped: true };
} }
var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile);
var start = new Date().getTime(); var start = new Date().getTime();
var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile); var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile);
ts.emitTime += new Date().getTime() - start; ts.emitTime += new Date().getTime() - start;
return emitResult; return emitResult;
} }
function getSourceFile(fileName) { function getSourceFile(fileName) {
fileName = host.getCanonicalFileName(fileName); fileName = host.getCanonicalFileName(ts.normalizeSlashes(fileName));
return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined;
} }
function getDiagnosticsHelper(sourceFile, getDiagnostics) { function getDiagnosticsHelper(sourceFile, getDiagnostics) {
@ -25615,42 +25671,49 @@ var ts;
function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) {
var start; var start;
var length; var length;
var extensions;
var diagnosticArgument;
if (refEnd !== undefined && refPos !== undefined) { if (refEnd !== undefined && refPos !== undefined) {
start = refPos; start = refPos;
length = refEnd - refPos; length = refEnd - refPos;
} }
var diagnostic; var diagnostic;
if (hasExtension(fileName)) { if (hasExtension(fileName)) {
if (!options.allowNonTsExtensions && !ts.fileExtensionIs(host.getCanonicalFileName(fileName), ".ts")) { if (!options.allowNonTsExtensions && !ts.forEach(ts.supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) {
diagnostic = ts.Diagnostics.File_0_must_have_extension_ts_or_d_ts; diagnostic = ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1;
diagnosticArgument = [fileName, "'" + ts.supportedExtensions.join("', '") + "'"];
} }
else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
diagnosticArgument = [fileName];
} }
else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) { else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) {
diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself; diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself;
diagnosticArgument = [fileName];
} }
} }
else { else {
if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
diagnosticArgument = [fileName];
} }
else if (!findSourceFile(fileName + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(fileName + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) { else if (!ts.forEach(ts.supportedExtensions, function (extension) { return findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd); })) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
fileName += ".ts"; fileName += ".ts";
diagnosticArgument = [fileName];
} }
} }
if (diagnostic) { if (diagnostic) {
if (refFile) { if (refFile) {
diagnostics.add(ts.createFileDiagnostic(refFile, start, length, diagnostic, fileName)); diagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, start, length, diagnostic].concat(diagnosticArgument)));
} }
else { else {
diagnostics.add(ts.createCompilerDiagnostic(diagnostic, fileName)); diagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument)));
} }
} }
} }
function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) { function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) {
var canonicalName = host.getCanonicalFileName(fileName); var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName));
if (ts.hasProperty(filesByName, canonicalName)) { if (ts.hasProperty(filesByName, canonicalName)) {
return getSourceFileFromCache(fileName, canonicalName, false); return getSourceFileFromCache(fileName, canonicalName, false);
} }
@ -25710,9 +25773,10 @@ var ts;
var moduleNameText = moduleNameExpr.text; var moduleNameText = moduleNameExpr.text;
if (moduleNameText) { if (moduleNameText) {
var searchPath = basePath; var searchPath = basePath;
var searchName;
while (true) { while (true) {
var searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleNameText)); searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleNameText));
if (findModuleSourceFile(searchName + ".ts", moduleNameExpr) || findModuleSourceFile(searchName + ".d.ts", moduleNameExpr)) { if (ts.forEach(ts.supportedExtensions, function (extension) { return findModuleSourceFile(searchName + extension, moduleNameExpr); })) {
break; break;
} }
var parentPath = ts.getDirectoryPath(searchPath); var parentPath = ts.getDirectoryPath(searchPath);
@ -25732,10 +25796,7 @@ var ts;
var moduleName = nameLiteral.text; var moduleName = nameLiteral.text;
if (moduleName) { if (moduleName) {
var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName)); var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName));
var tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral); ts.forEach(ts.supportedExtensions, function (extension) { return findModuleSourceFile(searchName + extension, nameLiteral); });
if (!tsFile) {
findModuleSourceFile(searchName + ".d.ts", nameLiteral);
}
} }
} }
}); });
@ -25825,10 +25886,10 @@ var ts;
} }
if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
if (options.mapRoot) { if (options.mapRoot) {
diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option)); diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option));
} }
if (options.sourceRoot) { if (options.sourceRoot) {
diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option)); diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option));
} }
return; return;
} }
@ -26402,10 +26463,10 @@ var ts;
ts.forEach(program.getSourceFiles(), function (sourceFile) { ts.forEach(program.getSourceFiles(), function (sourceFile) {
cancellationToken.throwIfCancellationRequested(); cancellationToken.throwIfCancellationRequested();
var nameToDeclarations = sourceFile.getNamedDeclarations(); var nameToDeclarations = sourceFile.getNamedDeclarations();
for (var name_22 in nameToDeclarations) { for (var name_23 in nameToDeclarations) {
var declarations = ts.getProperty(nameToDeclarations, name_22); var declarations = ts.getProperty(nameToDeclarations, name_23);
if (declarations) { if (declarations) {
var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_22); var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_23);
if (!matches) { if (!matches) {
continue; continue;
} }
@ -26416,14 +26477,14 @@ var ts;
if (!containers) { if (!containers) {
return undefined; return undefined;
} }
matches = patternMatcher.getMatches(containers, name_22); matches = patternMatcher.getMatches(containers, name_23);
if (!matches) { if (!matches) {
continue; continue;
} }
} }
var fileName = sourceFile.fileName; var fileName = sourceFile.fileName;
var matchKind = bestMatchKind(matches); var matchKind = bestMatchKind(matches);
rawItems.push({ name: name_22, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); rawItems.push({ name: name_23, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration });
} }
} }
} }
@ -26753,9 +26814,9 @@ var ts;
case 199: case 199:
case 153: case 153:
var variableDeclarationNode; var variableDeclarationNode;
var name_23; var name_24;
if (node.kind === 153) { if (node.kind === 153) {
name_23 = node.name; name_24 = node.name;
variableDeclarationNode = node; variableDeclarationNode = node;
while (variableDeclarationNode && variableDeclarationNode.kind !== 199) { while (variableDeclarationNode && variableDeclarationNode.kind !== 199) {
variableDeclarationNode = variableDeclarationNode.parent; variableDeclarationNode = variableDeclarationNode.parent;
@ -26765,16 +26826,16 @@ var ts;
else { else {
ts.Debug.assert(!ts.isBindingPattern(node.name)); ts.Debug.assert(!ts.isBindingPattern(node.name));
variableDeclarationNode = node; variableDeclarationNode = node;
name_23 = node.name; name_24 = node.name;
} }
if (ts.isConst(variableDeclarationNode)) { if (ts.isConst(variableDeclarationNode)) {
return createItem(node, getTextOfNode(name_23), ts.ScriptElementKind.constElement); return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.constElement);
} }
else if (ts.isLet(variableDeclarationNode)) { else if (ts.isLet(variableDeclarationNode)) {
return createItem(node, getTextOfNode(name_23), ts.ScriptElementKind.letElement); return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.letElement);
} }
else { else {
return createItem(node, getTextOfNode(name_23), ts.ScriptElementKind.variableElement); return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.variableElement);
} }
case 136: case 136:
return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement);
@ -28766,9 +28827,9 @@ var ts;
} }
Rules.prototype.getRuleName = function (rule) { Rules.prototype.getRuleName = function (rule) {
var o = this; var o = this;
for (var name_24 in o) { for (var name_25 in o) {
if (o[name_24] === rule) { if (o[name_25] === rule) {
return name_24; return name_25;
} }
} }
throw new Error("Unknown rule"); throw new Error("Unknown rule");
@ -31751,6 +31812,7 @@ var ts;
var syntaxTreeCache = new SyntaxTreeCache(host); var syntaxTreeCache = new SyntaxTreeCache(host);
var ruleProvider; var ruleProvider;
var program; var program;
var lastProjectVersion;
var useCaseSensitivefileNames = false; var useCaseSensitivefileNames = false;
var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken());
if (!ts.localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) { if (!ts.localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) {
@ -31780,6 +31842,15 @@ var ts;
return ruleProvider; return ruleProvider;
} }
function synchronizeHostData() { function synchronizeHostData() {
if (host.getProjectVersion) {
var hostProjectVersion = host.getProjectVersion();
if (hostProjectVersion) {
if (lastProjectVersion === hostProjectVersion) {
return;
}
lastProjectVersion = hostProjectVersion;
}
}
var hostCache = new HostCache(host, getCanonicalFileName); var hostCache = new HostCache(host, getCanonicalFileName);
if (programUpToDate()) { if (programUpToDate()) {
return; return;
@ -32217,12 +32288,14 @@ var ts;
|| containingNodeKind === 136 || containingNodeKind === 136
|| containingNodeKind === 159 || containingNodeKind === 159
|| containingNodeKind === 154 || containingNodeKind === 154
|| containingNodeKind === 170; || containingNodeKind === 170
|| containingNodeKind === 143;
case 16: case 16:
return containingNodeKind === 158 return containingNodeKind === 158
|| containingNodeKind === 136 || containingNodeKind === 136
|| containingNodeKind === 159 || containingNodeKind === 159
|| containingNodeKind === 162; || containingNodeKind === 162
|| containingNodeKind === 150;
case 18: case 18:
return containingNodeKind === 154; return containingNodeKind === 154;
case 117: case 117:
@ -32316,6 +32389,8 @@ var ts;
containingNodeKind === 151; containingNodeKind === 151;
case 20: case 20:
return containingNodeKind === 152; return containingNodeKind === 152;
case 51:
return containingNodeKind === 153;
case 18: case 18:
return containingNodeKind === 152; return containingNodeKind === 152;
case 16: case 16:
@ -32358,6 +32433,7 @@ var ts;
case 104: case 104:
case 70: case 70:
case 110: case 110:
case 124:
return true; return true;
} }
switch (previousToken.getText()) { switch (previousToken.getText()) {
@ -32451,10 +32527,10 @@ var ts;
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var sourceFile = _a[_i]; var sourceFile = _a[_i];
var nameTable = getNameTable(sourceFile); var nameTable = getNameTable(sourceFile);
for (var name_25 in nameTable) { for (var name_26 in nameTable) {
if (!allNames[name_25]) { if (!allNames[name_26]) {
allNames[name_25] = name_25; allNames[name_26] = name_26;
var displayName = getCompletionEntryDisplayName(name_25, target, true); var displayName = getCompletionEntryDisplayName(name_26, target, true);
if (displayName) { if (displayName) {
var entry = { var entry = {
name: displayName, name: displayName,
@ -34133,17 +34209,17 @@ var ts;
if (isNameOfPropertyAssignment(node)) { if (isNameOfPropertyAssignment(node)) {
var objectLiteral = node.parent.parent; var objectLiteral = node.parent.parent;
var contextualType = typeChecker.getContextualType(objectLiteral); var contextualType = typeChecker.getContextualType(objectLiteral);
var name_26 = node.text; var name_27 = node.text;
if (contextualType) { if (contextualType) {
if (contextualType.flags & 16384) { if (contextualType.flags & 16384) {
var unionProperty = contextualType.getProperty(name_26); var unionProperty = contextualType.getProperty(name_27);
if (unionProperty) { if (unionProperty) {
return [unionProperty]; return [unionProperty];
} }
else { else {
var result_4 = []; var result_4 = [];
ts.forEach(contextualType.types, function (t) { ts.forEach(contextualType.types, function (t) {
var symbol = t.getProperty(name_26); var symbol = t.getProperty(name_27);
if (symbol) { if (symbol) {
result_4.push(symbol); result_4.push(symbol);
} }
@ -34152,7 +34228,7 @@ var ts;
} }
} }
else { else {
var symbol_1 = contextualType.getProperty(name_26); var symbol_1 = contextualType.getProperty(name_27);
if (symbol_1) { if (symbol_1) {
return [symbol_1]; return [symbol_1];
} }
@ -34529,10 +34605,10 @@ var ts;
var kind = triviaScanner.scan(); var kind = triviaScanner.scan();
var end = triviaScanner.getTextPos(); var end = triviaScanner.getTextPos();
var width = end - start; var width = end - start;
if (ts.textSpanIntersectsWith(span, start, width)) {
if (!ts.isTrivia(kind)) { if (!ts.isTrivia(kind)) {
return; return;
} }
if (ts.textSpanIntersectsWith(span, start, width)) {
if (ts.isComment(kind)) { if (ts.isComment(kind)) {
pushClassification(start, width, 1); pushClassification(start, width, 1);
continue; continue;

1
bin/typescript.d.ts vendored
View file

@ -1379,6 +1379,7 @@ declare module "typescript" {
interface LanguageServiceHost { interface LanguageServiceHost {
getCompilationSettings(): CompilerOptions; getCompilationSettings(): CompilerOptions;
getNewLine?(): string; getNewLine?(): string;
getProjectVersion?(): string;
getScriptFileNames(): string[]; getScriptFileNames(): string[];
getScriptVersion(fileName: string): string; getScriptVersion(fileName: string): string;
getScriptSnapshot(fileName: string): IScriptSnapshot; getScriptSnapshot(fileName: string): IScriptSnapshot;

View file

@ -1129,9 +1129,18 @@ var ts;
return 3; return 3;
return 2; return 2;
} }
// Per RFC 1738 'file' URI schema has the shape file://<host>/<path>
// if <host> is omitted then it is assumed that host value is 'localhost',
// however slash after the omitted <host> is not removed.
// file:///folder1/file1 - this is a correct URI
// file://folder2/file2 - this is an incorrect URI
if (path.lastIndexOf("file:///", 0) === 0) {
return "file:///".length;
}
var idx = path.indexOf('://'); var idx = path.indexOf('://');
if (idx !== -1) if (idx !== -1) {
return idx + 3; return idx + "://".length;
}
return 0; return 0;
} }
ts.getRootLength = getRootLength; ts.getRootLength = getRootLength;
@ -1302,10 +1311,14 @@ var ts;
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
} }
ts.fileExtensionIs = fileExtensionIs; ts.fileExtensionIs = fileExtensionIs;
var supportedExtensions = [".d.ts", ".ts", ".js"]; /**
* List of supported extensions in order of file resolution precedence.
*/
ts.supportedExtensions = [".ts", ".d.ts"];
var extensionsToRemove = [".d.ts", ".ts", ".js"];
function removeFileExtension(path) { function removeFileExtension(path) {
for (var _i = 0; _i < supportedExtensions.length; _i++) { for (var _i = 0; _i < extensionsToRemove.length; _i++) {
var ext = supportedExtensions[_i]; var ext = extensionsToRemove[_i];
if (fileExtensionIs(path, ext)) { if (fileExtensionIs(path, ext)) {
return path.substr(0, path.length - ext.length); return path.substr(0, path.length - ext.length);
} }
@ -2101,8 +2114,8 @@ var ts;
Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." }, Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." }, Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." },
Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" }, Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option." }, Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5038, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourceMap' option." },
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: ts.DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option." }, Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5039, category: ts.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: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." },
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.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: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
@ -2122,7 +2135,7 @@ var ts;
Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." }, Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." },
Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: ts.DiagnosticCategory.Message, key: "Do not erase const enum declarations in generated code." }, Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: ts.DiagnosticCategory.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: ts.DiagnosticCategory.Message, key: "Do not emit outputs if any type checking errors were reported." }, Do_not_emit_outputs_if_any_errors_were_reported: { code: 6008, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs if any errors were reported." },
Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." },
Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." },
Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" },
@ -2155,7 +2168,7 @@ var ts;
Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." }, Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: ts.DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." }, Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: ts.DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." },
File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." }, File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." },
File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: ts.DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: ts.DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." },
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." },
Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },
@ -3978,6 +3991,18 @@ var ts;
else if (ts.isBlockOrCatchScoped(node)) { else if (ts.isBlockOrCatchScoped(node)) {
bindBlockScopedVariableDeclaration(node); bindBlockScopedVariableDeclaration(node);
} }
else if (ts.isParameterDeclaration(node)) {
// It is safe to walk up parent chain to find whether the node is a destructing parameter declaration
// because its parent chain has already been set up, since parents are set before descending into children.
//
// If node is a binding element in parameter declaration, we need to use ParameterExcludes.
// Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration
// For example:
// function foo([a,a]) {} // Duplicate Identifier error
// function bar(a,a) {} // Duplicate Identifier error, parameter declaration in this case is handled in bindParameter
// // which correctly set excluded symbols
bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false);
}
else { else {
bindDeclaration(node, 1 /* FunctionScopedVariable */, 107454 /* FunctionScopedVariableExcludes */, false); bindDeclaration(node, 1 /* FunctionScopedVariable */, 107454 /* FunctionScopedVariableExcludes */, false);
} }
@ -4577,9 +4602,6 @@ var ts;
case 141 /* IndexSignature */: case 141 /* IndexSignature */:
case 143 /* FunctionType */: case 143 /* FunctionType */:
case 144 /* ConstructorType */: case 144 /* ConstructorType */:
case 163 /* FunctionExpression */:
case 164 /* ArrowFunction */:
case 201 /* FunctionDeclaration */:
return true; return true;
} }
} }
@ -5220,6 +5242,18 @@ var ts;
return false; return false;
} }
ts.isModifier = isModifier; ts.isModifier = isModifier;
function isParameterDeclaration(node) {
var root = getRootDeclaration(node);
return root.kind === 130 /* Parameter */;
}
ts.isParameterDeclaration = isParameterDeclaration;
function getRootDeclaration(node) {
while (node.kind === 153 /* BindingElement */) {
node = node.parent.parent;
}
return node;
}
ts.getRootDeclaration = getRootDeclaration;
function nodeStartsNewLexicalEnvironment(n) { function nodeStartsNewLexicalEnvironment(n) {
return isFunctionLike(n) || n.kind === 206 /* ModuleDeclaration */ || n.kind === 228 /* SourceFile */; return isFunctionLike(n) || n.kind === 206 /* ModuleDeclaration */ || n.kind === 228 /* SourceFile */;
} }
@ -6840,13 +6874,6 @@ var ts;
return token === t && tryParse(nextTokenCanFollowModifier); return token === t && tryParse(nextTokenCanFollowModifier);
} }
function nextTokenCanFollowModifier() { function nextTokenCanFollowModifier() {
nextToken();
return canFollowModifier();
}
function parseAnyContextualModifier() {
return ts.isModifier(token) && tryParse(nextTokenCanFollowContextualModifier);
}
function nextTokenCanFollowContextualModifier() {
if (token === 70 /* ConstKeyword */) { if (token === 70 /* ConstKeyword */) {
// 'const' is only a modifier if followed by 'enum'. // 'const' is only a modifier if followed by 'enum'.
return nextToken() === 77 /* EnumKeyword */; return nextToken() === 77 /* EnumKeyword */;
@ -6864,6 +6891,9 @@ var ts;
nextToken(); nextToken();
return canFollowModifier(); return canFollowModifier();
} }
function parseAnyContextualModifier() {
return ts.isModifier(token) && tryParse(nextTokenCanFollowModifier);
}
function canFollowModifier() { function canFollowModifier() {
return token === 18 /* OpenBracketToken */ return token === 18 /* OpenBracketToken */
|| token === 14 /* OpenBraceToken */ || token === 14 /* OpenBraceToken */
@ -11531,10 +11561,11 @@ var ts;
return symbol; return symbol;
} }
} }
var fileName;
var sourceFile; var sourceFile;
while (true) { while (true) {
var fileName = ts.normalizePath(ts.combinePaths(searchPath, moduleName)); fileName = ts.normalizePath(ts.combinePaths(searchPath, moduleName));
sourceFile = host.getSourceFile(fileName + ".ts") || host.getSourceFile(fileName + ".d.ts"); sourceFile = ts.forEach(ts.supportedExtensions, function (extension) { return host.getSourceFile(fileName + extension); });
if (sourceFile || isRelative) { if (sourceFile || isRelative) {
break; break;
} }
@ -12605,14 +12636,8 @@ var ts;
resolutionTargets.pop(); resolutionTargets.pop();
return resolutionResults.pop(); return resolutionResults.pop();
} }
function getRootDeclaration(node) {
while (node.kind === 153 /* BindingElement */) {
node = node.parent.parent;
}
return node;
}
function getDeclarationContainer(node) { function getDeclarationContainer(node) {
node = getRootDeclaration(node); node = ts.getRootDeclaration(node);
// Parent chain: // Parent chain:
// VaribleDeclaration -> VariableDeclarationList -> VariableStatement -> 'Declaration Container' // VaribleDeclaration -> VariableDeclarationList -> VariableStatement -> 'Declaration Container'
return node.kind === 199 /* VariableDeclaration */ ? node.parent.parent.parent : node.parent; return node.kind === 199 /* VariableDeclaration */ ? node.parent.parent.parent : node.parent;
@ -12823,7 +12848,7 @@ var ts;
type = declaration.dotDotDotToken ? anyArrayType : anyType; type = declaration.dotDotDotToken ? anyArrayType : anyType;
// Report implicit any errors unless this is a private property within an ambient declaration // Report implicit any errors unless this is a private property within an ambient declaration
if (reportErrors && compilerOptions.noImplicitAny) { if (reportErrors && compilerOptions.noImplicitAny) {
var root = getRootDeclaration(declaration); var root = ts.getRootDeclaration(declaration);
if (!isPrivateWithinAmbient(root) && !(root.kind === 130 /* Parameter */ && isPrivateWithinAmbient(root.parent))) { if (!isPrivateWithinAmbient(root) && !(root.kind === 130 /* Parameter */ && isPrivateWithinAmbient(root.parent))) {
reportImplicitAnyError(declaration, type); reportImplicitAnyError(declaration, type);
} }
@ -12945,7 +12970,15 @@ var ts;
function getTypeOfAlias(symbol) { function getTypeOfAlias(symbol) {
var links = getSymbolLinks(symbol); var links = getSymbolLinks(symbol);
if (!links.type) { if (!links.type) {
links.type = getTypeOfSymbol(resolveAlias(symbol)); var targetSymbol = resolveAlias(symbol);
// It only makes sense to get the type of a value symbol. If the result of resolving
// the alias is not a value, then it has no type. To get the type associated with a
// type symbol, call getDeclaredTypeOfSymbol.
// This check is important because without it, a call to getTypeOfSymbol could end
// up recursively calling getTypeOfAlias, causing a stack overflow.
links.type = targetSymbol.flags & 107455 /* Value */
? getTypeOfSymbol(targetSymbol)
: unknownType;
} }
return links.type; return links.type;
} }
@ -14021,7 +14054,17 @@ var ts;
} }
return false; return false;
} }
// Since removeSubtypes checks the subtype relation, and the subtype relation on a union
// may attempt to reduce a union, it is possible that removeSubtypes could be called
// recursively on the same set of types. The removeSubtypesStack is used to track which
// sets of types are currently undergoing subtype reduction.
var removeSubtypesStack = [];
function removeSubtypes(types) { function removeSubtypes(types) {
var typeListId = getTypeListId(types);
if (removeSubtypesStack.lastIndexOf(typeListId) >= 0) {
return;
}
removeSubtypesStack.push(typeListId);
var i = types.length; var i = types.length;
while (i > 0) { while (i > 0) {
i--; i--;
@ -14029,6 +14072,7 @@ var ts;
types.splice(i, 1); types.splice(i, 1);
} }
} }
removeSubtypesStack.pop();
} }
function containsAnyType(types) { function containsAnyType(types) {
for (var _i = 0; _i < types.length; _i++) { for (var _i = 0; _i < types.length; _i++) {
@ -15730,21 +15774,16 @@ var ts;
if (!isTypeSubtypeOf(rightType, globalFunctionType)) { if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
return type; return type;
} }
// Target type is type of prototype property var targetType;
var prototypeProperty = getPropertyOfType(rightType, "prototype"); var prototypeProperty = getPropertyOfType(rightType, "prototype");
if (prototypeProperty) { if (prototypeProperty) {
var targetType = getTypeOfSymbol(prototypeProperty); // Target type is type of the protoype property
if (targetType !== anyType) { var prototypePropertyType = getTypeOfSymbol(prototypeProperty);
// Narrow to the target type if it's a subtype of the current type if (prototypePropertyType !== anyType) {
if (isTypeSubtypeOf(targetType, type)) { targetType = prototypePropertyType;
return targetType;
}
// If the current type is a union type, remove all constituents that aren't subtypes of the target.
if (type.flags & 16384 /* Union */) {
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
}
} }
} }
if (!targetType) {
// Target type is type of construct signature // Target type is type of construct signature
var constructSignatures; var constructSignatures;
if (rightType.flags & 2048 /* Interface */) { if (rightType.flags & 2048 /* Interface */) {
@ -15753,13 +15792,19 @@ var ts;
else if (rightType.flags & 32768 /* Anonymous */) { else if (rightType.flags & 32768 /* Anonymous */) {
constructSignatures = getSignaturesOfType(rightType, 1 /* Construct */); constructSignatures = getSignaturesOfType(rightType, 1 /* Construct */);
} }
if (constructSignatures && constructSignatures.length !== 0) { if (constructSignatures && constructSignatures.length) {
var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); })); targetType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); }));
// Pickup type from union types }
if (type.flags & 16384 /* Union */) { }
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); })); if (targetType) {
// Narrow to the target type if it's a subtype of the current type
if (isTypeSubtypeOf(targetType, type)) {
return targetType;
}
// If the current type is a union type, remove all constituents that aren't subtypes of the target.
if (type.flags & 16384 /* Union */) {
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
} }
return instanceType;
} }
return type; return type;
} }
@ -19019,7 +19064,7 @@ var ts;
// ambient context - no codegen impact // ambient context - no codegen impact
return false; return false;
} }
var root = getRootDeclaration(node); var root = ts.getRootDeclaration(node);
if (root.kind === 130 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) { if (root.kind === 130 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) {
// just an overload - no codegen impact // just an overload - no codegen impact
return false; return false;
@ -19107,7 +19152,7 @@ var ts;
// let x = 0; // symbol for this declaration will be 'symbol' // let x = 0; // symbol for this declaration will be 'symbol'
// } // }
// skip block-scoped variables and parameters // skip block-scoped variables and parameters
if ((ts.getCombinedNodeFlags(node) & 12288 /* BlockScoped */) !== 0 || isParameterDeclaration(node)) { if ((ts.getCombinedNodeFlags(node) & 12288 /* BlockScoped */) !== 0 || ts.isParameterDeclaration(node)) {
return; return;
} }
// skip variable declarations that don't have initializers // skip variable declarations that don't have initializers
@ -19146,15 +19191,9 @@ var ts;
} }
} }
} }
function isParameterDeclaration(node) {
while (node.kind === 153 /* BindingElement */) {
node = node.parent.parent;
}
return node.kind === 130 /* Parameter */;
}
// Check that a parameter initializer contains no references to parameters declared to the right of itself // Check that a parameter initializer contains no references to parameters declared to the right of itself
function checkParameterInitializer(node) { function checkParameterInitializer(node) {
if (getRootDeclaration(node).kind !== 130 /* Parameter */) { if (ts.getRootDeclaration(node).kind !== 130 /* Parameter */) {
return; return;
} }
var func = ts.getContainingFunction(node); var func = ts.getContainingFunction(node);
@ -19203,7 +19242,7 @@ var ts;
ts.forEach(node.name.elements, checkSourceElement); ts.forEach(node.name.elements, checkSourceElement);
} }
// For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body // For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body
if (node.initializer && getRootDeclaration(node).kind === 130 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { if (node.initializer && ts.getRootDeclaration(node).kind === 130 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) {
error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
return; return;
} }
@ -24263,7 +24302,7 @@ var ts;
var exportSpecifiers; var exportSpecifiers;
var exportEquals; var exportEquals;
var hasExportStars; var hasExportStars;
/** write emitted output to disk*/ /** Write emitted output to disk */
var writeEmittedFiles = writeJavaScriptFile; var writeEmittedFiles = writeJavaScriptFile;
var detachedCommentsInfo; var detachedCommentsInfo;
var writeComment = ts.writeCommentRange; var writeComment = ts.writeCommentRange;
@ -25321,7 +25360,7 @@ var ts;
} }
return true; return true;
} }
function emitListWithSpread(elements, multiLine, trailingComma) { function emitListWithSpread(elements, alwaysCopy, multiLine, trailingComma) {
var pos = 0; var pos = 0;
var group = 0; var group = 0;
var length = elements.length; var length = elements.length;
@ -25338,6 +25377,9 @@ var ts;
e = e.expression; e = e.expression;
emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e));
pos++; pos++;
if (pos === length && group === 0 && alwaysCopy && e.kind !== 154 /* ArrayLiteralExpression */) {
write(".slice()");
}
} }
else { else {
var i = pos; var i = pos;
@ -25375,7 +25417,7 @@ var ts;
write("]"); write("]");
} }
else { else {
emitListWithSpread(elements, (node.flags & 512 /* MultiLine */) !== 0, emitListWithSpread(elements, true, (node.flags & 512 /* MultiLine */) !== 0,
/*trailingComma*/ elements.hasTrailingComma); /*trailingComma*/ elements.hasTrailingComma);
} }
} }
@ -25747,7 +25789,7 @@ var ts;
write("void 0"); write("void 0");
} }
write(", "); write(", ");
emitListWithSpread(node.arguments, false, false); emitListWithSpread(node.arguments, false, false, false);
write(")"); write(")");
} }
function emitCallExpression(node) { function emitCallExpression(node) {
@ -26451,7 +26493,8 @@ var ts;
if (node.flags & 1 /* Export */) { if (node.flags & 1 /* Export */) {
writeLine(); writeLine();
emitStart(node); emitStart(node);
if (compilerOptions.module === 4 /* System */) { // emit call to exporter only for top level nodes
if (compilerOptions.module === 4 /* System */ && node.parent === currentSourceFile) {
// emit export default <smth> as // emit export default <smth> as
// export("default", <smth>) // export("default", <smth>)
write(exportFunctionForFile + "(\""); write(exportFunctionForFile + "(\"");
@ -26824,15 +26867,17 @@ var ts;
node.parent.kind === 228 /* SourceFile */; node.parent.kind === 228 /* SourceFile */;
} }
function emitVariableStatement(node) { function emitVariableStatement(node) {
var startIsEmitted = true; var startIsEmitted = false;
if (!(node.flags & 1 /* Export */)) { if (node.flags & 1 /* Export */) {
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); if (isES6ExportedDeclaration(node)) {
}
else if (isES6ExportedDeclaration(node)) {
// Exported ES6 module member // Exported ES6 module member
write("export "); write("export ");
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
} }
}
else {
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
}
if (startIsEmitted) { if (startIsEmitted) {
emitCommaList(node.declarationList.declarations); emitCommaList(node.declarationList.declarations);
write(";"); write(";");
@ -28028,6 +28073,8 @@ var ts;
if (!shouldEmitEnumDeclaration(node)) { if (!shouldEmitEnumDeclaration(node)) {
return; return;
} }
if (!shouldHoistDeclarationInSystemJsModule(node)) {
// do not emit var if variable was already hoisted
if (!(node.flags & 1 /* Export */) || isES6ExportedDeclaration(node)) { if (!(node.flags & 1 /* Export */) || isES6ExportedDeclaration(node)) {
emitStart(node); emitStart(node);
if (isES6ExportedDeclaration(node)) { if (isES6ExportedDeclaration(node)) {
@ -28038,6 +28085,7 @@ var ts;
emitEnd(node); emitEnd(node);
write(";"); write(";");
} }
}
writeLine(); writeLine();
emitStart(node); emitStart(node);
write("(function ("); write("(function (");
@ -28058,7 +28106,8 @@ var ts;
emitModuleMemberName(node); emitModuleMemberName(node);
write(" = {}));"); write(" = {}));");
emitEnd(node); emitEnd(node);
if (!isES6ExportedDeclaration(node) && node.flags & 1 /* Export */) { if (!isES6ExportedDeclaration(node) && node.flags & 1 /* Export */ && !shouldHoistDeclarationInSystemJsModule(node)) {
// do not emit var if variable was already hoisted
writeLine(); writeLine();
emitStart(node); emitStart(node);
write("var "); write("var ");
@ -28069,6 +28118,15 @@ var ts;
write(";"); write(";");
} }
if (languageVersion < 2 /* ES6 */ && node.parent === currentSourceFile) { if (languageVersion < 2 /* ES6 */ && node.parent === currentSourceFile) {
if (compilerOptions.module === 4 /* System */ && (node.flags & 1 /* Export */)) {
// write the call to exporter for enum
writeLine();
write(exportFunctionForFile + "(\"");
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
}
emitExportMemberAssignments(node.name); emitExportMemberAssignments(node.name);
} }
} }
@ -28708,12 +28766,26 @@ var ts;
if (hoistedVars) { if (hoistedVars) {
writeLine(); writeLine();
write("var "); write("var ");
var seen = {};
for (var i = 0; i < hoistedVars.length; ++i) { for (var i = 0; i < hoistedVars.length; ++i) {
var local = hoistedVars[i]; var local = hoistedVars[i];
var name_21 = local.kind === 65 /* Identifier */
? local
: local.name;
if (name_21) {
// do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables
var text = ts.unescapeIdentifier(name_21.text);
if (ts.hasProperty(seen, text)) {
continue;
}
else {
seen[text] = text;
}
}
if (i !== 0) { if (i !== 0) {
write(", "); write(", ");
} }
if (local.kind === 202 /* ClassDeclaration */ || local.kind === 206 /* ModuleDeclaration */) { if (local.kind === 202 /* ClassDeclaration */ || local.kind === 206 /* ModuleDeclaration */ || local.kind === 205 /* EnumDeclaration */) {
emitDeclarationName(local); emitDeclarationName(local);
} }
else { else {
@ -28744,6 +28816,9 @@ var ts;
} }
return exportedDeclarations; return exportedDeclarations;
function visit(node) { function visit(node) {
if (node.flags & 2 /* Ambient */) {
return;
}
if (node.kind === 201 /* FunctionDeclaration */) { if (node.kind === 201 /* FunctionDeclaration */) {
if (!hoistedFunctionDeclarations) { if (!hoistedFunctionDeclarations) {
hoistedFunctionDeclarations = []; hoistedFunctionDeclarations = [];
@ -28752,31 +28827,41 @@ var ts;
return; return;
} }
if (node.kind === 202 /* ClassDeclaration */) { if (node.kind === 202 /* ClassDeclaration */) {
// TODO: rename block scoped classes
if (!hoistedVars) { if (!hoistedVars) {
hoistedVars = []; hoistedVars = [];
} }
hoistedVars.push(node); hoistedVars.push(node);
return; return;
} }
if (node.kind === 206 /* ModuleDeclaration */ && shouldEmitModuleDeclaration(node)) { if (node.kind === 205 /* EnumDeclaration */) {
if (shouldEmitEnumDeclaration(node)) {
if (!hoistedVars) { if (!hoistedVars) {
hoistedVars = []; hoistedVars = [];
} }
hoistedVars.push(node); hoistedVars.push(node);
}
return;
}
if (node.kind === 206 /* ModuleDeclaration */) {
if (shouldEmitModuleDeclaration(node)) {
if (!hoistedVars) {
hoistedVars = [];
}
hoistedVars.push(node);
}
return; return;
} }
if (node.kind === 199 /* VariableDeclaration */ || node.kind === 153 /* BindingElement */) { if (node.kind === 199 /* VariableDeclaration */ || node.kind === 153 /* BindingElement */) {
if (shouldHoistVariable(node, false)) { if (shouldHoistVariable(node, false)) {
var name_21 = node.name; var name_22 = node.name;
if (name_21.kind === 65 /* Identifier */) { if (name_22.kind === 65 /* Identifier */) {
if (!hoistedVars) { if (!hoistedVars) {
hoistedVars = []; hoistedVars = [];
} }
hoistedVars.push(name_21); hoistedVars.push(name_22);
} }
else { else {
ts.forEachChild(name_21, visit); ts.forEachChild(name_22, visit);
} }
} }
return; return;
@ -29755,14 +29840,19 @@ var ts;
// Create the emit resolver outside of the "emitTime" tracking code below. That way // Create the emit resolver outside of the "emitTime" tracking code below. That way
// any cost associated with it (like type checking) are appropriate associated with // any cost associated with it (like type checking) are appropriate associated with
// the type-checking counter. // the type-checking counter.
var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); //
// If the -out option is specified, we should not pass the source file to getEmitResolver.
// This is because in the -out scenario all files need to be emitted, and therefore all
// files need to be type checked. And the way to specify that all files need to be type
// checked is to not pass the file to getEmitResolver.
var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile);
var start = new Date().getTime(); var start = new Date().getTime();
var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile); var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile);
ts.emitTime += new Date().getTime() - start; ts.emitTime += new Date().getTime() - start;
return emitResult; return emitResult;
} }
function getSourceFile(fileName) { function getSourceFile(fileName) {
fileName = host.getCanonicalFileName(fileName); fileName = host.getCanonicalFileName(ts.normalizeSlashes(fileName));
return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined;
} }
function getDiagnosticsHelper(sourceFile, getDiagnostics) { function getDiagnosticsHelper(sourceFile, getDiagnostics) {
@ -29819,43 +29909,50 @@ var ts;
function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) {
var start; var start;
var length; var length;
var extensions;
var diagnosticArgument;
if (refEnd !== undefined && refPos !== undefined) { if (refEnd !== undefined && refPos !== undefined) {
start = refPos; start = refPos;
length = refEnd - refPos; length = refEnd - refPos;
} }
var diagnostic; var diagnostic;
if (hasExtension(fileName)) { if (hasExtension(fileName)) {
if (!options.allowNonTsExtensions && !ts.fileExtensionIs(host.getCanonicalFileName(fileName), ".ts")) { if (!options.allowNonTsExtensions && !ts.forEach(ts.supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) {
diagnostic = ts.Diagnostics.File_0_must_have_extension_ts_or_d_ts; diagnostic = ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1;
diagnosticArgument = [fileName, "'" + ts.supportedExtensions.join("', '") + "'"];
} }
else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
diagnosticArgument = [fileName];
} }
else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) { else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) {
diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself; diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself;
diagnosticArgument = [fileName];
} }
} }
else { else {
if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
diagnosticArgument = [fileName];
} }
else if (!findSourceFile(fileName + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(fileName + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) { else if (!ts.forEach(ts.supportedExtensions, function (extension) { return findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd); })) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
fileName += ".ts"; fileName += ".ts";
diagnosticArgument = [fileName];
} }
} }
if (diagnostic) { if (diagnostic) {
if (refFile) { if (refFile) {
diagnostics.add(ts.createFileDiagnostic(refFile, start, length, diagnostic, fileName)); diagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, start, length, diagnostic].concat(diagnosticArgument)));
} }
else { else {
diagnostics.add(ts.createCompilerDiagnostic(diagnostic, fileName)); diagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument)));
} }
} }
} }
// Get source file from normalized fileName // Get source file from normalized fileName
function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) { function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) {
var canonicalName = host.getCanonicalFileName(fileName); var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName));
if (ts.hasProperty(filesByName, canonicalName)) { if (ts.hasProperty(filesByName, canonicalName)) {
// We've already looked for this file, use cached result // We've already looked for this file, use cached result
return getSourceFileFromCache(fileName, canonicalName, false); return getSourceFileFromCache(fileName, canonicalName, false);
@ -29918,9 +30015,10 @@ var ts;
var moduleNameText = moduleNameExpr.text; var moduleNameText = moduleNameExpr.text;
if (moduleNameText) { if (moduleNameText) {
var searchPath = basePath; var searchPath = basePath;
var searchName;
while (true) { while (true) {
var searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleNameText)); searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleNameText));
if (findModuleSourceFile(searchName + ".ts", moduleNameExpr) || findModuleSourceFile(searchName + ".d.ts", moduleNameExpr)) { if (ts.forEach(ts.supportedExtensions, function (extension) { return findModuleSourceFile(searchName + extension, moduleNameExpr); })) {
break; break;
} }
var parentPath = ts.getDirectoryPath(searchPath); var parentPath = ts.getDirectoryPath(searchPath);
@ -29948,10 +30046,7 @@ var ts;
// An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules // An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules
// only through top - level external module names. Relative external module names are not permitted. // only through top - level external module names. Relative external module names are not permitted.
var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName)); var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName));
var tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral); ts.forEach(ts.supportedExtensions, function (extension) { return findModuleSourceFile(searchName + extension, nameLiteral); });
if (!tsFile) {
findModuleSourceFile(searchName + ".d.ts", nameLiteral);
}
} }
} }
}); });
@ -30046,10 +30141,10 @@ var ts;
if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
// Error to specify --mapRoot or --sourceRoot without mapSourceFiles // Error to specify --mapRoot or --sourceRoot without mapSourceFiles
if (options.mapRoot) { if (options.mapRoot) {
diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option)); diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option));
} }
if (options.sourceRoot) { if (options.sourceRoot) {
diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option)); diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option));
} }
return; return;
} }
@ -30197,7 +30292,7 @@ var ts;
{ {
name: "noEmitOnError", name: "noEmitOnError",
type: "boolean", type: "boolean",
description: ts.Diagnostics.Do_not_emit_outputs_if_any_type_checking_errors_were_reported description: ts.Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported
}, },
{ {
name: "noImplicitAny", name: "noImplicitAny",
@ -30684,12 +30779,12 @@ var ts;
ts.forEach(program.getSourceFiles(), function (sourceFile) { ts.forEach(program.getSourceFiles(), function (sourceFile) {
cancellationToken.throwIfCancellationRequested(); cancellationToken.throwIfCancellationRequested();
var nameToDeclarations = sourceFile.getNamedDeclarations(); var nameToDeclarations = sourceFile.getNamedDeclarations();
for (var name_22 in nameToDeclarations) { for (var name_23 in nameToDeclarations) {
var declarations = ts.getProperty(nameToDeclarations, name_22); var declarations = ts.getProperty(nameToDeclarations, name_23);
if (declarations) { if (declarations) {
// First do a quick check to see if the name of the declaration matches the // First do a quick check to see if the name of the declaration matches the
// last portion of the (possibly) dotted name they're searching for. // last portion of the (possibly) dotted name they're searching for.
var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_22); var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_23);
if (!matches) { if (!matches) {
continue; continue;
} }
@ -30702,14 +30797,14 @@ var ts;
if (!containers) { if (!containers) {
return undefined; return undefined;
} }
matches = patternMatcher.getMatches(containers, name_22); matches = patternMatcher.getMatches(containers, name_23);
if (!matches) { if (!matches) {
continue; continue;
} }
} }
var fileName = sourceFile.fileName; var fileName = sourceFile.fileName;
var matchKind = bestMatchKind(matches); var matchKind = bestMatchKind(matches);
rawItems.push({ name: name_22, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); rawItems.push({ name: name_23, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration });
} }
} }
} }
@ -31092,9 +31187,9 @@ var ts;
case 199 /* VariableDeclaration */: case 199 /* VariableDeclaration */:
case 153 /* BindingElement */: case 153 /* BindingElement */:
var variableDeclarationNode; var variableDeclarationNode;
var name_23; var name_24;
if (node.kind === 153 /* BindingElement */) { if (node.kind === 153 /* BindingElement */) {
name_23 = node.name; name_24 = node.name;
variableDeclarationNode = node; variableDeclarationNode = node;
// binding elements are added only for variable declarations // binding elements are added only for variable declarations
// bubble up to the containing variable declaration // bubble up to the containing variable declaration
@ -31106,16 +31201,16 @@ var ts;
else { else {
ts.Debug.assert(!ts.isBindingPattern(node.name)); ts.Debug.assert(!ts.isBindingPattern(node.name));
variableDeclarationNode = node; variableDeclarationNode = node;
name_23 = node.name; name_24 = node.name;
} }
if (ts.isConst(variableDeclarationNode)) { if (ts.isConst(variableDeclarationNode)) {
return createItem(node, getTextOfNode(name_23), ts.ScriptElementKind.constElement); return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.constElement);
} }
else if (ts.isLet(variableDeclarationNode)) { else if (ts.isLet(variableDeclarationNode)) {
return createItem(node, getTextOfNode(name_23), ts.ScriptElementKind.letElement); return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.letElement);
} }
else { else {
return createItem(node, getTextOfNode(name_23), ts.ScriptElementKind.variableElement); return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.variableElement);
} }
case 136 /* Constructor */: case 136 /* Constructor */:
return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement);
@ -33702,9 +33797,9 @@ var ts;
} }
Rules.prototype.getRuleName = function (rule) { Rules.prototype.getRuleName = function (rule) {
var o = this; var o = this;
for (var name_24 in o) { for (var name_25 in o) {
if (o[name_24] === rule) { if (o[name_25] === rule) {
return name_24; return name_25;
} }
} }
throw new Error("Unknown rule"); throw new Error("Unknown rule");
@ -37125,6 +37220,7 @@ var ts;
var syntaxTreeCache = new SyntaxTreeCache(host); var syntaxTreeCache = new SyntaxTreeCache(host);
var ruleProvider; var ruleProvider;
var program; var program;
var lastProjectVersion;
var useCaseSensitivefileNames = false; var useCaseSensitivefileNames = false;
var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken());
// Check if the localized messages json is set, otherwise query the host for it // Check if the localized messages json is set, otherwise query the host for it
@ -37156,6 +37252,16 @@ var ts;
return ruleProvider; return ruleProvider;
} }
function synchronizeHostData() { function synchronizeHostData() {
// perform fast check if host supports it
if (host.getProjectVersion) {
var hostProjectVersion = host.getProjectVersion();
if (hostProjectVersion) {
if (lastProjectVersion === hostProjectVersion) {
return;
}
lastProjectVersion = hostProjectVersion;
}
}
// Get a fresh cache of the host information // Get a fresh cache of the host information
var hostCache = new HostCache(host, getCanonicalFileName); var hostCache = new HostCache(host, getCanonicalFileName);
// If the program is already up-to-date, we can reuse it // If the program is already up-to-date, we can reuse it
@ -37712,12 +37818,14 @@ var ts;
|| containingNodeKind === 136 /* Constructor */ // constructor( a, | public, protected, private keywords are allowed here, so show completion || containingNodeKind === 136 /* Constructor */ // constructor( a, | public, protected, private keywords are allowed here, so show completion
|| containingNodeKind === 159 /* NewExpression */ // new C(a, | || containingNodeKind === 159 /* NewExpression */ // new C(a, |
|| containingNodeKind === 154 /* ArrayLiteralExpression */ // [a, | || containingNodeKind === 154 /* ArrayLiteralExpression */ // [a, |
|| containingNodeKind === 170 /* BinaryExpression */; // let x = (a, | || containingNodeKind === 170 /* BinaryExpression */ // let x = (a, |
|| containingNodeKind === 143 /* FunctionType */; // var x: (s: string, list|
case 16 /* OpenParenToken */: case 16 /* OpenParenToken */:
return containingNodeKind === 158 /* CallExpression */ // func( | return containingNodeKind === 158 /* CallExpression */ // func( |
|| containingNodeKind === 136 /* Constructor */ // constructor( | || containingNodeKind === 136 /* Constructor */ // constructor( |
|| containingNodeKind === 159 /* NewExpression */ // new C(a| || containingNodeKind === 159 /* NewExpression */ // new C(a|
|| containingNodeKind === 162 /* ParenthesizedExpression */; // let x = (a| || containingNodeKind === 162 /* ParenthesizedExpression */ // let x = (a|
|| containingNodeKind === 150 /* ParenthesizedType */; // function F(pred: (a| this can become an arrow function, where 'a' is the argument
case 18 /* OpenBracketToken */: case 18 /* OpenBracketToken */:
return containingNodeKind === 154 /* ArrayLiteralExpression */; // [ | return containingNodeKind === 154 /* ArrayLiteralExpression */; // [ |
case 117 /* ModuleKeyword */: // module | case 117 /* ModuleKeyword */: // module |
@ -37814,6 +37922,8 @@ var ts;
containingNodeKind === 151 /* ObjectBindingPattern */; // function func({ x, y| containingNodeKind === 151 /* ObjectBindingPattern */; // function func({ x, y|
case 20 /* DotToken */: case 20 /* DotToken */:
return containingNodeKind === 152 /* ArrayBindingPattern */; // var [.| return containingNodeKind === 152 /* ArrayBindingPattern */; // var [.|
case 51 /* ColonToken */:
return containingNodeKind === 153 /* BindingElement */; // var {x :html|
case 18 /* OpenBracketToken */: case 18 /* OpenBracketToken */:
return containingNodeKind === 152 /* ArrayBindingPattern */; // var [x| return containingNodeKind === 152 /* ArrayBindingPattern */; // var [x|
case 16 /* OpenParenToken */: case 16 /* OpenParenToken */:
@ -37856,6 +37966,7 @@ var ts;
case 104 /* LetKeyword */: case 104 /* LetKeyword */:
case 70 /* ConstKeyword */: case 70 /* ConstKeyword */:
case 110 /* YieldKeyword */: case 110 /* YieldKeyword */:
case 124 /* TypeKeyword */:
return true; return true;
} }
// Previous token may have been a keyword that was converted to an identifier. // Previous token may have been a keyword that was converted to an identifier.
@ -37954,10 +38065,10 @@ var ts;
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var sourceFile = _a[_i]; var sourceFile = _a[_i];
var nameTable = getNameTable(sourceFile); var nameTable = getNameTable(sourceFile);
for (var name_25 in nameTable) { for (var name_26 in nameTable) {
if (!allNames[name_25]) { if (!allNames[name_26]) {
allNames[name_25] = name_25; allNames[name_26] = name_26;
var displayName = getCompletionEntryDisplayName(name_25, target, true); var displayName = getCompletionEntryDisplayName(name_26, target, true);
if (displayName) { if (displayName) {
var entry = { var entry = {
name: displayName, name: displayName,
@ -39839,19 +39950,19 @@ var ts;
if (isNameOfPropertyAssignment(node)) { if (isNameOfPropertyAssignment(node)) {
var objectLiteral = node.parent.parent; var objectLiteral = node.parent.parent;
var contextualType = typeChecker.getContextualType(objectLiteral); var contextualType = typeChecker.getContextualType(objectLiteral);
var name_26 = node.text; var name_27 = node.text;
if (contextualType) { if (contextualType) {
if (contextualType.flags & 16384 /* Union */) { if (contextualType.flags & 16384 /* Union */) {
// This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types)
// if not, search the constituent types for the property // if not, search the constituent types for the property
var unionProperty = contextualType.getProperty(name_26); var unionProperty = contextualType.getProperty(name_27);
if (unionProperty) { if (unionProperty) {
return [unionProperty]; return [unionProperty];
} }
else { else {
var result_4 = []; var result_4 = [];
ts.forEach(contextualType.types, function (t) { ts.forEach(contextualType.types, function (t) {
var symbol = t.getProperty(name_26); var symbol = t.getProperty(name_27);
if (symbol) { if (symbol) {
result_4.push(symbol); result_4.push(symbol);
} }
@ -39860,7 +39971,7 @@ var ts;
} }
} }
else { else {
var symbol_1 = contextualType.getProperty(name_26); var symbol_1 = contextualType.getProperty(name_27);
if (symbol_1) { if (symbol_1) {
return [symbol_1]; return [symbol_1];
} }
@ -40280,10 +40391,12 @@ var ts;
var kind = triviaScanner.scan(); var kind = triviaScanner.scan();
var end = triviaScanner.getTextPos(); var end = triviaScanner.getTextPos();
var width = end - start; var width = end - start;
if (ts.textSpanIntersectsWith(span, start, width)) { // The moment we get something that isn't trivia, then stop processing.
if (!ts.isTrivia(kind)) { if (!ts.isTrivia(kind)) {
return; return;
} }
// Only bother with the trivia if it at least intersects the span of interest.
if (ts.textSpanIntersectsWith(span, start, width)) {
if (ts.isComment(kind)) { if (ts.isComment(kind)) {
// Simple comment. Just add as is. // Simple comment. Just add as is.
pushClassification(start, width, 1 /* comment */); pushClassification(start, width, 1 /* comment */);
@ -41726,6 +41839,13 @@ var ts;
LanguageServiceShimHostAdapter.prototype.error = function (s) { LanguageServiceShimHostAdapter.prototype.error = function (s) {
this.shimHost.error(s); this.shimHost.error(s);
}; };
LanguageServiceShimHostAdapter.prototype.getProjectVersion = function () {
if (!this.shimHost.getProjectVersion) {
// shimmed host does not support getProjectVersion
return undefined;
}
return this.shimHost.getProjectVersion();
};
LanguageServiceShimHostAdapter.prototype.getCompilationSettings = function () { LanguageServiceShimHostAdapter.prototype.getCompilationSettings = function () {
var settingsJson = this.shimHost.getCompilationSettings(); var settingsJson = this.shimHost.getCompilationSettings();
if (settingsJson == null || settingsJson == "") { if (settingsJson == null || settingsJson == "") {
@ -42238,7 +42358,7 @@ var ts;
return { return {
options: configFile.options, options: configFile.options,
files: configFile.fileNames, files: configFile.fileNames,
errors: [realizeDiagnostics(configFile.errors, '\r\n')] errors: realizeDiagnostics(configFile.errors, '\r\n')
}; };
}); });
}; };

View file

@ -1379,6 +1379,7 @@ declare module ts {
interface LanguageServiceHost { interface LanguageServiceHost {
getCompilationSettings(): CompilerOptions; getCompilationSettings(): CompilerOptions;
getNewLine?(): string; getNewLine?(): string;
getProjectVersion?(): string;
getScriptFileNames(): string[]; getScriptFileNames(): string[];
getScriptVersion(fileName: string): string; getScriptVersion(fileName: string): string;
getScriptSnapshot(fileName: string): IScriptSnapshot; getScriptSnapshot(fileName: string): IScriptSnapshot;

View file

@ -1129,9 +1129,18 @@ var ts;
return 3; return 3;
return 2; return 2;
} }
// Per RFC 1738 'file' URI schema has the shape file://<host>/<path>
// if <host> is omitted then it is assumed that host value is 'localhost',
// however slash after the omitted <host> is not removed.
// file:///folder1/file1 - this is a correct URI
// file://folder2/file2 - this is an incorrect URI
if (path.lastIndexOf("file:///", 0) === 0) {
return "file:///".length;
}
var idx = path.indexOf('://'); var idx = path.indexOf('://');
if (idx !== -1) if (idx !== -1) {
return idx + 3; return idx + "://".length;
}
return 0; return 0;
} }
ts.getRootLength = getRootLength; ts.getRootLength = getRootLength;
@ -1302,10 +1311,14 @@ var ts;
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
} }
ts.fileExtensionIs = fileExtensionIs; ts.fileExtensionIs = fileExtensionIs;
var supportedExtensions = [".d.ts", ".ts", ".js"]; /**
* List of supported extensions in order of file resolution precedence.
*/
ts.supportedExtensions = [".ts", ".d.ts"];
var extensionsToRemove = [".d.ts", ".ts", ".js"];
function removeFileExtension(path) { function removeFileExtension(path) {
for (var _i = 0; _i < supportedExtensions.length; _i++) { for (var _i = 0; _i < extensionsToRemove.length; _i++) {
var ext = supportedExtensions[_i]; var ext = extensionsToRemove[_i];
if (fileExtensionIs(path, ext)) { if (fileExtensionIs(path, ext)) {
return path.substr(0, path.length - ext.length); return path.substr(0, path.length - ext.length);
} }
@ -2101,8 +2114,8 @@ var ts;
Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." }, Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." }, Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." },
Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" }, Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option." }, Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5038, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourceMap' option." },
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: ts.DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option." }, Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5039, category: ts.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: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." },
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.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: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
@ -2122,7 +2135,7 @@ var ts;
Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." }, Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." },
Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: ts.DiagnosticCategory.Message, key: "Do not erase const enum declarations in generated code." }, Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: ts.DiagnosticCategory.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: ts.DiagnosticCategory.Message, key: "Do not emit outputs if any type checking errors were reported." }, Do_not_emit_outputs_if_any_errors_were_reported: { code: 6008, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs if any errors were reported." },
Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." },
Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." },
Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" },
@ -2155,7 +2168,7 @@ var ts;
Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." }, Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: ts.DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." }, Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: ts.DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." },
File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." }, File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." },
File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: ts.DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: ts.DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." },
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." },
Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },
@ -3978,6 +3991,18 @@ var ts;
else if (ts.isBlockOrCatchScoped(node)) { else if (ts.isBlockOrCatchScoped(node)) {
bindBlockScopedVariableDeclaration(node); bindBlockScopedVariableDeclaration(node);
} }
else if (ts.isParameterDeclaration(node)) {
// It is safe to walk up parent chain to find whether the node is a destructing parameter declaration
// because its parent chain has already been set up, since parents are set before descending into children.
//
// If node is a binding element in parameter declaration, we need to use ParameterExcludes.
// Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration
// For example:
// function foo([a,a]) {} // Duplicate Identifier error
// function bar(a,a) {} // Duplicate Identifier error, parameter declaration in this case is handled in bindParameter
// // which correctly set excluded symbols
bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false);
}
else { else {
bindDeclaration(node, 1 /* FunctionScopedVariable */, 107454 /* FunctionScopedVariableExcludes */, false); bindDeclaration(node, 1 /* FunctionScopedVariable */, 107454 /* FunctionScopedVariableExcludes */, false);
} }
@ -4577,9 +4602,6 @@ var ts;
case 141 /* IndexSignature */: case 141 /* IndexSignature */:
case 143 /* FunctionType */: case 143 /* FunctionType */:
case 144 /* ConstructorType */: case 144 /* ConstructorType */:
case 163 /* FunctionExpression */:
case 164 /* ArrowFunction */:
case 201 /* FunctionDeclaration */:
return true; return true;
} }
} }
@ -5220,6 +5242,18 @@ var ts;
return false; return false;
} }
ts.isModifier = isModifier; ts.isModifier = isModifier;
function isParameterDeclaration(node) {
var root = getRootDeclaration(node);
return root.kind === 130 /* Parameter */;
}
ts.isParameterDeclaration = isParameterDeclaration;
function getRootDeclaration(node) {
while (node.kind === 153 /* BindingElement */) {
node = node.parent.parent;
}
return node;
}
ts.getRootDeclaration = getRootDeclaration;
function nodeStartsNewLexicalEnvironment(n) { function nodeStartsNewLexicalEnvironment(n) {
return isFunctionLike(n) || n.kind === 206 /* ModuleDeclaration */ || n.kind === 228 /* SourceFile */; return isFunctionLike(n) || n.kind === 206 /* ModuleDeclaration */ || n.kind === 228 /* SourceFile */;
} }
@ -6840,13 +6874,6 @@ var ts;
return token === t && tryParse(nextTokenCanFollowModifier); return token === t && tryParse(nextTokenCanFollowModifier);
} }
function nextTokenCanFollowModifier() { function nextTokenCanFollowModifier() {
nextToken();
return canFollowModifier();
}
function parseAnyContextualModifier() {
return ts.isModifier(token) && tryParse(nextTokenCanFollowContextualModifier);
}
function nextTokenCanFollowContextualModifier() {
if (token === 70 /* ConstKeyword */) { if (token === 70 /* ConstKeyword */) {
// 'const' is only a modifier if followed by 'enum'. // 'const' is only a modifier if followed by 'enum'.
return nextToken() === 77 /* EnumKeyword */; return nextToken() === 77 /* EnumKeyword */;
@ -6864,6 +6891,9 @@ var ts;
nextToken(); nextToken();
return canFollowModifier(); return canFollowModifier();
} }
function parseAnyContextualModifier() {
return ts.isModifier(token) && tryParse(nextTokenCanFollowModifier);
}
function canFollowModifier() { function canFollowModifier() {
return token === 18 /* OpenBracketToken */ return token === 18 /* OpenBracketToken */
|| token === 14 /* OpenBraceToken */ || token === 14 /* OpenBraceToken */
@ -11531,10 +11561,11 @@ var ts;
return symbol; return symbol;
} }
} }
var fileName;
var sourceFile; var sourceFile;
while (true) { while (true) {
var fileName = ts.normalizePath(ts.combinePaths(searchPath, moduleName)); fileName = ts.normalizePath(ts.combinePaths(searchPath, moduleName));
sourceFile = host.getSourceFile(fileName + ".ts") || host.getSourceFile(fileName + ".d.ts"); sourceFile = ts.forEach(ts.supportedExtensions, function (extension) { return host.getSourceFile(fileName + extension); });
if (sourceFile || isRelative) { if (sourceFile || isRelative) {
break; break;
} }
@ -12605,14 +12636,8 @@ var ts;
resolutionTargets.pop(); resolutionTargets.pop();
return resolutionResults.pop(); return resolutionResults.pop();
} }
function getRootDeclaration(node) {
while (node.kind === 153 /* BindingElement */) {
node = node.parent.parent;
}
return node;
}
function getDeclarationContainer(node) { function getDeclarationContainer(node) {
node = getRootDeclaration(node); node = ts.getRootDeclaration(node);
// Parent chain: // Parent chain:
// VaribleDeclaration -> VariableDeclarationList -> VariableStatement -> 'Declaration Container' // VaribleDeclaration -> VariableDeclarationList -> VariableStatement -> 'Declaration Container'
return node.kind === 199 /* VariableDeclaration */ ? node.parent.parent.parent : node.parent; return node.kind === 199 /* VariableDeclaration */ ? node.parent.parent.parent : node.parent;
@ -12823,7 +12848,7 @@ var ts;
type = declaration.dotDotDotToken ? anyArrayType : anyType; type = declaration.dotDotDotToken ? anyArrayType : anyType;
// Report implicit any errors unless this is a private property within an ambient declaration // Report implicit any errors unless this is a private property within an ambient declaration
if (reportErrors && compilerOptions.noImplicitAny) { if (reportErrors && compilerOptions.noImplicitAny) {
var root = getRootDeclaration(declaration); var root = ts.getRootDeclaration(declaration);
if (!isPrivateWithinAmbient(root) && !(root.kind === 130 /* Parameter */ && isPrivateWithinAmbient(root.parent))) { if (!isPrivateWithinAmbient(root) && !(root.kind === 130 /* Parameter */ && isPrivateWithinAmbient(root.parent))) {
reportImplicitAnyError(declaration, type); reportImplicitAnyError(declaration, type);
} }
@ -12945,7 +12970,15 @@ var ts;
function getTypeOfAlias(symbol) { function getTypeOfAlias(symbol) {
var links = getSymbolLinks(symbol); var links = getSymbolLinks(symbol);
if (!links.type) { if (!links.type) {
links.type = getTypeOfSymbol(resolveAlias(symbol)); var targetSymbol = resolveAlias(symbol);
// It only makes sense to get the type of a value symbol. If the result of resolving
// the alias is not a value, then it has no type. To get the type associated with a
// type symbol, call getDeclaredTypeOfSymbol.
// This check is important because without it, a call to getTypeOfSymbol could end
// up recursively calling getTypeOfAlias, causing a stack overflow.
links.type = targetSymbol.flags & 107455 /* Value */
? getTypeOfSymbol(targetSymbol)
: unknownType;
} }
return links.type; return links.type;
} }
@ -14021,7 +14054,17 @@ var ts;
} }
return false; return false;
} }
// Since removeSubtypes checks the subtype relation, and the subtype relation on a union
// may attempt to reduce a union, it is possible that removeSubtypes could be called
// recursively on the same set of types. The removeSubtypesStack is used to track which
// sets of types are currently undergoing subtype reduction.
var removeSubtypesStack = [];
function removeSubtypes(types) { function removeSubtypes(types) {
var typeListId = getTypeListId(types);
if (removeSubtypesStack.lastIndexOf(typeListId) >= 0) {
return;
}
removeSubtypesStack.push(typeListId);
var i = types.length; var i = types.length;
while (i > 0) { while (i > 0) {
i--; i--;
@ -14029,6 +14072,7 @@ var ts;
types.splice(i, 1); types.splice(i, 1);
} }
} }
removeSubtypesStack.pop();
} }
function containsAnyType(types) { function containsAnyType(types) {
for (var _i = 0; _i < types.length; _i++) { for (var _i = 0; _i < types.length; _i++) {
@ -15730,21 +15774,16 @@ var ts;
if (!isTypeSubtypeOf(rightType, globalFunctionType)) { if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
return type; return type;
} }
// Target type is type of prototype property var targetType;
var prototypeProperty = getPropertyOfType(rightType, "prototype"); var prototypeProperty = getPropertyOfType(rightType, "prototype");
if (prototypeProperty) { if (prototypeProperty) {
var targetType = getTypeOfSymbol(prototypeProperty); // Target type is type of the protoype property
if (targetType !== anyType) { var prototypePropertyType = getTypeOfSymbol(prototypeProperty);
// Narrow to the target type if it's a subtype of the current type if (prototypePropertyType !== anyType) {
if (isTypeSubtypeOf(targetType, type)) { targetType = prototypePropertyType;
return targetType;
}
// If the current type is a union type, remove all constituents that aren't subtypes of the target.
if (type.flags & 16384 /* Union */) {
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
}
} }
} }
if (!targetType) {
// Target type is type of construct signature // Target type is type of construct signature
var constructSignatures; var constructSignatures;
if (rightType.flags & 2048 /* Interface */) { if (rightType.flags & 2048 /* Interface */) {
@ -15753,13 +15792,19 @@ var ts;
else if (rightType.flags & 32768 /* Anonymous */) { else if (rightType.flags & 32768 /* Anonymous */) {
constructSignatures = getSignaturesOfType(rightType, 1 /* Construct */); constructSignatures = getSignaturesOfType(rightType, 1 /* Construct */);
} }
if (constructSignatures && constructSignatures.length !== 0) { if (constructSignatures && constructSignatures.length) {
var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); })); targetType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); }));
// Pickup type from union types }
if (type.flags & 16384 /* Union */) { }
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); })); if (targetType) {
// Narrow to the target type if it's a subtype of the current type
if (isTypeSubtypeOf(targetType, type)) {
return targetType;
}
// If the current type is a union type, remove all constituents that aren't subtypes of the target.
if (type.flags & 16384 /* Union */) {
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
} }
return instanceType;
} }
return type; return type;
} }
@ -19019,7 +19064,7 @@ var ts;
// ambient context - no codegen impact // ambient context - no codegen impact
return false; return false;
} }
var root = getRootDeclaration(node); var root = ts.getRootDeclaration(node);
if (root.kind === 130 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) { if (root.kind === 130 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) {
// just an overload - no codegen impact // just an overload - no codegen impact
return false; return false;
@ -19107,7 +19152,7 @@ var ts;
// let x = 0; // symbol for this declaration will be 'symbol' // let x = 0; // symbol for this declaration will be 'symbol'
// } // }
// skip block-scoped variables and parameters // skip block-scoped variables and parameters
if ((ts.getCombinedNodeFlags(node) & 12288 /* BlockScoped */) !== 0 || isParameterDeclaration(node)) { if ((ts.getCombinedNodeFlags(node) & 12288 /* BlockScoped */) !== 0 || ts.isParameterDeclaration(node)) {
return; return;
} }
// skip variable declarations that don't have initializers // skip variable declarations that don't have initializers
@ -19146,15 +19191,9 @@ var ts;
} }
} }
} }
function isParameterDeclaration(node) {
while (node.kind === 153 /* BindingElement */) {
node = node.parent.parent;
}
return node.kind === 130 /* Parameter */;
}
// Check that a parameter initializer contains no references to parameters declared to the right of itself // Check that a parameter initializer contains no references to parameters declared to the right of itself
function checkParameterInitializer(node) { function checkParameterInitializer(node) {
if (getRootDeclaration(node).kind !== 130 /* Parameter */) { if (ts.getRootDeclaration(node).kind !== 130 /* Parameter */) {
return; return;
} }
var func = ts.getContainingFunction(node); var func = ts.getContainingFunction(node);
@ -19203,7 +19242,7 @@ var ts;
ts.forEach(node.name.elements, checkSourceElement); ts.forEach(node.name.elements, checkSourceElement);
} }
// For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body // For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body
if (node.initializer && getRootDeclaration(node).kind === 130 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { if (node.initializer && ts.getRootDeclaration(node).kind === 130 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) {
error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
return; return;
} }
@ -24263,7 +24302,7 @@ var ts;
var exportSpecifiers; var exportSpecifiers;
var exportEquals; var exportEquals;
var hasExportStars; var hasExportStars;
/** write emitted output to disk*/ /** Write emitted output to disk */
var writeEmittedFiles = writeJavaScriptFile; var writeEmittedFiles = writeJavaScriptFile;
var detachedCommentsInfo; var detachedCommentsInfo;
var writeComment = ts.writeCommentRange; var writeComment = ts.writeCommentRange;
@ -25321,7 +25360,7 @@ var ts;
} }
return true; return true;
} }
function emitListWithSpread(elements, multiLine, trailingComma) { function emitListWithSpread(elements, alwaysCopy, multiLine, trailingComma) {
var pos = 0; var pos = 0;
var group = 0; var group = 0;
var length = elements.length; var length = elements.length;
@ -25338,6 +25377,9 @@ var ts;
e = e.expression; e = e.expression;
emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e));
pos++; pos++;
if (pos === length && group === 0 && alwaysCopy && e.kind !== 154 /* ArrayLiteralExpression */) {
write(".slice()");
}
} }
else { else {
var i = pos; var i = pos;
@ -25375,7 +25417,7 @@ var ts;
write("]"); write("]");
} }
else { else {
emitListWithSpread(elements, (node.flags & 512 /* MultiLine */) !== 0, emitListWithSpread(elements, true, (node.flags & 512 /* MultiLine */) !== 0,
/*trailingComma*/ elements.hasTrailingComma); /*trailingComma*/ elements.hasTrailingComma);
} }
} }
@ -25747,7 +25789,7 @@ var ts;
write("void 0"); write("void 0");
} }
write(", "); write(", ");
emitListWithSpread(node.arguments, false, false); emitListWithSpread(node.arguments, false, false, false);
write(")"); write(")");
} }
function emitCallExpression(node) { function emitCallExpression(node) {
@ -26451,7 +26493,8 @@ var ts;
if (node.flags & 1 /* Export */) { if (node.flags & 1 /* Export */) {
writeLine(); writeLine();
emitStart(node); emitStart(node);
if (compilerOptions.module === 4 /* System */) { // emit call to exporter only for top level nodes
if (compilerOptions.module === 4 /* System */ && node.parent === currentSourceFile) {
// emit export default <smth> as // emit export default <smth> as
// export("default", <smth>) // export("default", <smth>)
write(exportFunctionForFile + "(\""); write(exportFunctionForFile + "(\"");
@ -26824,15 +26867,17 @@ var ts;
node.parent.kind === 228 /* SourceFile */; node.parent.kind === 228 /* SourceFile */;
} }
function emitVariableStatement(node) { function emitVariableStatement(node) {
var startIsEmitted = true; var startIsEmitted = false;
if (!(node.flags & 1 /* Export */)) { if (node.flags & 1 /* Export */) {
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); if (isES6ExportedDeclaration(node)) {
}
else if (isES6ExportedDeclaration(node)) {
// Exported ES6 module member // Exported ES6 module member
write("export "); write("export ");
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
} }
}
else {
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
}
if (startIsEmitted) { if (startIsEmitted) {
emitCommaList(node.declarationList.declarations); emitCommaList(node.declarationList.declarations);
write(";"); write(";");
@ -28028,6 +28073,8 @@ var ts;
if (!shouldEmitEnumDeclaration(node)) { if (!shouldEmitEnumDeclaration(node)) {
return; return;
} }
if (!shouldHoistDeclarationInSystemJsModule(node)) {
// do not emit var if variable was already hoisted
if (!(node.flags & 1 /* Export */) || isES6ExportedDeclaration(node)) { if (!(node.flags & 1 /* Export */) || isES6ExportedDeclaration(node)) {
emitStart(node); emitStart(node);
if (isES6ExportedDeclaration(node)) { if (isES6ExportedDeclaration(node)) {
@ -28038,6 +28085,7 @@ var ts;
emitEnd(node); emitEnd(node);
write(";"); write(";");
} }
}
writeLine(); writeLine();
emitStart(node); emitStart(node);
write("(function ("); write("(function (");
@ -28058,7 +28106,8 @@ var ts;
emitModuleMemberName(node); emitModuleMemberName(node);
write(" = {}));"); write(" = {}));");
emitEnd(node); emitEnd(node);
if (!isES6ExportedDeclaration(node) && node.flags & 1 /* Export */) { if (!isES6ExportedDeclaration(node) && node.flags & 1 /* Export */ && !shouldHoistDeclarationInSystemJsModule(node)) {
// do not emit var if variable was already hoisted
writeLine(); writeLine();
emitStart(node); emitStart(node);
write("var "); write("var ");
@ -28069,6 +28118,15 @@ var ts;
write(";"); write(";");
} }
if (languageVersion < 2 /* ES6 */ && node.parent === currentSourceFile) { if (languageVersion < 2 /* ES6 */ && node.parent === currentSourceFile) {
if (compilerOptions.module === 4 /* System */ && (node.flags & 1 /* Export */)) {
// write the call to exporter for enum
writeLine();
write(exportFunctionForFile + "(\"");
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
}
emitExportMemberAssignments(node.name); emitExportMemberAssignments(node.name);
} }
} }
@ -28708,12 +28766,26 @@ var ts;
if (hoistedVars) { if (hoistedVars) {
writeLine(); writeLine();
write("var "); write("var ");
var seen = {};
for (var i = 0; i < hoistedVars.length; ++i) { for (var i = 0; i < hoistedVars.length; ++i) {
var local = hoistedVars[i]; var local = hoistedVars[i];
var name_21 = local.kind === 65 /* Identifier */
? local
: local.name;
if (name_21) {
// do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables
var text = ts.unescapeIdentifier(name_21.text);
if (ts.hasProperty(seen, text)) {
continue;
}
else {
seen[text] = text;
}
}
if (i !== 0) { if (i !== 0) {
write(", "); write(", ");
} }
if (local.kind === 202 /* ClassDeclaration */ || local.kind === 206 /* ModuleDeclaration */) { if (local.kind === 202 /* ClassDeclaration */ || local.kind === 206 /* ModuleDeclaration */ || local.kind === 205 /* EnumDeclaration */) {
emitDeclarationName(local); emitDeclarationName(local);
} }
else { else {
@ -28744,6 +28816,9 @@ var ts;
} }
return exportedDeclarations; return exportedDeclarations;
function visit(node) { function visit(node) {
if (node.flags & 2 /* Ambient */) {
return;
}
if (node.kind === 201 /* FunctionDeclaration */) { if (node.kind === 201 /* FunctionDeclaration */) {
if (!hoistedFunctionDeclarations) { if (!hoistedFunctionDeclarations) {
hoistedFunctionDeclarations = []; hoistedFunctionDeclarations = [];
@ -28752,31 +28827,41 @@ var ts;
return; return;
} }
if (node.kind === 202 /* ClassDeclaration */) { if (node.kind === 202 /* ClassDeclaration */) {
// TODO: rename block scoped classes
if (!hoistedVars) { if (!hoistedVars) {
hoistedVars = []; hoistedVars = [];
} }
hoistedVars.push(node); hoistedVars.push(node);
return; return;
} }
if (node.kind === 206 /* ModuleDeclaration */ && shouldEmitModuleDeclaration(node)) { if (node.kind === 205 /* EnumDeclaration */) {
if (shouldEmitEnumDeclaration(node)) {
if (!hoistedVars) { if (!hoistedVars) {
hoistedVars = []; hoistedVars = [];
} }
hoistedVars.push(node); hoistedVars.push(node);
}
return;
}
if (node.kind === 206 /* ModuleDeclaration */) {
if (shouldEmitModuleDeclaration(node)) {
if (!hoistedVars) {
hoistedVars = [];
}
hoistedVars.push(node);
}
return; return;
} }
if (node.kind === 199 /* VariableDeclaration */ || node.kind === 153 /* BindingElement */) { if (node.kind === 199 /* VariableDeclaration */ || node.kind === 153 /* BindingElement */) {
if (shouldHoistVariable(node, false)) { if (shouldHoistVariable(node, false)) {
var name_21 = node.name; var name_22 = node.name;
if (name_21.kind === 65 /* Identifier */) { if (name_22.kind === 65 /* Identifier */) {
if (!hoistedVars) { if (!hoistedVars) {
hoistedVars = []; hoistedVars = [];
} }
hoistedVars.push(name_21); hoistedVars.push(name_22);
} }
else { else {
ts.forEachChild(name_21, visit); ts.forEachChild(name_22, visit);
} }
} }
return; return;
@ -29755,14 +29840,19 @@ var ts;
// Create the emit resolver outside of the "emitTime" tracking code below. That way // Create the emit resolver outside of the "emitTime" tracking code below. That way
// any cost associated with it (like type checking) are appropriate associated with // any cost associated with it (like type checking) are appropriate associated with
// the type-checking counter. // the type-checking counter.
var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); //
// If the -out option is specified, we should not pass the source file to getEmitResolver.
// This is because in the -out scenario all files need to be emitted, and therefore all
// files need to be type checked. And the way to specify that all files need to be type
// checked is to not pass the file to getEmitResolver.
var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile);
var start = new Date().getTime(); var start = new Date().getTime();
var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile); var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile);
ts.emitTime += new Date().getTime() - start; ts.emitTime += new Date().getTime() - start;
return emitResult; return emitResult;
} }
function getSourceFile(fileName) { function getSourceFile(fileName) {
fileName = host.getCanonicalFileName(fileName); fileName = host.getCanonicalFileName(ts.normalizeSlashes(fileName));
return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined;
} }
function getDiagnosticsHelper(sourceFile, getDiagnostics) { function getDiagnosticsHelper(sourceFile, getDiagnostics) {
@ -29819,43 +29909,50 @@ var ts;
function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) {
var start; var start;
var length; var length;
var extensions;
var diagnosticArgument;
if (refEnd !== undefined && refPos !== undefined) { if (refEnd !== undefined && refPos !== undefined) {
start = refPos; start = refPos;
length = refEnd - refPos; length = refEnd - refPos;
} }
var diagnostic; var diagnostic;
if (hasExtension(fileName)) { if (hasExtension(fileName)) {
if (!options.allowNonTsExtensions && !ts.fileExtensionIs(host.getCanonicalFileName(fileName), ".ts")) { if (!options.allowNonTsExtensions && !ts.forEach(ts.supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) {
diagnostic = ts.Diagnostics.File_0_must_have_extension_ts_or_d_ts; diagnostic = ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1;
diagnosticArgument = [fileName, "'" + ts.supportedExtensions.join("', '") + "'"];
} }
else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
diagnosticArgument = [fileName];
} }
else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) { else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) {
diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself; diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself;
diagnosticArgument = [fileName];
} }
} }
else { else {
if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
diagnosticArgument = [fileName];
} }
else if (!findSourceFile(fileName + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(fileName + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) { else if (!ts.forEach(ts.supportedExtensions, function (extension) { return findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd); })) {
diagnostic = ts.Diagnostics.File_0_not_found; diagnostic = ts.Diagnostics.File_0_not_found;
fileName += ".ts"; fileName += ".ts";
diagnosticArgument = [fileName];
} }
} }
if (diagnostic) { if (diagnostic) {
if (refFile) { if (refFile) {
diagnostics.add(ts.createFileDiagnostic(refFile, start, length, diagnostic, fileName)); diagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, start, length, diagnostic].concat(diagnosticArgument)));
} }
else { else {
diagnostics.add(ts.createCompilerDiagnostic(diagnostic, fileName)); diagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument)));
} }
} }
} }
// Get source file from normalized fileName // Get source file from normalized fileName
function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) { function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) {
var canonicalName = host.getCanonicalFileName(fileName); var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName));
if (ts.hasProperty(filesByName, canonicalName)) { if (ts.hasProperty(filesByName, canonicalName)) {
// We've already looked for this file, use cached result // We've already looked for this file, use cached result
return getSourceFileFromCache(fileName, canonicalName, false); return getSourceFileFromCache(fileName, canonicalName, false);
@ -29918,9 +30015,10 @@ var ts;
var moduleNameText = moduleNameExpr.text; var moduleNameText = moduleNameExpr.text;
if (moduleNameText) { if (moduleNameText) {
var searchPath = basePath; var searchPath = basePath;
var searchName;
while (true) { while (true) {
var searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleNameText)); searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleNameText));
if (findModuleSourceFile(searchName + ".ts", moduleNameExpr) || findModuleSourceFile(searchName + ".d.ts", moduleNameExpr)) { if (ts.forEach(ts.supportedExtensions, function (extension) { return findModuleSourceFile(searchName + extension, moduleNameExpr); })) {
break; break;
} }
var parentPath = ts.getDirectoryPath(searchPath); var parentPath = ts.getDirectoryPath(searchPath);
@ -29948,10 +30046,7 @@ var ts;
// An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules // An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules
// only through top - level external module names. Relative external module names are not permitted. // only through top - level external module names. Relative external module names are not permitted.
var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName)); var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName));
var tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral); ts.forEach(ts.supportedExtensions, function (extension) { return findModuleSourceFile(searchName + extension, nameLiteral); });
if (!tsFile) {
findModuleSourceFile(searchName + ".d.ts", nameLiteral);
}
} }
} }
}); });
@ -30046,10 +30141,10 @@ var ts;
if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
// Error to specify --mapRoot or --sourceRoot without mapSourceFiles // Error to specify --mapRoot or --sourceRoot without mapSourceFiles
if (options.mapRoot) { if (options.mapRoot) {
diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option)); diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option));
} }
if (options.sourceRoot) { if (options.sourceRoot) {
diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option)); diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option));
} }
return; return;
} }
@ -30197,7 +30292,7 @@ var ts;
{ {
name: "noEmitOnError", name: "noEmitOnError",
type: "boolean", type: "boolean",
description: ts.Diagnostics.Do_not_emit_outputs_if_any_type_checking_errors_were_reported description: ts.Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported
}, },
{ {
name: "noImplicitAny", name: "noImplicitAny",
@ -30684,12 +30779,12 @@ var ts;
ts.forEach(program.getSourceFiles(), function (sourceFile) { ts.forEach(program.getSourceFiles(), function (sourceFile) {
cancellationToken.throwIfCancellationRequested(); cancellationToken.throwIfCancellationRequested();
var nameToDeclarations = sourceFile.getNamedDeclarations(); var nameToDeclarations = sourceFile.getNamedDeclarations();
for (var name_22 in nameToDeclarations) { for (var name_23 in nameToDeclarations) {
var declarations = ts.getProperty(nameToDeclarations, name_22); var declarations = ts.getProperty(nameToDeclarations, name_23);
if (declarations) { if (declarations) {
// First do a quick check to see if the name of the declaration matches the // First do a quick check to see if the name of the declaration matches the
// last portion of the (possibly) dotted name they're searching for. // last portion of the (possibly) dotted name they're searching for.
var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_22); var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_23);
if (!matches) { if (!matches) {
continue; continue;
} }
@ -30702,14 +30797,14 @@ var ts;
if (!containers) { if (!containers) {
return undefined; return undefined;
} }
matches = patternMatcher.getMatches(containers, name_22); matches = patternMatcher.getMatches(containers, name_23);
if (!matches) { if (!matches) {
continue; continue;
} }
} }
var fileName = sourceFile.fileName; var fileName = sourceFile.fileName;
var matchKind = bestMatchKind(matches); var matchKind = bestMatchKind(matches);
rawItems.push({ name: name_22, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); rawItems.push({ name: name_23, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration });
} }
} }
} }
@ -31092,9 +31187,9 @@ var ts;
case 199 /* VariableDeclaration */: case 199 /* VariableDeclaration */:
case 153 /* BindingElement */: case 153 /* BindingElement */:
var variableDeclarationNode; var variableDeclarationNode;
var name_23; var name_24;
if (node.kind === 153 /* BindingElement */) { if (node.kind === 153 /* BindingElement */) {
name_23 = node.name; name_24 = node.name;
variableDeclarationNode = node; variableDeclarationNode = node;
// binding elements are added only for variable declarations // binding elements are added only for variable declarations
// bubble up to the containing variable declaration // bubble up to the containing variable declaration
@ -31106,16 +31201,16 @@ var ts;
else { else {
ts.Debug.assert(!ts.isBindingPattern(node.name)); ts.Debug.assert(!ts.isBindingPattern(node.name));
variableDeclarationNode = node; variableDeclarationNode = node;
name_23 = node.name; name_24 = node.name;
} }
if (ts.isConst(variableDeclarationNode)) { if (ts.isConst(variableDeclarationNode)) {
return createItem(node, getTextOfNode(name_23), ts.ScriptElementKind.constElement); return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.constElement);
} }
else if (ts.isLet(variableDeclarationNode)) { else if (ts.isLet(variableDeclarationNode)) {
return createItem(node, getTextOfNode(name_23), ts.ScriptElementKind.letElement); return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.letElement);
} }
else { else {
return createItem(node, getTextOfNode(name_23), ts.ScriptElementKind.variableElement); return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.variableElement);
} }
case 136 /* Constructor */: case 136 /* Constructor */:
return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement);
@ -33702,9 +33797,9 @@ var ts;
} }
Rules.prototype.getRuleName = function (rule) { Rules.prototype.getRuleName = function (rule) {
var o = this; var o = this;
for (var name_24 in o) { for (var name_25 in o) {
if (o[name_24] === rule) { if (o[name_25] === rule) {
return name_24; return name_25;
} }
} }
throw new Error("Unknown rule"); throw new Error("Unknown rule");
@ -37125,6 +37220,7 @@ var ts;
var syntaxTreeCache = new SyntaxTreeCache(host); var syntaxTreeCache = new SyntaxTreeCache(host);
var ruleProvider; var ruleProvider;
var program; var program;
var lastProjectVersion;
var useCaseSensitivefileNames = false; var useCaseSensitivefileNames = false;
var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken());
// Check if the localized messages json is set, otherwise query the host for it // Check if the localized messages json is set, otherwise query the host for it
@ -37156,6 +37252,16 @@ var ts;
return ruleProvider; return ruleProvider;
} }
function synchronizeHostData() { function synchronizeHostData() {
// perform fast check if host supports it
if (host.getProjectVersion) {
var hostProjectVersion = host.getProjectVersion();
if (hostProjectVersion) {
if (lastProjectVersion === hostProjectVersion) {
return;
}
lastProjectVersion = hostProjectVersion;
}
}
// Get a fresh cache of the host information // Get a fresh cache of the host information
var hostCache = new HostCache(host, getCanonicalFileName); var hostCache = new HostCache(host, getCanonicalFileName);
// If the program is already up-to-date, we can reuse it // If the program is already up-to-date, we can reuse it
@ -37712,12 +37818,14 @@ var ts;
|| containingNodeKind === 136 /* Constructor */ // constructor( a, | public, protected, private keywords are allowed here, so show completion || containingNodeKind === 136 /* Constructor */ // constructor( a, | public, protected, private keywords are allowed here, so show completion
|| containingNodeKind === 159 /* NewExpression */ // new C(a, | || containingNodeKind === 159 /* NewExpression */ // new C(a, |
|| containingNodeKind === 154 /* ArrayLiteralExpression */ // [a, | || containingNodeKind === 154 /* ArrayLiteralExpression */ // [a, |
|| containingNodeKind === 170 /* BinaryExpression */; // let x = (a, | || containingNodeKind === 170 /* BinaryExpression */ // let x = (a, |
|| containingNodeKind === 143 /* FunctionType */; // var x: (s: string, list|
case 16 /* OpenParenToken */: case 16 /* OpenParenToken */:
return containingNodeKind === 158 /* CallExpression */ // func( | return containingNodeKind === 158 /* CallExpression */ // func( |
|| containingNodeKind === 136 /* Constructor */ // constructor( | || containingNodeKind === 136 /* Constructor */ // constructor( |
|| containingNodeKind === 159 /* NewExpression */ // new C(a| || containingNodeKind === 159 /* NewExpression */ // new C(a|
|| containingNodeKind === 162 /* ParenthesizedExpression */; // let x = (a| || containingNodeKind === 162 /* ParenthesizedExpression */ // let x = (a|
|| containingNodeKind === 150 /* ParenthesizedType */; // function F(pred: (a| this can become an arrow function, where 'a' is the argument
case 18 /* OpenBracketToken */: case 18 /* OpenBracketToken */:
return containingNodeKind === 154 /* ArrayLiteralExpression */; // [ | return containingNodeKind === 154 /* ArrayLiteralExpression */; // [ |
case 117 /* ModuleKeyword */: // module | case 117 /* ModuleKeyword */: // module |
@ -37814,6 +37922,8 @@ var ts;
containingNodeKind === 151 /* ObjectBindingPattern */; // function func({ x, y| containingNodeKind === 151 /* ObjectBindingPattern */; // function func({ x, y|
case 20 /* DotToken */: case 20 /* DotToken */:
return containingNodeKind === 152 /* ArrayBindingPattern */; // var [.| return containingNodeKind === 152 /* ArrayBindingPattern */; // var [.|
case 51 /* ColonToken */:
return containingNodeKind === 153 /* BindingElement */; // var {x :html|
case 18 /* OpenBracketToken */: case 18 /* OpenBracketToken */:
return containingNodeKind === 152 /* ArrayBindingPattern */; // var [x| return containingNodeKind === 152 /* ArrayBindingPattern */; // var [x|
case 16 /* OpenParenToken */: case 16 /* OpenParenToken */:
@ -37856,6 +37966,7 @@ var ts;
case 104 /* LetKeyword */: case 104 /* LetKeyword */:
case 70 /* ConstKeyword */: case 70 /* ConstKeyword */:
case 110 /* YieldKeyword */: case 110 /* YieldKeyword */:
case 124 /* TypeKeyword */:
return true; return true;
} }
// Previous token may have been a keyword that was converted to an identifier. // Previous token may have been a keyword that was converted to an identifier.
@ -37954,10 +38065,10 @@ var ts;
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var sourceFile = _a[_i]; var sourceFile = _a[_i];
var nameTable = getNameTable(sourceFile); var nameTable = getNameTable(sourceFile);
for (var name_25 in nameTable) { for (var name_26 in nameTable) {
if (!allNames[name_25]) { if (!allNames[name_26]) {
allNames[name_25] = name_25; allNames[name_26] = name_26;
var displayName = getCompletionEntryDisplayName(name_25, target, true); var displayName = getCompletionEntryDisplayName(name_26, target, true);
if (displayName) { if (displayName) {
var entry = { var entry = {
name: displayName, name: displayName,
@ -39839,19 +39950,19 @@ var ts;
if (isNameOfPropertyAssignment(node)) { if (isNameOfPropertyAssignment(node)) {
var objectLiteral = node.parent.parent; var objectLiteral = node.parent.parent;
var contextualType = typeChecker.getContextualType(objectLiteral); var contextualType = typeChecker.getContextualType(objectLiteral);
var name_26 = node.text; var name_27 = node.text;
if (contextualType) { if (contextualType) {
if (contextualType.flags & 16384 /* Union */) { if (contextualType.flags & 16384 /* Union */) {
// This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types)
// if not, search the constituent types for the property // if not, search the constituent types for the property
var unionProperty = contextualType.getProperty(name_26); var unionProperty = contextualType.getProperty(name_27);
if (unionProperty) { if (unionProperty) {
return [unionProperty]; return [unionProperty];
} }
else { else {
var result_4 = []; var result_4 = [];
ts.forEach(contextualType.types, function (t) { ts.forEach(contextualType.types, function (t) {
var symbol = t.getProperty(name_26); var symbol = t.getProperty(name_27);
if (symbol) { if (symbol) {
result_4.push(symbol); result_4.push(symbol);
} }
@ -39860,7 +39971,7 @@ var ts;
} }
} }
else { else {
var symbol_1 = contextualType.getProperty(name_26); var symbol_1 = contextualType.getProperty(name_27);
if (symbol_1) { if (symbol_1) {
return [symbol_1]; return [symbol_1];
} }
@ -40280,10 +40391,12 @@ var ts;
var kind = triviaScanner.scan(); var kind = triviaScanner.scan();
var end = triviaScanner.getTextPos(); var end = triviaScanner.getTextPos();
var width = end - start; var width = end - start;
if (ts.textSpanIntersectsWith(span, start, width)) { // The moment we get something that isn't trivia, then stop processing.
if (!ts.isTrivia(kind)) { if (!ts.isTrivia(kind)) {
return; return;
} }
// Only bother with the trivia if it at least intersects the span of interest.
if (ts.textSpanIntersectsWith(span, start, width)) {
if (ts.isComment(kind)) { if (ts.isComment(kind)) {
// Simple comment. Just add as is. // Simple comment. Just add as is.
pushClassification(start, width, 1 /* comment */); pushClassification(start, width, 1 /* comment */);
@ -41726,6 +41839,13 @@ var ts;
LanguageServiceShimHostAdapter.prototype.error = function (s) { LanguageServiceShimHostAdapter.prototype.error = function (s) {
this.shimHost.error(s); this.shimHost.error(s);
}; };
LanguageServiceShimHostAdapter.prototype.getProjectVersion = function () {
if (!this.shimHost.getProjectVersion) {
// shimmed host does not support getProjectVersion
return undefined;
}
return this.shimHost.getProjectVersion();
};
LanguageServiceShimHostAdapter.prototype.getCompilationSettings = function () { LanguageServiceShimHostAdapter.prototype.getCompilationSettings = function () {
var settingsJson = this.shimHost.getCompilationSettings(); var settingsJson = this.shimHost.getCompilationSettings();
if (settingsJson == null || settingsJson == "") { if (settingsJson == null || settingsJson == "") {
@ -42238,7 +42358,7 @@ var ts;
return { return {
options: configFile.options, options: configFile.options,
files: configFile.fileNames, files: configFile.fileNames,
errors: [realizeDiagnostics(configFile.errors, '\r\n')] errors: realizeDiagnostics(configFile.errors, '\r\n')
}; };
}); });
}; };