Skip to content

Commit cf72f2a

Browse files
committed
Merge branch 'master' into watchImprovements
2 parents 4f7c0e5 + be5c00f commit cf72f2a

File tree

213 files changed

+1781
-954
lines changed

Some content is hidden

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

213 files changed

+1781
-954
lines changed

src/compiler/checker.ts

Lines changed: 59 additions & 49 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,7 +3098,7 @@
30983098
"category": "Message",
30993099
"code": 6132
31003100
},
3101-
"'{0}' is declared but never used.": {
3101+
"'{0}' is declared but its value is never read.": {
31023102
"category": "Error",
31033103
"code": 6133
31043104
},
@@ -3118,7 +3118,7 @@
31183118
"category": "Error",
31193119
"code": 6137
31203120
},
3121-
"Property '{0}' is declared but never used.": {
3121+
"Property '{0}' is declared but its value is never read.": {
31223122
"category": "Error",
31233123
"code": 6138
31243124
},

src/compiler/transformers/es2017.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ namespace ts {
2121
const compilerOptions = context.getCompilerOptions();
2222
const languageVersion = getEmitScriptTarget(compilerOptions);
2323

24-
// These variables contain state that changes as we descend into the tree.
25-
let currentSourceFile: SourceFile;
26-
2724
/**
2825
* Keeps track of whether expression substitution has been enabled for specific edge cases.
2926
* They are persisted between each SourceFile transformation and should not be reset.
@@ -51,12 +48,8 @@ namespace ts {
5148
return node;
5249
}
5350

54-
currentSourceFile = node;
55-
5651
const visited = visitEachChild(node, visitor, context);
5752
addEmitHelpers(visited, context.readEmitHelpers());
58-
59-
currentSourceFile = undefined;
6053
return visited;
6154
}
6255

src/compiler/transformers/generators.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ namespace ts {
244244
const previousOnSubstituteNode = context.onSubstituteNode;
245245
context.onSubstituteNode = onSubstituteNode;
246246

247-
let currentSourceFile: SourceFile;
248247
let renamedCatchVariables: Map<boolean>;
249248
let renamedCatchVariableDeclarations: Identifier[];
250249

@@ -300,12 +299,9 @@ namespace ts {
300299
return node;
301300
}
302301

303-
currentSourceFile = node;
304302

305303
const visited = visitEachChild(node, visitor, context);
306304
addEmitHelpers(visited, context.readEmitHelpers());
307-
308-
currentSourceFile = undefined;
309305
return visited;
310306
}
311307

src/compiler/utilities.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,11 @@ namespace ts {
503503
case SyntaxKind.ArrowFunction:
504504
return true;
505505
default:
506-
staticAssertNever(node);
506+
assertTypeIsNever(node);
507507
return false;
508508
}
509509
}
510510

511-
function staticAssertNever(_: never): void {}
512-
513511
// Gets the nearest enclosing block scope container that has the provided node
514512
// as a descendant, that is not the provided node.
515513
export function getEnclosingBlockScopeContainer(node: Node): Node {
@@ -3505,6 +3503,46 @@ namespace ts {
35053503
return symbol.exportSymbol ? symbol.exportSymbol.flags | symbol.flags : symbol.flags;
35063504
}
35073505

3506+
export function isWriteOnlyAccess(node: Node) {
3507+
return accessKind(node) === AccessKind.Write;
3508+
}
3509+
3510+
export function isWriteAccess(node: Node) {
3511+
return accessKind(node) !== AccessKind.Read;
3512+
}
3513+
3514+
const enum AccessKind {
3515+
/** Only reads from a variable. */
3516+
Read,
3517+
/** Only writes to a variable without using the result. E.g.: `x++;`. */
3518+
Write,
3519+
/** Writes to a variable and uses the result as an expression. E.g.: `f(x++);`. */
3520+
ReadWrite
3521+
}
3522+
function accessKind(node: Node): AccessKind {
3523+
const { parent } = node;
3524+
if (!parent) return AccessKind.Read;
3525+
3526+
switch (parent.kind) {
3527+
case SyntaxKind.PostfixUnaryExpression:
3528+
case SyntaxKind.PrefixUnaryExpression:
3529+
const { operator } = parent as PrefixUnaryExpression | PostfixUnaryExpression;
3530+
return operator === SyntaxKind.PlusPlusToken || operator === SyntaxKind.MinusMinusToken ? writeOrReadWrite() : AccessKind.Read;
3531+
case SyntaxKind.BinaryExpression:
3532+
const { left, operatorToken } = parent as BinaryExpression;
3533+
return left === node && isAssignmentOperator(operatorToken.kind) ? writeOrReadWrite() : AccessKind.Read;
3534+
case SyntaxKind.PropertyAccessExpression:
3535+
return (parent as PropertyAccessExpression).name !== node ? AccessKind.Read : accessKind(parent);
3536+
default:
3537+
return AccessKind.Read;
3538+
}
3539+
3540+
function writeOrReadWrite(): AccessKind {
3541+
// If grandparent is not an ExpressionStatement, this is used as an expression in addition to having a side effect.
3542+
return parent.parent && parent.parent.kind === SyntaxKind.ExpressionStatement ? AccessKind.Write : AccessKind.ReadWrite;
3543+
}
3544+
}
3545+
35083546
export function compareDataObjects(dst: any, src: any): boolean {
35093547
if (!dst || !src || Object.keys(dst).length !== Object.keys(src).length) {
35103548
return false;

src/compiler/watchedProgram.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ namespace ts {
239239
let program: Program;
240240
let needsReload: boolean; // true if the config file changed and needs to reload it from the disk
241241
let missingFilesMap: Map<FileWatcher>; // Map of file watchers for the missing files
242-
let configFileWatcher: FileWatcher; // watcher for the config file
243-
let watchedWildcardDirectories: Map<WildcardDirectoryWatcher>; // map of watchers for the wild card directories in the config file
242+
let watchedWildcardDirectories: Map<WildcardDirectoryWatcher>; // map of watchers for the wild card directories in the config file
244243
let timerToUpdateProgram: any; // timer callback to recompile the program
245244

246245
const sourceFilesCache = createMap<HostFileInfo | string>(); // Cache that stores the source file and version info
@@ -259,7 +258,7 @@ namespace ts {
259258

260259
const partialSystem = configFileName ? createCachedPartialSystem(system) : system;
261260
if (configFileName) {
262-
configFileWatcher = watchFile(system, configFileName, scheduleProgramReload, writeLog);
261+
watchFile(system, configFileName, scheduleProgramReload, writeLog);
263262
}
264263

265264
const getCurrentDirectory = memoize(() => partialSystem.getCurrentDirectory());

src/harness/compilerRunner.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,13 @@ const enum CompilerTestType {
1111
class CompilerBaselineRunner extends RunnerBase {
1212
private basePath = "tests/cases";
1313
private testSuiteName: TestRunnerKind;
14-
private errors: boolean;
1514
private emit: boolean;
16-
private decl: boolean;
17-
private output: boolean;
1815

1916
public options: string;
2017

2118
constructor(public testType: CompilerTestType) {
2219
super();
23-
this.errors = true;
2420
this.emit = true;
25-
this.decl = true;
26-
this.output = true;
2721
if (testType === CompilerTestType.Conformance) {
2822
this.testSuiteName = "conformance";
2923
}
@@ -214,26 +208,14 @@ class CompilerBaselineRunner extends RunnerBase {
214208

215209
private parseOptions() {
216210
if (this.options && this.options.length > 0) {
217-
this.errors = false;
218211
this.emit = false;
219-
this.decl = false;
220-
this.output = false;
221212

222213
const opts = this.options.split(",");
223214
for (let i = 0; i < opts.length; i++) {
224215
switch (opts[i]) {
225-
case "error":
226-
this.errors = true;
227-
break;
228216
case "emit":
229217
this.emit = true;
230218
break;
231-
case "decl":
232-
this.decl = true;
233-
break;
234-
case "output":
235-
this.output = true;
236-
break;
237219
default:
238220
throw new Error("unsupported flag");
239221
}

src/harness/fourslash.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,11 +2758,11 @@ namespace FourSlash {
27582758
}
27592759
}
27602760

2761-
private getSelection() {
2762-
return ({
2761+
private getSelection(): ts.TextRange {
2762+
return {
27632763
pos: this.currentCaretPosition,
27642764
end: this.selectionEnd === -1 ? this.currentCaretPosition : this.selectionEnd
2765-
});
2765+
};
27662766
}
27672767

27682768
public verifyRefactorAvailable(negative: boolean, name: string, actionName?: string) {
@@ -2803,7 +2803,7 @@ namespace FourSlash {
28032803
}
28042804
}
28052805

2806-
public applyRefactor({ refactorName, actionName, actionDescription }: FourSlashInterface.ApplyRefactorOptions) {
2806+
public applyRefactor({ refactorName, actionName, actionDescription, newContent: newContentWithRenameMarker }: FourSlashInterface.ApplyRefactorOptions) {
28072807
const range = this.getSelection();
28082808
const refactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, range);
28092809
const refactor = refactors.find(r => r.name === refactorName);
@@ -2823,6 +2823,35 @@ namespace FourSlash {
28232823
for (const edit of editInfo.edits) {
28242824
this.applyEdits(edit.fileName, edit.textChanges, /*isFormattingEdit*/ false);
28252825
}
2826+
2827+
const { renamePosition, newContent } = parseNewContent();
2828+
2829+
this.verifyCurrentFileContent(newContent);
2830+
2831+
if (renamePosition === undefined) {
2832+
if (editInfo.renameLocation !== undefined) {
2833+
this.raiseError(`Did not expect a rename location, got ${editInfo.renameLocation}`);
2834+
}
2835+
}
2836+
else {
2837+
// TODO: test editInfo.renameFilename value
2838+
assert.isDefined(editInfo.renameFilename);
2839+
if (renamePosition !== editInfo.renameLocation) {
2840+
this.raiseError(`Expected rename position of ${renamePosition}, but got ${editInfo.renameLocation}`);
2841+
}
2842+
}
2843+
2844+
function parseNewContent(): { renamePosition: number | undefined, newContent: string } {
2845+
const renamePosition = newContentWithRenameMarker.indexOf("/*RENAME*/");
2846+
if (renamePosition === -1) {
2847+
return { renamePosition: undefined, newContent: newContentWithRenameMarker };
2848+
}
2849+
else {
2850+
const newContent = newContentWithRenameMarker.slice(0, renamePosition) + newContentWithRenameMarker.slice(renamePosition + "/*RENAME*/".length);
2851+
return { renamePosition, newContent };
2852+
}
2853+
}
2854+
28262855
}
28272856

28282857
public verifyFileAfterApplyingRefactorAtMarker(
@@ -4319,6 +4348,7 @@ namespace FourSlashInterface {
43194348
refactorName: string;
43204349
actionName: string;
43214350
actionDescription: string;
4351+
newContent: string;
43224352
}
43234353

43244354
export interface CompletionsAtOptions {

src/harness/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ if (taskConfigsFolder) {
216216

217217
for (let i = 0; i < workerCount; i++) {
218218
const config = workerConfigs[i];
219-
// use last worker to run unit tests
220-
config.runUnitTests = i === workerCount - 1;
219+
// use last worker to run unit tests if we're not just running a single specific runner
220+
config.runUnitTests = runners.length !== 1 && i === workerCount - 1;
221221
Harness.IO.writeFile(ts.combinePaths(taskConfigsFolder, `task-config${i}.json`), JSON.stringify(workerConfigs[i]));
222222
}
223223
}

src/harness/rwcRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class RWCRunner extends RunnerBase {
263263
*/
264264
public initializeTests(): void {
265265
// Read in and evaluate the test list
266-
const testList = this.enumerateTestFiles();
266+
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();
267267
for (let i = 0; i < testList.length; i++) {
268268
this.runTest(testList[i]);
269269
}

0 commit comments

Comments
 (0)