Skip to content
Permalink
Browse files
Don't remove space before dot if in property access on numeric literal (
#50695)

* Add failing test

* Don't remove space before dot if in property access on numeric literal
  • Loading branch information
jakebailey committed Sep 9, 2022
1 parent 7c918fb commit 1a1c27167536e005a4d241ef84c43c0c0ca0aaf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
@@ -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),
@@ -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);
}
}
@@ -0,0 +1,7 @@
/// <reference path='fourslash.ts' />

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

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

0 comments on commit 1a1c271

Please sign in to comment.