Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't remove space before dot if in property access on numeric literal #50695

Merged
merged 2 commits into from Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/services/formatting/rules.ts
Expand Up @@ -59,7 +59,7 @@ 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, SyntaxKind.QuestionDotToken], [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
rule("NoSpaceBeforeDot", anyToken, [SyntaxKind.DotToken, SyntaxKind.QuestionDotToken], [isNonJsxSameLineTokenContext, isNotPropertyAccessOnNumericLiteral], RuleAction.DeleteSpace),
rule("NoSpaceAfterDot", [SyntaxKind.DotToken, SyntaxKind.QuestionDotToken], anyToken, [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),

rule("NoSpaceBetweenImportParenInImportType", SyntaxKind.ImportKeyword, SyntaxKind.OpenParenToken, [isNonJsxSameLineTokenContext, isImportTypeContext], RuleAction.DeleteSpace),
Expand Down Expand Up @@ -893,4 +893,8 @@ namespace ts.formatting {
function isSemicolonInsertionContext(context: FormattingContext): boolean {
return positionIsASICandidate(context.currentTokenSpan.end, context.currentTokenParent, context.sourceFile);
}

function isNotPropertyAccessOnNumericLiteral(context: FormattingContext): boolean {
return !isPropertyAccessExpression(context.contextNode) || !isNumericLiteral(context.contextNode.expression);
}
}
7 changes: 7 additions & 0 deletions tests/cases/fourslash/formatDotAfterNumber.ts
@@ -0,0 +1,7 @@
/// <reference path='fourslash.ts' />

////1+ 2 .toString() +3/**/

format.document();
goTo.marker("");
verify.currentLineContentIs("1 + 2 .toString() + 3");