diff --git a/internal/ast/ast.go b/internal/ast/ast.go index 91813b4c2d3..78e589f0ec7 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -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() } @@ -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 { diff --git a/internal/fourslash/_scripts/convertFourslash.mts b/internal/fourslash/_scripts/convertFourslash.mts index 83a8993c35b..363ae90d5dc 100755 --- a/internal/fourslash/_scripts/convertFourslash.mts +++ b/internal/fourslash/_scripts/convertFourslash.mts @@ -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}, )`; } @@ -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": diff --git a/internal/fourslash/_scripts/crashingTests.txt b/internal/fourslash/_scripts/crashingTests.txt index fe0c6c212a5..e48faa1019f 100644 --- a/internal/fourslash/_scripts/crashingTests.txt +++ b/internal/fourslash/_scripts/crashingTests.txt @@ -1,4 +1,3 @@ TestFindReferencesBindingPatternInJsdocNoCrash1 TestFindReferencesBindingPatternInJsdocNoCrash2 -TestFormattingJsxTexts4 TestQuickInfoBindingPatternInJsdocNoCrash1 diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index b8575b19336..6cee0b0aef0 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -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 = "/" @@ -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") - 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] diff --git a/internal/fourslash/tests/formatDocumentNoCrashJsxNamespacedName1_test.go b/internal/fourslash/tests/formatDocumentNoCrashJsxNamespacedName1_test.go new file mode 100644 index 00000000000..669cfb8ea47 --- /dev/null +++ b/internal/fourslash/tests/formatDocumentNoCrashJsxNamespacedName1_test.go @@ -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 = ; +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, "const x = ;\n") +}