Skip to content

Commit 755c7af

Browse files
committed
Avoid using Fragment for plain strings
1 parent 52f9e4f commit 755c7af

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

.eslintrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
root: true
22

3+
parser: '@babel/eslint-parser'
4+
35
extends:
46
- pegasus
57
- plugin:react/recommended
@@ -8,6 +10,7 @@ extends:
810
rules:
911
react/react-in-jsx-scope: off
1012
react/prop-types: off
13+
class-methods-use-this: off # TODO: Remove after pegasus update to v3
1114

1215
overrides:
1316
- files:

package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
},
4343
"devDependencies": {
4444
"@babel/core": "^7.15.8",
45+
"@babel/eslint-parser": "^7.15.8",
4546
"@babel/preset-env": "^7.15.8",
4647
"@rollup/plugin-babel": "^5.3.0",
4748
"@rollup/plugin-commonjs": "^21.0.1",

src/ReactRenderer.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { createElement, Fragment } from 'react';
1+
import { createElement } from 'react';
22

33
class ReactRenderer {
4-
constructor() {
5-
this.elementId = 0;
6-
}
4+
elementId = 0;
75

86
crel(el, children, props) {
97
const elProps = {
@@ -14,18 +12,14 @@ class ReactRenderer {
1412
return createElement(el, { ...props, ...elProps }, children);
1513
}
1614

17-
heading(text, level) {
18-
return this.crel(`h${level}`, text);
15+
heading(children, level) {
16+
return this.crel(`h${level}`, children);
1917
}
2018

2119
paragraph(children) {
2220
return this.crel('p', children);
2321
}
2422

25-
text(text) {
26-
return this.crel(Fragment, text);
27-
}
28-
2923
link(href, text, openLinksInNewTab) {
3024
const target = openLinksInNewTab ? '_blank' : null;
3125
return this.crel('a', text, { href, target });
@@ -43,22 +37,22 @@ class ReactRenderer {
4337
return this.crel('pre', this.codespan(code, lang));
4438
}
4539

46-
blockquote(quote) {
47-
return this.crel('blockquote', quote);
40+
blockquote(children) {
41+
return this.crel('blockquote', children);
4842
}
4943

5044
list(ordered, children) {
5145
return this.crel(ordered ? 'ol' : 'ul', children);
5246
}
5347

54-
checkbox(checked = false) {
55-
return this.crel('input', null, { type: 'checkbox', disabled: true, checked });
56-
}
57-
5848
listItem(children) {
5949
return this.crel('li', children);
6050
}
6151

52+
checkbox(checked = false) {
53+
return this.crel('input', null, { type: 'checkbox', disabled: true, checked });
54+
}
55+
6256
table(children) {
6357
return this.crel('table', children);
6458
}
@@ -92,8 +86,12 @@ class ReactRenderer {
9286
return this.crel('del', children);
9387
}
9488

89+
text(text) {
90+
return text;
91+
}
92+
9593
html(html) {
96-
return this.crel(Fragment, html);
94+
return html;
9795
}
9896

9997
hr() {

0 commit comments

Comments
 (0)