Skip to content

Commit eb40134

Browse files
authoredSep 9, 2022
Don't leave space for property access on non-integer literals (#50703)
1 parent a70bb9d commit eb40134

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed
 

‎src/services/formatting/rules.ts

+5-3
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, isNotPropertyAccessOnNumericLiteral], RuleAction.DeleteSpace),
62+
rule("NoSpaceBeforeDot", anyToken, [SyntaxKind.DotToken, SyntaxKind.QuestionDotToken], [isNonJsxSameLineTokenContext, isNotPropertyAccessOnIntegerLiteral], 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),
@@ -894,7 +894,9 @@ namespace ts.formatting {
894894
return positionIsASICandidate(context.currentTokenSpan.end, context.currentTokenParent, context.sourceFile);
895895
}
896896

897-
function isNotPropertyAccessOnNumericLiteral(context: FormattingContext): boolean {
898-
return !isPropertyAccessExpression(context.contextNode) || !isNumericLiteral(context.contextNode.expression);
897+
function isNotPropertyAccessOnIntegerLiteral(context: FormattingContext): boolean {
898+
return !isPropertyAccessExpression(context.contextNode)
899+
|| !isNumericLiteral(context.contextNode.expression)
900+
|| context.contextNode.expression.getText().indexOf(".") !== -1;
899901
}
900902
}
+19-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
/// <reference path='fourslash.ts' />
22

3-
////1+ 2 .toString() +3/**/
3+
////1+ 2 .toString() +3/*1*/
4+
////1+ 2. .toString() +3/*2*/
5+
////1+ 2.0 .toString() +3/*3*/
6+
////1+ (2) .toString() +3/*4*/
7+
////1+ 2_000 .toString() +3/*5*/
48

59
format.document();
6-
goTo.marker("");
10+
11+
goTo.marker("1");
712
verify.currentLineContentIs("1 + 2 .toString() + 3");
13+
14+
goTo.marker("2");
15+
verify.currentLineContentIs("1 + 2..toString() + 3");
16+
17+
goTo.marker("3");
18+
verify.currentLineContentIs("1 + 2.0.toString() + 3");
19+
20+
goTo.marker("4");
21+
verify.currentLineContentIs("1 + (2).toString() + 3");
22+
23+
goTo.marker("5");
24+
verify.currentLineContentIs("1 + 2_000 .toString() + 3");

0 commit comments

Comments
 (0)
Please sign in to comment.