diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 75720555f5248..8a86cd7a65de2 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -59,8 +59,8 @@ namespace ts.formatting { // in other cases there should be no space between '?' and next token rule("NoSpaceAfterQuestionMark", SyntaxKind.QuestionToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace), - rule("NoSpaceBeforeDot", anyToken, SyntaxKind.DotToken, [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace), - rule("NoSpaceAfterDot", SyntaxKind.DotToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace), + rule("NoSpaceBeforeDot", anyToken, [SyntaxKind.DotToken, SyntaxKind.QuestionDotToken], [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace), + rule("NoSpaceAfterDot", [SyntaxKind.DotToken, SyntaxKind.QuestionDotToken], anyToken, [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace), rule("NoSpaceBetweenImportParenInImportType", SyntaxKind.ImportKeyword, SyntaxKind.OpenParenToken, [isNonJsxSameLineTokenContext, isImportTypeContext], RuleAction.DeleteSpace), diff --git a/tests/cases/fourslash/formattingSpaceBetweenOptionalChaining.ts b/tests/cases/fourslash/formattingSpaceBetweenOptionalChaining.ts new file mode 100644 index 0000000000000..53f2debf5592e --- /dev/null +++ b/tests/cases/fourslash/formattingSpaceBetweenOptionalChaining.ts @@ -0,0 +1,10 @@ +/// + +/////*1*/a ?. b ?. c . d; +/////*2*/o . m() ?. length; + +format.document(); +goTo.marker("1"); +verify.currentLineContentIs("a?.b?.c.d;"); +goTo.marker("2"); +verify.currentLineContentIs("o.m()?.length;");