Skip to content

Use numeric literal source text when formatting property access - #64592

Open
Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:preserve-numeric-literal-dot-formatting
Open

Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:preserve-numeric-literal-dot-formatting

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 14:28
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 2, 2026
@typescript-automation

Copy link
Copy Markdown
Contributor

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

return !ast.IsPropertyAccessExpression(context.contextNode) ||
!ast.IsNumericLiteral(context.contextNode.Expression()) ||
strings.Contains(context.contextNode.Expression().Text(), ".")
strings.Contains(scanner.GetSourceTextOfNodeFromSourceFile(context.SourceFile, context.contextNode.Expression(), false /*includeTrivia*/), ".")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this matches Strada that was reading the original source text:

function isNotPropertyAccessOnIntegerLiteral(context: FormattingContext): boolean {
return !isPropertyAccessExpression(context.contextNode)
|| !isNumericLiteral(context.contextNode.expression)
|| context.contextNode.expression.getText().includes(".");
}

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR updates the formatter’s integer-literal property access detection to use the numeric literal’s original source text, and re-enables a previously skipped fourslash regression test.

Changes:

  • Re-enabled formatDotAfterNumber fourslash test by removing the unconditional skip.
  • Updated integer-literal property access detection to inspect the numeric literal’s source text (via scanner.GetSourceTextOfNodeFromSourceFile) rather than the AST node’s Text().
File Description
tsc/​internal/​fourslash/​tests/​formatDotAfterNumber_test.go Re-enables a regression test covering numeric-literal dot formatting.
tsc/​internal/​format/​rulecontext.go Uses source text for numeric literals to correctly detect . in the literal as written.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 625 to 629
func isNotPropertyAccessOnIntegerLiteral(context *FormattingContext) bool {
return !ast.IsPropertyAccessExpression(context.contextNode) ||
!ast.IsNumericLiteral(context.contextNode.Expression()) ||
strings.Contains(context.contextNode.Expression().Text(), ".")
strings.Contains(scanner.GetSourceTextOfNodeFromSourceFile(context.SourceFile, context.contextNode.Expression(), false /*includeTrivia*/), ".")
}

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 2 Medium severity

Open (2)

Comment on lines 625 to 629
func isNotPropertyAccessOnIntegerLiteral(context *FormattingContext) bool {
return !ast.IsPropertyAccessExpression(context.contextNode) ||
!ast.IsNumericLiteral(context.contextNode.Expression()) ||
strings.Contains(context.contextNode.Expression().Text(), ".")
strings.Contains(scanner.GetSourceTextOfNodeFromSourceFile(context.SourceFile, context.contextNode.Expression(), false /*includeTrivia*/), ".")
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

2 participants