Skip to content

Simplify nested tables#46

Merged
cyyynthia merged 3 commits intosquirrelchat:mistressfrom
penalosa:penalosa/simplify-nested-tables
Nov 13, 2025
Merged

Simplify nested tables#46
cyyynthia merged 3 commits intosquirrelchat:mistressfrom
penalosa:penalosa/simplify-nested-tables

Conversation

@penalosa
Copy link
Copy Markdown
Contributor

@penalosa penalosa commented Nov 13, 2025

As part of trying to migrate to smol-toml from @iarna/toml in Cloudflare's Wrangler, we've been running into some differences in how smol-toml renders nested tables when stringifying. For instance, the following object:

{
  a: {
    b: [
      { b: 1, c: 2 },
    ],
  },
}

is rendered by smol-toml as

[a]
[[a.b]]
b = 1
c = 2

and by @iarna/toml as

[[a.b]]
b = 1
c = 2

Both are valid, but the @iarna/toml output seems clearer and easier to work with. As such, this PR modifies the smol-toml stringify logic to not render a table key if:

  1. The table has children
  2. All children are themselves arrays or tables
  • I've added tests
  • I've run the TOML test suite, which passed

@cyyynthia cyyynthia added the enhancement New feature or request label Nov 13, 2025
@cyyynthia cyyynthia self-assigned this Nov 13, 2025
Copy link
Copy Markdown
Member

@cyyynthia cyyynthia left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I took the initiative to refactor it so there is only a single iteration over the table's keys, which makes the performance impact of this change almost negligible.

Thanks for the tests too! 🩷

@cyyynthia cyyynthia merged commit 8a1ed6d into squirrelchat:mistress Nov 13, 2025
25 checks passed
@cyyynthia
Copy link
Copy Markdown
Member

v1.5.0 is now released with this change. Thanks again for the PR!

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants