Skip to content

fix: escape pipe in enum member value table cell#141

Open
greymoth-jp wants to merge 1 commit into
kazupon:masterfrom
greymoth-jp:fix/enum-table-pipe-escape
Open

fix: escape pipe in enum member value table cell#141
greymoth-jp wants to merge 1 commit into
kazupon:masterfrom
greymoth-jp:fix/enum-table-pipe-escape

Conversation

@greymoth-jp

Copy link
Copy Markdown

What

The Members table generated for an enum prints each member's initializer
value straight from initializerExcerpt.text without escaping it:

| ${memberEnum.displayName} | ${
  memberEnum.initializerExcerpt.text
} | ${ ... } |

When the initializer contains a pipe, that raw | adds an extra column to the
row. For a flags enum such as:

enum FileAccess {
  Read = 1 << 1,
  Write = 1 << 2,
  ReadWrite = Read | Write,
}

the ReadWrite row becomes | ReadWrite | Read | Write | ... |, which has four
cells against a three-column header. GitHub-Flavored Markdown then splits the
value (Read / Write) and pushes the Description out of the row, so the
table loses data.

Fix

The parameters table already escapes its excerpt before putting it in a cell.
The Type column runs p.parameterTypeExcerpt.text through
escapeTextForTable for exactly this reason (union types contain pipes too).
This change routes the enum value column through the same helper so both
columns escape consistently. escapeTextForTable maps | to &#124;, which
renders as a literal pipe and keeps the row at three cells.

Tests

  • Added test/enum-pipe.test.ts with a fixture whose member initializer is
    Read | Write, asserting the value stays in one cell and the description
    survives.
  • Updated the existing enum snapshots: the value column now escapes the same
    way the Type column already does, so "%" becomes &quot;%&quot; (the
    same treatment as DumbType&lt;T&gt;).

npm run lint and the unit tests pass.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant