diff --git a/.mailmap b/.mailmap index 7ae5cb19818..98f004c58dc 100644 --- a/.mailmap +++ b/.mailmap @@ -276,4 +276,15 @@ Francois Wouts Jan Melcher Jan Melcher Matt Mitchell Maxwell Paul Brickner -Tycho Grouwstra \ No newline at end of file +Tycho Grouwstra +Adrian Leonhard +Alex Chugaev +Henry Mercer +Ivan Enderlin +Joe Calzaretta +Magnus Kulke +Stas Vilchik +Taras Mankovski +Thomas den Hollander +Vakhurin Sergey +Zeeshan Ahmed \ No newline at end of file diff --git a/AUTHORS.md b/AUTHORS.md index 4f94a67f7dd..c554a588715 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -3,8 +3,10 @@ TypeScript is authored by: * Abubaker Bashir * Adam Freidin * Adi Dahiya +* Adrian Leonhard * Ahmad Farid * Akshar Patel +* Alex Chugaev * Alex Eagle * Alexander Kuvaev * Alexander Rusakov @@ -105,6 +107,7 @@ TypeScript is authored by: * Halasi Tamás * Harald Niesche * Hendrik Liebau +* Henry Mercer * Herrington Darkholme * Homa Wong * Iain Monro @@ -112,6 +115,7 @@ TypeScript is authored by: * Ika * Ingvar Stepanyan * Isiah Meadows +* Ivan Enderlin * Ivo Gabe de Wolff * Iwata Hidetaka * Jakub Młokosiewicz @@ -127,6 +131,7 @@ TypeScript is authored by: * Jeffrey Morlan * Jesse Schalken * Jiri Tobisek +* Joe Calzaretta * Joe Chung * Joel Day * Joey Wilson @@ -161,6 +166,7 @@ TypeScript is authored by: * Lucien Greathouse * Lukas Elmer * Magnus Hiie +* Magnus Kulke * Manish Giri * Marin Marinov * Marius Schulz @@ -232,13 +238,16 @@ TypeScript is authored by: * Soo Jae Hwang * Stan Thomas * Stanislav Sysoev +* Stas Vilchik * Steve Lucco * Sudheesh Singanamalla * Sébastien Arod * @T18970237136 * @t_ +* Taras Mankovski * Tarik Ozket * Tetsuharu Ohzeki +* Thomas den Hollander * Thomas Loubiou * Tien Hoanhtien * Tim Lancina @@ -253,6 +262,7 @@ TypeScript is authored by: * TruongSinh Tran-Nguyen * Tycho Grouwstra * Vadi Taslim +* Vakhurin Sergey * Vidar Tonaas Fauske * Viktor Zozulyak * Vilic Vane @@ -263,5 +273,6 @@ TypeScript is authored by: * York Yao * @yortus * Yuichi Nukiyama +* Zeeshan Ahmed * Zev Spitz * Zhengbo Li \ No newline at end of file diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 4cacb5765db..35a62a644d8 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -143,6 +143,15 @@ namespace ts { let subtreeTransformFlags: TransformFlags = TransformFlags.None; let skipTransformFlagAggregation: boolean; + /** + * Inside the binder, we may create a diagnostic for an as-yet unbound node (with potentially no parent pointers, implying no accessible source file) + * If so, the node _must_ be in the current file (as that's the only way anything could have traversed to it to yield it as the error node) + * This version of `createDiagnosticForNode` uses the binder's context to account for this, and always yields correct diagnostics even in these situations. + */ + function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic { + return createDiagnosticForNodeInSourceFile(getSourceFileOfNode(node) || file, node, message, arg0, arg1, arg2); + } + function bindSourceFile(f: SourceFile, opts: CompilerOptions) { file = f; options = opts; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d47a77a7440..2cad5dbf652 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20034,7 +20034,7 @@ namespace ts { function checkJSDocAugmentsTag(node: JSDocAugmentsTag): void { const classLike = getJSDocHost(node); if (!isClassDeclaration(classLike) && !isClassExpression(classLike)) { - error(classLike, Diagnostics.JSDoc_augments_is_not_attached_to_a_class_declaration); + error(classLike, Diagnostics.JSDoc_0_is_not_attached_to_a_class, idText(node.tagName)); return; } @@ -20049,7 +20049,7 @@ namespace ts { if (extend) { const className = getIdentifierFromEntityNameExpression(extend.expression); if (className && name.escapedText !== className.escapedText) { - error(name, Diagnostics.JSDoc_augments_0_does_not_match_the_extends_1_clause, idText(name), idText(className)); + error(name, Diagnostics.JSDoc_0_1_does_not_match_the_extends_2_clause, idText(node.tagName), idText(name), idText(className)); } } } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 45a4a04b6ab..fb5000a58bf 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -356,21 +356,6 @@ namespace ts { return array; } - export function removeWhere(array: T[], f: (x: T) => boolean): boolean { - let outIndex = 0; - for (const item of array) { - if (!f(item)) { - array[outIndex] = item; - outIndex++; - } - } - if (outIndex !== array.length) { - array.length = outIndex; - return true; - } - return false; - } - export function filterMutate(array: T[], f: (x: T, i: number, array: T[]) => boolean): void { let outIndex = 0; for (let i = 0; i < array.length; i++) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 91ad9e52bfd..251e84ca8f4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3519,11 +3519,11 @@ "category": "Error", "code": 8021 }, - "JSDoc '@augments' is not attached to a class declaration.": { + "JSDoc '@{0}' is not attached to a class.": { "category": "Error", "code": 8022 }, - "JSDoc '@augments {0}' does not match the 'extends {1}' clause.": { + "JSDoc '@{0} {1}' does not match the 'extends {2}' clause.": { "category": "Error", "code": 8023 }, @@ -3661,7 +3661,7 @@ "category": "Message", "code": 90013 }, - "Change {0} to {1}.": { + "Change '{0}' to '{1}'.": { "category": "Message", "code": 90014 }, diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index aecc6989891..680ed98a84a 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -141,7 +141,10 @@ namespace ts { resolvedModuleNames.clear(); resolvedTypeReferenceDirectives.clear(); allFilesHaveInvalidatedResolution = false; - Debug.assert(perDirectoryResolvedModuleNames.size === 0 && perDirectoryResolvedTypeReferenceDirectives.size === 0); + // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update + // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution) + perDirectoryResolvedModuleNames.clear(); + perDirectoryResolvedTypeReferenceDirectives.clear(); } function startRecordingFilesWithChangedResolutions() { @@ -166,7 +169,10 @@ namespace ts { } function startCachingPerDirectoryResolution() { - Debug.assert(perDirectoryResolvedModuleNames.size === 0 && perDirectoryResolvedTypeReferenceDirectives.size === 0); + // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update + // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution) + perDirectoryResolvedModuleNames.clear(); + perDirectoryResolvedTypeReferenceDirectives.clear(); } function finishCachingPerDirectoryResolution() { diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 2ab3ccc5ce6..4fc67c1cc8f 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -322,6 +322,9 @@ namespace ts { if (hasChangedCompilerOptions) { newLine = getNewLineCharacter(compilerOptions, system); + if (program && changesAffectModuleResolution(program.getCompilerOptions(), compilerOptions)) { + resolutionCache.clear(); + } } const hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(); @@ -329,14 +332,11 @@ namespace ts { return; } - if (hasChangedCompilerOptions && changesAffectModuleResolution(program && program.getCompilerOptions(), compilerOptions)) { - resolutionCache.clear(); - } - const needsUpdateInTypeRootWatch = hasChangedCompilerOptions || !program; - hasChangedCompilerOptions = false; beforeCompile(compilerOptions); // Compile the program + const needsUpdateInTypeRootWatch = hasChangedCompilerOptions || !program; + hasChangedCompilerOptions = false; resolutionCache.startCachingPerDirectoryResolution(); compilerHost.hasInvalidatedResolution = hasInvalidatedResolution; compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index debb7290678..de6d92eda05 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2381,7 +2381,7 @@ Actual: ${stringify(fullActual)}`); })); return ts.flatMap(ts.deduplicate(diagnosticsForCodeFix, ts.equalOwnProperties), diagnostic => { - if (errorCode && errorCode !== diagnostic.code) { + if (errorCode !== undefined && errorCode !== diagnostic.code) { return; } diff --git a/src/harness/parallel/host.ts b/src/harness/parallel/host.ts index 2aaa4f78728..d7bba70408e 100644 --- a/src/harness/parallel/host.ts +++ b/src/harness/parallel/host.ts @@ -38,20 +38,45 @@ namespace Harness.Parallel.Host { return undefined; } - function hashName(runner: TestRunnerKind, test: string) { + function hashName(runner: TestRunnerKind | "unittest", test: string) { return `tsrunner-${runner}://${test}`; } + let tasks: { runner: TestRunnerKind | "unittest", file: string, size: number }[] = []; + const newTasks: { runner: TestRunnerKind | "unittest", file: string, size: number }[] = []; + let unknownValue: string | undefined; export function start() { - initializeProgressBarsDependencies(); - console.log("Discovering tests..."); - const discoverStart = +(new Date()); - const { statSync }: { statSync(path: string): { size: number }; } = require("fs"); - let tasks: { runner: TestRunnerKind, file: string, size: number }[] = []; - const newTasks: { runner: TestRunnerKind, file: string, size: number }[] = []; const perfData = readSavedPerfData(configOption); let totalCost = 0; - let unknownValue: string | undefined; + if (runUnitTests) { + (global as any).describe = (suiteName: string) => { + // Note, sub-suites are not indexed (we assume such granularity is not required) + let size = 0; + if (perfData) { + size = perfData[hashName("unittest", suiteName)]; + if (size === undefined) { + newTasks.push({ runner: "unittest", file: suiteName, size: 0 }); + unknownValue = suiteName; + return; + } + } + tasks.push({ runner: "unittest", file: suiteName, size }); + totalCost += size; + }; + } + else { + (global as any).describe = ts.noop; + } + + setTimeout(() => startDelayed(perfData, totalCost), 0); // Do real startup on next tick, so all unit tests have been collected + } + + function startDelayed(perfData: {[testHash: string]: number}, totalCost: number) { + initializeProgressBarsDependencies(); + console.log(`Discovered ${tasks.length} unittest suites` + (newTasks.length ? ` and ${newTasks.length} new suites.` : ".")); + console.log("Discovering runner-based tests..."); + const discoverStart = +(new Date()); + const { statSync }: { statSync(path: string): { size: number }; } = require("fs"); for (const runner of runners) { const files = runner.enumerateTestFiles(); for (const file of files) { @@ -87,8 +112,7 @@ namespace Harness.Parallel.Host { } tasks.sort((a, b) => a.size - b.size); tasks = tasks.concat(newTasks); - // 1 fewer batches than threads to account for unittests running on the final thread - const batchCount = runners.length === 1 ? workerCount : workerCount - 1; + const batchCount = workerCount; const packfraction = 0.9; const chunkSize = 1000; // ~1KB or 1s for sending batches near the end of a test const batchSize = (totalCost / workerCount) * packfraction; // Keep spare tests for unittest thread in reserve @@ -113,7 +137,7 @@ namespace Harness.Parallel.Host { let closedWorkers = 0; for (let i = 0; i < workerCount; i++) { // TODO: Just send the config over the IPC channel or in the command line arguments - const config: TestConfig = { light: Harness.lightMode, listenForWork: true, runUnitTests: runners.length === 1 ? false : i === workerCount - 1 }; + const config: TestConfig = { light: Harness.lightMode, listenForWork: true, runUnitTests: runners.length !== 1 }; const configPath = ts.combinePaths(taskConfigsFolder, `task-config${i}.json`); Harness.IO.writeFile(configPath, JSON.stringify(config)); const child = fork(__filename, [`--config="${configPath}"`]); @@ -187,7 +211,7 @@ namespace Harness.Parallel.Host { // It's only really worth doing an initial batching if there are a ton of files to go through if (totalFiles > 1000) { console.log("Batching initial test lists..."); - const batches: { runner: TestRunnerKind, file: string, size: number }[][] = new Array(batchCount); + const batches: { runner: TestRunnerKind | "unittest", file: string, size: number }[][] = new Array(batchCount); const doneBatching = new Array(batchCount); let scheduledTotal = 0; batcher: while (true) { @@ -230,7 +254,7 @@ namespace Harness.Parallel.Host { if (payload) { worker.send({ type: "batch", payload }); } - else { // Unittest thread - send off just one test + else { // Out of batches, send off just one test const payload = tasks.pop(); ts.Debug.assert(!!payload); // The reserve kept above should ensure there is always an initial task available, even in suboptimal scenarios worker.send({ type: "test", payload }); diff --git a/src/harness/parallel/shared.ts b/src/harness/parallel/shared.ts index 85d885c14a1..2eb7777f828 100644 --- a/src/harness/parallel/shared.ts +++ b/src/harness/parallel/shared.ts @@ -1,14 +1,14 @@ /// /// namespace Harness.Parallel { - export type ParallelTestMessage = { type: "test", payload: { runner: TestRunnerKind, file: string } } | never; + export type ParallelTestMessage = { type: "test", payload: { runner: TestRunnerKind | "unittest", file: string } } | never; export type ParallelBatchMessage = { type: "batch", payload: ParallelTestMessage["payload"][] } | never; export type ParallelCloseMessage = { type: "close" } | never; export type ParallelHostMessage = ParallelTestMessage | ParallelCloseMessage | ParallelBatchMessage; export type ParallelErrorMessage = { type: "error", payload: { error: string, stack: string, name?: string[] } } | never; export type ErrorInfo = ParallelErrorMessage["payload"] & { name: string[] }; - export type ParallelResultMessage = { type: "result", payload: { passing: number, errors: ErrorInfo[], duration: number, runner: TestRunnerKind, file: string } } | never; + export type ParallelResultMessage = { type: "result", payload: { passing: number, errors: ErrorInfo[], duration: number, runner: TestRunnerKind | "unittest", file: string } } | never; export type ParallelBatchProgressMessage = { type: "progress", payload: ParallelResultMessage["payload"] } | never; export type ParallelClientMessage = ParallelErrorMessage | ParallelResultMessage | ParallelBatchProgressMessage; } \ No newline at end of file diff --git a/src/harness/parallel/worker.ts b/src/harness/parallel/worker.ts index 7e95831535a..c32b9660a39 100644 --- a/src/harness/parallel/worker.ts +++ b/src/harness/parallel/worker.ts @@ -1,22 +1,13 @@ namespace Harness.Parallel.Worker { let errors: ErrorInfo[] = []; let passing = 0; - let reportedUnitTests = false; type Executor = {name: string, callback: Function, kind: "suite" | "test"} | never; function resetShimHarnessAndExecute(runner: RunnerBase) { - if (reportedUnitTests) { - errors = []; - passing = 0; - testList.length = 0; - } - reportedUnitTests = true; - if (testList.length) { - // Execute unit tests - testList.forEach(({ name, callback, kind }) => executeCallback(name, callback, kind)); - testList.length = 0; - } + errors = []; + passing = 0; + testList.length = 0; const start = +(new Date()); runner.initializeTests(); testList.forEach(({ name, callback, kind }) => executeCallback(name, callback, kind)); @@ -226,13 +217,46 @@ namespace Harness.Parallel.Worker { shimMochaHarness(); } - function handleTest(runner: TestRunnerKind, file: string) { - if (!runners.has(runner)) { - runners.set(runner, createRunner(runner)); + function handleTest(runner: TestRunnerKind | "unittest", file: string) { + collectUnitTestsIfNeeded(); + if (runner === unittest) { + return executeUnitTest(file); + } + else { + if (!runners.has(runner)) { + runners.set(runner, createRunner(runner)); + } + const instance = runners.get(runner); + instance.tests = [file]; + return { ...resetShimHarnessAndExecute(instance), runner, file }; } - const instance = runners.get(runner); - instance.tests = [file]; - return { ...resetShimHarnessAndExecute(instance), runner, file }; } } + + const unittest: "unittest" = "unittest"; + let unitTests: {[name: string]: Function}; + function collectUnitTestsIfNeeded() { + if (!unitTests && testList.length) { + unitTests = {}; + for (const test of testList) { + unitTests[test.name] = test.callback; + } + testList.length = 0; + } + } + + function executeUnitTest(name: string) { + if (!unitTests) { + throw new Error(`Asked to run unit test ${name}, but no unit tests were discovered!`); + } + if (unitTests[name]) { + errors = []; + passing = 0; + const start = +(new Date()); + executeSuiteCallback(name, unitTests[name]); + delete unitTests[name]; + return { file: name, runner: unittest, errors, passing, duration: +(new Date()) - start }; + } + throw new Error(`Unit test with name "${name}" was asked to be run, but such a test does not exist!`); + } } \ No newline at end of file diff --git a/src/harness/unittests/compileOnSave.ts b/src/harness/unittests/compileOnSave.ts index 1e765054eee..fdec5b192ee 100644 --- a/src/harness/unittests/compileOnSave.ts +++ b/src/harness/unittests/compileOnSave.ts @@ -619,7 +619,7 @@ namespace ts.projectSystem { assert.isTrue(host.fileExists(expectedOutFileName)); const outFileContent = host.readFile(expectedOutFileName); verifyContentHasString(outFileContent, file1.content); - verifyContentHasString(outFileContent, `//# sourceMappingURL=${outFileName}.map`); + verifyContentHasString(outFileContent, `//# ${"sourceMappingURL"}=${outFileName}.map`); // Sometimes tools can sometimes see this line as a source mapping url comment, so we obfuscate it a little // Verify map file const expectedMapFileName = expectedOutFileName + ".map"; diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 765a3188443..7d5a172aad7 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -842,6 +842,9 @@ namespace ts.server { this.logger.info(`remove project: ${project.getRootFiles().toString()}`); project.close(); + if (Debug.shouldAssert(AssertionLevel.Normal)) { + this.filenameToScriptInfo.forEach(info => Debug.assert(!info.isAttached(project))); + } // Remove the project from pending project updates this.pendingProjectUpdates.delete(project.getProjectName()); diff --git a/src/server/project.ts b/src/server/project.ts index c2a799d0845..7f7c3132136 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -233,9 +233,9 @@ namespace ts.server { this.realpath = path => host.realpath(path); } - this.languageService = createLanguageService(this, this.documentRegistry); // Use the current directory as resolution root only if the project created using current directory string this.resolutionCache = createResolutionCache(this, currentDirectory && this.currentDirectory); + this.languageService = createLanguageService(this, this.documentRegistry); if (!languageServiceEnabled) { this.disableLanguageService(); } @@ -498,25 +498,23 @@ namespace ts.server { close() { if (this.program) { - // if we have a program - release all files that are enlisted in program + // if we have a program - release all files that are enlisted in program but arent root + // The releasing of the roots happens later + // The project could have pending update remaining and hence the info could be in the files but not in program graph for (const f of this.program.getSourceFiles()) { - const info = this.projectService.getScriptInfo(f.fileName); - // We might not find the script info in case its not associated with the project any more - // and project graph was not updated (eg delayed update graph in case of files changed/deleted on the disk) - if (info) { - info.detachFromProject(this); - } + this.detachScriptInfoIfNotRoot(f.fileName); } } - if (!this.program || !this.languageServiceEnabled) { - // release all root files either if there is no program or language service is disabled. - // in the latter case set of root files can be larger than the set of files in program. - for (const root of this.rootFiles) { - root.detachFromProject(this); - } + // Release external files + forEach(this.externalFiles, externalFile => this.detachScriptInfoIfNotRoot(externalFile)); + // Always remove root files from the project + for (const root of this.rootFiles) { + root.detachFromProject(this); } + this.rootFiles = undefined; this.rootFilesMap = undefined; + this.externalFiles = undefined; this.program = undefined; this.builder = undefined; this.resolutionCache.clear(); @@ -535,6 +533,15 @@ namespace ts.server { this.languageService = undefined; } + private detachScriptInfoIfNotRoot(uncheckedFilename: string) { + const info = this.projectService.getScriptInfo(uncheckedFilename); + // We might not find the script info in case its not associated with the project any more + // and project graph was not updated (eg delayed update graph in case of files changed/deleted on the disk) + if (info && !this.isRoot(info)) { + info.detachFromProject(this); + } + } + isClosed() { return this.rootFiles === undefined; } @@ -735,7 +742,6 @@ namespace ts.server { */ updateGraph(): boolean { this.resolutionCache.startRecordingFilesWithChangedResolutions(); - this.hasInvalidatedResolution = this.resolutionCache.createHasInvalidatedResolution(); let hasChanges = this.updateGraphWorker(); @@ -795,9 +801,10 @@ namespace ts.server { private updateGraphWorker() { const oldProgram = this.program; - + Debug.assert(!this.isClosed(), "Called update graph worker of closed project"); this.writeLog(`Starting updateGraphWorker: Project: ${this.getProjectName()}`); const start = timestamp(); + this.hasInvalidatedResolution = this.resolutionCache.createHasInvalidatedResolution(); this.resolutionCache.startCachingPerDirectoryResolution(); this.program = this.languageService.getProgram(); this.resolutionCache.finishCachingPerDirectoryResolution(); @@ -1320,8 +1327,6 @@ namespace ts.server { } close() { - super.close(); - if (this.configFileWatcher) { this.configFileWatcher.close(); this.configFileWatcher = undefined; @@ -1330,6 +1335,7 @@ namespace ts.server { this.stopWatchingWildCards(); this.projectErrors = undefined; this.configFileSpecs = undefined; + super.close(); } addOpenRef() { diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index a9583106fc6..19bd592b7a7 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -92,7 +92,7 @@ namespace ts.codefix { classDeclarationSourceFile, classDeclaration, staticInitialization, - { suffix: context.newLineCharacter }); + { prefix: context.newLineCharacter, suffix: context.newLineCharacter }); const initializeStaticAction = { description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_static_property_0), [tokenName]), changes: staticInitializationChangeTracker.getChanges() @@ -112,11 +112,11 @@ namespace ts.codefix { createIdentifier("undefined"))); const propertyInitializationChangeTracker = textChanges.ChangeTracker.fromContext(context); - propertyInitializationChangeTracker.insertNodeAt( + propertyInitializationChangeTracker.insertNodeBefore( classDeclarationSourceFile, - classConstructor.body.getEnd() - 1, + classConstructor.body.getLastToken(), propertyInitialization, - { prefix: context.newLineCharacter, suffix: context.newLineCharacter }); + { suffix: context.newLineCharacter }); const initializeAction = { description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_property_0_in_the_constructor), [tokenName]), diff --git a/src/services/completions.ts b/src/services/completions.ts index 44ad611de79..c2224256937 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1195,6 +1195,11 @@ namespace ts.Completions { if (isClassLike(location)) { return location; } + // class c { method() { } b| } + if (isFromClassElementDeclaration(location) && + (location.parent as ClassElement).name === location) { + return location.parent.parent as ClassLikeDeclaration; + } break; default: diff --git a/src/services/refactors/convertFunctionToEs6Class.ts b/src/services/refactors/convertFunctionToEs6Class.ts index e4cd1a42083..110f64d1220 100644 --- a/src/services/refactors/convertFunctionToEs6Class.ts +++ b/src/services/refactors/convertFunctionToEs6Class.ts @@ -243,7 +243,8 @@ namespace ts.refactor.convertFunctionToES6Class { memberElements.unshift(createConstructor(/*decorators*/ undefined, /*modifiers*/ undefined, initializer.parameters, initializer.body)); } - const cls = createClassDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, node.name, + const modifiers = getExportModifierFromSource(precedingNode); + const cls = createClassDeclaration(/*decorators*/ undefined, modifiers, node.name, /*typeParameters*/ undefined, /*heritageClauses*/ undefined, memberElements); // Don't call copyComments here because we'll already leave them in place return cls; @@ -255,10 +256,15 @@ namespace ts.refactor.convertFunctionToES6Class { memberElements.unshift(createConstructor(/*decorators*/ undefined, /*modifiers*/ undefined, node.parameters, node.body)); } - const cls = createClassDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, node.name, + const modifiers = getExportModifierFromSource(node); + const cls = createClassDeclaration(/*decorators*/ undefined, modifiers, node.name, /*typeParameters*/ undefined, /*heritageClauses*/ undefined, memberElements); // Don't call copyComments here because we'll already leave them in place return cls; } + + function getExportModifierFromSource(source: Node) { + return filter(source.modifiers, modifier => modifier.kind === SyntaxKind.ExportKeyword); + } } } \ No newline at end of file diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 5991eb85c70..b1595030df0 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -7145,6 +7145,7 @@ declare namespace ts.server { getExternalFiles(): SortedReadonlyArray; getSourceFile(path: Path): SourceFile; close(): void; + private detachScriptInfoIfNotRoot(uncheckedFilename); isClosed(): boolean; hasRoots(): boolean; getRootFiles(): NormalizedPath[]; diff --git a/tests/baselines/reference/castFunctionExpressionShouldBeParenthesized.js b/tests/baselines/reference/castFunctionExpressionShouldBeParenthesized.js new file mode 100644 index 00000000000..e96b93bae85 --- /dev/null +++ b/tests/baselines/reference/castFunctionExpressionShouldBeParenthesized.js @@ -0,0 +1,5 @@ +//// [castFunctionExpressionShouldBeParenthesized.ts] +(function a() { } as any)().foo() + +//// [castFunctionExpressionShouldBeParenthesized.js] +(function a() { }().foo()); diff --git a/tests/baselines/reference/castFunctionExpressionShouldBeParenthesized.symbols b/tests/baselines/reference/castFunctionExpressionShouldBeParenthesized.symbols new file mode 100644 index 00000000000..975a9480c3c --- /dev/null +++ b/tests/baselines/reference/castFunctionExpressionShouldBeParenthesized.symbols @@ -0,0 +1,4 @@ +=== tests/cases/compiler/castFunctionExpressionShouldBeParenthesized.ts === +(function a() { } as any)().foo() +>a : Symbol(a, Decl(castFunctionExpressionShouldBeParenthesized.ts, 0, 1)) + diff --git a/tests/baselines/reference/castFunctionExpressionShouldBeParenthesized.types b/tests/baselines/reference/castFunctionExpressionShouldBeParenthesized.types new file mode 100644 index 00000000000..337c5163ff2 --- /dev/null +++ b/tests/baselines/reference/castFunctionExpressionShouldBeParenthesized.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/castFunctionExpressionShouldBeParenthesized.ts === +(function a() { } as any)().foo() +>(function a() { } as any)().foo() : any +>(function a() { } as any)().foo : any +>(function a() { } as any)() : any +>(function a() { } as any) : any +>function a() { } as any : any +>function a() { } : () => void +>a : () => void +>foo : any + diff --git a/tests/baselines/reference/jsdocAugments_notAClass.errors.txt b/tests/baselines/reference/jsdocAugments_notAClass.errors.txt index 9f8528f0cd8..daf20aaf884 100644 --- a/tests/baselines/reference/jsdocAugments_notAClass.errors.txt +++ b/tests/baselines/reference/jsdocAugments_notAClass.errors.txt @@ -1,4 +1,4 @@ -/b.js(3,10): error TS8022: JSDoc '@augments' is not attached to a class declaration. +/b.js(3,10): error TS8022: JSDoc '@augments' is not attached to a class. ==== /b.js (1 errors) ==== @@ -6,5 +6,5 @@ /** @augments A */ function b() {} ~ -!!! error TS8022: JSDoc '@augments' is not attached to a class declaration. +!!! error TS8022: JSDoc '@augments' is not attached to a class. \ No newline at end of file diff --git a/tests/cases/compiler/castFunctionExpressionShouldBeParenthesized.ts b/tests/cases/compiler/castFunctionExpressionShouldBeParenthesized.ts new file mode 100644 index 00000000000..3fb1aaf7079 --- /dev/null +++ b/tests/cases/compiler/castFunctionExpressionShouldBeParenthesized.ts @@ -0,0 +1 @@ +(function a() { } as any)().foo() \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixAddMissingMember4.ts b/tests/cases/fourslash/codeFixAddMissingMember4.ts index cfbec8977f6..a17b777ae5f 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember4.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember4.ts @@ -15,12 +15,11 @@ verify.codeFix({ description: "Initialize property 'foo' in the constructor.", index: 0, - // TODO: GH#18741 and GH#18445 + // TODO: GH#18445 newFileContent: `class C { constructor() { - \r -this.foo = undefined;\r -} + this.foo = undefined;\r + } method() { this.foo === 10; } diff --git a/tests/cases/fourslash/codeFixAddMissingMember5.ts b/tests/cases/fourslash/codeFixAddMissingMember5.ts index 804a3910a8c..562c4a10f21 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember5.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember5.ts @@ -13,11 +13,12 @@ verify.codeFix({ description: "Initialize static property 'foo'.", index: 0, - // TODO: GH#18743 and GH#18445 + // TODO: GH#18445 newFileContent: `class C { static method() { ()=>{ this.foo === 10 }; } -}C.foo = undefined;\r +}\r +C.foo = undefined;\r ` }); diff --git a/tests/cases/fourslash/codeFixAddMissingMember6.ts b/tests/cases/fourslash/codeFixAddMissingMember6.ts index 2598014dde5..32525066657 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember6.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember6.ts @@ -13,12 +13,11 @@ verify.codeFix({ description: "Initialize property 'foo' in the constructor.", index: 0, - // TODO: GH#18741 and GH#18445 + // TODO: GH#18445 newFileContent: `class C { constructor() { - \r -this.foo = undefined;\r -} + this.foo = undefined;\r + } prop = ()=>{ this.foo === 10 }; }` }); diff --git a/tests/cases/fourslash/codeFixAddMissingMember7.ts b/tests/cases/fourslash/codeFixAddMissingMember7.ts index 4ed9c9293d7..014ab6102dd 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember7.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember7.ts @@ -11,9 +11,10 @@ verify.codeFix({ description: "Initialize static property 'foo'.", index: 2, - // TODO: GH#18743 and GH#18445 + // TODO: GH#18445 newFileContent: `class C { static p = ()=>{ this.foo === 10 }; -}C.foo = undefined;\r +}\r +C.foo = undefined;\r ` }); diff --git a/tests/cases/fourslash/codeFixChangeExtendsToImplements.ts b/tests/cases/fourslash/codeFixChangeExtendsToImplements.ts index bfaedf2818a..bf3b8b7b8a4 100644 --- a/tests/cases/fourslash/codeFixChangeExtendsToImplements.ts +++ b/tests/cases/fourslash/codeFixChangeExtendsToImplements.ts @@ -3,4 +3,7 @@ //// interface I {} //// [|/* */ class /* */ C /* */ extends /* */ I|]{} -verify.rangeAfterCodeFix("/* */ class /* */ C /* */ implements /* */ I"); \ No newline at end of file +verify.codeFix({ + description: "Change 'extends' to 'implements'.", + newRangeContent: "/* */ class /* */ C /* */ implements /* */ I", +}); diff --git a/tests/cases/fourslash/codeFixChangeExtendsToImplementsAbstractModifier.ts b/tests/cases/fourslash/codeFixChangeExtendsToImplementsAbstractModifier.ts index 5f5ca93c28f..7f309a22965 100644 --- a/tests/cases/fourslash/codeFixChangeExtendsToImplementsAbstractModifier.ts +++ b/tests/cases/fourslash/codeFixChangeExtendsToImplementsAbstractModifier.ts @@ -5,4 +5,8 @@ //// [|abstract class A extends I1 implements I2|] { } -verify.rangeAfterCodeFix("abstract class A implements I1, I2"); \ No newline at end of file +verify.codeFix({ + description: "Change 'extends' to 'implements'.", + // TODO: GH#18794 + newRangeContent: "abstract class A implements I1 , I2", +}); diff --git a/tests/cases/fourslash/codeFixChangeExtendsToImplementsTypeParams.ts b/tests/cases/fourslash/codeFixChangeExtendsToImplementsTypeParams.ts index 869bd1a5dc0..2cca0b277fd 100644 --- a/tests/cases/fourslash/codeFixChangeExtendsToImplementsTypeParams.ts +++ b/tests/cases/fourslash/codeFixChangeExtendsToImplementsTypeParams.ts @@ -3,4 +3,7 @@ ////interface I { x: X} ////[|class C extends I|]{} -verify.rangeAfterCodeFix("class C implements I"); \ No newline at end of file +verify.codeFix({ + description: "Change 'extends' to 'implements'.", + newRangeContent: "class C implements I", +}); diff --git a/tests/cases/fourslash/codeFixChangeExtendsToImplementsWithDecorator.ts b/tests/cases/fourslash/codeFixChangeExtendsToImplementsWithDecorator.ts index 9671f41def3..e031251ac1b 100644 --- a/tests/cases/fourslash/codeFixChangeExtendsToImplementsWithDecorator.ts +++ b/tests/cases/fourslash/codeFixChangeExtendsToImplementsWithDecorator.ts @@ -10,4 +10,8 @@ //// @sealed //// [|class A extends I1 implements I2 { }|] -verify.rangeAfterCodeFix("class A implements I1, I2 { }"); \ No newline at end of file +verify.codeFix({ + description: "Change 'extends' to 'implements'.", + // TODO: GH#18794 + newRangeContent: "class A implements I1 , I2 { }", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax1.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax1.ts index 93107ef669b..1a4e967df45 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax1.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax1.ts @@ -1,4 +1,7 @@ /// //// var x: [|?|] = 12; -verify.rangeAfterCodeFix("any"); +verify.codeFix({ + description: "Change '?' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax10.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax10.ts index 3e6754588fd..12ddb66c6fd 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax10.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax10.ts @@ -2,4 +2,10 @@ /// //// function f(x: [|number?|]) { //// } -verify.rangeAfterCodeFix("number | null", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0); + +verify.codeFix({ + description: "Change 'number?' to 'number | null'.", + errorCode: 8020, + index: 0, + newRangeContent: "number | null", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax11.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax11.ts index 7ac80125775..8edcbb35da2 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax11.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax11.ts @@ -2,4 +2,10 @@ /// //// var f = function f(x: [|string?|]) { //// } -verify.rangeAfterCodeFix("string | null | undefined", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 1); + +verify.codeFix({ + description: "Change 'string?' to 'string | null | undefined'.", + errorCode: 8020, + index: 1, + newRangeContent: "string | null | undefined", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax12.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax12.ts index 37eb5df41ee..a2221897aa8 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax12.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax12.ts @@ -3,4 +3,10 @@ ////class C { //// p: [|*|] ////} -verify.rangeAfterCodeFix("any", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0); + +verify.codeFix({ + description: "Change '*' to 'any'.", + errorCode: 8020, + index: 0, + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax13.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax13.ts index 5b374b508f1..65fef47feda 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax13.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax13.ts @@ -3,4 +3,10 @@ ////class C { //// p: [|*|] = 12 ////} -verify.rangeAfterCodeFix("any", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0); + +verify.codeFix({ + description: "Change '*' to 'any'.", + errorCode: 8020, + index: 0, + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax14.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax14.ts index 69478fc3abc..71f21dd8301 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax14.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax14.ts @@ -2,4 +2,9 @@ /// //// var x = 12 as [|number?|]; -verify.rangeAfterCodeFix("number | null", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0); +verify.codeFix({ + description: "Change 'number?' to 'number | null'.", + errorCode: 8020, + index: 0, + newRangeContent: "number | null", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax15.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax15.ts index 9482830c19d..b0e8c069e1e 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax15.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax15.ts @@ -2,4 +2,9 @@ //// var f = <[|function(number?): number|]>(x => x); // note: without --strict, number? --> number, not number | null -verify.rangeAfterCodeFix("(arg0: number) => number", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0); +verify.codeFix({ + description: "Change 'function(number?): number' to '(arg0: number) => number'.", + errorCode: 8020, + index: 0, + newRangeContent: "(arg0: number) => number", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax16.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax16.ts index 111aec1dce7..264e490d961 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax16.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax16.ts @@ -1,4 +1,7 @@ /// //// var f: { [K in keyof number]: [|*|] }; -verify.rangeAfterCodeFix("any"); +verify.codeFix({ + description: "Change '*' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax17.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax17.ts index 6a3ce2ed3df..63973222a8a 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax17.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax17.ts @@ -1,3 +1,7 @@ /// //// declare function index(ix: number): [|*|]; -verify.rangeAfterCodeFix("any"); + +verify.codeFix({ + description: "Change '*' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax18.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax18.ts index 30a3815516a..31b04bef0f6 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax18.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax18.ts @@ -1,3 +1,7 @@ /// //// var index: { (ix: number): [|?|] }; -verify.rangeAfterCodeFix("any"); + +verify.codeFix({ + description: "Change '?' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax19.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax19.ts index e6344881227..d254cf6d8dd 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax19.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax19.ts @@ -1,3 +1,7 @@ /// //// var index: { new (ix: number): [|?|] }; -verify.rangeAfterCodeFix("any"); + +verify.codeFix({ + description: "Change '?' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax2.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax2.ts index 333b108538f..d2dc0986a59 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax2.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax2.ts @@ -1,4 +1,7 @@ /// //// var x: [|*|] = 12; -verify.rangeAfterCodeFix("any"); +verify.codeFix({ + description: "Change '*' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax20.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax20.ts index dc153730841..32cfe73fd4a 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax20.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax20.ts @@ -1,3 +1,7 @@ /// //// var index = { get p(): [|*|] { return 12 } }; -verify.rangeAfterCodeFix("any"); + +verify.codeFix({ + description: "Change '*' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax21.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax21.ts index 442414e4577..efb53d53009 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax21.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax21.ts @@ -1,3 +1,7 @@ /// //// var index = { set p(x: [|*|]) { } }; -verify.rangeAfterCodeFix("any"); + +verify.codeFix({ + description: "Change '*' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax22.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax22.ts index c575f1ca7ce..06ff23c3cf5 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax22.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax22.ts @@ -1,3 +1,7 @@ /// //// var index: { [s: string]: [|*|] }; -verify.rangeAfterCodeFix("any"); + +verify.codeFix({ + description: "Change '*' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax23.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax23.ts index 7ab70e18ee7..29a49ff641c 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax23.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax23.ts @@ -3,4 +3,8 @@ //// m(): [|*|] { //// } ////} -verify.rangeAfterCodeFix("any"); + +verify.codeFix({ + description: "Change '*' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax24.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax24.ts index 7ea2d1f6faf..6c9a840a373 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax24.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax24.ts @@ -2,4 +2,8 @@ ////declare class C { //// m(): [|*|]; ////} -verify.rangeAfterCodeFix("any"); + +verify.codeFix({ + description: "Change '*' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax25.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax25.ts index 6486a70417e..74a7ea9fa18 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax25.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax25.ts @@ -2,4 +2,8 @@ ////declare class C { //// p: [|*|]; ////} -verify.rangeAfterCodeFix("any"); + +verify.codeFix({ + description: "Change '*' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax26.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax26.ts index dc31f1dfffd..4287539173a 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax26.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax26.ts @@ -2,4 +2,8 @@ ////class C { //// p: [|*|] = 12; ////} -verify.rangeAfterCodeFix("any"); + +verify.codeFix({ + description: "Change '*' to 'any'.", + newRangeContent: "any", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax27.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax27.ts index a259b2dd719..998a9ebd28a 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax27.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax27.ts @@ -1,4 +1,10 @@ // @strict: true /// ////type T = [|...number?|]; -verify.rangeAfterCodeFix("number[] | null", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0); + +verify.codeFix({ + description: "Change '...number?' to 'number[] | null'.", + errorCode: 8020, + index: 0, + newRangeContent: "number[] | null", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax3.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax3.ts index f3b02cb84f1..2c804edb615 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax3.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax3.ts @@ -1,4 +1,7 @@ /// //// var x: [|......number[][]|] = 12; -verify.rangeAfterCodeFix("number[][][][]"); +verify.codeFix({ + description: "Change '......number[][]' to 'number[][][][]'.", + newRangeContent: "number[][][][]", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax4.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax4.ts index e9522331d38..f2df4abfd33 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax4.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax4.ts @@ -1,4 +1,7 @@ /// //// var x: [|Array.|] = 12; -verify.rangeAfterCodeFix("number[]"); +verify.codeFix({ + description: "Change 'Array.' to 'number[]'.", + newRangeContent: "number[]", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax5.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax5.ts index 6f46f3082e1..39cca325a4c 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax5.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax5.ts @@ -2,4 +2,9 @@ /// //// var x: [|?number|] = 12; -verify.rangeAfterCodeFix("number | null", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0); +verify.codeFix({ + description: "Change '?number' to 'number | null'.", + errorCode: 8020, + index: 0, + newRangeContent: "number | null", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax6.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax6.ts index 8af9f09d99d..da692d723bb 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax6.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax6.ts @@ -2,4 +2,8 @@ /// //// var x: [|number?|] = 12; -verify.rangeAfterCodeFix("number | null | undefined", /*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 1); +verify.codeFix({ + description: "Change 'number?' to 'number | null | undefined'.", + index: 1, + newRangeContent: "number | null | undefined", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax7.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax7.ts index c80d08b3bac..1d557896fe9 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax7.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax7.ts @@ -1,4 +1,7 @@ /// //// var x: [|!number|] = 12; -verify.rangeAfterCodeFix("number"); +verify.codeFix({ + description: "Change '!number' to 'number'.", + newRangeContent: "number", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax8.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax8.ts index 0fa7ddf229c..c35badc88cf 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax8.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax8.ts @@ -1,4 +1,7 @@ /// //// var x: [|function(this: number, number): string|] = 12; -verify.rangeAfterCodeFix("(this: number, arg1: number) => string"); +verify.codeFix({ + description: "Change 'function(this: number, number): string' to '(this: number, arg1: number) => string'.", + newRangeContent: "(this: number, arg1: number) => string", +}); diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax9.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax9.ts index 061ded158ea..6ce049b6a42 100644 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax9.ts +++ b/tests/cases/fourslash/codeFixChangeJSDocSyntax9.ts @@ -1,4 +1,7 @@ /// //// var x: [|function(new: number)|] = 12; -verify.rangeAfterCodeFix("new () => number"); +verify.codeFix({ + description: "Change 'function(new: number)' to 'new () => number'.", + newRangeContent: "new () => number", +}); diff --git a/tests/cases/fourslash/codeFixClassExprClassImplementClassFunctionVoidInferred.ts b/tests/cases/fourslash/codeFixClassExprClassImplementClassFunctionVoidInferred.ts index 2568111fb90..b582c5e8960 100644 --- a/tests/cases/fourslash/codeFixClassExprClassImplementClassFunctionVoidInferred.ts +++ b/tests/cases/fourslash/codeFixClassExprClassImplementClassFunctionVoidInferred.ts @@ -1,13 +1,16 @@ /// -//// class A { -//// f() {} -//// } +////class A { +//// f() {} +////} //// -//// let B = class implements A {[| |]} +////let B = class implements A {[| |]} -verify.rangeAfterCodeFix(` -f(): void{ - throw new Error("Method not implemented."); -} -`); +verify.codeFix({ + description: "Implement interface 'A'.", + // TODO: GH#18795 + newRangeContent: `f(): void {\r + throw new Error("Method not implemented.");\r +}\r + ` +}); diff --git a/tests/cases/fourslash/codeFixClassExprExtendsAbstractExpressionWithTypeArgs.ts b/tests/cases/fourslash/codeFixClassExprExtendsAbstractExpressionWithTypeArgs.ts index a7690b4f5bf..198cb9ea673 100644 --- a/tests/cases/fourslash/codeFixClassExprExtendsAbstractExpressionWithTypeArgs.ts +++ b/tests/cases/fourslash/codeFixClassExprExtendsAbstractExpressionWithTypeArgs.ts @@ -1,14 +1,17 @@ /// -//// function foo(a: T) { -//// abstract class C { -//// abstract a: T | U; -//// } -//// return C; -//// } +////function foo(a: T) { +//// abstract class C { +//// abstract a: T | U; +//// } +//// return C; +////} //// -//// let B = class extends foo("s") {[| |]} +////let B = class extends foo("s") {[| |]} -verify.rangeAfterCodeFix(` -a: string | number; -`); +verify.codeFix({ + description: "Implement inherited abstract class.", + // TODO: GH#18795 + newRangeContent: `a: string | number;\r + ` +}); diff --git a/tests/cases/fourslash/codeFixClassExtendAbstractExpressionWithTypeArgs.ts b/tests/cases/fourslash/codeFixClassExtendAbstractExpressionWithTypeArgs.ts index 5796bea6fb4..ed574348b9f 100644 --- a/tests/cases/fourslash/codeFixClassExtendAbstractExpressionWithTypeArgs.ts +++ b/tests/cases/fourslash/codeFixClassExtendAbstractExpressionWithTypeArgs.ts @@ -1,14 +1,17 @@ /// -//// function foo(a: T) { -//// abstract class C { -//// abstract a: T | U; -//// } -//// return C; -//// } +////function foo(a: T) { +//// abstract class C { +//// abstract a: T | U; +//// } +//// return C; +////} //// -//// class B extends foo("s") {[| |]} +////class B extends foo("s") {[| |]} -verify.rangeAfterCodeFix(` -a: string | number; -`); \ No newline at end of file +verify.codeFix({ + description: "Implement inherited abstract class.", + // TODO: GH#18795 + newRangeContent: `a: string | number;\r + ` +}); diff --git a/tests/cases/fourslash/codeFixClassExtendAbstractGetterSetter.ts b/tests/cases/fourslash/codeFixClassExtendAbstractGetterSetter.ts index bc437c93bcd..3522b1d39da 100644 --- a/tests/cases/fourslash/codeFixClassExtendAbstractGetterSetter.ts +++ b/tests/cases/fourslash/codeFixClassExtendAbstractGetterSetter.ts @@ -1,31 +1,34 @@ /// -//// abstract class A { -//// private _a: string; +////abstract class A { +//// private _a: string; //// -//// abstract get a(): number | string; -//// abstract get b(): this; -//// abstract get c(): A; +//// abstract get a(): number | string; +//// abstract get b(): this; +//// abstract get c(): A; //// -//// abstract set d(arg: number | string); -//// abstract set e(arg: this); -//// abstract set f(arg: A); +//// abstract set d(arg: number | string); +//// abstract set e(arg: this); +//// abstract set f(arg: A); //// -//// abstract get g(): string; -//// abstract set g(newName: string); -//// } -//// -//// // Don't need to add anything in this case. -//// abstract class B extends A {} -//// -//// class C extends A {[| |]} +//// abstract get g(): string; +//// abstract set g(newName: string); +////} +//// +////// Don't need to add anything in this case. +////abstract class B extends A {} +//// +////class C extends A {[| |]} -verify.rangeAfterCodeFix(` - a: string | number; - b: this; - c: A; - d: string | number; - e: this; - f: A; - g: string; -`); +verify.codeFix({ + description: "Implement inherited abstract class.", + // TODO: GH#18795 + newRangeContent: `a: string | number;\r +b: this;\r +c: A;\r +d: string | number;\r +e: this;\r +f: A;\r +g: string;\r + ` +}); diff --git a/tests/cases/fourslash/codeFixClassExtendAbstractMethod.ts b/tests/cases/fourslash/codeFixClassExtendAbstractMethod.ts index 7e51e2216dc..de9500552ab 100644 --- a/tests/cases/fourslash/codeFixClassExtendAbstractMethod.ts +++ b/tests/cases/fourslash/codeFixClassExtendAbstractMethod.ts @@ -1,24 +1,27 @@ /// -//// abstract class A { +////abstract class A { //// abstract f(a: number, b: string): boolean; //// abstract f(a: number, b: string): this; //// abstract f(a: string, b: number): Function; //// abstract f(a: string): Function; //// abstract foo(): number; -//// } +////} //// -//// class C extends A {[| |]} +////class C extends A {[| |]} -verify.rangeAfterCodeFix(` - f(a: number, b: string): boolean; - f(a: number, b: string): this; - f(a: string, b: number): Function; - f(a: string): Function; - f(a: any, b?: any) { - throw new Error("Method not implemented."); - } - foo(): number { - throw new Error("Method not implemented."); - } -`); +verify.codeFix({ + description: "Implement inherited abstract class.", + // TODO: GH#18795 + newRangeContent: `f(a: number, b: string): boolean;\r +f(a: number, b: string): this;\r +f(a: string, b: number): Function;\r +f(a: string): Function;\r +f(a: any, b?: any) {\r + throw new Error("Method not implemented.");\r +}\r +foo(): number {\r + throw new Error("Method not implemented.");\r +}\r + ` +}); diff --git a/tests/cases/fourslash/codeFixClassExtendAbstractMethodThis.ts b/tests/cases/fourslash/codeFixClassExtendAbstractMethodThis.ts index a462ac98121..e33338b45a9 100644 --- a/tests/cases/fourslash/codeFixClassExtendAbstractMethodThis.ts +++ b/tests/cases/fourslash/codeFixClassExtendAbstractMethodThis.ts @@ -1,13 +1,16 @@ /// -//// abstract class A { +////abstract class A { //// abstract f(): this; -//// } +////} //// -//// class C extends A {[| |]} +////class C extends A {[| |]} -verify.rangeAfterCodeFix(` - f(): this { - throw new Error("Method not implemented."); - } -`); +verify.codeFix({ + description: "Implement inherited abstract class.", + // TODO: GH#18795 + newRangeContent: `f(): this {\r + throw new Error("Method not implemented.");\r +}\r + ` +}); diff --git a/tests/cases/fourslash/codeFixClassExtendAbstractMethodTypeParamsInstantiateNumber.ts b/tests/cases/fourslash/codeFixClassExtendAbstractMethodTypeParamsInstantiateNumber.ts index c1a55e88034..395d9348b79 100644 --- a/tests/cases/fourslash/codeFixClassExtendAbstractMethodTypeParamsInstantiateNumber.ts +++ b/tests/cases/fourslash/codeFixClassExtendAbstractMethodTypeParamsInstantiateNumber.ts @@ -1,12 +1,16 @@ /// -//// abstract class A { +////abstract class A { //// abstract f(x: T): T; -//// } +////} //// -//// class C extends A {[| |]} +////class C extends A {[| |]} -verify.rangeAfterCodeFix(`f(x: number): number{ - throw new Error("Method not implemented."); -} -`); \ No newline at end of file +verify.codeFix({ + description: "Implement inherited abstract class.", + // TODO: GH#18795 + newRangeContent: `f(x: number): number {\r + throw new Error("Method not implemented.");\r +}\r + ` +}); diff --git a/tests/cases/fourslash/codeFixClassExtendAbstractMethodTypeParamsInstantiateU.ts b/tests/cases/fourslash/codeFixClassExtendAbstractMethodTypeParamsInstantiateU.ts index c2ec5ff8035..408406a9efe 100644 --- a/tests/cases/fourslash/codeFixClassExtendAbstractMethodTypeParamsInstantiateU.ts +++ b/tests/cases/fourslash/codeFixClassExtendAbstractMethodTypeParamsInstantiateU.ts @@ -1,12 +1,16 @@ /// -//// abstract class A { +////abstract class A { //// abstract f(x: T): T; -//// } +////} //// -//// class C extends A {[| |]} +////class C extends A {[| |]} -verify.rangeAfterCodeFix(`f(x: U): U{ - throw new Error("Method not implemented."); -} -`); \ No newline at end of file +verify.codeFix({ + description: "Implement inherited abstract class.", + // TODO: GH#18795 + newRangeContent: `f(x: U): U {\r + throw new Error("Method not implemented.");\r +}\r + ` +}); diff --git a/tests/cases/fourslash/codeFixClassExtendAbstractProperty.ts b/tests/cases/fourslash/codeFixClassExtendAbstractProperty.ts index 701903d6770..fbdb13f4f2c 100644 --- a/tests/cases/fourslash/codeFixClassExtendAbstractProperty.ts +++ b/tests/cases/fourslash/codeFixClassExtendAbstractProperty.ts @@ -1,15 +1,18 @@ /// -//// abstract class A { +////abstract class A { //// abstract x: number; //// abstract y: this; //// abstract z: A; -//// } +////} //// -//// class C extends A {[| |]} +////class C extends A {[| |]} -verify.rangeAfterCodeFix(` - x: number; - y: this; - z: A; -`); +verify.codeFix({ + description: "Implement inherited abstract class.", + // TODO: GH#18795 + newRangeContent: `x: number;\r +y: this;\r +z: A;\r + ` +}); diff --git a/tests/cases/fourslash/completionEntryForClassMembers3.ts b/tests/cases/fourslash/completionEntryForClassMembers3.ts new file mode 100644 index 00000000000..a27c5959e6d --- /dev/null +++ b/tests/cases/fourslash/completionEntryForClassMembers3.ts @@ -0,0 +1,32 @@ +/// + +////interface IFoo { +//// bar(): void; +////} +////class Foo1 implements IFoo { +//// zap() { } +//// /*1*/ +////} +////class Foo2 implements IFoo { +//// zap() { } +//// b/*2*/() { } +////} +////class Foo3 implements IFoo { +//// zap() { } +//// b/*3*/: any; +////} +const allowedKeywordCount = verify.allowedClassElementKeywords.length; +function verifyHasBar() { + verify.completionListContains("bar", "(method) IFoo.bar(): void", /*documentation*/ undefined, "method"); + verify.completionListContainsClassElementKeywords(); + verify.completionListCount(allowedKeywordCount + 1); +} + +goTo.marker("1"); +verifyHasBar(); +edit.insert("b"); +verifyHasBar(); +goTo.marker("2"); +verifyHasBar(); +goTo.marker("3"); +verifyHasBar(); \ No newline at end of file diff --git a/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier1.ts b/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier1.ts new file mode 100644 index 00000000000..940a68a05b6 --- /dev/null +++ b/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier1.ts @@ -0,0 +1,19 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: test123.js +////export function /**/MyClass() { +////} +////MyClass.prototype.foo = function() { +////} + +verify.applicableRefactorAvailableAtMarker(""); +verify.fileAfterApplyingRefactorAtMarker("", +`export class MyClass { + constructor() { + } + foo() { + } +} +`, +'Convert to ES2015 class', 'convert'); diff --git a/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier2.ts b/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier2.ts new file mode 100644 index 00000000000..fb1276d4f03 --- /dev/null +++ b/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier2.ts @@ -0,0 +1,19 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: test123.js +////export const /**/foo = function() { +////}; +////foo.prototype.instanceMethod = function() { +////}; + +verify.applicableRefactorAvailableAtMarker(""); +verify.fileAfterApplyingRefactorAtMarker("", +`export class foo { + constructor() { + } + instanceMethod() { + } +} +`, +'Convert to ES2015 class', 'convert'); diff --git a/tests/cases/fourslash/unusedMethodInClass1.ts b/tests/cases/fourslash/unusedMethodInClass1.ts index a5e3789c8af..175d95e2490 100644 --- a/tests/cases/fourslash/unusedMethodInClass1.ts +++ b/tests/cases/fourslash/unusedMethodInClass1.ts @@ -1,11 +1,12 @@ /// // @noUnusedLocals: true -////[| class greeter { +////class greeter { //// private function1() { //// } -////} |] +////} -verify.rangeAfterCodeFix(` -class greeter { -}`); +verify.codeFix({ + description: `Remove declaration for: 'function1'.`, + newFileContent: "class greeter {\n}", +}); diff --git a/tests/cases/fourslash/unusedMethodInClass2.ts b/tests/cases/fourslash/unusedMethodInClass2.ts index cce621236d4..884f7ecce4e 100644 --- a/tests/cases/fourslash/unusedMethodInClass2.ts +++ b/tests/cases/fourslash/unusedMethodInClass2.ts @@ -1,15 +1,17 @@ /// // @noUnusedLocals: true -//// [| class greeter { +////class greeter { //// public function2() { //// } //// private function1() { //// } -////} |] +////} -verify.rangeAfterCodeFix(` -class greeter { +verify.codeFix({ + description: `Remove declaration for: 'function1'.`, + newFileContent: `class greeter { public function2() { } -}`); +}`, +}); diff --git a/tests/cases/fourslash/unusedMethodInClass3.ts b/tests/cases/fourslash/unusedMethodInClass3.ts index ccf98c4bbc5..f76a1acde09 100644 --- a/tests/cases/fourslash/unusedMethodInClass3.ts +++ b/tests/cases/fourslash/unusedMethodInClass3.ts @@ -1,11 +1,12 @@ /// // @noUnusedLocals: true -////[|class greeter { +////class greeter { //// private function1 = function() { //// } -////} |] +////} -verify.rangeAfterCodeFix(` -class greeter { -}`); +verify.codeFix({ + description: `Remove declaration for: 'function1'.`, + newFileContent: "class greeter {\n}", +}); diff --git a/tests/cases/fourslash/unusedMethodInClass4.ts b/tests/cases/fourslash/unusedMethodInClass4.ts index 962b80f5bc1..9f882a3b76e 100644 --- a/tests/cases/fourslash/unusedMethodInClass4.ts +++ b/tests/cases/fourslash/unusedMethodInClass4.ts @@ -8,5 +8,9 @@ //// } |] ////} -verify.rangeAfterCodeFix(`public function2(){ -}`); +verify.codeFix({ + description: `Remove declaration for: 'function1'.`, + newRangeContent: `public function2(){ + } +`, +}); diff --git a/tests/cases/fourslash/unusedMethodInClass5.ts b/tests/cases/fourslash/unusedMethodInClass5.ts index 806e619817f..c53a31b5d36 100644 --- a/tests/cases/fourslash/unusedMethodInClass5.ts +++ b/tests/cases/fourslash/unusedMethodInClass5.ts @@ -1,8 +1,11 @@ /// // @noUnusedLocals: true -//// [|class C { -//// private ["string"] (){} -//// }|] +////class C { +//// private ["string"] (){} +////} -verify.rangeAfterCodeFix("class C { }"); \ No newline at end of file +verify.codeFix({ + description: `Remove declaration for: '"string"'.`, + newFileContent: "class C {\n}", +}); diff --git a/tests/cases/fourslash/unusedMethodInClass6.ts b/tests/cases/fourslash/unusedMethodInClass6.ts index d223b3d6857..eef00d1cdd0 100644 --- a/tests/cases/fourslash/unusedMethodInClass6.ts +++ b/tests/cases/fourslash/unusedMethodInClass6.ts @@ -1,8 +1,11 @@ /// // @noUnusedLocals: true -//// [|class C { -//// private "string" (){} -//// }|] +////class C { +//// private "string" (){} +////} -verify.rangeAfterCodeFix("class C { }"); \ No newline at end of file +verify.codeFix({ + description: `Remove declaration for: '"string"'.`, + newFileContent: "class C {\n}", +}); diff --git a/tests/cases/fourslash/unusedNamespaceInNamespace.ts b/tests/cases/fourslash/unusedNamespaceInNamespace.ts index 802336454c6..4391a6a158c 100644 --- a/tests/cases/fourslash/unusedNamespaceInNamespace.ts +++ b/tests/cases/fourslash/unusedNamespaceInNamespace.ts @@ -1,13 +1,13 @@ /// // @noUnusedLocals: true -//// [|namespace A { +////namespace A { //// namespace B { -//// } -//// }|] - -verify.rangeAfterCodeFix(` -namespace A { -} -`); +//// } +////} +verify.codeFix({ + description: "Remove declaration for: 'B'.", + newFileContent: `namespace A { +}`, +}); diff --git a/tests/cases/fourslash/unusedParameterInConstructor1.ts b/tests/cases/fourslash/unusedParameterInConstructor1.ts index 33fe34c7e61..46a8c1f3b52 100644 --- a/tests/cases/fourslash/unusedParameterInConstructor1.ts +++ b/tests/cases/fourslash/unusedParameterInConstructor1.ts @@ -5,4 +5,8 @@ //// [|constructor(private p1: string, public p2: boolean, public p3: any, p5)|] { p5; } //// } -verify.rangeAfterCodeFix("constructor(public p2: boolean, public p3: any, p5)", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'p1'.", + index: 0, + newRangeContent: "constructor(public p2: boolean, public p3: any, p5)", +}); diff --git a/tests/cases/fourslash/unusedParameterInConstructor1AddUnderscore.ts b/tests/cases/fourslash/unusedParameterInConstructor1AddUnderscore.ts index 31882978951..634561a5c65 100644 --- a/tests/cases/fourslash/unusedParameterInConstructor1AddUnderscore.ts +++ b/tests/cases/fourslash/unusedParameterInConstructor1AddUnderscore.ts @@ -5,4 +5,8 @@ //// [|constructor(private p1: string, public p2: boolean, public p3: any, p5) |] { p5; } //// } -verify.rangeAfterCodeFix("constructor(private _p1: string, public p2: boolean, public p3: any, p5)", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 1); \ No newline at end of file +verify.codeFix({ + description: "Prefix 'p1' with an underscore.", + index: 1, + newRangeContent: "constructor(private _p1: string, public p2: boolean, public p3: any, p5)", +}); diff --git a/tests/cases/fourslash/unusedParameterInConstructor2.ts b/tests/cases/fourslash/unusedParameterInConstructor2.ts index 71595a9c81c..b8208bb5359 100644 --- a/tests/cases/fourslash/unusedParameterInConstructor2.ts +++ b/tests/cases/fourslash/unusedParameterInConstructor2.ts @@ -5,4 +5,8 @@ //// [|constructor(public p1: string, private p2: boolean, public p3: any, p5)|] { p5; } //// } -verify.rangeAfterCodeFix("constructor(public p1: string, public p3: any, p5)", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'p2'.", + index: 0, + newRangeContent: "constructor(public p1: string, public p3: any, p5)", +}); diff --git a/tests/cases/fourslash/unusedParameterInConstructor3.ts b/tests/cases/fourslash/unusedParameterInConstructor3.ts index 3da0e85407f..c36f24595a7 100644 --- a/tests/cases/fourslash/unusedParameterInConstructor3.ts +++ b/tests/cases/fourslash/unusedParameterInConstructor3.ts @@ -5,4 +5,8 @@ //// [|constructor(public p1: string, public p2: boolean, private p3: any, p5)|] { p5; } //// } -verify.rangeAfterCodeFix("constructor(public p1: string, public p2: boolean, p5)", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'p3'.", + index: 0, + newRangeContent: "constructor(public p1: string, public p2: boolean, p5)", +}); diff --git a/tests/cases/fourslash/unusedParameterInConstructor4.ts b/tests/cases/fourslash/unusedParameterInConstructor4.ts index 860a7befa9b..99e98d64cda 100644 --- a/tests/cases/fourslash/unusedParameterInConstructor4.ts +++ b/tests/cases/fourslash/unusedParameterInConstructor4.ts @@ -5,4 +5,8 @@ //// [|constructor(private readonly p2: boolean, p5)|] { p5; } //// } -verify.rangeAfterCodeFix("constructor(p5)", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'p2'.", + index: 0, + newRangeContent: "constructor(p5)", +}); diff --git a/tests/cases/fourslash/unusedParameterInFunction1.ts b/tests/cases/fourslash/unusedParameterInFunction1.ts index bc6f081ecaa..3f979f78766 100644 --- a/tests/cases/fourslash/unusedParameterInFunction1.ts +++ b/tests/cases/fourslash/unusedParameterInFunction1.ts @@ -4,4 +4,8 @@ ////function [|greeter( x)|] { ////} -verify.rangeAfterCodeFix("greeter()", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0); +verify.codeFix({ + description: "Remove declaration for: 'x'.", + index: 0, + newRangeContent: "greeter()", +}); diff --git a/tests/cases/fourslash/unusedParameterInFunction1AddUnderscore.ts b/tests/cases/fourslash/unusedParameterInFunction1AddUnderscore.ts index 137625869c8..c248c5e1a94 100644 --- a/tests/cases/fourslash/unusedParameterInFunction1AddUnderscore.ts +++ b/tests/cases/fourslash/unusedParameterInFunction1AddUnderscore.ts @@ -4,4 +4,8 @@ ////function [|greeter( x) |] { ////} -verify.rangeAfterCodeFix("greeter( _x)", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 1); +verify.codeFix({ + description: "Prefix 'x' with an underscore.", + index: 1, + newRangeContent: "greeter( _x)", +}); diff --git a/tests/cases/fourslash/unusedParameterInFunction2.ts b/tests/cases/fourslash/unusedParameterInFunction2.ts index 6d1a772b0a8..74d95c99221 100644 --- a/tests/cases/fourslash/unusedParameterInFunction2.ts +++ b/tests/cases/fourslash/unusedParameterInFunction2.ts @@ -5,4 +5,8 @@ //// use(x); ////} -verify.rangeAfterCodeFix("greeter(x)", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'y'.", + index: 0, + newRangeContent: "greeter(x)", +}); diff --git a/tests/cases/fourslash/unusedParameterInFunction3.ts b/tests/cases/fourslash/unusedParameterInFunction3.ts index dcbe53163db..30dc2a94060 100644 --- a/tests/cases/fourslash/unusedParameterInFunction3.ts +++ b/tests/cases/fourslash/unusedParameterInFunction3.ts @@ -5,4 +5,8 @@ //// y++; ////} -verify.rangeAfterCodeFix("greeter(y)", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'x'.", + index: 0, + newRangeContent: "greeter(y)", +}); diff --git a/tests/cases/fourslash/unusedParameterInFunction4.ts b/tests/cases/fourslash/unusedParameterInFunction4.ts index e3ee2585384..87b5880ba70 100644 --- a/tests/cases/fourslash/unusedParameterInFunction4.ts +++ b/tests/cases/fourslash/unusedParameterInFunction4.ts @@ -5,4 +5,8 @@ //// use(x, z); ////} -verify.rangeAfterCodeFix("function greeter(x,z)", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'y'.", + index: 0, + newRangeContent: "function greeter(x,z) ", +}); diff --git a/tests/cases/fourslash/unusedParameterInLambda1.ts b/tests/cases/fourslash/unusedParameterInLambda1.ts index a5f735c7016..325502ebb6d 100644 --- a/tests/cases/fourslash/unusedParameterInLambda1.ts +++ b/tests/cases/fourslash/unusedParameterInLambda1.ts @@ -6,4 +6,8 @@ //// [|return (x:number) => {}|] //// } -verify.rangeAfterCodeFix("return () => {}", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0); +verify.codeFix({ + description: "Remove declaration for: 'x'.", + index: 0, + newRangeContent: "return () => {}", +}); diff --git a/tests/cases/fourslash/unusedParameterInLambda1AddUnderscore.ts b/tests/cases/fourslash/unusedParameterInLambda1AddUnderscore.ts index 916c32d82eb..1b05c66dd2f 100644 --- a/tests/cases/fourslash/unusedParameterInLambda1AddUnderscore.ts +++ b/tests/cases/fourslash/unusedParameterInLambda1AddUnderscore.ts @@ -6,4 +6,8 @@ //// [|return (x:number) => {} |] //// } -verify.rangeAfterCodeFix("return (_x:number) => {}", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 1); +verify.codeFix({ + description: "Prefix 'x' with an underscore.", + index: 1, + newRangeContent: "return (_x:number) => {}", +}); diff --git a/tests/cases/fourslash/unusedTypeAliasInNamespace1.ts b/tests/cases/fourslash/unusedTypeAliasInNamespace1.ts index 2314ebbe447..13c87f6afd6 100644 --- a/tests/cases/fourslash/unusedTypeAliasInNamespace1.ts +++ b/tests/cases/fourslash/unusedTypeAliasInNamespace1.ts @@ -1,11 +1,14 @@ /// // @noUnusedLocals: true -//// [| namespace greeter { -//// type hw = "Hello" |"world"; -//// export type nw = "No" | "Way"; -//// } |] +////namespace greeter { +//// type hw = "Hello" |"world"; +//// export type nw = "No" | "Way"; +////} -verify.rangeAfterCodeFix(`namespace greeter { +verify.codeFix({ + description: "Remove declaration for: 'hw'.", + newFileContent: `namespace greeter { export type nw = "No" | "Way"; -}`); +}`, +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInClass1.ts b/tests/cases/fourslash/unusedTypeParametersInClass1.ts index 322921ab471..6574362511f 100644 --- a/tests/cases/fourslash/unusedTypeParametersInClass1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInClass1.ts @@ -4,4 +4,7 @@ ////[|class greeter |] { ////} -verify.rangeAfterCodeFix("class greeter"); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'T'.", + newRangeContent: "class greeter ", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInClass2.ts b/tests/cases/fourslash/unusedTypeParametersInClass2.ts index feaf9d3a14b..3cb984a11ec 100644 --- a/tests/cases/fourslash/unusedTypeParametersInClass2.ts +++ b/tests/cases/fourslash/unusedTypeParametersInClass2.ts @@ -5,4 +5,7 @@ //// public a: X; ////} -verify.rangeAfterCodeFix("class greeter"); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'Y'.", + newRangeContent: "class greeter ", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInClass3.ts b/tests/cases/fourslash/unusedTypeParametersInClass3.ts index b1151265fe3..13ebc352cb0 100644 --- a/tests/cases/fourslash/unusedTypeParametersInClass3.ts +++ b/tests/cases/fourslash/unusedTypeParametersInClass3.ts @@ -6,4 +6,7 @@ //// public b: Z; ////} -verify.rangeAfterCodeFix("class greeter"); +verify.codeFix({ + description: "Remove declaration for: 'Y'.", + newRangeContent: "class greeter ", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInFunction1.ts b/tests/cases/fourslash/unusedTypeParametersInFunction1.ts index a11156badaa..b7289fc1e0a 100644 --- a/tests/cases/fourslash/unusedTypeParametersInFunction1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInFunction1.ts @@ -3,4 +3,7 @@ // @noUnusedLocals: true //// [|function f1() {}|] -verify.rangeAfterCodeFix("function f1() {}"); +verify.codeFix({ + description: "Remove declaration for: 'T'.", + newRangeContent: "function f1() {}", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInFunction2.ts b/tests/cases/fourslash/unusedTypeParametersInFunction2.ts index a011f093dab..e2851b34605 100644 --- a/tests/cases/fourslash/unusedTypeParametersInFunction2.ts +++ b/tests/cases/fourslash/unusedTypeParametersInFunction2.ts @@ -3,4 +3,7 @@ // @noUnusedLocals: true //// [|function f1(a: X) {a}|] -verify.rangeAfterCodeFix("function f1(a: X) {a}"); +verify.codeFix({ + description: "Remove declaration for: 'Y'.", + newRangeContent: "function f1(a: X) {a}", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInFunction3.ts b/tests/cases/fourslash/unusedTypeParametersInFunction3.ts index 6dc56ccc7cb..4be2dc5feb3 100644 --- a/tests/cases/fourslash/unusedTypeParametersInFunction3.ts +++ b/tests/cases/fourslash/unusedTypeParametersInFunction3.ts @@ -3,4 +3,7 @@ // @noUnusedLocals: true //// [|function f1(a: X) {a;var b:Z;b}|] -verify.rangeAfterCodeFix("function f1(a: X) {a;var b:Z;b}"); +verify.codeFix({ + description: "Remove declaration for: 'Y'.", + newRangeContent: "function f1(a: X) {a;var b:Z;b}", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInInterface1.ts b/tests/cases/fourslash/unusedTypeParametersInInterface1.ts index b5363b369be..bc3a95d63b6 100644 --- a/tests/cases/fourslash/unusedTypeParametersInInterface1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInInterface1.ts @@ -4,4 +4,7 @@ // @noUnusedParameters: true //// [|interface I {}|] -verify.rangeAfterCodeFix("interface I {}"); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'T'.", + newRangeContent: "interface I {}", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInLambda1.ts b/tests/cases/fourslash/unusedTypeParametersInLambda1.ts index 01c1ebd24f5..3d7310d6ae6 100644 --- a/tests/cases/fourslash/unusedTypeParametersInLambda1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInLambda1.ts @@ -6,4 +6,7 @@ //// [|return (x:number) => {x}|] //// } -verify.rangeAfterCodeFix("return (x:number) => {x}"); +verify.codeFix({ + description: "Remove declaration for: 'T'.", + newRangeContent: "return(x:number) => {x}", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInLambda2.ts b/tests/cases/fourslash/unusedTypeParametersInLambda2.ts index e5a4acc31c5..b2b89d3373e 100644 --- a/tests/cases/fourslash/unusedTypeParametersInLambda2.ts +++ b/tests/cases/fourslash/unusedTypeParametersInLambda2.ts @@ -6,4 +6,7 @@ //// [|new (a: T): void;|] //// } -verify.rangeAfterCodeFix("new (a: T): void;"); +verify.codeFix({ + description: "Remove declaration for: 'U'.", + newRangeContent: "new (a: T): void;", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInLambda3.ts b/tests/cases/fourslash/unusedTypeParametersInLambda3.ts index e6d866dcb6a..1f994c45905 100644 --- a/tests/cases/fourslash/unusedTypeParametersInLambda3.ts +++ b/tests/cases/fourslash/unusedTypeParametersInLambda3.ts @@ -7,4 +7,7 @@ //// [|new (a: T): A;|] //// } -verify.rangeAfterCodeFix("new (a: T): A;"); +verify.codeFix({ + description: "Remove declaration for: 'K'.", + newRangeContent: "new (a: T): A;", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInLambda4.ts b/tests/cases/fourslash/unusedTypeParametersInLambda4.ts index 04bd7c7e9be..d5c01202d26 100644 --- a/tests/cases/fourslash/unusedTypeParametersInLambda4.ts +++ b/tests/cases/fourslash/unusedTypeParametersInLambda4.ts @@ -6,4 +6,7 @@ //// } //// [|var y: new (a:T)=>void;|] -verify.rangeAfterCodeFix("var y: new (a:T)=>void;"); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'U'.", + newRangeContent: "var y: new (a:T)=>void;", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInMethod1.ts b/tests/cases/fourslash/unusedTypeParametersInMethod1.ts index bc14952eca9..f4d036f54f4 100644 --- a/tests/cases/fourslash/unusedTypeParametersInMethod1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInMethod1.ts @@ -5,4 +5,7 @@ //// [|f1()|] {} //// } -verify.rangeAfterCodeFix("f1()"); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'T'.", + newRangeContent: "f1()", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInMethod2.ts b/tests/cases/fourslash/unusedTypeParametersInMethod2.ts index c12fd53f66b..25556ebc57d 100644 --- a/tests/cases/fourslash/unusedTypeParametersInMethod2.ts +++ b/tests/cases/fourslash/unusedTypeParametersInMethod2.ts @@ -5,4 +5,7 @@ //// [|f1(a: U)|] {a;} //// } -verify.rangeAfterCodeFix("f1(a: U)"); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'T'.", + newRangeContent: "f1(a: U)", +}); diff --git a/tests/cases/fourslash/unusedTypeParametersInMethods1.ts b/tests/cases/fourslash/unusedTypeParametersInMethods1.ts index d0b170491f5..62f22246431 100644 --- a/tests/cases/fourslash/unusedTypeParametersInMethods1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInMethods1.ts @@ -5,4 +5,7 @@ //// [|public f1(a: X)|] { a; var b: Z; b } //// } -verify.rangeAfterCodeFix("public f1(a: X)"); +verify.codeFix({ + description: "Remove declaration for: 'Y'.", + newRangeContent: "public f1(a: X)", +}); diff --git a/tests/cases/fourslash/unusedVariableInBlocks.ts b/tests/cases/fourslash/unusedVariableInBlocks.ts index 2a33d0c4cf5..fe3c002916b 100644 --- a/tests/cases/fourslash/unusedVariableInBlocks.ts +++ b/tests/cases/fourslash/unusedVariableInBlocks.ts @@ -1,15 +1,18 @@ /// // @noUnusedLocals: true -//// function f1 () { +////function f1 () { //// [|let x = 10; //// { //// let x = 11; //// } //// x;|] -//// } +////} -verify.rangeAfterCodeFix(`let x = 10; - { - } - x;`); +verify.codeFix({ + description: "Remove declaration for: 'x'.", + newRangeContent: `let x = 10; + { + } + x;`, +}); diff --git a/tests/cases/fourslash/unusedVariableInClass1.ts b/tests/cases/fourslash/unusedVariableInClass1.ts index 8b0ca0db727..e4cec171e8e 100644 --- a/tests/cases/fourslash/unusedVariableInClass1.ts +++ b/tests/cases/fourslash/unusedVariableInClass1.ts @@ -5,4 +5,7 @@ //// [|private greeting: string;|] ////} -verify.rangeAfterCodeFix(""); +verify.codeFix({ + description: "Remove declaration for: 'greeting'.", + newRangeContent: "", +}); diff --git a/tests/cases/fourslash/unusedVariableInClass2.ts b/tests/cases/fourslash/unusedVariableInClass2.ts index 6503dd02872..1f632a43ce8 100644 --- a/tests/cases/fourslash/unusedVariableInClass2.ts +++ b/tests/cases/fourslash/unusedVariableInClass2.ts @@ -6,4 +6,7 @@ //// private greeting: string;|] ////} -verify.rangeAfterCodeFix("public greeting1;"); +verify.codeFix({ + description: "Remove declaration for: 'greeting'.", + newRangeContent: "public greeting1;\n", +}); diff --git a/tests/cases/fourslash/unusedVariableInClass3.ts b/tests/cases/fourslash/unusedVariableInClass3.ts index 3ac306170a2..eec4e6bbe8f 100644 --- a/tests/cases/fourslash/unusedVariableInClass3.ts +++ b/tests/cases/fourslash/unusedVariableInClass3.ts @@ -5,4 +5,7 @@ //// private X = function() {}; ////|]} -verify.rangeAfterCodeFix(""); +verify.codeFix({ + description: "Remove declaration for: 'X'.", + newRangeContent: "\n", +}); diff --git a/tests/cases/fourslash/unusedVariableInForLoop1FS.ts b/tests/cases/fourslash/unusedVariableInForLoop1FS.ts index 760d8487b34..2a4feffd474 100644 --- a/tests/cases/fourslash/unusedVariableInForLoop1FS.ts +++ b/tests/cases/fourslash/unusedVariableInForLoop1FS.ts @@ -7,5 +7,7 @@ //// } //// } -verify.rangeAfterCodeFix("for(; ;)"); - +verify.codeFix({ + description: "Remove declaration for: 'i'.", + newRangeContent: "for(; ;) ", +}); diff --git a/tests/cases/fourslash/unusedVariableInForLoop2FS.ts b/tests/cases/fourslash/unusedVariableInForLoop2FS.ts index a16f21e8417..d913ae5ce94 100644 --- a/tests/cases/fourslash/unusedVariableInForLoop2FS.ts +++ b/tests/cases/fourslash/unusedVariableInForLoop2FS.ts @@ -7,4 +7,7 @@ //// } //// } -verify.rangeAfterCodeFix("for(var i = 0; ;i++)"); +verify.codeFix({ + description: "Remove declaration for: 'j'.", + newRangeContent: "for(var i = 0; ;i++)", +}); diff --git a/tests/cases/fourslash/unusedVariableInForLoop3FS.ts b/tests/cases/fourslash/unusedVariableInForLoop3FS.ts index 07d13307ca7..6f3beae5c74 100644 --- a/tests/cases/fourslash/unusedVariableInForLoop3FS.ts +++ b/tests/cases/fourslash/unusedVariableInForLoop3FS.ts @@ -7,4 +7,7 @@ //// } //// } -verify.rangeAfterCodeFix("for(var i = 0, k=0; ;i++,k++)"); \ No newline at end of file +verify.codeFix({ + description: "Remove declaration for: 'j'.", + newRangeContent: "for(var i = 0, k=0; ;i++, k++)", +}); diff --git a/tests/cases/fourslash/unusedVariableInForLoop4FS.ts b/tests/cases/fourslash/unusedVariableInForLoop4FS.ts index d54f8baaa3d..661012958d4 100644 --- a/tests/cases/fourslash/unusedVariableInForLoop4FS.ts +++ b/tests/cases/fourslash/unusedVariableInForLoop4FS.ts @@ -7,4 +7,7 @@ //// } //// } -verify.rangeAfterCodeFix("for(var j = 0, k=0; ;j++,k++)"); +verify.codeFix({ + description: "Remove declaration for: 'i'.", + newRangeContent: "for(var j= 0, k=0; ;j++, k++) ", +}); diff --git a/tests/cases/fourslash/unusedVariableInForLoop5FSAddUnderscore.ts b/tests/cases/fourslash/unusedVariableInForLoop5FSAddUnderscore.ts index 2948bfab207..87783ff67fc 100644 --- a/tests/cases/fourslash/unusedVariableInForLoop5FSAddUnderscore.ts +++ b/tests/cases/fourslash/unusedVariableInForLoop5FSAddUnderscore.ts @@ -7,4 +7,7 @@ //// } //// } -verify.rangeAfterCodeFix(`for (const _elem in ["a", "b", "c"])`, /*includeWhiteSpace*/ true, /*errorCode*/ 0); +verify.codeFix({ + description: "Prefix 'elem' with an underscore.", + newRangeContent: 'for (const _elem in ["a", "b", "c"])' +}); diff --git a/tests/cases/fourslash/unusedVariableInForLoop6FS.ts b/tests/cases/fourslash/unusedVariableInForLoop6FS.ts index fa1948438bc..9661514d431 100644 --- a/tests/cases/fourslash/unusedVariableInForLoop6FS.ts +++ b/tests/cases/fourslash/unusedVariableInForLoop6FS.ts @@ -7,5 +7,8 @@ //// } //// } -verify.rangeAfterCodeFix("const {} of ", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0); - +verify.codeFix({ + description: "Remove declaration for: 'elem'.", + index: 0, + newRangeContent: "const {} of", +}); diff --git a/tests/cases/fourslash/unusedVariableInForLoop6FSAddUnderscore.ts b/tests/cases/fourslash/unusedVariableInForLoop6FSAddUnderscore.ts index 4faa6893b7f..9f8c7b19f99 100644 --- a/tests/cases/fourslash/unusedVariableInForLoop6FSAddUnderscore.ts +++ b/tests/cases/fourslash/unusedVariableInForLoop6FSAddUnderscore.ts @@ -7,5 +7,9 @@ //// } //// } -verify.rangeAfterCodeFix("const _elem of", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 1); +verify.codeFix({ + description: "Prefix 'elem' with an underscore.", + index: 1, + newRangeContent: "const _elem of" +}); diff --git a/tests/cases/fourslash/unusedVariableInForLoop7FS.ts b/tests/cases/fourslash/unusedVariableInForLoop7FS.ts index 7f99863ba46..c42bf8bc97a 100644 --- a/tests/cases/fourslash/unusedVariableInForLoop7FS.ts +++ b/tests/cases/fourslash/unusedVariableInForLoop7FS.ts @@ -9,8 +9,11 @@ ////}|] //// -verify.rangeAfterCodeFix(`{ +verify.codeFix({ + description: "Remove declaration for: 'x'.", + newRangeContent: `{ for (const elem of ["a", "b", "c"]) { elem; } -}`, /*includeWhiteSpace*/ true); +}` +}); diff --git a/tests/cases/fourslash/unusedVariableInModule1.ts b/tests/cases/fourslash/unusedVariableInModule1.ts index e9fe9515e6d..7a0a3ad8601 100644 --- a/tests/cases/fourslash/unusedVariableInModule1.ts +++ b/tests/cases/fourslash/unusedVariableInModule1.ts @@ -6,4 +6,7 @@ //// [|var x: string; //// export var y: string;|] -verify.rangeAfterCodeFix("export var y: string;"); +verify.codeFix({ + description: "Remove declaration for: 'x'.", + newRangeContent: "export var y: string;", +}); diff --git a/tests/cases/fourslash/unusedVariableInModule2.ts b/tests/cases/fourslash/unusedVariableInModule2.ts index ac6e7120d8b..e8a1ae762d4 100644 --- a/tests/cases/fourslash/unusedVariableInModule2.ts +++ b/tests/cases/fourslash/unusedVariableInModule2.ts @@ -7,4 +7,7 @@ //// z; //// export var y: string; -verify.rangeAfterCodeFix("var z: number;"); +verify.codeFix({ + description: "Remove declaration for: 'x'.", + newRangeContent: "var z: number;", +}); diff --git a/tests/cases/fourslash/unusedVariableInModule3.ts b/tests/cases/fourslash/unusedVariableInModule3.ts index 0185b89e3a6..56b08f5499e 100644 --- a/tests/cases/fourslash/unusedVariableInModule3.ts +++ b/tests/cases/fourslash/unusedVariableInModule3.ts @@ -6,4 +6,7 @@ //// [|var x = function f1() {} //// export var y: string;|] -verify.rangeAfterCodeFix("export var y: string;"); +verify.codeFix({ + description: "Remove declaration for: 'x'.", + newRangeContent: "export var y: string;", +}); diff --git a/tests/cases/fourslash/unusedVariableInModule4.ts b/tests/cases/fourslash/unusedVariableInModule4.ts index 6d80d59c2ce..71890893b9e 100644 --- a/tests/cases/fourslash/unusedVariableInModule4.ts +++ b/tests/cases/fourslash/unusedVariableInModule4.ts @@ -7,4 +7,8 @@ //// x; //// export var y: string; -verify.rangeAfterCodeFix(`var x = function f1() {}`, /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0); +verify.codeFix({ + description: "Remove declaration for: 'm'.", + index: 0, + newRangeContent: `var x = function f1() {}`, +}); diff --git a/tests/cases/fourslash/unusedVariableInNamespace1.ts b/tests/cases/fourslash/unusedVariableInNamespace1.ts index c9f38473a51..6dd14233683 100644 --- a/tests/cases/fourslash/unusedVariableInNamespace1.ts +++ b/tests/cases/fourslash/unusedVariableInNamespace1.ts @@ -5,4 +5,7 @@ //// [|let a = "dummy entry";|] ////} -verify.rangeAfterCodeFix(""); +verify.codeFix({ + description: "Remove declaration for: 'a'.", + newRangeContent: "", +}); diff --git a/tests/cases/fourslash/unusedVariableInNamespace2.ts b/tests/cases/fourslash/unusedVariableInNamespace2.ts index 61fc3ec137c..9bf546f6f53 100644 --- a/tests/cases/fourslash/unusedVariableInNamespace2.ts +++ b/tests/cases/fourslash/unusedVariableInNamespace2.ts @@ -8,4 +8,7 @@ //// } ////} -verify.rangeAfterCodeFix(`let a = "dummy entry", c = 0;`); +verify.codeFix({ + description: "Remove declaration for: 'b'.", + newRangeContent: 'let a = "dummy entry", c = 0;', +}); diff --git a/tests/cases/fourslash/unusedVariableInNamespace3.ts b/tests/cases/fourslash/unusedVariableInNamespace3.ts index 7d2f3d251f3..85e1889c3e1 100644 --- a/tests/cases/fourslash/unusedVariableInNamespace3.ts +++ b/tests/cases/fourslash/unusedVariableInNamespace3.ts @@ -8,4 +8,7 @@ //// } ////} -verify.rangeAfterCodeFix(`let a = "dummy entry", b;`); +verify.codeFix({ + description: "Remove declaration for: 'c'.", + newRangeContent: 'let a = "dummy entry", b;', +});