Skip to content

Fixup misported TokensAreOnSameLine - #64597

Open
Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:fix-template-brace-spacing
Open

Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:fix-template-brace-spacing

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 16:58
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label 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.

func (this *FormattingContext) TokensAreOnSameLine() bool {
if this.tokensAreOnSameLine == core.TSUnknown {
this.tokensAreOnSameLine = this.rangeIsOnOneLine(core.NewTextRange(this.currentTokenSpan.Loc.Pos(), this.nextTokenSpan.Loc.End()))
this.tokensAreOnSameLine = this.rangeIsOnOneLine(core.NewTextRange(this.currentTokenSpan.Loc.Pos(), this.nextTokenSpan.Loc.Pos()))

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.

Strada's logic here:

public TokensAreOnSameLine(): boolean {
if (this.tokensAreOnSameLine === undefined) {
const startLine = this.sourceFile.getLineAndCharacterOfPosition(this.currentTokenSpan.pos).line;
const endLine = this.sourceFile.getLineAndCharacterOfPosition(this.nextTokenSpan.pos).line;
this.tokensAreOnSameLine = startLine === endLine;
}
return this.tokensAreOnSameLine;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm surprised this matters, what tokens are multiline?

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.

For example, the TemplateTail here:

const s = `${1}
`;

defer done()
f.FormatDocument(t, "")
f.VerifyCurrentFileContent(t, "const x = <HangupButton customClass= 'ha\n")
f.VerifyCurrentFileContent(t, "const x = <HangupButton customClass='ha\n")

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 test didn't exist in Strada and it just crashes there. That's why the output is different here (and why this test isn't simply unskipped like the other ones)

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: None

What changed in this PR

Enables previously skipped fourslash formatter tests and fixes a misported implementation of TokensAreOnSameLine, updating an expected formatting output accordingly.

Changes:

  • Removed t.Skip from two template-literal spacing formatter tests so they run in CI.
  • Corrected TokensAreOnSameLine to compute same-line status using the next token’s start position.
  • Updated JSX unterminated-string formatting expectation to match the formatter’s output.
File Description
tsc/​internal/​fourslash/​tests/​formatSpaceAfterTemplateHeadAndMiddle_test.go Unskips a formatter fourslash test for template literal spacing.
tsc/​internal/​fourslash/​tests/​formatNoSpaceAfterTemplateHeadAndMiddle_test.go Unskips a formatter fourslash test for template literal spacing.
tsc/​internal/​fourslash/​tests/​formatDocumentNoCrashJsxAttrUnterminatedString_test.go Updates expected formatted output for unterminated JSX attribute string case.
tsc/​internal/​format/​context.go Fixes TokensAreOnSameLine logic to use next token start position.

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

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.

3 participants