@@ -10,28 +10,26 @@ const outputPath = resolve(repoRoot, "docs/errors.md")
1010globalThis . __DEV__ = true
1111const { niceErrors } = require ( errorsPath )
1212
13- function getParamNames ( fn ) {
14- const match = fn . toString ( ) . match ( / ^ [ ^ ( ] * \( ( [ ^ ) ] * ) \) / )
15- return match ? match [ 1 ] . split ( "," ) . map ( name => name . trim ( ) ) . filter ( Boolean ) : [ ]
16- }
17-
18- function renderMessage ( message ) {
19- if ( typeof message !== "function" ) {
20- return message
13+ function formatMarkdownCell ( message ) {
14+ let value = message
15+
16+ if ( typeof message === "function" ) {
17+ // Render dynamic errors with visible placeholders instead of real runtime values
18+ const match = message . toString ( ) . match ( / ^ [ ^ ( ] * \( ( [ ^ ) ] * ) \) / )
19+ const params = match ? match [ 1 ] : ""
20+ const names = params . split ( "," ) . map ( name => name . trim ( ) ) . filter ( Boolean )
21+ const args = names . map ( name => `{${ name } }` )
22+ value = message ( ...args ) . replace ( "String" , args [ 0 ] )
2123 }
2224
23- const args = getParamNames ( message ) . map ( name => `{${ name } }` )
24- return message ( ...args ) . replace ( "String" , args [ 0 ] )
25- }
26-
27- function escapeMarkdownTableCell ( value ) {
25+ // Keep the generated table valid Markdown
2826 return String ( value ) . replace ( / \r ? \n / g, "<br />" ) . replace ( / \| / g, "\\|" )
2927}
3028
3129function renderDocs ( errors ) {
3230 const rows = Object . keys ( errors )
3331 . sort ( ( left , right ) => Number ( left ) - Number ( right ) )
34- . map ( code => `| ${ code } | ${ escapeMarkdownTableCell ( renderMessage ( errors [ code ] ) ) } |` )
32+ . map ( code => `| ${ code } | ${ formatMarkdownCell ( errors [ code ] ) } |` )
3533 . join ( "\n" )
3634
3735 return `---
0 commit comments