Skip to content

Commit

Permalink
[JS/TS] Fix fable-compiler#4029
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Feb 1, 2025
1 parent 9949737 commit e189216
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* [Python] - Print root module and module function comments (by @alfonsogarciacaro)
* [JS/TS] - Fix anonymous record printing (#4029) (by @alfonsogarciacaro)

## 5.0.0-alpha.9 - 2025-01-28

Expand Down
1 change: 1 addition & 0 deletions src/Fable.Compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* [Python] - Print root module and module function comments (by @alfonsogarciacaro)
* [JS/TS] - Fix anonymous record printing (#4029) (by @alfonsogarciacaro)

## 5.0.0-alpha.9 - 2025-01-28

Expand Down
2 changes: 1 addition & 1 deletion src/fable-library-ts/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function seqToString<T>(self: Iterable<T>): string {

export function toString(x: any, callStack = 0): string {
if (x != null && typeof x === "object") {
if (typeof x.toString === "function") {
if (typeof x.toString === "function" && x.toString !== Object.prototype.toString) {
return x.toString();
} else if (Symbol.iterator in x) {
return seqToString(x);
Expand Down
6 changes: 6 additions & 0 deletions tests/Js/Main/StringTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ let tests = testList "Strings" [
$"Hi! My name is %s{person.Name} %s{person.Surname.ToUpper()}. I'm %i{person.Age} years old and I'm from %s{person.Country}!"
|> equal "Hi! My name is John DOE. I'm 32 years old and I'm from The United Kingdom!"

testCase "Printf %A works with anonymous records" <| fun () -> // See #4029
let person = {| FirstName = "John"; LastName = "Doe" |}
let s = sprintf "%A" person
System.Text.RegularExpressions.Regex.Replace(s.Replace("\"", ""), @"\s+", " ")
|> equal """{ FirstName = John LastName = Doe }"""

testCase "Interpolated strings keep empty lines" <| fun () ->
let s1 = $"""1
Expand Down

0 comments on commit e189216

Please sign in to comment.