From 5625cb023743215d4721bf07b2d41f831399977d Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Tue, 24 Sep 2019 17:31:12 -0700 Subject: [PATCH] Omit last element semicolon from single-line object-like types --- src/server/protocol.ts | 2 + src/services/formatting/rules.ts | 11 +++- src/services/textChanges.ts | 4 +- src/services/types.ts | 2 + src/services/utilities.ts | 54 +++++++++++++++---- .../reference/api/tsserverlibrary.d.ts | 4 +- tests/baselines/reference/api/typescript.d.ts | 2 +- ...on_catchBlockUniqueParamsBindingPattern.ts | 2 +- ...tFunction_VariableDeclaration_Multiple1.ts | 2 +- ...tFunction_VariableDeclaration_Multiple3.ts | 2 +- ...ction_VariableDeclaration_Writes_Mixed3.ts | 2 +- ...riableDeclaration_Writes_UnionUndefined.ts | 2 +- .../fourslash/annotateWithTypeFromJSDoc22.ts | 2 +- .../fourslash/annotateWithTypeFromJSDoc3.ts | 2 +- .../fourslash/annotateWithTypeFromJSDoc4.ts | 2 +- ...FixClassImplementInterfaceObjectLiteral.ts | 2 +- ...assImplementInterfacePropertySignatures.ts | 12 ++--- ...ImplementInterfaceSomePropertiesPresent.ts | 2 +- ...mentInterfaceTypeParamInstantiateDeeply.ts | 2 +- .../codeFixInferFromCallInAssignment.ts | 2 +- .../codeFixInferFromExpressionStatement.ts | 2 +- ...ixInferFromFunctionThisUsageImplicitAny.ts | 2 +- ...odeFixInferFromFunctionThisUsageLiteral.ts | 2 +- .../codeFixInferFromFunctionUsage.ts | 2 +- .../codeFixInferFromUsageEmptyTypePriority.ts | 2 +- .../codeFixInferFromUsageJSXElement.ts | 2 +- ...codeFixInferFromUsageMultipleParameters.ts | 2 +- .../codeFixInferFromUsagePropertyAccess.ts | 2 +- ...deFixInferFromUsageStringIndexSignature.ts | 2 +- ...codeFixInferFromUsageUnifyAnonymousType.ts | 2 +- ...odeFixUndeclaredMethodObjectLiteralArgs.ts | 12 ++--- .../codeFixUndeclaredPropertyObjectLiteral.ts | 2 +- ...edPropertyObjectLiteralStrictNullChecks.ts | 2 +- .../extract-const-callback-function-this1.ts | 2 +- .../extract-const-callback-function-this2.ts | 2 +- tests/cases/fourslash/extract-method18.ts | 2 +- tests/cases/fourslash/extract-method2.ts | 2 +- tests/cases/fourslash/formatAddSemicolons1.ts | 2 +- ...sToDestructuredObject_allParamsOptional.ts | 2 +- ...aramsToDestructuredObject_arrowFunction.ts | 2 +- ...ParamsToDestructuredObject_callComments.ts | 2 +- ...aramsToDestructuredObject_callComments2.ts | 2 +- ...tParamsToDestructuredObject_chainedCall.ts | 2 +- ...cturedObject_classDeclarationGoodUsages.ts | 2 +- ...amsToDestructuredObject_classExpression.ts | 2 +- ...ucturedObject_classExpressionGoodUsages.ts | 2 +- ...oDestructuredObject_classTypeParameters.ts | 2 +- ...tParamsToDestructuredObject_constructor.ts | 2 +- ...vertParamsToDestructuredObject_function.ts | 2 +- ...msToDestructuredObject_functionComments.ts | 2 +- ...sToDestructuredObject_functionComments1.ts | 2 +- ...ToDestructuredObject_functionExpression.ts | 2 +- ...structuredObject_functionTypeParameters.ts | 2 +- ...msToDestructuredObject_importedFunction.ts | 2 +- ...sToDestructuredObject_importedFunction2.ts | 2 +- ...sToDestructuredObject_importedFunction3.ts | 2 +- ...sToDestructuredObject_importedFunction4.ts | 2 +- ...sToDestructuredObject_importedFunction5.ts | 2 +- ...sToDestructuredObject_importedFunction6.ts | 2 +- ...DestructuredObject_inheritedConstructor.ts | 2 +- ...amsToDestructuredObject_inheritedMethod.ts | 2 +- ...tParamsToDestructuredObject_initializer.ts | 2 +- ...DestructuredObject_initializerInference.ts | 2 +- ...onvertParamsToDestructuredObject_method.ts | 2 +- ...tParamsToDestructuredObject_methodCalls.ts | 2 +- ...aramsToDestructuredObject_namelessClass.ts | 2 +- ...sToDestructuredObject_recursiveFunction.ts | 2 +- ...ToDestructuredObject_restParamInference.ts | 2 +- ...sToDestructuredObject_shorthandProperty.ts | 2 +- ...ParamsToDestructuredObject_staticMethod.ts | 2 +- ...ertParamsToDestructuredObject_superCall.ts | 2 +- ...amsToDestructuredObject_templateLiteral.ts | 2 +- ...ertParamsToDestructuredObject_thisParam.ts | 2 +- ...ramsToDestructuredObject_tupleRestParam.ts | 8 +-- ...ramsToDestructuredObject_typedRestParam.ts | 2 +- .../fourslash/typeToStringCrashInCodeFix.ts | 2 +- 76 files changed, 144 insertions(+), 99 deletions(-) diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 0ec27a3a2bb..745284524e7 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2960,6 +2960,8 @@ namespace ts.server.protocol { Ignore = "ignore", Insert = "insert", Remove = "remove", + /*@internal*/ + RemoveUnconventional = "remove-unconventional" } export interface EditorSettings { diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 7fa2845edc0..2fe396c2677 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -314,6 +314,7 @@ namespace ts.formatting { rule("SpaceBeforeTypeAnnotation", anyToken, SyntaxKind.ColonToken, [isOptionEnabled("insertSpaceBeforeTypeAnnotation"), isNonJsxSameLineTokenContext, isTypeAnnotationContext], RuleAction.Space), rule("NoSpaceBeforeTypeAnnotation", anyToken, SyntaxKind.ColonToken, [isOptionDisabledOrUndefined("insertSpaceBeforeTypeAnnotation"), isNonJsxSameLineTokenContext, isTypeAnnotationContext], RuleAction.DeleteTrivia), rule("NoOptionalSemicolon", SyntaxKind.SemicolonToken, anyTokenIncludingEOF, [optionEquals("semicolons", SemicolonPreference.Remove), isSemicolonDeletionContext], RuleAction.DeleteToken), + rule("NoUnconventionalSemicolon", SyntaxKind.SemicolonToken, anyTokenIncludingEOF, [optionEquals("semicolons", SemicolonPreference.RemoveUnconventional), isUnconventionalSemicolonDeletionContext], RuleAction.DeleteToken), rule("OptionalSemicolon", anyToken, anyTokenIncludingEOF, [optionEquals("semicolons", SemicolonPreference.Insert), isSemicolonInsertionContext], RuleAction.TrailingSemicolon), ]; @@ -790,6 +791,14 @@ namespace ts.formatting { return context.contextNode.kind === SyntaxKind.NonNullExpression; } + function isUnconventionalSemicolonDeletionContext(context: FormattingContext): boolean { + return nodeAllowsUnconventionalTrailingSemicolon( + context.currentTokenParent, + context.contextNode, + context.nextTokenSpan.kind, + context.sourceFile); + } + function isSemicolonDeletionContext(context: FormattingContext): boolean { let nextTokenKind = context.nextTokenSpan.kind; let nextTokenStart = context.nextTokenSpan.pos; @@ -859,7 +868,7 @@ namespace ts.formatting { if (ancestor.end !== context.currentTokenSpan.end) { return "quit"; } - return syntaxMayBeASICandidate(ancestor.kind); + return nodeMayBeASICandidate(ancestor); }); return !!contextAncestor && isASICandidate(contextAncestor, context.sourceFile); diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index dd690c8824e..a47ef6684c8 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -836,12 +836,12 @@ namespace ts.textChanges { return { ...context.options, // If the user has no semicolon preference defined and the file doesn’t use semicolons, - // make the formatter remove them. Otherwise, ignore semicolons in the formatter because + // make the formatter remove them. Otherwise, only remove unconventional semicolons because // the writer will insert them by default. semicolons: context.options.semicolons === SemicolonPreference.Remove || (!context.options.semicolons || context.options.semicolons === SemicolonPreference.Ignore) && !probablyUsesSemicolons(sourceFile) ? SemicolonPreference.Remove - : SemicolonPreference.Ignore, + : SemicolonPreference.RemoveUnconventional, }; } diff --git a/src/services/types.ts b/src/services/types.ts index 75e8b2680ef..702132d4175 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -684,6 +684,8 @@ namespace ts { Ignore = "ignore", Insert = "insert", Remove = "remove", + /*@internal*/ + RemoveUnconventional = "remove-unconventional" } /* @deprecated - consider using EditorSettings instead */ diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 5f59cef602b..e657634c0f5 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2027,13 +2027,37 @@ namespace ts { || kind === SyntaxKind.ExportAssignment; } - export const syntaxMayBeASICandidate = or( - syntaxRequiresTrailingCommaOrSemicolonOrASI, - syntaxRequiresTrailingFunctionBlockOrSemicolonOrASI, - syntaxRequiresTrailingModuleBlockOrSemicolonOrASI, - syntaxRequiresTrailingSemicolonOrASI); + function isMappedTypeNodeType(node: Node) { + return node.parent && isMappedTypeNode(node.parent) && node.parent.type === node; + } - export function isASICandidate(node: Node, sourceFile: SourceFileLike): boolean { + export function nodeMayBeASICandidate(node: Node) { + if (syntaxRequiresTrailingCommaOrSemicolonOrASI(node.kind) || + syntaxRequiresTrailingFunctionBlockOrSemicolonOrASI(node.kind) || + syntaxRequiresTrailingModuleBlockOrSemicolonOrASI(node.kind) || + syntaxRequiresTrailingSemicolonOrASI(node.kind)) { + return true; + } + return isMappedTypeNodeType(node); + } + + export function nodeAllowsUnconventionalTrailingSemicolon(node: Node, contextNode: Node, nextTokenKind: SyntaxKind | undefined, sourceFile: SourceFileLike) { + if (isMappedTypeNodeType(node)) { + return rangeIsOnSingleLine(contextNode, sourceFile as SourceFile); + } + if (syntaxRequiresTrailingCommaOrSemicolonOrASI(node.kind)) { + return nextTokenKind === SyntaxKind.CloseBraceToken && rangeIsOnSingleLine(contextNode, sourceFile as SourceFile); + } + return false; + } + + /** + * @param strict Return true for positions that allow semicolons but conventionally + * drop them, even in code that largely contains semicolons. Examples include the last + * declaration inside the curly braces of single-line object type literals and mapped types, + * e.g. `type X = { x: string; }` and `type X = { [K in keyof T]: T[K]; }`. + */ + export function isASICandidate(node: Node, sourceFile: SourceFileLike, strict?: boolean): boolean { const lastToken = node.getLastToken(sourceFile); if (lastToken && lastToken.kind === SyntaxKind.SemicolonToken) { return false; @@ -2060,20 +2084,28 @@ namespace ts { return false; } + let nextToken = getNextToken(); + const contextNode = findAncestor(node, or(isObjectTypeDeclaration, isMappedTypeNode)); + if (contextNode && nodeAllowsUnconventionalTrailingSemicolon(node, contextNode, nextToken && nextToken.kind, sourceFile)) { + return !!strict; + } + // See comment in parser’s `parseDoStatement` if (node.kind === SyntaxKind.DoStatement) { return true; } - const topNode = findAncestor(node, ancestor => !ancestor.parent)!; - const nextToken = findNextToken(node, topNode, sourceFile); if (!nextToken || nextToken.kind === SyntaxKind.CloseBraceToken) { return true; } - const startLine = sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line; - const endLine = sourceFile.getLineAndCharacterOfPosition(nextToken.getStart(sourceFile)).line; - return startLine !== endLine; + return !positionsAreOnSameLine(node.getEnd(), + nextToken.getStart(sourceFile), + sourceFile as SourceFile); + + function getNextToken(): Node | undefined { + return nextToken || (nextToken = findNextToken(node, findAncestor(node, ancestor => !ancestor.parent)!, sourceFile)); + } } export function probablyUsesSemicolons(sourceFile: SourceFile): boolean { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index ca07eebc536..98273495b75 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5297,7 +5297,7 @@ declare namespace ts { enum SemicolonPreference { Ignore = "ignore", Insert = "insert", - Remove = "remove" + Remove = "remove", } interface EditorOptions { BaseIndentSize?: number; @@ -8202,7 +8202,7 @@ declare namespace ts.server.protocol { enum SemicolonPreference { Ignore = "ignore", Insert = "insert", - Remove = "remove" + Remove = "remove", } interface EditorSettings { baseIndentSize?: number; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index d24f1e9c89c..1134469dc33 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5297,7 +5297,7 @@ declare namespace ts { enum SemicolonPreference { Ignore = "ignore", Insert = "insert", - Remove = "remove" + Remove = "remove", } interface EditorOptions { BaseIndentSize?: number; diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.ts index ff7ac4bc944..5766e096dda 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.ts @@ -7,7 +7,7 @@ function /*[#|*/f/*|]*/() { // ==ASYNC FUNCTION::Convert to async function== async function f() { - let result: { x: number; } | { x: string; }; + let result: { x: number } | { x: string }; try { await Promise.resolve(); result = ({ x: 3 }); diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Multiple1.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Multiple1.ts index 07ec452e360..7194456b850 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Multiple1.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Multiple1.ts @@ -5,7 +5,7 @@ x; y; // ==SCOPE::Extract to function in global scope== -const { x, y }: { x: number; y: string; } = /*RENAME*/newFunction(); +const { x, y }: { x: number; y: string } = /*RENAME*/newFunction(); x; y; function newFunction() { diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Multiple3.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Multiple3.ts index b8ae2b72883..06da60f571b 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Multiple3.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Multiple3.ts @@ -6,7 +6,7 @@ x; y; z; // ==SCOPE::Extract to function in global scope== -var { x, y, z }: { x: number; y: string; z: number; } = /*RENAME*/newFunction(); +var { x, y, z }: { x: number; y: string; z: number } = /*RENAME*/newFunction(); x; y; z; function newFunction() { diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed3.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed3.ts index b2c53e3f160..f4bfb66dea8 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed3.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed3.ts @@ -11,7 +11,7 @@ function f() { function f() { let a = 1; - let { x, y }: { x: number; y: number; } = /*RENAME*/newFunction(); + let { x, y }: { x: number; y: number } = /*RENAME*/newFunction(); a; x; y; function newFunction() { diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_UnionUndefined.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_UnionUndefined.ts index b76bf6c4999..7f216b3365b 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_UnionUndefined.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_UnionUndefined.ts @@ -12,7 +12,7 @@ function f() { function f() { let a = 1; - let { x, y, z }: { x: number; y: number; z: number; } = /*RENAME*/newFunction(); + let { x, y, z }: { x: number; y: number; z: number } = /*RENAME*/newFunction(); a; x; y; z; function newFunction() { diff --git a/tests/cases/fourslash/annotateWithTypeFromJSDoc22.ts b/tests/cases/fourslash/annotateWithTypeFromJSDoc22.ts index 98ccf84c3d6..a8f6fa7a1ad 100644 --- a/tests/cases/fourslash/annotateWithTypeFromJSDoc22.ts +++ b/tests/cases/fourslash/annotateWithTypeFromJSDoc22.ts @@ -14,7 +14,7 @@ verify.codeFix({ ` /** @param {Object} sb * @param {Object} ns */ -function f(sb: { [s: string]: boolean; }, ns: { [n: number]: string; }) { +function f(sb: { [s: string]: boolean }, ns: { [n: number]: string }) { sb; ns; }`, }); diff --git a/tests/cases/fourslash/annotateWithTypeFromJSDoc3.ts b/tests/cases/fourslash/annotateWithTypeFromJSDoc3.ts index f7d0522018a..a4234127c46 100644 --- a/tests/cases/fourslash/annotateWithTypeFromJSDoc3.ts +++ b/tests/cases/fourslash/annotateWithTypeFromJSDoc3.ts @@ -30,7 +30,7 @@ verify.codeFix({ * @param alpha - the other best parameter * @param {*} beta - I have no idea how this got here */ -function f(x: number, y: { a: string; b: Date; }, z: string, alpha, beta: any) { +function f(x: number, y: { a: string; b: Date }, z: string, alpha, beta: any) { x; y; z; alpha; beta; }`, }); diff --git a/tests/cases/fourslash/annotateWithTypeFromJSDoc4.ts b/tests/cases/fourslash/annotateWithTypeFromJSDoc4.ts index 4421afbd867..e432e8f0b20 100644 --- a/tests/cases/fourslash/annotateWithTypeFromJSDoc4.ts +++ b/tests/cases/fourslash/annotateWithTypeFromJSDoc4.ts @@ -26,7 +26,7 @@ verify.codeFix({ * @param {number?} gamma * @param {number!} delta */ -function f(x: any, y: any, z: number | undefined, alpha: number[], beta: (this: { a: string; }, arg1: string, arg2: number) => boolean, gamma: number | null, delta: number) { +function f(x: any, y: any, z: number | undefined, alpha: number[], beta: (this: { a: string }, arg1: string, arg2: number) => boolean, gamma: number | null, delta: number) { x; y; z; alpha; beta; gamma; delta; }`, }); diff --git a/tests/cases/fourslash/codeFixClassImplementInterfaceObjectLiteral.ts b/tests/cases/fourslash/codeFixClassImplementInterfaceObjectLiteral.ts index f2e05b24f57..dba46a50050 100644 --- a/tests/cases/fourslash/codeFixClassImplementInterfaceObjectLiteral.ts +++ b/tests/cases/fourslash/codeFixClassImplementInterfaceObjectLiteral.ts @@ -18,6 +18,6 @@ verify.codeFix({ } } class Person implements IPerson { - coordinate: { x: number; y: number; }; + coordinate: { x: number; y: number }; }`, }); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixClassImplementInterfacePropertySignatures.ts b/tests/cases/fourslash/codeFixClassImplementInterfacePropertySignatures.ts index 52d69b466fd..778aca58dc1 100644 --- a/tests/cases/fourslash/codeFixClassImplementInterfacePropertySignatures.ts +++ b/tests/cases/fourslash/codeFixClassImplementInterfacePropertySignatures.ts @@ -43,13 +43,13 @@ class C implements I { a0: {}; a1: (b1: number, c1: string) => number; a2: (b2: number, c2: string) => number; - a3: { (b3: number, c3: string): number; x: number; }; + a3: { (b3: number, c3: string): number; x: number }; a4: new (b1: number, c1: string) => number; a5: new (b2: number, c2: string) => number; - a6: { new(b3: number, c3: string): number; x: number; }; - a7: { foo(b7: number, c7: string): number; }; - a8: { (b81: number, c81: string): number; new(b82: number, c82: string): number; }; - a9: { (b9: number, c9: string): number;[d9: number]: I; }; - a10: { (b10: number, c10: string): number;[d10: string]: I; }; + a6: { new(b3: number, c3: string): number; x: number }; + a7: { foo(b7: number, c7: string): number }; + a8: { (b81: number, c81: string): number; new(b82: number, c82: string): number }; + a9: { (b9: number, c9: string): number;[d9: number]: I }; + a10: { (b10: number, c10: string): number;[d10: string]: I }; }`, }); diff --git a/tests/cases/fourslash/codeFixClassImplementInterfaceSomePropertiesPresent.ts b/tests/cases/fourslash/codeFixClassImplementInterfaceSomePropertiesPresent.ts index e667783b995..f43a02886d5 100644 --- a/tests/cases/fourslash/codeFixClassImplementInterfaceSomePropertiesPresent.ts +++ b/tests/cases/fourslash/codeFixClassImplementInterfaceSomePropertiesPresent.ts @@ -12,5 +12,5 @@ //// } verify.rangeAfterCodeFix(` -z: number & { __iBrand: any; }; +z: number & { __iBrand: any }; `); diff --git a/tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamInstantiateDeeply.ts b/tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamInstantiateDeeply.ts index cf8926ff33e..6b396a23cdd 100644 --- a/tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamInstantiateDeeply.ts +++ b/tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamInstantiateDeeply.ts @@ -12,6 +12,6 @@ verify.codeFix({ x: { y: T, z: T[] }; } class C implements I { - x: { y: number; z: number[]; }; + x: { y: number; z: number[] }; }`, }); diff --git a/tests/cases/fourslash/codeFixInferFromCallInAssignment.ts b/tests/cases/fourslash/codeFixInferFromCallInAssignment.ts index 85e1d3bc509..5eb564b8305 100644 --- a/tests/cases/fourslash/codeFixInferFromCallInAssignment.ts +++ b/tests/cases/fourslash/codeFixInferFromCallInAssignment.ts @@ -6,4 +6,4 @@ //// return result //// } -verify.rangeAfterCodeFix("app: { use: (arg0: string) => any; }"); +verify.rangeAfterCodeFix("app: { use: (arg0: string) => any }"); diff --git a/tests/cases/fourslash/codeFixInferFromExpressionStatement.ts b/tests/cases/fourslash/codeFixInferFromExpressionStatement.ts index b5969c79378..282df322de0 100644 --- a/tests/cases/fourslash/codeFixInferFromExpressionStatement.ts +++ b/tests/cases/fourslash/codeFixInferFromExpressionStatement.ts @@ -5,4 +5,4 @@ //// app.use('hi') //// } -verify.rangeAfterCodeFix("app: { use: (arg0: string) => void; }"); +verify.rangeAfterCodeFix("app: { use: (arg0: string) => void }"); diff --git a/tests/cases/fourslash/codeFixInferFromFunctionThisUsageImplicitAny.ts b/tests/cases/fourslash/codeFixInferFromFunctionThisUsageImplicitAny.ts index 3f71ae9ddd2..f7a0191b8f7 100644 --- a/tests/cases/fourslash/codeFixInferFromFunctionThisUsageImplicitAny.ts +++ b/tests/cases/fourslash/codeFixInferFromFunctionThisUsageImplicitAny.ts @@ -21,5 +21,5 @@ verify.codeFix({ description: "Infer 'this' type of 'returnThisMember' from usage", index: 0, - newRangeContent: "this: { member: string; returnThisMember: () => any; } ", + newRangeContent: "this: { member: string; returnThisMember: () => any } ", }); diff --git a/tests/cases/fourslash/codeFixInferFromFunctionThisUsageLiteral.ts b/tests/cases/fourslash/codeFixInferFromFunctionThisUsageLiteral.ts index f626e4cba2d..ccee3d37fc6 100644 --- a/tests/cases/fourslash/codeFixInferFromFunctionThisUsageLiteral.ts +++ b/tests/cases/fourslash/codeFixInferFromFunctionThisUsageLiteral.ts @@ -13,5 +13,5 @@ verify.codeFix({ description: "Infer 'this' type of 'returnThisMember' from usage", index: 0, - newRangeContent: "this: { member: string; returnThisMember: () => any; } ", + newRangeContent: "this: { member: string; returnThisMember: () => any } ", }); diff --git a/tests/cases/fourslash/codeFixInferFromFunctionUsage.ts b/tests/cases/fourslash/codeFixInferFromFunctionUsage.ts index 31068469b4d..dc059ef1945 100644 --- a/tests/cases/fourslash/codeFixInferFromFunctionUsage.ts +++ b/tests/cases/fourslash/codeFixInferFromFunctionUsage.ts @@ -6,4 +6,4 @@ //// } // https://github.com/Microsoft/TypeScript/issues/29330 -verify.rangeAfterCodeFix("arr: { other: (arg0: (a: number, b: number) => 1 | -1) => void; }"); +verify.rangeAfterCodeFix("arr: { other: (arg0: (a: number, b: number) => 1 | -1) => void }"); diff --git a/tests/cases/fourslash/codeFixInferFromUsageEmptyTypePriority.ts b/tests/cases/fourslash/codeFixInferFromUsageEmptyTypePriority.ts index e9288303781..c655138cf8c 100644 --- a/tests/cases/fourslash/codeFixInferFromUsageEmptyTypePriority.ts +++ b/tests/cases/fourslash/codeFixInferFromUsageEmptyTypePriority.ts @@ -10,4 +10,4 @@ //// var beforeExpr = !!conf.beforeExpr; ////}; -verify.rangeAfterCodeFix("label: any, conf: { keyword?: any; beforeExpr?: any; } | undefined",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0); +verify.rangeAfterCodeFix("label: any, conf: { keyword?: any; beforeExpr?: any } | undefined",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0); diff --git a/tests/cases/fourslash/codeFixInferFromUsageJSXElement.ts b/tests/cases/fourslash/codeFixInferFromUsageJSXElement.ts index abe35fe46c8..86c2d747b24 100644 --- a/tests/cases/fourslash/codeFixInferFromUsageJSXElement.ts +++ b/tests/cases/fourslash/codeFixInferFromUsageJSXElement.ts @@ -30,4 +30,4 @@ //// } -verify.rangeAfterCodeFix("props: { isLoading: any; update: (arg0: any) => any; }",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0); +verify.rangeAfterCodeFix("props: { isLoading: any; update: (arg0: any) => any }",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0); diff --git a/tests/cases/fourslash/codeFixInferFromUsageMultipleParameters.ts b/tests/cases/fourslash/codeFixInferFromUsageMultipleParameters.ts index 89e2c935e87..d17a250cdf7 100644 --- a/tests/cases/fourslash/codeFixInferFromUsageMultipleParameters.ts +++ b/tests/cases/fourslash/codeFixInferFromUsageMultipleParameters.ts @@ -6,4 +6,4 @@ //// f(1, "string", { a: 1 }, {shouldNotBeHere: 2}, {shouldNotBeHere: 2}, 3, "string"); -verify.rangeAfterCodeFix("a: number, b: string, c: { a: number; }, d: number, e = 0, ...d: (string | number)[]", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 1); +verify.rangeAfterCodeFix("a: number, b: string, c: { a: number }, d: number, e = 0, ...d: (string | number)[]", /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 1); diff --git a/tests/cases/fourslash/codeFixInferFromUsagePropertyAccess.ts b/tests/cases/fourslash/codeFixInferFromUsagePropertyAccess.ts index 44d2e2d7b1c..94270415f54 100644 --- a/tests/cases/fourslash/codeFixInferFromUsagePropertyAccess.ts +++ b/tests/cases/fourslash/codeFixInferFromUsagePropertyAccess.ts @@ -12,4 +12,4 @@ //// return x.y.z ////} -verify.rangeAfterCodeFix("a: { b: { c: void; }; }, m: { n: () => number; }, x: { y: { z: number[]; }; }", /*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, /*index*/0); +verify.rangeAfterCodeFix("a: { b: { c: void } }, m: { n: () => number }, x: { y: { z: number[] } }", /*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, /*index*/0); diff --git a/tests/cases/fourslash/codeFixInferFromUsageStringIndexSignature.ts b/tests/cases/fourslash/codeFixInferFromUsageStringIndexSignature.ts index 765f788e054..9213df8222a 100644 --- a/tests/cases/fourslash/codeFixInferFromUsageStringIndexSignature.ts +++ b/tests/cases/fourslash/codeFixInferFromUsageStringIndexSignature.ts @@ -5,4 +5,4 @@ //// return a['hi']; ////} -verify.rangeAfterCodeFix("a: { [x: string]: any; }",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0); +verify.rangeAfterCodeFix("a: { [x: string]: any }",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0); diff --git a/tests/cases/fourslash/codeFixInferFromUsageUnifyAnonymousType.ts b/tests/cases/fourslash/codeFixInferFromUsageUnifyAnonymousType.ts index 76e25ab0fe7..a4919e4bc17 100644 --- a/tests/cases/fourslash/codeFixInferFromUsageUnifyAnonymousType.ts +++ b/tests/cases/fourslash/codeFixInferFromUsageUnifyAnonymousType.ts @@ -16,4 +16,4 @@ ////kw("6", { beforeExpr: true, prefix: true, startsExpr: true }) -verify.rangeAfterCodeFix("name: string, options: { startsExpr?: boolean; beforeExpr?: boolean; isLoop?: boolean; prefix?: boolean; keyword?: any; } | undefined",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0); +verify.rangeAfterCodeFix("name: string, options: { startsExpr?: boolean; beforeExpr?: boolean; isLoop?: boolean; prefix?: boolean; keyword?: any } | undefined",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0); diff --git a/tests/cases/fourslash/codeFixUndeclaredMethodObjectLiteralArgs.ts b/tests/cases/fourslash/codeFixUndeclaredMethodObjectLiteralArgs.ts index 5c0698ad653..06b28552dc0 100644 --- a/tests/cases/fourslash/codeFixUndeclaredMethodObjectLiteralArgs.ts +++ b/tests/cases/fourslash/codeFixUndeclaredMethodObjectLiteralArgs.ts @@ -12,7 +12,7 @@ verify.codeFix({ description: "Declare method 'foo1'", index: 0, newRangeContent: ` - foo1(arg0: null, arg1: {}, arg2: { a: number; b: string; }) { + foo1(arg0: null, arg1: {}, arg2: { a: number; b: string }) { throw new Error("Method not implemented."); } `, @@ -23,10 +23,10 @@ verify.codeFix({ description: "Declare method 'foo2'", index: 0, newRangeContent: ` - foo2(arg0: null, arg1: {}, arg2: { a: number; b: string; }) { + foo2(arg0: null, arg1: {}, arg2: { a: number; b: string }) { throw new Error("Method not implemented."); } - foo1(arg0: null, arg1: {}, arg2: { a: number; b: string; }) { + foo1(arg0: null, arg1: {}, arg2: { a: number; b: string }) { throw new Error("Method not implemented."); } `, @@ -37,13 +37,13 @@ verify.codeFix({ description: "Declare method 'foo3'", index: 0, newRangeContent: ` - foo3(arg0: null, arg1: {}, arg2: { a: number; b: string; }): number { + foo3(arg0: null, arg1: {}, arg2: { a: number; b: string }): number { throw new Error("Method not implemented."); } - foo2(arg0: null, arg1: {}, arg2: { a: number; b: string; }) { + foo2(arg0: null, arg1: {}, arg2: { a: number; b: string }) { throw new Error("Method not implemented."); } - foo1(arg0: null, arg1: {}, arg2: { a: number; b: string; }) { + foo1(arg0: null, arg1: {}, arg2: { a: number; b: string }) { throw new Error("Method not implemented."); } ` diff --git a/tests/cases/fourslash/codeFixUndeclaredPropertyObjectLiteral.ts b/tests/cases/fourslash/codeFixUndeclaredPropertyObjectLiteral.ts index a2647c5a21e..d60f62da777 100644 --- a/tests/cases/fourslash/codeFixUndeclaredPropertyObjectLiteral.ts +++ b/tests/cases/fourslash/codeFixUndeclaredPropertyObjectLiteral.ts @@ -9,7 +9,7 @@ verify.rangeAfterCodeFix(` class A { - x: { a: number; b: string; c: any; d: any; e: any; }; + x: { a: number; b: string; c: any; d: any; e: any }; constructor() { let e: any = 10; diff --git a/tests/cases/fourslash/codeFixUndeclaredPropertyObjectLiteralStrictNullChecks.ts b/tests/cases/fourslash/codeFixUndeclaredPropertyObjectLiteralStrictNullChecks.ts index 0b0ab8cdd59..4c824e9e63c 100644 --- a/tests/cases/fourslash/codeFixUndeclaredPropertyObjectLiteralStrictNullChecks.ts +++ b/tests/cases/fourslash/codeFixUndeclaredPropertyObjectLiteralStrictNullChecks.ts @@ -11,7 +11,7 @@ verify.rangeAfterCodeFix(` class A { - x: { a: number; b: string; c: undefined; d: null; e: any; }; + x: { a: number; b: string; c: undefined; d: null; e: any }; constructor() { let e: any = 10; diff --git a/tests/cases/fourslash/extract-const-callback-function-this1.ts b/tests/cases/fourslash/extract-const-callback-function-this1.ts index b0d269400bb..26bc5338932 100644 --- a/tests/cases/fourslash/extract-const-callback-function-this1.ts +++ b/tests/cases/fourslash/extract-const-callback-function-this1.ts @@ -10,6 +10,6 @@ edit.applyRefactor({ actionDescription: "Extract to constant in enclosing scope", newContent: `declare function fWithThis(fn: (this: { a: string }, a: string) => string): void; -const newLocal = function(this: { a: string; }, a: string): string { return this.a; }; +const newLocal = function(this: { a: string }, a: string): string { return this.a; }; fWithThis(/*RENAME*/newLocal);` }); diff --git a/tests/cases/fourslash/extract-const-callback-function-this2.ts b/tests/cases/fourslash/extract-const-callback-function-this2.ts index 518c39e26e5..42fbd4da7ea 100644 --- a/tests/cases/fourslash/extract-const-callback-function-this2.ts +++ b/tests/cases/fourslash/extract-const-callback-function-this2.ts @@ -10,6 +10,6 @@ edit.applyRefactor({ actionDescription: "Extract to constant in enclosing scope", newContent: `declare function fWithThis(fn: (this: { a: string }, a: string) => string): void; -const newLocal = function(this: { a: string; }, a: string): string { return this.a; }; +const newLocal = function(this: { a: string }, a: string): string { return this.a; }; fWithThis(/*RENAME*/newLocal);` }); diff --git a/tests/cases/fourslash/extract-method18.ts b/tests/cases/fourslash/extract-method18.ts index 0a488a04106..70a9a3230a8 100644 --- a/tests/cases/fourslash/extract-method18.ts +++ b/tests/cases/fourslash/extract-method18.ts @@ -19,7 +19,7 @@ edit.applyRefactor({ /*RENAME*/newFunction(x); } -function newFunction(x: { m: number; }) { +function newFunction(x: { m: number }) { x.m = 3; } ` diff --git a/tests/cases/fourslash/extract-method2.ts b/tests/cases/fourslash/extract-method2.ts index 419d6379075..8d562324d26 100644 --- a/tests/cases/fourslash/extract-method2.ts +++ b/tests/cases/fourslash/extract-method2.ts @@ -25,7 +25,7 @@ edit.applyRefactor({ } } -function newFunction(m: number, j: string, k: { x: string; }) { +function newFunction(m: number, j: string, k: { x: string }) { return m + j + k; } ` diff --git a/tests/cases/fourslash/formatAddSemicolons1.ts b/tests/cases/fourslash/formatAddSemicolons1.ts index a24c8673254..0b0dfa43011 100644 --- a/tests/cases/fourslash/formatAddSemicolons1.ts +++ b/tests/cases/fourslash/formatAddSemicolons1.ts @@ -46,4 +46,4 @@ enum E { type M = { [K in keyof T]: any }; declare module 'foo' { } declare module 'bar'; -type T = { x: string, y: number; };`); +type T = { x: string, y: number };`); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_allParamsOptional.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_allParamsOptional.ts index 8d8db719608..f08498f515a 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_allParamsOptional.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_allParamsOptional.ts @@ -10,7 +10,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function f({ a, b = "1" }: { a?: number; b?: string; } = {}): string { + newContent: `function f({ a, b = "1" }: { a?: number; b?: string } = {}): string { return b; } f();` diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_arrowFunction.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_arrowFunction.ts index 97d337d8d1a..e5ffd37ea03 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_arrowFunction.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_arrowFunction.ts @@ -8,6 +8,6 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `const foo = ({ a, b }: { a: number; b: number; }) => { }; + newContent: `const foo = ({ a, b }: { a: number; b: number }) => { }; foo({ a: 1, b: 2 });` }); \ No newline at end of file diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_callComments.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_callComments.ts index 2e30f96cd59..c58bcd5804b 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_callComments.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_callComments.ts @@ -10,7 +10,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function foo({ a, b, rest = [] }: { a: number; b: number; rest?: number[]; }) { + newContent: `function foo({ a, b, rest = [] }: { a: number; b: number; rest?: number[] }) { return a + b; } foo({ /**a*/ a: 1 /**b*/, /**c*/ b: 2 /**d*/, rest: [/**e*/ 3 /**f*/, /**g*/ 4 /**h*/] });` diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_callComments2.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_callComments2.ts index fcb50b6b8e1..4c9b6a253ae 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_callComments2.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_callComments2.ts @@ -19,7 +19,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function foo({ a, b, rest = [] }: { a: number; b: number; rest?: number[]; }) { + newContent: `function foo({ a, b, rest = [] }: { a: number; b: number; rest?: number[] }) { return a + b; } foo( diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_chainedCall.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_chainedCall.ts index 0b033200666..440beec20c1 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_chainedCall.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_chainedCall.ts @@ -10,7 +10,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function foo({ a, b }: { a: number; b: number; }) { + newContent: `function foo({ a, b }: { a: number; b: number }) { return { bar: () => a + b }; } var x = foo({ a: 1, b: 2 }).bar();` diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classDeclarationGoodUsages.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classDeclarationGoodUsages.ts index beba49c17e3..510a96ae0af 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classDeclarationGoodUsages.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classDeclarationGoodUsages.ts @@ -19,7 +19,7 @@ edit.applyRefactor({ actionDescription: "Convert parameters to destructured object", newContent: `class C { static a: number = 2; - constructor({ a, b }: { a: number; b: number; }) { } + constructor({ a, b }: { a: number; b: number }) { } } const newC = new C({ a: 1, b: 2 }); const b = C.a; diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classExpression.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classExpression.ts index f779170d643..b654174d385 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classExpression.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classExpression.ts @@ -11,7 +11,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `const c = class { - constructor({ a, b = { x: 1 } }: { a: number; b?: { x: number; }; }) { } + constructor({ a, b = { x: 1 } }: { a: number; b?: { x: number } }) { } } var x = new c({ a: 2 });` }); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classExpressionGoodUsages.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classExpressionGoodUsages.ts index ce0054fd92a..7221bffd913 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classExpressionGoodUsages.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classExpressionGoodUsages.ts @@ -15,7 +15,7 @@ edit.applyRefactor({ actionDescription: "Convert parameters to destructured object", newContent: `const c = class C { static a: number = 2; - constructor({ a, b }: { a: number; b: number; }) { } + constructor({ a, b }: { a: number; b: number }) { } } const a = new c({ a: 0, b: 1 }); const b = c.a; diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classTypeParameters.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classTypeParameters.ts index d8c884356bd..1b6656cbb54 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classTypeParameters.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_classTypeParameters.ts @@ -14,7 +14,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `class Foo { - bar({ t, s }: { t: T; s: T; }) { + bar({ t, s }: { t: T; s: T }) { return s; } } diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_constructor.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_constructor.ts index 1503f2fe7eb..ac8ad18ddfd 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_constructor.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_constructor.ts @@ -18,7 +18,7 @@ edit.applyRefactor({ newContent: `class Foo { t: string; s: string; - constructor({ t, s }: { t: string; s: string; }) { + constructor({ t, s }: { t: string; s: string }) { this.t = t; this.s = s; } diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_function.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_function.ts index d5eed686068..423136a6f1b 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_function.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_function.ts @@ -10,7 +10,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function f({ a, b }: { a: number; b: string; }): string { + newContent: `function f({ a, b }: { a: number; b: string }): string { return b; } f({ a: 4, b: "b" });` diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionComments.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionComments.ts index 5340004a060..a53757c997b 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionComments.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionComments.ts @@ -14,7 +14,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `foo({ a: 1, b: 2 }); /**a*/ -/**b*/ function foo(/**this1*/ this /**this2*/: /**void1*/ void /**void2*/, { a, b = /**k*/ 1 /**l*/ }: { /**c*/ a /**d*/: /**e*/ number /**f*/; /**g*/ b /**h*/?: /**i*/ number /**j*/; }) { +/**b*/ function foo(/**this1*/ this /**this2*/: /**void1*/ void /**void2*/, { a, b = /**k*/ 1 /**l*/ }: { /**c*/ a /**d*/: /**e*/ number /**f*/; /**g*/ b /**h*/?: /**i*/ number /**j*/ }) { // m /**n*/ return a + b; // o // p diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionComments1.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionComments1.ts index 07bc755c076..3a2b725629d 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionComments1.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionComments1.ts @@ -9,7 +9,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function foo({ a, b }: { a: number /** a */; b: number /** b */; }) { + newContent: `function foo({ a, b }: { a: number /** a */; b: number /** b */ }) { return a + b; }` }); \ No newline at end of file diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionExpression.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionExpression.ts index c4e81cf7926..75ff05d1420 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionExpression.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionExpression.ts @@ -8,6 +8,6 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `const foo = function({ a, b }: { a: number; b: number; }) { }; + newContent: `const foo = function({ a, b }: { a: number; b: number }) { }; foo({ a: 1, b: 2 });` }); \ No newline at end of file diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionTypeParameters.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionTypeParameters.ts index 9a27ae4f09e..7b540957de4 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionTypeParameters.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_functionTypeParameters.ts @@ -10,7 +10,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function foo({ t, s }: { t: T; s: S; }) { + newContent: `function foo({ t, s }: { t: T; s: S }) { return s; } foo({ t: "a", s: "b" });` diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction.ts index a4b37c7405a..3d8c97597df 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction.ts @@ -14,7 +14,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `export function f({ a, b }: { a: number; b: string; }): string { + newContent: `export function f({ a, b }: { a: number; b: string }): string { return b; }` }); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction2.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction2.ts index a83c11bd1fd..42465d86f5e 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction2.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction2.ts @@ -14,7 +14,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `export default function f({ a, b }: { a: number; b: string; }): string { + newContent: `export default function f({ a, b }: { a: number; b: string }): string { return b; }` }); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction3.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction3.ts index 6a2ecc1cfc3..a72adaa1daf 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction3.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction3.ts @@ -14,7 +14,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function foo({ a, b }: { a: string; b: string; }) { } + newContent: `function foo({ a, b }: { a: string; b: string }) { } export = foo;` }); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction4.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction4.ts index 729878b2b22..7739e1df43c 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction4.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction4.ts @@ -17,7 +17,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `export { foo as default }; -function foo({ a, b }: { a: number; b: number; }) { +function foo({ a, b }: { a: number; b: number }) { return a + b; }` }); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction5.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction5.ts index 17a41880a55..9a7a1c2f38d 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction5.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction5.ts @@ -17,7 +17,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `export class C { - constructor({ a, b }: { a: number; b: number; }) { } + constructor({ a, b }: { a: number; b: number }) { } }` }); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction6.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction6.ts index 615a49c0267..fc1d86570e1 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction6.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_importedFunction6.ts @@ -13,7 +13,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `export function foo({ a, b }: { a: string; b: string; }) { }` + newContent: `export function foo({ a, b }: { a: string; b: string }) { }` }); goTo.file("a.ts"); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inheritedConstructor.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inheritedConstructor.ts index 70a5d2022b5..a40cdc183bd 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inheritedConstructor.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inheritedConstructor.ts @@ -13,7 +13,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `class Foo { - constructor({ t, s }: { t: string; s: string; }) { } + constructor({ t, s }: { t: string; s: string }) { } } class Bar extends Foo { } var bar = new Bar({ t: "a", s: "b" }); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inheritedMethod.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inheritedMethod.ts index a04560886c0..e61d325290d 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inheritedMethod.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_inheritedMethod.ts @@ -15,7 +15,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `class Foo { - bar({ t, s }: { t: string; s: string; }): string { + bar({ t, s }: { t: string; s: string }): string { return s + t; } } diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_initializer.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_initializer.ts index 3f0da9f13a3..9bb6e5f022f 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_initializer.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_initializer.ts @@ -10,7 +10,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function f({ a, b = "1" }: { a: number; b?: string; }): string { + newContent: `function f({ a, b = "1" }: { a: number; b?: string }): string { return b; } f({ a: 4, b: "b" });` diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_initializerInference.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_initializerInference.ts index f2b92fc89e7..6fe36e73a37 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_initializerInference.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_initializerInference.ts @@ -10,7 +10,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function f({ a, b = { x: 1, z: { s: true } } }: { a: number; b?: { x: number; z: { s: boolean; }; }; }) { + newContent: `function f({ a, b = { x: 1, z: { s: true } } }: { a: number; b?: { x: number; z: { s: boolean } } }) { return b; } f({ a: 2 });` diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_method.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_method.ts index f3f78de391e..2272c390209 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_method.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_method.ts @@ -14,7 +14,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `class Foo { - bar({ t, s }: { t: string; s: string; }): string { + bar({ t, s }: { t: string; s: string }): string { return s + t; } } diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_methodCalls.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_methodCalls.ts index d1347ad877b..753c7f8472f 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_methodCalls.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_methodCalls.ts @@ -15,7 +15,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `class Foo { - bar({ t, s }: { t: string; s: string; }): string { + bar({ t, s }: { t: string; s: string }): string { return s + t; } } diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_namelessClass.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_namelessClass.ts index d38bff48b24..4530fecafec 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_namelessClass.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_namelessClass.ts @@ -16,7 +16,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `export default class { - constructor({ a, b }: { a: string; b: string; }) { } + constructor({ a, b }: { a: string; b: string }) { } }` }); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_recursiveFunction.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_recursiveFunction.ts index 7655af05100..755394aa1c5 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_recursiveFunction.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_recursiveFunction.ts @@ -12,7 +12,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `const f = function foo({ a, b }: { a: number; b: number; }) { + newContent: `const f = function foo({ a, b }: { a: number; b: number }) { foo({ a: 1, b: 2 }); } function foo(a: number, b: number) { } diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_restParamInference.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_restParamInference.ts index 1c6350d89f5..11ebc9cfc0c 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_restParamInference.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_restParamInference.ts @@ -9,7 +9,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function log({ a, b, args = [] }: { a: number; b: number; args?: any[]; }) { } + newContent: `function log({ a, b, args = [] }: { a: number; b: number; args?: any[] }) { } let l = log({ a: -1, b: -2, args: [3, 4, 5] }); let k = log({ a: 1, b: 2 });` }); \ No newline at end of file diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_shorthandProperty.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_shorthandProperty.ts index 86ea98582ab..7b4096c79d2 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_shorthandProperty.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_shorthandProperty.ts @@ -15,7 +15,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function f({ a, b, rest = [] }: { a: number; b: number; rest?: string[]; }) { } + newContent: `function f({ a, b, rest = [] }: { a: number; b: number; rest?: string[] }) { } const a = 4; const b = 5; f({ a, b }); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_staticMethod.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_staticMethod.ts index 8c19582c145..43cdbf8aa77 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_staticMethod.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_staticMethod.ts @@ -13,7 +13,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `class Foo { - static bar({ t, s }: { t: string; s: string; }): string { + static bar({ t, s }: { t: string; s: string }): string { return s + t; } } diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_superCall.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_superCall.ts index 2bdee836472..88f8e2cdb1e 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_superCall.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_superCall.ts @@ -15,7 +15,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: `class A { - constructor({ a, b }: { a: string; b: string; }) { } + constructor({ a, b }: { a: string; b: string }) { } } class B extends A { constructor(a: string, b: string, c: string) { diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_templateLiteral.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_templateLiteral.ts index 1075fb7dddb..2cef3d9b08f 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_templateLiteral.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_templateLiteral.ts @@ -10,7 +10,7 @@ edit.applyRefactor({ actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", newContent: [ - 'function insert({ template, overwriteBefore = 0 }: { template: string; overwriteBefore?: number; }) {}', + 'function insert({ template, overwriteBefore = 0 }: { template: string; overwriteBefore?: number }) {}', 'insert({ template: `this is \\${not} a substitution` });' ].join('\n') }); diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_thisParam.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_thisParam.ts index 05a6620707f..a01a4cf9cef 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_thisParam.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_thisParam.ts @@ -10,7 +10,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function foo(this: void, { t, s }: { t: string; s: string; }) { + newContent: `function foo(this: void, { t, s }: { t: string; s: string }) { return s; } foo({ t: "a", s: "b" });` diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_tupleRestParam.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_tupleRestParam.ts index 7584308fec0..6fb05f7c02e 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_tupleRestParam.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_tupleRestParam.ts @@ -23,7 +23,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function fn1({ a, b, args }: { a: number; b: number; args: [number, number]; }) { } + newContent: `function fn1({ a, b, args }: { a: number; b: number; args: [number, number] }) { } fn1({ a: 1, b: 2, args: [3, 4] });` }); @@ -32,7 +32,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function fn2({ a, b, args }: { a: number; b: number; args: [number, number, ...string[]]; }) { } + newContent: `function fn2({ a, b, args }: { a: number; b: number; args: [number, number, ...string[]] }) { } fn2({ a: 1, b: 2, args: [3, 4] }); fn2({ a: 1, b: 2, args: [3, 4, "a"] });` }); @@ -42,7 +42,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function fn3({ b, c }: { b: boolean; c: []; }) { } + newContent: `function fn3({ b, c }: { b: boolean; c: [] }) { } fn3({ b: true, c: [] });` }); @@ -51,7 +51,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function fn4({ a, args = [] }: { a: number; args?: [...string[]]; }) { } + newContent: `function fn4({ a, args = [] }: { a: number; args?: [...string[]] }) { } fn4({ a: 2 }); fn4({ a: 1, args: ["two", "three"] });` }); \ No newline at end of file diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_typedRestParam.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_typedRestParam.ts index 88401d83c4b..e65a61b10ab 100644 --- a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_typedRestParam.ts +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_typedRestParam.ts @@ -9,7 +9,7 @@ edit.applyRefactor({ refactorName: "Convert parameters to destructured object", actionName: "Convert parameters to destructured object", actionDescription: "Convert parameters to destructured object", - newContent: `function buildName({ firstName, middleName, restOfName = [] }: { firstName: string; middleName?: string; restOfName?: string[]; }) { } + newContent: `function buildName({ firstName, middleName, restOfName = [] }: { firstName: string; middleName?: string; restOfName?: string[] }) { } let employeeName = buildName({ firstName: "Joseph", middleName: "Samuel", restOfName: ["Lucas", "MacKinzie"] }); let myName = buildName({ firstName: "Joseph" });` }); \ No newline at end of file diff --git a/tests/cases/fourslash/typeToStringCrashInCodeFix.ts b/tests/cases/fourslash/typeToStringCrashInCodeFix.ts index 5201a6b77fb..8a9c19817a5 100644 --- a/tests/cases/fourslash/typeToStringCrashInCodeFix.ts +++ b/tests/cases/fourslash/typeToStringCrashInCodeFix.ts @@ -3,4 +3,4 @@ // @noImplicitAny: true //// function f([|y |], z = { p: y[ -verify.rangeAfterCodeFix("y: { [x: string]: any; }",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0); +verify.rangeAfterCodeFix("y: { [x: string]: any }",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0);