Merge branch 'master' into supportedExtensions

This commit is contained in:
Mohamed Hegazy
2015-05-07 11:28:15 -07:00
78 changed files with 2624 additions and 6649 deletions

View File

@@ -88,12 +88,11 @@ module ts {
let undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined");
let nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefinedOrNull, "null");
let unknownType = createIntrinsicType(TypeFlags.Any, "unknown");
let resolvingType = createIntrinsicType(TypeFlags.Any, "__resolving__");
let emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
let anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
let noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
let anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false);
let unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false);
@@ -118,7 +117,7 @@ module ts {
let getGlobalParameterDecoratorType: () => ObjectType;
let getGlobalPropertyDecoratorType: () => ObjectType;
let getGlobalMethodDecoratorType: () => ObjectType;
let tupleTypes: Map<TupleType> = {};
let unionTypes: Map<UnionType> = {};
let stringLiteralTypes: Map<StringLiteralType> = {};
@@ -126,6 +125,9 @@ module ts {
let emitDecorate = false;
let emitParam = false;
let resolutionTargets: Object[] = [];
let resolutionResults: boolean[] = [];
let mergedSymbols: Symbol[] = [];
let symbolLinks: SymbolLinks[] = [];
let nodeLinks: NodeLinks[] = [];
@@ -350,9 +352,9 @@ module ts {
}
else if (location.kind === SyntaxKind.SourceFile ||
(location.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>location).name.kind === SyntaxKind.StringLiteral)) {
result = getSymbol(getSymbolOfNode(location).exports, "default", meaning & SymbolFlags.ModuleMember);
result = getSymbolOfNode(location).exports["default"];
let localSymbol = getLocalSymbolForExportDefault(result);
if (result && (result.flags & meaning) && localSymbol && localSymbol.name === name) {
if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) {
break loop;
}
result = undefined;
@@ -801,7 +803,9 @@ module ts {
let symbol: Symbol;
if (name.kind === SyntaxKind.Identifier) {
symbol = resolveName(name, (<Identifier>name).text, meaning, Diagnostics.Cannot_find_name_0, <Identifier>name);
let message = meaning === SymbolFlags.Namespace ? Diagnostics.Cannot_find_namespace_0 : Diagnostics.Cannot_find_name_0;
symbol = resolveName(name, (<Identifier>name).text, meaning, message, <Identifier>name);
if (!symbol) {
return undefined;
}
@@ -1981,7 +1985,7 @@ module ts {
}
}
function collectLinkedAliases(node: Identifier): Node[]{
function collectLinkedAliases(node: Identifier): Node[] {
var exportSymbol: Symbol;
if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) {
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node);
@@ -2015,6 +2019,38 @@ module ts {
}
}
// Push an entry on the type resolution stack. If an entry with the given target is not already on the stack,
// a new entry with that target and an associated result value of true is pushed on the stack, and the value
// true is returned. Otherwise, a circularity has occurred and the result values of the existing entry and
// all entries pushed after it are changed to false, and the value false is returned. The target object provides
// a unique identity for a particular type resolution result: Symbol instances are used to track resolution of
// SymbolLinks.type, SymbolLinks instances are used to track resolution of SymbolLinks.declaredType, and
// Signature instances are used to track resolution of Signature.resolvedReturnType.
function pushTypeResolution(target: Object): boolean {
let i = 0;
let count = resolutionTargets.length;
while (i < count && resolutionTargets[i] !== target) {
i++;
}
if (i < count) {
do {
resolutionResults[i++] = false;
}
while (i < count);
return false;
}
resolutionTargets.push(target);
resolutionResults.push(true);
return true;
}
// Pop an entry from the type resolution stack and return its associated result value. The result value will
// be true if no circularities were detected, or false if a circularity was found.
function popTypeResolution(): boolean {
resolutionTargets.pop();
return resolutionResults.pop();
}
function getRootDeclaration(node: Node): Node {
while (node.kind === SyntaxKind.BindingElement) {
node = node.parent.parent;
@@ -2272,20 +2308,27 @@ module ts {
return links.type = checkExpression((<ExportAssignment>declaration).expression);
}
// Handle variable, parameter or property
links.type = resolvingType;
if (!pushTypeResolution(symbol)) {
return unknownType;
}
let type = getWidenedTypeForVariableLikeDeclaration(<VariableLikeDeclaration>declaration, /*reportErrors*/ true);
if (links.type === resolvingType) {
links.type = type;
}
}
else if (links.type === resolvingType) {
links.type = anyType;
if (compilerOptions.noImplicitAny) {
let diagnostic = (<VariableLikeDeclaration>symbol.valueDeclaration).type ?
Diagnostics._0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation :
Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer;
error(symbol.valueDeclaration, diagnostic, symbolToString(symbol));
if (!popTypeResolution()) {
if ((<VariableLikeDeclaration>symbol.valueDeclaration).type) {
// Variable has type annotation that circularly references the variable itself
type = unknownType;
error(symbol.valueDeclaration, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation,
symbolToString(symbol));
}
else {
// Variable has initializer that circularly references the variable itself
type = anyType;
if (compilerOptions.noImplicitAny) {
error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer,
symbolToString(symbol));
}
}
}
links.type = type;
}
return links.type;
}
@@ -2309,19 +2352,13 @@ module ts {
function getTypeOfAccessors(symbol: Symbol): Type {
let links = getSymbolLinks(symbol);
checkAndStoreTypeOfAccessors(symbol, links);
return links.type;
}
function checkAndStoreTypeOfAccessors(symbol: Symbol, links?: SymbolLinks) {
links = links || getSymbolLinks(symbol);
if (!links.type) {
links.type = resolvingType;
if (!pushTypeResolution(symbol)) {
return unknownType;
}
let getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
let setter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.SetAccessor);
let type: Type;
// First try to see if the user specified a return type on the get-accessor.
let getterReturnType = getAnnotatedAccessorType(getter);
if (getterReturnType) {
@@ -2343,23 +2380,20 @@ module ts {
if (compilerOptions.noImplicitAny) {
error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbolToString(symbol));
}
type = anyType;
}
}
}
if (links.type === resolvingType) {
links.type = type;
}
}
else if (links.type === resolvingType) {
links.type = anyType;
if (compilerOptions.noImplicitAny) {
let getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
error(getter, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol));
if (!popTypeResolution()) {
type = anyType;
if (compilerOptions.noImplicitAny) {
let getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
error(getter, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol));
}
}
links.type = type;
}
return links.type;
}
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
@@ -2452,7 +2486,7 @@ module ts {
return result;
}
function getBaseTypes(type: InterfaceType): ObjectType[]{
function getBaseTypes(type: InterfaceType): ObjectType[] {
let typeWithBaseTypes = <InterfaceTypeWithBaseTypes>type;
if (!typeWithBaseTypes.baseTypes) {
if (type.symbol.flags & SymbolFlags.Class) {
@@ -2537,17 +2571,18 @@ module ts {
function getDeclaredTypeOfTypeAlias(symbol: Symbol): Type {
let links = getSymbolLinks(symbol);
if (!links.declaredType) {
links.declaredType = resolvingType;
// Note that we use the links object as the target here because the symbol object is used as the unique
// identity for resolution of the 'type' property in SymbolLinks.
if (!pushTypeResolution(links)) {
return unknownType;
}
let declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
let type = getTypeFromTypeNode(declaration.type);
if (links.declaredType === resolvingType) {
links.declaredType = type;
if (!popTypeResolution()) {
type = unknownType;
error(declaration.name, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
}
}
else if (links.declaredType === resolvingType) {
links.declaredType = unknownType;
let declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
error(declaration.name, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
links.declaredType = type;
}
return links.declaredType;
}
@@ -3151,7 +3186,9 @@ module ts {
function getReturnTypeOfSignature(signature: Signature): Type {
if (!signature.resolvedReturnType) {
signature.resolvedReturnType = resolvingType;
if (!pushTypeResolution(signature)) {
return unknownType;
}
let type: Type;
if (signature.target) {
type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper);
@@ -3162,21 +3199,19 @@ module ts {
else {
type = getReturnTypeFromBody(<FunctionLikeDeclaration>signature.declaration);
}
if (signature.resolvedReturnType === resolvingType) {
signature.resolvedReturnType = type;
}
}
else if (signature.resolvedReturnType === resolvingType) {
signature.resolvedReturnType = anyType;
if (compilerOptions.noImplicitAny) {
let declaration = <Declaration>signature.declaration;
if (declaration.name) {
error(declaration.name, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, declarationNameToString(declaration.name));
}
else {
error(declaration, Diagnostics.Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions);
if (!popTypeResolution()) {
type = anyType;
if (compilerOptions.noImplicitAny) {
let declaration = <Declaration>signature.declaration;
if (declaration.name) {
error(declaration.name, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, declarationNameToString(declaration.name));
}
else {
error(declaration, Diagnostics.Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions);
}
}
}
signature.resolvedReturnType = type;
}
return signature.resolvedReturnType;
}
@@ -5352,17 +5387,35 @@ module ts {
}
// Target type is type of prototype property
let prototypeProperty = getPropertyOfType(rightType, "prototype");
if (!prototypeProperty) {
return type;
if (prototypeProperty) {
let targetType = getTypeOfSymbol(prototypeProperty);
if (targetType !== anyType) {
// 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 & TypeFlags.Union) {
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, targetType)));
}
}
}
let targetType = getTypeOfSymbol(prototypeProperty);
// Narrow to target type if it is a subtype of current type
if (isTypeSubtypeOf(targetType, type)) {
return targetType;
// Target type is type of construct signature
let constructSignatures: Signature[];
if (rightType.flags & TypeFlags.Interface) {
constructSignatures = resolveDeclaredMembers(<InterfaceType>rightType).declaredConstructSignatures;
}
// If current type is a union type, remove all constituents that aren't subtypes of target type
if (type.flags & TypeFlags.Union) {
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, targetType)));
else if (rightType.flags & TypeFlags.Anonymous) {
constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct);
}
if (constructSignatures && constructSignatures.length !== 0) {
let instanceType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature))));
// Pickup type from union types
if (type.flags & TypeFlags.Union) {
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, instanceType)));
}
return instanceType;
}
return type;
}
@@ -7343,10 +7396,9 @@ module ts {
if (isContextSensitive(node)) {
assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper);
}
if (!node.type) {
signature.resolvedReturnType = resolvingType;
if (!node.type && !signature.resolvedReturnType) {
let returnType = getReturnTypeFromBody(node, contextualMapper);
if (signature.resolvedReturnType === resolvingType) {
if (!signature.resolvedReturnType) {
signature.resolvedReturnType = returnType;
}
}
@@ -8360,8 +8412,7 @@ module ts {
}
}
}
checkAndStoreTypeOfAccessors(getSymbolOfNode(node));
getTypeOfAccessors(getSymbolOfNode(node));
}
checkFunctionLikeDeclaration(node);

