.ts, .tsx - Format according to prettier

This commit is contained in:
2019-12-15 16:38:38 +05:30
parent 1019de3d9f
commit 509775028c
3 changed files with 28 additions and 28 deletions
+13 -13
View File
@@ -1,23 +1,23 @@
import * as React from "react"; import * as React from 'react';
import { render } from "../src/renderer"; import { render } from '../src/renderer';
test("should render plain text", () => { test('should render plain text', () => {
expect((render("abcd") as string).trim()).toBe("abcd"); expect((render('abcd') as string).trim()).toBe('abcd');
}); });
test("should render numbers as text", () => { test('should render numbers as text', () => {
expect((render(123) as string).trim()).toBe("123"); expect((render(123) as string).trim()).toBe('123');
}); });
test("should render null and not fail for empty values", () => { test('should render null and not fail for empty values', () => {
expect(render(null)).toBe(null); expect(render(null)).toBe(null);
expect(render(undefined)).toBe(null); expect(render(undefined)).toBe(null);
expect(render([])).toBe(null); expect(render([])).toBe(null);
}); });
test("should render plain text with simple Function Component", () => { test('should render plain text with simple Function Component', () => {
function TestComponent() { function TestComponent() {
return "abcd"; return 'abcd';
} }
// Note: Rendering string from JSX shows TS error (https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544). This is a workaround. // Note: Rendering string from JSX shows TS error (https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544). This is a workaround.
@@ -25,15 +25,15 @@ test("should render plain text with simple Function Component", () => {
(render( (render(
React.createElement((TestComponent as unknown) as React.FunctionComponent) React.createElement((TestComponent as unknown) as React.FunctionComponent)
) as string).trim() ) as string).trim()
).toBe("abcd"); ).toBe('abcd');
}); });
test("should render plain text with simple Class Component", () => { test('should render plain text with simple Class Component', () => {
class TestComponent extends React.Component { class TestComponent extends React.Component {
render() { render() {
return "abcd"; return 'abcd';
} }
} }
expect((render(<TestComponent />) as string).trim()).toBe("abcd"); expect((render(<TestComponent />) as string).trim()).toBe('abcd');
}); });
+4 -4
View File
@@ -3,8 +3,8 @@ import {
ElementType, ElementType,
FunctionComponent, FunctionComponent,
PropsWithChildren, PropsWithChildren,
ReactText ReactText,
} from "react"; } from 'react';
export interface IReactElementSubset<TProps = {}> { export interface IReactElementSubset<TProps = {}> {
props: PropsWithChildren<TProps>; props: PropsWithChildren<TProps>;
@@ -22,7 +22,7 @@ export function isFunctionalComponent(
eleType: ElementType eleType: ElementType
): eleType is FunctionComponent { ): eleType is FunctionComponent {
return ( return (
typeof eleType === "function" && // can be various things typeof eleType === 'function' && // can be various things
!( !(
(eleType.prototype && eleType.prototype.isReactComponent) // native arrows don't have prototypes // special property (eleType.prototype && eleType.prototype.isReactComponent) // native arrows don't have prototypes // special property
) )
@@ -33,7 +33,7 @@ export function isClassComponent(
eleType: ElementType eleType: ElementType
): eleType is ComponentClass { ): eleType is ComponentClass {
return !!( return !!(
typeof eleType === "function" && typeof eleType === 'function' &&
eleType.prototype && eleType.prototype &&
eleType.prototype.isReactComponent eleType.prototype.isReactComponent
); );
+11 -11
View File
@@ -1,15 +1,15 @@
import { root, text } from "mdast-builder"; import { root, text } from 'mdast-builder';
import { Children as ReactChildren } from "react"; import { Children as ReactChildren } from 'react';
import * as stringify from "remark-stringify"; import * as stringify from 'remark-stringify';
import * as unified from "unified"; import * as unified from 'unified';
// tslint:disable-next-line: no-implicit-dependencies // tslint:disable-next-line: no-implicit-dependencies
import { Parent as MDASTParent } from "unist"; import { Parent as MDASTParent } from 'unist';
import { import {
isClassComponent, isClassComponent,
isFunctionalComponent, isFunctionalComponent,
ReactElementSubsetWithPrimitive ReactElementSubsetWithPrimitive,
} from "./helpers"; } from './helpers';
function render( function render(
node: ReactElementSubsetWithPrimitive, node: ReactElementSubsetWithPrimitive,
@@ -24,7 +24,7 @@ function render(
if (node === null || node === undefined) { if (node === null || node === undefined) {
// Handle (skip) null and undefined nodes // Handle (skip) null and undefined nodes
} else if (typeof node === "string" || typeof node === "number") { } else if (typeof node === 'string' || typeof node === 'number') {
// Handle (render) string and number nodes as string in markdown // Handle (render) string and number nodes as string in markdown
const currASTNode = text(node.toString()); const currASTNode = text(node.toString());
@@ -82,10 +82,10 @@ function render(
// For root call, return string // For root call, return string
if (parentASTNode === undefined && parentASTNodeMod.children.length > 0) { if (parentASTNode === undefined && parentASTNodeMod.children.length > 0) {
const processor = unified().use(stringify, { const processor = unified().use(stringify, {
bullet: "-", bullet: '-',
fence: "`", fence: '`',
fences: true, fences: true,
incrementListMarker: false incrementListMarker: false,
}); });
const output = processor.stringify(parentASTNodeMod); const output = processor.stringify(parentASTNodeMod);