-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from Spy-Seth/fix/flow-errors
Fix flow errors
- Loading branch information
Showing
11 changed files
with
176 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/* @flow */ | ||
|
||
import formatReactElementNode from './formatReactElementNode'; | ||
import formatTreeNode from './formatTreeNode'; | ||
import type { Options } from './../options'; | ||
import type { TreeNode } from './../tree'; | ||
|
||
export default (node: TreeNode, options: Options): string => | ||
formatReactElementNode(node, false, 0, options); | ||
formatTreeNode(node, false, 0, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,35 @@ | ||
/* @flow */ | ||
|
||
import { createStringTreeNode } from './../tree'; | ||
import type { TreeNode } from './../tree'; | ||
|
||
export default ( | ||
previousNodes: TreeNode[], | ||
currentNode: TreeNode | ||
): TreeNode[] => { | ||
const lastNode = previousNodes[previousNodes.length - 1]; | ||
const newNode = { ...currentNode }; | ||
|
||
if (newNode.type === 'number') { | ||
newNode.type = 'string'; | ||
newNode.value = String(newNode.value); | ||
} | ||
const nodes = previousNodes.slice( | ||
0, | ||
previousNodes.length > 0 ? previousNodes.length - 1 : 0 | ||
); | ||
const previousNode = previousNodes[previousNodes.length - 1]; | ||
|
||
if ( | ||
lastNode && | ||
lastNode.type === 'string' && | ||
typeof lastNode.value === 'string' && | ||
newNode.type === 'string' | ||
previousNode && | ||
(currentNode.type === 'string' || currentNode.type === 'number') && | ||
(previousNode.type === 'string' || previousNode.type === 'number') | ||
) { | ||
lastNode.value += newNode.value || ''; | ||
nodes.push( | ||
createStringTreeNode( | ||
String(previousNode.value) + String(currentNode.value) | ||
) | ||
); | ||
} else { | ||
previousNodes.push(newNode); | ||
if (previousNode) { | ||
nodes.push(previousNode); | ||
} | ||
|
||
nodes.push(currentNode); | ||
} | ||
|
||
return previousNodes; | ||
return nodes; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,48 @@ | ||
/* @flow */ | ||
/* eslint-disable no-use-before-define */ | ||
|
||
export type TreeNode = {| | ||
type: 'ReactElement' | 'string' | 'number', | ||
type PropsType = { [key: string]: any }; | ||
type DefaultPropsType = { [key: string]: any }; | ||
|
||
value?: string | number, | ||
export type StringTreeNode = {| | ||
type: 'string', | ||
value: string, | ||
|}; | ||
|
||
export type NumberTreeNode = {| | ||
type: 'number', | ||
value: number, | ||
|}; | ||
|
||
displayName?: string, | ||
props?: { [key: string]: TreeNode }, | ||
defaultProps?: { [key: string]: TreeNode }, | ||
childrens?: TreeNode[], | ||
export type ReactElementTreeNode = {| | ||
type: 'ReactElement', | ||
displayName: string, | ||
props: PropsType, | ||
defaultProps: DefaultPropsType, | ||
childrens: TreeNode[], | ||
|}; | ||
|
||
export type TreeNode = StringTreeNode | NumberTreeNode | ReactElementTreeNode; | ||
|
||
export const createStringTreeNode = (value: string): StringTreeNode => ({ | ||
type: 'string', | ||
value, | ||
}); | ||
|
||
export const createNumberTreeNode = (value: number): NumberTreeNode => ({ | ||
type: 'number', | ||
value, | ||
}); | ||
|
||
export const createReactElementTreeNode = ( | ||
displayName: string, | ||
props: PropsType, | ||
defaultProps: DefaultPropsType, | ||
childrens: TreeNode[] | ||
): ReactElementTreeNode => ({ | ||
type: 'ReactElement', | ||
displayName, | ||
props, | ||
defaultProps, | ||
childrens, | ||
}); |
Oops, something went wrong.