Merge branch 'master' into addUndefinedCheckToCollectLinkedAliases · linuxcodefire/TypeScript@319faab · GitHub
Skip to content

Commit 319faab

Browse files
committed
Merge branch 'master' into addUndefinedCheckToCollectLinkedAliases
2 parents 2eb73a0 + efc573f commit 319faab

67 files changed

Lines changed: 1341 additions & 89 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 42 additions & 0 deletions

Jakefile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ function getLinterOptions() {
893893

894894
function lintFileContents(options, path, contents) {
895895
var ll = new Linter(path, contents, options);
896+
console.log("Linting '" + path + "'.")
896897
return ll.lint();
897898
}
898899

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"istanbul": "latest",
3737
"mocha-fivemat-progress-reporter": "latest",
3838
"tslint": "next",
39-
"typescript": "next",
39+
"typescript": "1.8.0-dev.20160113",
4040
"tsd": "latest"
4141
},
4242
"scripts": {

src/compiler/checker.ts

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,9 @@ namespace ts {
741741

742742
if (!result) {
743743
if (nameNotFoundMessage) {
744-
error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg));
744+
if (!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg)) {
745+
error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg));
746+
}
745747
}
746748
return undefined;
747749
}
@@ -778,6 +780,43 @@ namespace ts {
778780
return result;
779781
}
780782

783+
function checkAndReportErrorForMissingPrefix(errorLocation: Node, name: string, nameArg: string | Identifier): boolean {
784+
if (!errorLocation || (errorLocation.kind === SyntaxKind.Identifier && (isTypeReferenceIdentifier(<Identifier>errorLocation)) || isInTypeQuery(errorLocation))) {
785+
return false;
786+
}
787+
788+
const container = getThisContainer(errorLocation, /* includeArrowFunctions */ true);
789+
let location = container;
790+
while (location) {
791+
if (isClassLike(location.parent)) {
792+
const classSymbol = getSymbolOfNode(location.parent);
793+
if (!classSymbol) {
794+
break;
795+
}
796+
797+
// Check to see if a static member exists.
798+
const constructorType = getTypeOfSymbol(classSymbol);
799+
if (getPropertyOfType(constructorType, name)) {
800+
error(errorLocation, Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg), symbolToString(classSymbol));
801+
return true;
802+
}
803+
804+
// No static member is present.
805+
// Check if we're in an instance method and look for a relevant instance member.
806+
if (location === container && !(location.flags & NodeFlags.Static)) {
807+
const instanceType = (<InterfaceType>getDeclaredTypeOfSymbol(classSymbol)).thisType;
808+
if (getPropertyOfType(instanceType, name)) {
809+
error(errorLocation, Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg));
810+
return true;
811+
}
812+
}
813+
}
814+
815+
location = location.parent;
816+
}
817+
return false;
818+
}
819+
781820
function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void {
782821
Debug.assert((result.flags & SymbolFlags.BlockScopedVariable) !== 0);
783822
// Block-scoped variables cannot be used before their definition
@@ -6688,10 +6727,6 @@ namespace ts {
66886727
if (typeInfo && typeInfo.type === undefinedType) {
66896728
return type;
66906729
}
6691-
// If the type to be narrowed is any and we're checking a primitive with assumeTrue=true, return the primitive
6692-
if (!!(type.flags & TypeFlags.Any) && typeInfo && assumeTrue) {
6693-
return typeInfo.type;
6694-
}
66956730
let flags: TypeFlags;
66966731
if (typeInfo) {
66976732
flags = typeInfo.flags;
@@ -6702,6 +6737,10 @@ namespace ts {
67026737
}
67036738
// At this point we can bail if it's not a union
67046739
if (!(type.flags & TypeFlags.Union)) {
6740+
// If we're on the true branch and the type is a subtype, we should return the primitive type
6741+
if (assumeTrue && typeInfo && isTypeSubtypeOf(typeInfo.type, type)) {
6742+
return typeInfo.type;
6743+
}
67056744
// If the active non-union type would be removed from a union by this type guard, return an empty union
67066745
return filterUnion(type) ? type : emptyUnionType;
67076746
}

src/compiler/core.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,9 @@ namespace ts {
616616
return path.substr(0, rootLength) + normalized.join(directorySeparator);
617617
}
618618

619-
export function getDirectoryPath(path: string) {
619+
export function getDirectoryPath(path: Path): Path;
620+
export function getDirectoryPath(path: string): string;
621+
export function getDirectoryPath(path: string): any {
620622
return path.substr(0, Math.max(getRootLength(path), path.lastIndexOf(directorySeparator)));
621623
}
622624

@@ -874,4 +876,11 @@ namespace ts {
874876
}
875877
return copiedList;
876878
}
879+
880+
export function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string {
881+
return useCaseSensitivefileNames
882+
? ((fileName) => fileName)
883+
: ((fileName) => fileName.toLowerCase());
884+
}
885+
877886
}

src/compiler/diagnosticMessages.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,14 @@
17671767
"category": "Error",
17681768
"code": 2661
17691769
},
1770+
"Cannot find name '{0}'. Did you mean the static member '{1}.{0}'?": {
1771+
"category": "Error",
1772+
"code": 2662
1773+
},
1774+
"Cannot find name '{0}'. Did you mean the instance member 'this.{0}'?": {
1775+
"category": "Error",
1776+
"code": 2663
1777+
},
17701778
"Import declaration '{0}' is using private name '{1}'.": {
17711779
"category": "Error",
17721780
"code": 4000

src/compiler/emitter.ts

Lines changed: 2 additions & 1 deletion

0 commit comments

Comments
 (0)