-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qa(flow): fix flow errors in parser module
- Loading branch information
1 parent
e340ba9
commit b50fe85
Showing
3 changed files
with
82 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,39 @@ | ||
/* @flow */ | ||
/* eslint-disable no-use-before-define */ | ||
|
||
type PropsType = { [key: string]: any }; | ||
type DefaultPropsType = { [key: string]: any }; | ||
|
||
export type TreeNode = {| | ||
type: 'ReactElement' | 'string' | 'number', | ||
|
||
value?: string | number, | ||
|
||
displayName?: string, | ||
props?: { [key: string]: TreeNode }, | ||
defaultProps?: { [key: string]: TreeNode }, | ||
props?: PropsType, | ||
defaultProps?: DefaultPropsType, | ||
childrens?: TreeNode[], | ||
|}; | ||
|
||
export const createStringTreeNode = (value: string): TreeNode => ({ | ||
type: 'string', | ||
value, | ||
}); | ||
|
||
export const createNumberTreeNode = (value: number): TreeNode => ({ | ||
type: 'number', | ||
value, | ||
}); | ||
|
||
export const createReactElementTreeNode = ( | ||
displayName: string, | ||
props: PropsType, | ||
defaultProps: DefaultPropsType, | ||
childrens: TreeNode[] = [] | ||
): TreeNode => ({ | ||
type: 'ReactElement', | ||
displayName, | ||
props, | ||
defaultProps, | ||
childrens, | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* @flow */ | ||
|
||
import { | ||
createStringTreeNode, | ||
createNumberTreeNode, | ||
createReactElementTreeNode, | ||
} from './tree'; | ||
|
||
describe('createStringTreeNode', () => { | ||
it('generate a string typed node payload', () => { | ||
expect(createStringTreeNode('foo')).toEqual({ | ||
type: 'string', | ||
value: 'foo', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('createNumberTreeNode', () => { | ||
it('generate a number typed node payload', () => { | ||
expect(createNumberTreeNode(42)).toEqual({ | ||
type: 'number', | ||
value: 42, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('createReactElementTreeNode', () => { | ||
it('generate a react element typed node payload', () => { | ||
expect( | ||
createReactElementTreeNode('MyComponent', { foo: 42 }, { bar: 51 }, [ | ||
'abc', | ||
]) | ||
).toEqual({ | ||
type: 'ReactElement', | ||
displayName: 'MyComponent', | ||
props: { foo: 42 }, | ||
defaultProps: { bar: 51 }, | ||
childrens: ['abc'], | ||
}); | ||
}); | ||
}); |