Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
fix/table-parse-optional-chaining (#697)
Browse files Browse the repository at this point in the history
* Testing additional conditional checks.

* Further checks

* Migrating to optional chaining to cleanup syntax

* Integrating Optional Chaining into Markdown:
- Added babel parser + eslint inclusion of proposed optional chaining
- Moving table parsing pluging to use optional chaining
  • Loading branch information
gratcliff authored May 11, 2020
1 parent c667702 commit 38d3f51
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 60 deletions.
6 changes: 5 additions & 1 deletion packages/markdown/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
],
"@babel/preset-react"
],
"plugins": ["@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-object-rest-spread"]
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-optional-chaining"
]
}
1 change: 1 addition & 0 deletions packages/markdown/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"@readme/eslint-config",
"@readme/eslint-config/react"
],
"parser": "babel-eslint",
"root": true
}
90 changes: 36 additions & 54 deletions packages/markdown/dist/main.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions packages/markdown/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"license": "ISC",
"repository": "https://github.com/readmeio/api-explorer/tree/master/packages/markdown",
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.9.0",
"@readme/eslint-config": "^2.0.0",
"css-loader": "^3.4.2",
"eslint": "^6.5.0",
Expand Down
9 changes: 4 additions & 5 deletions packages/markdown/processor/plugin/table-flattening.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ function transformer(ast) {
// This is necessary to pullout all the relevant strings

// Parse Header Values
const headerChildren = header.children && header.children.length ? header.children[0].children : [];
const headerValue = headerChildren.map(hc => (hc.children.length && hc.children[0].value) || '').join(' ');
const headerChildren = header?.children?.[0]?.children || [];
const headerValue = headerChildren.map(hc => hc?.children?.[0]?.value || '').join(' ');
// Parse Body Values
const bodyChildren =
(body.children && body.children.map(bc => bc && bc.children).reduce((a, b) => a.concat(b), [])) || [];
const bodyValue = bodyChildren.map(bc => (bc.children.length && bc.children[0].value) || '').join(' ');
const bodyChildren = body?.children?.map(bc => bc?.children).reduce((a, b) => a.concat(b), []) || [];
const bodyValue = bodyChildren.map(bc => bc?.children?.[0]?.value || '').join(' ');

return [
{
Expand Down

0 comments on commit 38d3f51

Please sign in to comment.