Skip to content

Commit 630517b

Browse files
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript into typedefForJsdoc
2 parents 241920c + 4095602 commit 630517b

File tree

7 files changed

+53
-27
lines changed

7 files changed

+53
-27
lines changed

Jakefile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ function cleanTestDirs() {
680680
}
681681

682682
// used to pass data from jake command line directly to run.js
683-
function writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, testConfigFile) {
683+
function writeTestConfigFile(tests, light, taskConfigsFolder, workerCount) {
684684
var testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light: light, workerCount: workerCount, taskConfigsFolder: taskConfigsFolder });
685685
console.log('Running tests with config: ' + testConfigContents);
686686
fs.writeFileSync('test.config', testConfigContents);
@@ -716,7 +716,7 @@ function runConsoleTests(defaultReporter, runInParallel) {
716716
}
717717

718718
if (tests || light || taskConfigsFolder) {
719-
writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, testConfigFile);
719+
writeTestConfigFile(tests, light, taskConfigsFolder, workerCount);
720720
}
721721

722722
if (tests && tests.toLocaleLowerCase() === "rwc") {
@@ -850,7 +850,7 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory, servicesFi
850850
fs.unlinkSync(testConfigFile);
851851
}
852852
if(tests || light) {
853-
writeTestConfigFile(tests, light, testConfigFile);
853+
writeTestConfigFile(tests, light);
854854
}
855855

856856
tests = tests ? tests : '';

src/compiler/checker.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8655,25 +8655,23 @@ namespace ts {
86558655
function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type {
86568656
const func = parameter.parent;
86578657
if (isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
8658-
if (func.kind === SyntaxKind.FunctionExpression || func.kind === SyntaxKind.ArrowFunction) {
8659-
const iife = getImmediatelyInvokedFunctionExpression(func);
8660-
if (iife) {
8661-
const indexOfParameter = indexOf(func.parameters, parameter);
8662-
if (iife.arguments && indexOfParameter < iife.arguments.length) {
8663-
if (parameter.dotDotDotToken) {
8664-
const restTypes: Type[] = [];
8665-
for (let i = indexOfParameter; i < iife.arguments.length; i++) {
8666-
restTypes.push(getTypeOfExpression(iife.arguments[i]));
8667-
}
8668-
return createArrayType(getUnionType(restTypes));
8658+
const iife = getImmediatelyInvokedFunctionExpression(func);
8659+
if (iife) {
8660+
const indexOfParameter = indexOf(func.parameters, parameter);
8661+
if (iife.arguments && indexOfParameter < iife.arguments.length) {
8662+
if (parameter.dotDotDotToken) {
8663+
const restTypes: Type[] = [];
8664+
for (let i = indexOfParameter; i < iife.arguments.length; i++) {
8665+
restTypes.push(getTypeOfExpression(iife.arguments[i]));
86698666
}
8670-
const links = getNodeLinks(iife);
8671-
const cached = links.resolvedSignature;
8672-
links.resolvedSignature = anySignature;
8673-
const type = checkExpression(iife.arguments[indexOfParameter]);
8674-
links.resolvedSignature = cached;
8675-
return type;
8667+
return createArrayType(getUnionType(restTypes));
86768668
}
8669+
const links = getNodeLinks(iife);
8670+
const cached = links.resolvedSignature;
8671+
links.resolvedSignature = anySignature;
8672+
const type = checkExpression(iife.arguments[indexOfParameter]);
8673+
links.resolvedSignature = cached;
8674+
return type;
86778675
}
86788676
}
86798677
const contextualSignature = getContextualSignature(func);

src/harness/fourslash.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,12 @@ namespace FourSlash {
14861486
this.fixCaretPosition();
14871487
}
14881488

1489+
public formatOnType(pos: number, key: string) {
1490+
const edits = this.languageService.getFormattingEditsAfterKeystroke(this.activeFile.fileName, pos, key, this.formatCodeOptions);
1491+
this.currentCaretPosition += this.applyEdits(this.activeFile.fileName, edits, /*isFormattingEdit*/ true);
1492+
this.fixCaretPosition();
1493+
}
1494+
14891495
private updateMarkersForEdit(fileName: string, minChar: number, limChar: number, text: string) {
14901496
for (let i = 0; i < this.testData.markers.length; i++) {
14911497
const marker = this.testData.markers[i];
@@ -3223,6 +3229,10 @@ namespace FourSlashInterface {
32233229
this.state.formatSelection(this.state.getMarkerByName(startMarker).position, this.state.getMarkerByName(endMarker).position);
32243230
}
32253231

3232+
public onType(posMarker: string, key: string) {
3233+
this.state.formatOnType(this.state.getMarkerByName(posMarker).position, key);
3234+
}
3235+
32263236
public setOption(name: string, value: number): void;
32273237
public setOption(name: string, value: string): void;
32283238
public setOption(name: string, value: boolean): void;

src/harness/loggedIO.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,7 @@ namespace Playback {
226226
(path, extension, exclude) => findResultByPath(wrapper,
227227
replayLog.directoriesRead.filter(
228228
d => {
229-
if (d.extension === extension) {
230-
if (d.exclude) {
231-
return ts.arrayIsEqualTo(d.exclude, exclude);
232-
}
233-
return true;
234-
}
235-
return false;
229+
return d.extension === extension;
236230
}
237231
), path));
238232

src/services/formatting/formatting.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ namespace ts.formatting {
8181
while (isWhiteSpace(sourceFile.text.charCodeAt(endOfFormatSpan)) && !isLineBreak(sourceFile.text.charCodeAt(endOfFormatSpan))) {
8282
endOfFormatSpan--;
8383
}
84+
// if the character at the end of the span is a line break, we shouldn't include it, because it indicates we don't want to
85+
// touch the current line at all. Also, on some OSes the line break consists of two characters (\r\n), we should test if the
86+
// previous character before the end of format span is line break character as well.
87+
if (isLineBreak(sourceFile.text.charCodeAt(endOfFormatSpan))) {
88+
endOfFormatSpan--;
89+
}
8490
const span = {
8591
// get start position for the previous line
8692
pos: getStartPositionOfLine(line - 1, sourceFile),

tests/cases/fourslash/fourslash.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ declare namespace FourSlashInterface {
246246
copyFormatOptions(): FormatCodeOptions;
247247
setFormatOptions(options: FormatCodeOptions): any;
248248
selection(startMarker: string, endMarker: string): void;
249+
onType(posMarker: string, key: string): void;
249250
setOption(name: string, value: number): any;
250251
setOption(name: string, value: string): any;
251252
setOption(name: string, value: boolean): any;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
/////*3*/function listAPIFiles (path : string): string[] {
4+
//// /*1*/
5+
//// /*2*/
6+
////}
7+
8+
goTo.marker("1");
9+
format.onType("1", "\n");
10+
verify.currentLineContentIs(" ");
11+
12+
goTo.marker("2");
13+
format.onType("2", "\n");
14+
verify.currentLineContentIs(" ");
15+
16+
goTo.marker("3");
17+
verify.currentLineContentIs("function listAPIFiles(path: string): string[] {");

0 commit comments

Comments
 (0)