Skip to content

Commit 7fad769

Browse files
Merge branch 'master' into templates
2 parents c03dc10 + 20392de commit 7fad769

File tree

91 files changed

+15142
-5593
lines changed

Some content is hidden

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

91 files changed

+15142
-5593
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Your pull request should:
2626
* Include baseline changes with your change
2727
* All changed code must have 100% code coverage
2828
* Follow the code conventions descriped in [Coding guidlines](https://github.com/Microsoft/TypeScript/wiki/Coding-guidlines)
29+
* To avoid line ending issues, set `autocrlf = input` and `whitespace = cr-at-eol` in your git configuration
2930

3031
## Running the Tests
3132
To run all tests, invoke the runtests target using jake:

Jakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var servicesSources = [
5555
].map(function (f) {
5656
return path.join(compilerDirectory, f);
5757
}).concat([
58+
"breakpoints.ts",
5859
"services.ts",
5960
"shims.ts",
6061
"signatureHelp.ts",

bin/tsc.js

Lines changed: 2495 additions & 1557 deletions
Large diffs are not rendered by default.

bin/typescriptServices.js

Lines changed: 4698 additions & 2722 deletions
Large diffs are not rendered by default.

src/compiler/checker.ts

Lines changed: 78 additions & 71 deletions
Large diffs are not rendered by default.

src/compiler/parser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4083,22 +4083,22 @@ module ts {
40834083
}
40844084

40854085
function parseSourceElement() {
4086-
return parseSourceElementOrModuleElement(ModifierContext.SourceElements, /*allowLetAndConstDeclarations*/ false);
4086+
return parseSourceElementOrModuleElement(ModifierContext.SourceElements);
40874087
}
40884088

40894089
function parseModuleElement() {
4090-
return parseSourceElementOrModuleElement(ModifierContext.ModuleElements, /*allowLetAndConstDeclarations*/ true);
4090+
return parseSourceElementOrModuleElement(ModifierContext.ModuleElements);
40914091
}
40924092

4093-
function parseSourceElementOrModuleElement(modifierContext: ModifierContext, allowLetAndConstDeclarations: boolean): Statement {
4093+
function parseSourceElementOrModuleElement(modifierContext: ModifierContext): Statement {
40944094
if (isDeclaration()) {
40954095
return parseDeclaration(modifierContext);
40964096
}
40974097

40984098
var statementStart = scanner.getTokenPos();
40994099
var statementFirstTokenLength = scanner.getTextPos() - statementStart;
41004100
var errorCountBeforeStatement = file.syntacticErrors.length;
4101-
var statement = parseStatement(allowLetAndConstDeclarations);
4101+
var statement = parseStatement(/*allowLetAndConstDeclarations*/ true);
41024102

41034103
if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) {
41044104
grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts);

src/harness/fourslash.ts

Lines changed: 88 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -985,15 +985,85 @@ module FourSlash {
985985
return item.parameters[currentParam];
986986
}
987987

988-
public getBreakpointStatementLocation(pos: number) {
989-
this.taoInvalidReason = 'getBreakpointStatementLocation NYI';
988+
private alignmentForExtraInfo = 50;
989+
990+
private spanInfoToString(pos: number, spanInfo: TypeScript.TextSpan, prefixString: string) {
991+
var resultString = "SpanInfo: " + JSON.stringify(spanInfo);
992+
if (spanInfo) {
993+
var spanString = this.activeFile.content.substr(spanInfo.start(), spanInfo.length());
994+
var spanLineMap = ts.getLineStarts(spanString);
995+
for (var i = 0; i < spanLineMap.length; i++) {
996+
if (!i) {
997+
resultString += "\n";
998+
}
999+
resultString += prefixString + spanString.substring(spanLineMap[i], spanLineMap[i + 1]);
1000+
}
1001+
resultString += "\n" + prefixString + ":=> (" + this.getLineColStringAtPosition(spanInfo.start()) + ") to (" + this.getLineColStringAtPosition(spanInfo.end()) + ")";
1002+
}
1003+
1004+
return resultString;
1005+
}
1006+
1007+
private baselineCurrentFileLocations(getSpanAtPos: (pos: number) => TypeScript.TextSpan): string {
1008+
var fileLineMap = ts.getLineStarts(this.activeFile.content);
1009+
var nextLine = 0;
1010+
var resultString = "";
1011+
var currentLine: string;
1012+
var previousSpanInfo: string;
1013+
var startColumn: number;
1014+
var length: number;
1015+
var prefixString = " >";
1016+
1017+
var addSpanInfoString = () => {
1018+
if (previousSpanInfo) {
1019+
resultString += currentLine;
1020+
var thisLineMarker = repeatString(startColumn, " ") + repeatString(length, "~");
1021+
thisLineMarker += repeatString(this.alignmentForExtraInfo - thisLineMarker.length - prefixString.length + 1, " ");
1022+
resultString += thisLineMarker;
1023+
resultString += "=> Pos: (" + (pos - length) + " to " + (pos - 1) + ") ";
1024+
resultString += " " + previousSpanInfo;
1025+
previousSpanInfo = undefined;
1026+
}
1027+
};
9901028

991-
var spanInfo = this.languageService.getBreakpointStatementAtPosition(this.activeFile.fileName, pos);
992-
var resultString = "\n**Pos: " + pos + " SpanInfo: " + JSON.stringify(spanInfo) + "\n** Statement: ";
993-
if (spanInfo !== null) {
994-
resultString = resultString + this.activeFile.content.substr(spanInfo.start(), spanInfo.length());
1029+
for (var pos = 0; pos < this.activeFile.content.length; pos++) {
1030+
if (pos === 0 || pos === fileLineMap[nextLine]) {
1031+
nextLine++;
1032+
addSpanInfoString();
1033+
if (resultString.length) {
1034+
resultString += "\n--------------------------------";
1035+
}
1036+
currentLine = "\n" + nextLine.toString() + repeatString(3 - nextLine.toString().length, " ") + ">" + this.activeFile.content.substring(pos, fileLineMap[nextLine]) + "\n ";
1037+
startColumn = 0;
1038+
length = 0;
1039+
}
1040+
var spanInfo = this.spanInfoToString(pos, getSpanAtPos(pos), prefixString);
1041+
if (previousSpanInfo && previousSpanInfo !== spanInfo) {
1042+
addSpanInfoString();
1043+
previousSpanInfo = spanInfo;
1044+
startColumn = startColumn + length;
1045+
length = 1;
1046+
}
1047+
else {
1048+
previousSpanInfo = spanInfo;
1049+
length++;
1050+
}
9951051
}
1052+
addSpanInfoString();
9961053
return resultString;
1054+
1055+
function repeatString(count: number, char: string) {
1056+
var result = "";
1057+
for (var i = 0; i < count; i++) {
1058+
result += char;
1059+
}
1060+
return result;
1061+
}
1062+
}
1063+
1064+
public getBreakpointStatementLocation(pos: number) {
1065+
this.taoInvalidReason = 'getBreakpointStatementLocation NYI';
1066+
return this.languageService.getBreakpointStatementAtPosition(this.activeFile.fileName, pos);
9971067
}
9981068

9991069
public baselineCurrentFileBreakpointLocations() {
@@ -1003,12 +1073,7 @@ module FourSlash {
10031073
"Breakpoint Locations for " + this.activeFile.fileName,
10041074
this.testData.globalOptions[testOptMetadataNames.baselineFile],
10051075
() => {
1006-
var fileLength = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getLength();
1007-
var resultString = "";
1008-
for (var pos = 0; pos < fileLength; pos++) {
1009-
resultString = resultString + this.getBreakpointStatementLocation(pos);
1010-
}
1011-
return resultString;
1076+
return this.baselineCurrentFileLocations(pos => this.getBreakpointStatementLocation(pos));
10121077
},
10131078
true /* run immediately */);
10141079
}
@@ -1056,7 +1121,7 @@ module FourSlash {
10561121
}
10571122

10581123
public printBreakpointLocation(pos: number) {
1059-
Harness.IO.log(this.getBreakpointStatementLocation(pos));
1124+
Harness.IO.log("\n**Pos: " + pos + " " + this.spanInfoToString(pos, this.getBreakpointStatementLocation(pos), " "));
10601125
}
10611126

10621127
public printBreakpointAtCurrentLocation() {
@@ -1502,7 +1567,7 @@ module FourSlash {
15021567
throw new Error('verifyCaretAtMarker failed - expected to be in file "' + pos.fileName + '", but was in file "' + this.activeFile.fileName + '"');
15031568
}
15041569
if (pos.position !== this.currentCaretPosition) {
1505-
throw new Error('verifyCaretAtMarker failed - expected to be at marker "/*' + markerName + '*/, but was at position ' + this.currentCaretPosition + '(' + this.getLineColStringAtCaret() + ')');
1570+
throw new Error('verifyCaretAtMarker failed - expected to be at marker "/*' + markerName + '*/, but was at position ' + this.currentCaretPosition + '(' + this.getLineColStringAtPosition(this.currentCaretPosition) + ')');
15061571
}
15071572
}
15081573

@@ -1566,10 +1631,10 @@ module FourSlash {
15661631
this.taoInvalidReason = 'verifyCurrentNameOrDottedNameSpanText NYI';
15671632

15681633
var span = this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, this.currentCaretPosition, this.currentCaretPosition);
1569-
if (span === null) {
1634+
if (!span) {
15701635
this.raiseError('verifyCurrentNameOrDottedNameSpanText\n' +
15711636
'\tExpected: "' + text + '"\n' +
1572-
'\t Actual: null');
1637+
'\t Actual: undefined');
15731638
}
15741639

15751640
var actual = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getText(span.start(), span.end());
@@ -1581,12 +1646,8 @@ module FourSlash {
15811646
}
15821647

15831648
private getNameOrDottedNameSpan(pos: number) {
1584-
var spanInfo = this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, pos, pos);
1585-
var resultString = "\n**Pos: " + pos + " SpanInfo: " + JSON.stringify(spanInfo) + "\n** Statement: ";
1586-
if (spanInfo !== null) {
1587-
resultString = resultString + this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getText(spanInfo.start(), spanInfo.end());
1588-
}
1589-
return resultString;
1649+
this.taoInvalidReason = 'getNameOrDottedNameSpan NYI';
1650+
return this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, pos, pos);
15901651
}
15911652

15921653
public baselineCurrentFileNameOrDottedNameSpans() {
@@ -1596,18 +1657,14 @@ module FourSlash {
15961657
"Name OrDottedNameSpans for " + this.activeFile.fileName,
15971658
this.testData.globalOptions[testOptMetadataNames.baselineFile],
15981659
() => {
1599-
var fileLength = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getLength();
1600-
var resultString = "";
1601-
for (var pos = 0; pos < fileLength; pos++) {
1602-
resultString = resultString + this.getNameOrDottedNameSpan(pos);
1603-
}
1604-
return resultString;
1660+
return this.baselineCurrentFileLocations(pos =>
1661+
this.getNameOrDottedNameSpan(pos));
16051662
},
16061663
true /* run immediately */);
16071664
}
16081665

16091666
public printNameOrDottedNameSpans(pos: number) {
1610-
Harness.IO.log(this.getNameOrDottedNameSpan(pos));
1667+
Harness.IO.log(this.spanInfoToString(pos, this.getNameOrDottedNameSpan(pos), "**"));
16111668
}
16121669

16131670
private verifyClassifications(expected: { classificationType: string; text: string; textSpan?: TextSpan }[], actual: ts.ClassifiedSpan[]) {
@@ -2114,8 +2171,8 @@ module FourSlash {
21142171
return this.languageServiceShimHost.positionToZeroBasedLineCol(this.activeFile.fileName, this.currentCaretPosition).line + 1;
21152172
}
21162173

2117-
private getLineColStringAtCaret() {
2118-
var pos = this.languageServiceShimHost.positionToZeroBasedLineCol(this.activeFile.fileName, this.currentCaretPosition);
2174+
private getLineColStringAtPosition(position: number) {
2175+
var pos = this.languageServiceShimHost.positionToZeroBasedLineCol(this.activeFile.fileName, position);
21192176
return 'line ' + (pos.line + 1) + ', col ' + pos.character;
21202177
}
21212178

0 commit comments

Comments
 (0)