Skip to content

Commit a88c471

Browse files
fix: crash when compiling empty table cells (#1099)
| [![PR App][icn]][demo] | Part of CX-1934 | | :--------------------: | :-------------: | ## 🧰 Changes Fixes a crash when compiling empty table cells ## 🧬 QA & Testing - [Broken on production][prod]. - [Working in this PR app][demo]. [demo]: https://markdown-pr-PR_NUMBER.herokuapp.com [prod]: https://SUBDOMAIN.readme.io [icn]: https://user-images.githubusercontent.com/886627/160426047-1bee9488-305a-4145-bb2b-09d8b757d38a.svg
1 parent 0b209a5 commit a88c471

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

__tests__/compilers/tables.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,17 @@ describe('table compiler', () => {
325325
</Table>"
326326
`);
327327
});
328+
329+
it('compiles tables with empty cells', () => {
330+
const doc = `
331+
| col1 | col2 | col3 |
332+
| :--- | :--: | :----------------------- |
333+
| → | | ← empty cell to the left |
334+
`;
335+
const ast = mdast(doc);
336+
337+
expect(() => {
338+
mdx(ast);
339+
}).not.toThrow();
340+
});
328341
});

processor/transform/tables-to-jsx.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const visitor = (table: Table, index: number, parent: Parents) => {
2727
let hasFlowContent = false;
2828

2929
const tableCellVisitor = (cell: TableCell) => {
30+
if (cell.children.length === 0) return EXIT;
31+
3032
const content =
3133
cell.children.length === 1 && cell.children[0].type === 'paragraph'
3234
? (cell.children[0] as unknown as Paragraph).children[0]

0 commit comments

Comments
 (0)