Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -9176,9 +9176,9 @@ func (f *NodeFactory) NewJsxNamespacedName(namespace *IdentifierNode, name *Iden
return f.newNode(KindJsxNamespacedName, data)
}

func (f *NodeFactory) UpdateJsxNamespacedName(node *JsxNamespacedName, name *IdentifierNode, namespace *IdentifierNode) *Node {
if name != node.name || namespace != node.Namespace {
return updateNode(f.NewJsxNamespacedName(name, namespace), node.AsNode(), f.hooks)
func (f *NodeFactory) UpdateJsxNamespacedName(node *JsxNamespacedName, namespace *IdentifierNode, name *IdentifierNode) *Node {
if namespace != node.Namespace || name != node.name {
return updateNode(f.NewJsxNamespacedName(namespace, name), node.AsNode(), f.hooks)
}
return node.AsNode()
}
Expand All @@ -9188,7 +9188,7 @@ func (node *JsxNamespacedName) ForEachChild(v Visitor) bool {
}

func (node *JsxNamespacedName) VisitEachChild(v *NodeVisitor) *Node {
return v.Factory.UpdateJsxNamespacedName(node, v.visitNode(node.name), v.visitNode(node.Namespace))
return v.Factory.UpdateJsxNamespacedName(node, v.visitNode(node.Namespace), v.visitNode(node.name))
}

func (node *JsxNamespacedName) Clone(f NodeFactoryCoercible) *Node {
Expand Down
10 changes: 5 additions & 5 deletions internal/fourslash/_scripts/convertFourslash.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3374,9 +3374,9 @@ function generateQuickInfoCommand({ kind, marker, text, docs }: VerifyQuickInfoC
}

function generateOrganizeImports({ expectedContent, mode, preferences }: VerifyOrganizeImportsCmd): string {
return `f.VerifyOrganizeImports(t,
${getGoMultiLineStringLiteral(expectedContent)},
${mode},
return `f.VerifyOrganizeImports(t,
${getGoMultiLineStringLiteral(expectedContent)},
${mode},
${preferences},
)`;
}
Expand Down Expand Up @@ -3606,9 +3606,9 @@ function generateCmd(cmd: Cmd): string {
case "verifyErrorExistsAtRange":
return `f.VerifyErrorExistsAtRange(t, ${cmd.range}, ${cmd.code}, ${getGoStringLiteral(cmd.message)})`;
case "verifyCurrentLineContentIs":
return `f.VerifyCurrentLineContentIs(t, ${getGoStringLiteral(cmd.text)})`;
return `f.VerifyCurrentLineContent(t, ${getGoStringLiteral(cmd.text)})`;
case "verifyCurrentFileContentIs":
return `f.VerifyCurrentFileContentIs(t, ${getGoStringLiteral(cmd.text)})`;
return `f.VerifyCurrentFileContent(t, ${getGoStringLiteral(cmd.text)})`;
case "verifyErrorExistsBetweenMarkers":
return `f.VerifyErrorExistsBetweenMarkers(t, ${getGoStringLiteral(cmd.startMarker)}, ${getGoStringLiteral(cmd.endMarker)})`;
case "verifyErrorExistsAfterMarker":
Expand Down
1 change: 0 additions & 1 deletion internal/fourslash/_scripts/crashingTests.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
TestFindReferencesBindingPatternInJsdocNoCrash1
TestFindReferencesBindingPatternInJsdocNoCrash2
TestFormattingJsxTexts4
TestQuickInfoBindingPatternInJsdocNoCrash1
31 changes: 1 addition & 30 deletions internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ func (s *scriptInfo) GetLineContent(line int) string {
end = core.TextPos(len(s.content))
}

// delete trailing newline
content := s.content[start:end]
if len(content) > 0 && content[len(content)-1] == '\n' {
content = content[:len(content)-1]
}
return content
return strings.TrimRight(s.content[start:end], "\r\n")
}

const rootDir = "/"
Expand Down Expand Up @@ -4204,30 +4199,6 @@ func (f *FourslashTest) VerifyErrorExistsAtRange(t *testing.T, rangeMarker *Rang
t.Fatalf("Expected error with code %d at range %v but it was not found", code, rangeMarker.LSRange)
}

// VerifyCurrentLineContentIs verifies that the current line content matches the expected text.
func (f *FourslashTest) VerifyCurrentLineContentIs(t *testing.T, expectedText string) {
script := f.getScriptInfo(f.activeFilename)
lines := strings.Split(script.content, "\n")
lineNum := int(f.currentCaretPosition.Line)
if lineNum >= len(lines) {
t.Fatalf("Current line %d is out of range (file has %d lines)", lineNum, len(lines))
}
actualLine := lines[lineNum]
// Handle \r if present
actualLine = strings.TrimSuffix(actualLine, "\r")
Comment on lines -4210 to -4217
Copy link
Member

Choose a reason for hiding this comment

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

I think @DanielRosenwasser recently look at code like this

Copy link
Member

@DanielRosenwasser DanielRosenwasser Mar 5, 2026

Choose a reason for hiding this comment

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

if actualLine != expectedText {
t.Fatalf("Current line content mismatch.\nExpected: %q\nActual: %q", expectedText, actualLine)
}
}

// VerifyCurrentFileContentIs verifies that the current file content matches the expected text.
func (f *FourslashTest) VerifyCurrentFileContentIs(t *testing.T, expectedText string) {
script := f.getScriptInfo(f.activeFilename)
if script.content != expectedText {
t.Fatalf("Current file content mismatch.\nExpected: %q\nActual: %q", expectedText, script.content)
}
}

// VerifyErrorExistsBetweenMarkers verifies that an error exists between the two markers.
func (f *FourslashTest) VerifyErrorExistsBetweenMarkers(t *testing.T, startMarkerName string, endMarkerName string) {
startMarker, ok := f.testData.MarkerPositions[startMarkerName]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/typescript-go/internal/fourslash"
"github.com/microsoft/typescript-go/internal/testutil"
)

func TestFormatDocumentNoCrashJsxNamespacedName1(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /a.tsx
const x = <foo:bar />;
`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.FormatDocument(t, "")
f.VerifyCurrentFileContent(t, "const x = <foo:bar />;\n")
}