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
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
# Instructions for Logging Issues
2+
3+
## 1. Read the FAQ
4+
5+
Please [read the FAQ](https://github.com/Microsoft/TypeScript/wiki/FAQ) before logging new issues, even if you think you have found a bug.
6+
7+
Issues that ask questions answered in the FAQ will be closed without elaboration.
8+
9+
## 2. Search for Duplicates
10+
11+
[Search the existing issues](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=is%3Aissue) before logging a new one.
12+
13+
## 3. Do you have a question?
14+
15+
The issue tracker is for **issues**, in other words, bugs and suggestions.
16+
If you have a *question*, please use [http://stackoverflow.com/questions/tagged/typescript](Stack Overflow), [https://gitter.im/Microsoft/TypeScript](Gitter), your favorite search engine, or other resources.
17+
Due to increased traffic, we can no longer answer questions in the issue tracker.
18+
19+
## 4. Did you find a bug?
20+
21+
When logging a bug, please be sure to include the following:
22+
* What version of TypeScript you're using (run `tsc --v`)
23+
* If at all possible, an *isolated* way to reproduce the behavior
24+
* The behavior you expect to see, and the actual behavior
25+
26+
You can try out the nightly build of TypeScript (`npm install typescript@next`) to see if the bug has already been fixed.
27+
28+
## 5. Do you have a suggestion?
29+
30+
We also accept suggestions in the issue tracker.
31+
Be sure to [check the FAQ](https://github.com/Microsoft/TypeScript/wiki/FAQ) and [search](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=is%3Aissue) first.
32+
33+
In general, things we find useful when reviewing suggestins are:
34+
* A description of the problem you're trying to solve
35+
* An overview of the suggested solution
36+
* Examples of how the suggestion would work in various places
37+
* Code examples showing e.g. "this would be an error, this wouldn't"
38+
* Code examples showing the generated JavaScript (if applicable)
39+
* If relevant, precedent in other languages can be useful for establishing context and expected behavior
40+
41+
# Instructions for Contributing Code
42+
143
## Contributing bug fixes
244

345
TypeScript is currently accepting contributions in the form of bug fixes. A bug must have an issue tracking it in the issue tracker that has been approved ("Milestone == Community") by the TypeScript team. Your pull request should include a link to the bug that you are fixing. If you've submitted a PR for a bug, please post a comment in the bug to avoid duplication of effort.

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
Original file line numberDiff line numberDiff line change
@@ -2886,7 +2886,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
28862886
case SyntaxKind.ForStatement:
28872887
case SyntaxKind.ForInStatement:
28882888
case SyntaxKind.ForOfStatement:
2889-
if ((<ForStatement | ForInStatement | ForOfStatement>node).initializer.kind === SyntaxKind.VariableDeclarationList) {
2889+
const initializer = (<ForStatement | ForInStatement | ForOfStatement>node).initializer;
2890+
if (initializer && initializer.kind === SyntaxKind.VariableDeclarationList) {
28902891
loopInitializer = <VariableDeclarationList>(<ForStatement | ForInStatement | ForOfStatement>node).initializer;
28912892
}
28922893
break;

0 commit comments

Comments
 (0)