Skip to content

Commit 227cbb4

Browse files
authored
fix: migration erroring when there is empty cell in table (#1223)
[![PR App][icn]][demo] | Fix RM-XYZ :-------------------:|:----------: ## 🧰 Changes Tables like: ```md | Name | Date | | ---- | ---- | | test | | ``` were throwing an error when migrating because we tried to access an attribute .type whilst content is not the expected object. This PR just does early exit when content is empty. ## 🧬 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 698390a commit 227cbb4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

__tests__/migration/tables.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
import { migrate } from '../helpers';
22

33
describe('mdx migration of tables', () => {
4+
it('compiles tables with empty cells', () => {
5+
const md = `
6+
| Name | Date |
7+
| ---- | ---- |
8+
| test | |
9+
`;
10+
const mdx = migrate(md);
11+
expect(mdx).toMatchInlineSnapshot(`
12+
"| Name | Date |
13+
| ---- | ---- |
14+
| test | |
15+
"
16+
`);
17+
});
18+
419
it('compiles tables with newlines and inline code', () => {
520
const md = `
621
[block:parameters]

processor/transform/tables-to-jsx.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ const visitor = (table: Table, index: number, parent: Parents) => {
3434
? (cell.children[0] as unknown as Paragraph).children[0]
3535
: cell.children[0];
3636

37+
// If cell is empty there's nothing to visit
38+
if (!content) return EXIT;
39+
3740
// @note: Compatibility with RDMD. Ideally, I'd put this in a separate
3841
// transformer, but then there'd be some duplication.
3942
visit(cell, 'break', (_, breakIndex, breakParent) => {

0 commit comments

Comments
 (0)