View File

@@ -363,6 +363,8 @@ module ts {
An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2499, category: DiagnosticCategory.Error, key: "An interface can only extend an identifier/qualified-name with optional type arguments." },
A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2500, category: DiagnosticCategory.Error, key: "A class can only implement an identifier/qualified-name with optional type arguments." },
A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." },
_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." },
Cannot_find_namespace_0: { code: 2503, category: DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
@@ -517,7 +519,6 @@ module ts {
Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." },
Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." },
Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." },
_0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 7021, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation." },
_0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." },
_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },

View File

@@ -1440,6 +1440,14 @@
"category": "Error",
"code": 2501
},
"'{0}' is referenced directly or indirectly in its own type annotation.": {
"category": "Error",
"code": 2502
},
"Cannot find namespace '{0}'.": {
"category": "Error",
"code": 2503
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
@@ -2060,10 +2068,6 @@
"category": "Error",
"code": 7020
},
"'{0}' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.": {
"category": "Error",
"code": 7021
},
"'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.": {
"category": "Error",
"code": 7022

File diff suppressed because it is too large Load Diff

View File

@@ -3898,6 +3898,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
scopeEmitEnd();
// TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now.
// For a decorated class, we need to assign its name (if it has one). This is because we emit
// the class as a class expression to avoid the double-binding of the identifier:
//
@@ -3907,15 +3909,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
//
if (thisNodeIsDecorated) {
write(";");
if (node.name) {
writeLine();
write("Object.defineProperty(");
emitDeclarationName(node);
write(", \"name\", { value: \"");
emitDeclarationName(node);
write("\", configurable: true });");
writeLine();
}
}
// Emit static property assignment. Because classDeclaration is lexically evaluated,

View File

@@ -1695,7 +1695,7 @@ module ts {
}
export function getLocalSymbolForExportDefault(symbol: Symbol) {
return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & NodeFlags.Default) ? symbol.valueDeclaration.localSymbol : undefined;
return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & NodeFlags.Default) ? symbol.valueDeclaration.localSymbol : undefined;
}
/**

View File

@@ -45,10 +45,10 @@ module Utils {
export function getExecutionEnvironment() {
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
return ExecutionEnvironment.CScript;
} else if (process && process.execPath && process.execPath.indexOf("node") !== -1) {
return ExecutionEnvironment.Node;
} else {
} else if (typeof window !== "undefined") {
return ExecutionEnvironment.Browser;
} else {
return ExecutionEnvironment.Node;
}
}
@@ -1610,7 +1610,6 @@ module Harness {
export module Baseline {
export interface BaselineOptions {
LineEndingSensitive?: boolean;
Subfolder?: string;
Baselinefolder?: string;
}
@@ -1702,13 +1701,6 @@ module Harness {
expected = IO.readFile(refFileName);
}
var lineEndingSensitive = opts && opts.LineEndingSensitive;
if (!lineEndingSensitive) {
expected = expected.replace(/\r\n?/g, '\n');
actual = actual.replace(/\r\n?/g, '\n');
}
return { expected, actual };
}

View File

@@ -12180,6 +12180,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
overrideMimeType(mime: string): void;
send(data?: Document): void;
send(data?: string): void;
send(data?: any): void;
setRequestHeader(header: string, value: string): void;
DONE: number;
HEADERS_RECEIVED: number;

2
src/lib/es6.d.ts vendored
View File

@@ -3580,6 +3580,7 @@ interface PromiseLike<T> {
* @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) => void): PromiseLike<TResult>;
}
/**
@@ -3593,6 +3594,7 @@ interface Promise<T> {
* @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) => void): Promise<TResult>;
/**
* Attaches a callback for only the rejection of the Promise.

View File

@@ -398,7 +398,7 @@ module ts.server {
export class ProjectService {
filenameToScriptInfo: ts.Map<ScriptInfo> = {};
// open, non-configured root files
// open, non-configured root files
openFileRoots: ScriptInfo[] = [];
// projects built from openFileRoots
inferredProjects: Project[] = [];
@@ -421,7 +421,7 @@ module ts.server {
hostInfo: "Unknown host"
}
}
getFormatCodeOptions(file?: string) {
if (file) {
var info = this.filenameToScriptInfo[file];
@@ -448,7 +448,7 @@ module ts.server {
}
}
}
log(msg: string, type = "Err") {
this.psLogger.msg(msg, type);
}
@@ -457,17 +457,17 @@ module ts.server {
if (args.file) {
var info = this.filenameToScriptInfo[args.file];
if (info) {
info.setFormatOptions(args.formatOptions);
info.setFormatOptions(args.formatOptions);
this.log("Host configuration update for file " + args.file, "Info");
}
}
else {
if (args.hostInfo !== undefined) {
this.hostConfiguration.hostInfo = args.hostInfo;
this.log("Host information " + args.hostInfo, "Info");
this.log("Host information " + args.hostInfo, "Info");
}
if (args.formatOptions) {
mergeFormatOptions(this.hostConfiguration.formatCodeOptions, args.formatOptions);
mergeFormatOptions(this.hostConfiguration.formatCodeOptions, args.formatOptions);
this.log("Format host information updated", "Info");
}
}
@@ -487,7 +487,7 @@ module ts.server {
fileDeletedInFilesystem(info: ScriptInfo) {
this.psLogger.info(info.fileName + " deleted");
if (info.fileWatcher) {
info.fileWatcher.close();
info.fileWatcher = undefined;
@@ -537,7 +537,7 @@ module ts.server {
}
return false;
}
addOpenFile(info: ScriptInfo) {
if (this.setConfiguredProjectRoot(info)) {
this.openFileRootsConfigured.push(info);
@@ -561,7 +561,7 @@ module ts.server {
copyListRemovingItem(r.defaultProject, this.inferredProjects);
// put r in referenced open file list
this.openFilesReferenced.push(r);
// set default project of r to the new project
// set default project of r to the new project
r.defaultProject = info.defaultProject;
}
else {
@@ -694,7 +694,7 @@ module ts.server {
this.openFilesReferenced = openFilesReferenced;
// Then, loop through all of the open files that are project roots.
// For each root file, note the project that it roots. Then see if
// For each root file, note the project that it roots. Then see if
// any other projects newly reference the file. If zero projects
// newly reference the file, keep it as a root. If one or more
// projects newly references the file, remove its project from the
@@ -719,7 +719,7 @@ module ts.server {
// Finally, if we found any open, referenced files that are no longer
// referenced by their default project, treat them as newly opened
// by the editor.
// by the editor.
for (var i = 0, len = unattachedOpenFiles.length; i < len; i++) {
this.addOpenFile(unattachedOpenFiles[i]);
}
@@ -809,7 +809,7 @@ module ts.server {
}
else {
this.log("Opened configuration file " + configFileName,"Info");
this.configuredProjects.push(configResult.project);
this.configuredProjects.push(configResult.project);
}
}
var info = this.openFile(fileName, true);
@@ -901,22 +901,22 @@ module ts.server {
}
return false;
}
openConfigFile(configFilename: string, clientFileName?: string): ProjectOpenResult {
configFilename = ts.normalizePath(configFilename);
// file references will be relative to dirPath (or absolute)
var dirPath = ts.getDirectoryPath(configFilename);
var rawConfig = <ProjectOptions>ts.readConfigFile(configFilename);
if (!rawConfig) {
return { errorMsg: "tsconfig syntax error" };
var rawConfig: { config?: ProjectOptions; error?: Diagnostic; } = ts.readConfigFile(configFilename);
if (rawConfig.error) {
return rawConfig.error;
}
else {
var parsedCommandLine = ts.parseConfigFile(rawConfig, ts.sys, dirPath);
var parsedCommandLine = ts.parseConfigFile(rawConfig.config, ts.sys, dirPath);
if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) {
return { errorMsg: "tsconfig option errors" };
}
else if (parsedCommandLine.fileNames) {
var projectOptions: ProjectOptions = {
var projectOptions: ProjectOptions = {
files: parsedCommandLine.fileNames,
compilerOptions: parsedCommandLine.options
};
@@ -1040,7 +1040,7 @@ module ts.server {
startPath: LineCollection[];
endBranch: LineCollection[] = [];
branchNode: LineNode;
// path to current node
// path to current node
stack: LineNode[];
state = CharRangeSection.Entire;
lineCollectionAtBranch: LineCollection;
@@ -1242,7 +1242,7 @@ module ts.server {
}
}
// text change information
// text change information
class TextChange {
constructor(public pos: number, public deleteLen: number, public insertedText?: string) {
}
@@ -1290,7 +1290,7 @@ module ts.server {
if (cb)
cb();
}
// reload whole script, leaving no change history behind reload
reload(script: string) {
this.currentVersion++;
@@ -1300,7 +1300,7 @@ module ts.server {
snap.index = new LineIndex();
var lm = LineIndex.linesFromText(script);
snap.index.load(lm.lines);
// REVIEW: could use linked list
// REVIEW: could use linked list
for (var i = this.minVersion; i < this.currentVersion; i++) {
this.versions[i] = undefined;
}
@@ -1381,7 +1381,7 @@ module ts.server {
return this.index.root.charCount();
}
// this requires linear space so don't hold on to these
// this requires linear space so don't hold on to these
getLineStartPositions(): number[] {
var starts: number[] = [-1];
var count = 1;
@@ -1643,7 +1643,7 @@ module ts.server {
}
walk(rangeStart: number, rangeLength: number, walkFns: ILineIndexWalker) {
// assume (rangeStart < this.totalChars) && (rangeLength <= this.totalChars)
// assume (rangeStart < this.totalChars) && (rangeLength <= this.totalChars)
var childIndex = 0;
var child = this.children[0];
var childCharCount = child.charCount();
@@ -1729,7 +1729,7 @@ module ts.server {
line: lineNumber,
offset: charOffset
}
}
}
else if (childInfo.child.isLeaf()) {
return {
line: lineNumber,
@@ -1917,4 +1917,4 @@ module ts.server {
return 1;
}
}
}
}

View File

@@ -1632,7 +1632,7 @@ module ts {
private fileNameToEntry: Map<HostFileInformation>;
private _compilationSettings: CompilerOptions;
constructor(private host: LanguageServiceHost) {
constructor(private host: LanguageServiceHost, private getCanonicalFileName: (fileName: string) => string) {
// script id => script index
this.fileNameToEntry = {};
@@ -1650,6 +1650,10 @@ module ts {
return this._compilationSettings;
}
private normalizeFileName(fileName: string): string {
return this.getCanonicalFileName(normalizeSlashes(fileName));
}
private createEntry(fileName: string) {
let entry: HostFileInformation;
let scriptSnapshot = this.host.getScriptSnapshot(fileName);
@@ -1661,15 +1665,15 @@ module ts {
};
}
return this.fileNameToEntry[normalizeSlashes(fileName)] = entry;
return this.fileNameToEntry[this.normalizeFileName(fileName)] = entry;
}
public getEntry(fileName: string): HostFileInformation {
return lookUp(this.fileNameToEntry, normalizeSlashes(fileName));
private getEntry(fileName: string): HostFileInformation {
return lookUp(this.fileNameToEntry, this.normalizeFileName(fileName));
}
public contains(fileName: string): boolean {
return hasProperty(this.fileNameToEntry, normalizeSlashes(fileName));
private contains(fileName: string): boolean {
return hasProperty(this.fileNameToEntry, this.normalizeFileName(fileName));
}
public getOrCreateEntry(fileName: string): HostFileInformation {
@@ -1684,8 +1688,10 @@ module ts {
let fileNames: string[] = [];
forEachKey(this.fileNameToEntry, key => {
if (hasProperty(this.fileNameToEntry, key) && this.fileNameToEntry[key])
fileNames.push(key);
let entry = this.getEntry(key);
if (entry) {
fileNames.push(entry.hostFileName);
}
});
return fileNames;
@@ -2387,7 +2393,7 @@ module ts {
function synchronizeHostData(): void {
// Get a fresh cache of the host information
let hostCache = new HostCache(host);
let hostCache = new HostCache(host, getCanonicalFileName);
// If the program is already up-to-date, we can reuse it
if (programUpToDate()) {
@@ -2408,7 +2414,7 @@ module ts {
let newProgram = createProgram(hostCache.getRootFileNames(), newSettings, {
getSourceFile: getOrCreateSourceFile,
getCancellationToken: () => cancellationToken,
getCanonicalFileName: (fileName) => useCaseSensitivefileNames ? fileName : fileName.toLowerCase(),
getCanonicalFileName,
useCaseSensitiveFileNames: () => useCaseSensitivefileNames,
getNewLine: () => host.getNewLine ? host.getNewLine() : "\r\n",
getDefaultLibFileName: (options) => host.getDefaultLibFileName(options),

View File

@@ -1,6 +1,6 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
@@ -83,7 +83,7 @@ module ts {
export interface Shim {
dispose(dummy: any): void;
}
export interface LanguageServiceShim extends Shim {
languageService: LanguageService;
@@ -145,7 +145,7 @@ module ts {
* { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[]
*/
getReferencesAtPosition(fileName: string, position: number): string;
/**
* Returns a JSON-encoded value of the type:
* { definition: <encoded>; references: <encoded>[] }[]
@@ -162,8 +162,8 @@ module ts {
/**
* Returns a JSON-encoded value of the type:
* { fileName: string; highlights: { start: number; length: number, isDefinition: boolean }[] }[]
*
* @param fileToSearch A JSON encoded string[] containing the file names that should be
*
* @param fileToSearch A JSON encoded string[] containing the file names that should be
* considered when searching.
*/
getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string;
@@ -244,7 +244,7 @@ module ts {
export class LanguageServiceShimHostAdapter implements LanguageServiceHost {
private files: string[];
constructor(private shimHost: LanguageServiceShimHost) {
}
@@ -255,7 +255,7 @@ module ts {
public trace(s: string): void {
this.shimHost.trace(s);
}
public error(s: string): void {
this.shimHost.error(s);
}
@@ -322,7 +322,7 @@ module ts {
}
}
}
export class CoreServicesShimHostAdapter implements ParseConfigHost {
constructor(private shimHost: CoreServicesShimHost) {
@@ -587,7 +587,7 @@ module ts {
/**
* Computes the definition location and file for the symbol
* at the requested position.
* at the requested position.
*/
public getDefinitionAtPosition(fileName: string, position: number): string {
return this.forwardJSONCall(
@@ -601,7 +601,7 @@ module ts {
/**
* Computes the definition location of the type of the symbol
* at the requested position.
* at the requested position.
*/
public getTypeDefinitionAtPosition(fileName: string, position: number): string {
return this.forwardJSONCall(
@@ -684,8 +684,8 @@ module ts {
/// COMPLETION LISTS
/**
* Get a string based representation of the completions
* to provide at the given source position and providing a member completion
* Get a string based representation of the completions
* to provide at the given source position and providing a member completion
* list if requested.
*/
public getCompletionsAtPosition(fileName: string, position: number) {
@@ -883,7 +883,7 @@ module ts {
return {
options: configFile.options,
files: configFile.fileNames,
errors: realizeDiagnostics(configFile.errors, '\r\n')
errors: [realizeDiagnostics(configFile.errors, '\r\n')]
};
});
}