Skip to content

Commit 1a1c271

Browse files
authored
Don't remove space before dot if in property access on numeric literal (microsoft#50695)
* Add failing test * Don't remove space before dot if in property access on numeric literal
1 parent 7c918fb commit 1a1c271

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/services/formatting/rules.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace ts.formatting {
5959
// in other cases there should be no space between '?' and next token
6060
rule("NoSpaceAfterQuestionMark", SyntaxKind.QuestionToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
6161

62-
rule("NoSpaceBeforeDot", anyToken, [SyntaxKind.DotToken, SyntaxKind.QuestionDotToken], [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
62+
rule("NoSpaceBeforeDot", anyToken, [SyntaxKind.DotToken, SyntaxKind.QuestionDotToken], [isNonJsxSameLineTokenContext, isNotPropertyAccessOnNumericLiteral], RuleAction.DeleteSpace),
6363
rule("NoSpaceAfterDot", [SyntaxKind.DotToken, SyntaxKind.QuestionDotToken], anyToken, [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
6464

6565
rule("NoSpaceBetweenImportParenInImportType", SyntaxKind.ImportKeyword, SyntaxKind.OpenParenToken, [isNonJsxSameLineTokenContext, isImportTypeContext], RuleAction.DeleteSpace),
@@ -893,4 +893,8 @@ namespace ts.formatting {
893893
function isSemicolonInsertionContext(context: FormattingContext): boolean {
894894
return positionIsASICandidate(context.currentTokenSpan.end, context.currentTokenParent, context.sourceFile);
895895
}
896+
897+
function isNotPropertyAccessOnNumericLiteral(context: FormattingContext): boolean {
898+
return !isPropertyAccessExpression(context.contextNode) || !isNumericLiteral(context.contextNode.expression);
899+
}
896900
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////1+ 2 .toString() +3/**/
4+
5+
format.document();
6+
goTo.marker("");
7+
verify.currentLineContentIs("1 + 2 .toString() + 3");

0 commit comments

Comments
 (0)