Skip to content

Commit c8cee27

Browse files
authored
Upgrade Flow (#168)
1 parent d099c68 commit c8cee27

File tree

7 files changed

+38
-41
lines changed

7 files changed

+38
-41
lines changed

.flowconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[ignore]
2-
.*/node_modules/@lerna/.*
2+
.*/node_modules/immutable/dist/immutable.js.flow
33

44
[include]
55

@@ -8,7 +8,6 @@
88
[options]
99
module.system=haste
1010
esproposal.class_static_fields=enable
11-
unsafe.enable_getters_and_setters=true
1211

1312
module.name_mapper='^draft-js-import-element$' -> '<PROJECT_ROOT>/packages/draft-js-import-element/src/main'
1413
module.name_mapper='^draft-js-utils$' -> '<PROJECT_ROOT>/packages/draft-js-utils/src/main'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"eslint-plugin-flowtype": "^2.35.1",
2727
"eslint-plugin-react": "^7.3.0",
2828
"expect": "^1.20.1",
29-
"flow-bin": "0.42.0",
29+
"flow-bin": "^0.92.1",
3030
"jest": "^20.0.4",
3131
"lerna": "^3.10.7",
3232
"prettier-eslint-cli": "^4.3.0",

packages/draft-js-export-markdown/src/stateToMarkdown.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,11 @@ class MarkupGenerator {
182182
this.listItemCounts[blockDepth] + 1);
183183
}
184184

185-
insertLineBreaks() {
185+
insertLineBreaks(n: number) {
186186
if (this.currentBlock > 0) {
187-
this.output.push('\n');
187+
for (let i = 0; i < n; i++) {
188+
this.output.push('\n');
189+
}
188190
}
189191
}
190192

packages/draft-js-import-html/src/stateFromHTML.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ type Options = {
1414
customInlineFn?: CustomInlineFn;
1515
};
1616

17+
const defaultOptions: Options = {};
18+
1719
export default function stateFromHTML(
1820
html: string,
1921
options?: Options,
2022
): ContentState {
21-
let {parser, ...otherOptions} = options || {};
23+
let {parser, ...otherOptions} = options || defaultOptions;
2224
if (parser == null) {
2325
parser = parseHTML;
2426
}

packages/synthetic-dom/src/SyntheticDOM.js

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export class Node {
3131
nodeType: number;
3232
nodeName: string;
3333
nodeValue: string;
34+
childNodes: ?Array<Node>;
35+
toString(isXHTML: ?boolean): string {
36+
return isXHTML ? '' : '';
37+
}
3438
}
3539

3640
export class TextNode extends Node {
@@ -41,7 +45,8 @@ export class TextNode extends Node {
4145
this.nodeValue = value;
4246
}
4347

44-
toString(): string {
48+
// eslint-disable-next-line no-unused-vars
49+
toString(isXHTML: ?boolean): string {
4550
return escape(this.nodeValue);
4651
}
4752
}
@@ -50,7 +55,7 @@ export class ElementNode extends Node {
5055
_name: string;
5156
_attrMap: Map<string, Attr>;
5257
_isSelfClosing: boolean;
53-
childNodes: Array<Node>;
58+
childNodes: ?Array<Node>;
5459
attributes: AttrList;
5560

5661
constructor(name: string, attributes: ?AttrList, childNodes: ?Array<Node>) {
@@ -72,14 +77,10 @@ export class ElementNode extends Node {
7277
}
7378

7479
appendChild(node: Node) {
75-
if (node.nodeType === NODE_TYPE_FRAGMENT) {
76-
if (node.childNodes != null) {
77-
// $FlowIssue - Flow doesn't realize that node is a FragmentNode.
78-
let childNodes: Array<Node> = node.childNodes;
79-
this.childNodes.push(...childNodes);
80-
}
80+
if (node.nodeType === NODE_TYPE_FRAGMENT && node.childNodes) {
81+
this.childNodes && this.childNodes.push(...node.childNodes);
8182
} else {
82-
this.childNodes.push(node);
83+
this.childNodes && this.childNodes.push(node);
8384
}
8485
}
8586

@@ -108,23 +109,16 @@ export class ElementNode extends Node {
108109
return '<' + this._name + attrString + (isXHTML ? '/>' : '>');
109110
}
110111
let childNodes = this.childNodes
111-
.map((node) => node.toString(isXHTML))
112-
.join('');
112+
? this.childNodes.map((node) => node.toString(isXHTML)).join('')
113+
: '';
113114
return (
114-
'<' +
115-
this._name +
116-
attrString +
117-
'>' +
118-
childNodes +
119-
'</' +
120-
this._name +
121-
'>'
115+
'<' + this._name + attrString + '>' + childNodes + '</' + this._name + '>'
122116
);
123117
}
124118
}
125119

126120
export class FragmentNode extends Node {
127-
childNodes: Array<Node>;
121+
childNodes: ?Array<Node>;
128122

129123
constructor(childNodes: Array<Node>) {
130124
super(...arguments);
@@ -136,19 +130,18 @@ export class FragmentNode extends Node {
136130
}
137131

138132
appendChild(node: Node) {
139-
if (node.nodeType === NODE_TYPE_FRAGMENT) {
140-
if (node.childNodes != null) {
141-
// $FlowIssue - Flow doesn't realize that node is a FragmentNode.
142-
let childNodes: Array<Node> = node.childNodes;
143-
this.childNodes.push(...childNodes);
144-
}
133+
if (node.nodeType === NODE_TYPE_FRAGMENT && node.childNodes) {
134+
this.childNodes && this.childNodes.push(...node.childNodes);
145135
} else {
146-
this.childNodes.push(node);
136+
this.childNodes && this.childNodes.push(node);
147137
}
148138
}
149139

150140
toString(isXHTML: ?boolean): string {
151-
return this.childNodes.map((node) => node.toString(isXHTML)).join('');
141+
let childNodes = this.childNodes;
142+
return childNodes
143+
? childNodes.map((node) => node.toString(isXHTML)).join('')
144+
: '';
152145
}
153146
}
154147

packages/synthetic-dom/src/__tests__/SyntheticDOM-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('Elements', () => {
4646
it('should ignore children for self-closing (void) tags', () => {
4747
let p = new ElementNode('p');
4848
let element = new ElementNode('hr', null, [p]);
49-
expect(element.childNodes.length).toBe(0);
49+
expect(element.childNodes && element.childNodes.length).toBe(0);
5050
expect(element.toString()).toBe('<hr>');
5151
});
5252

@@ -65,11 +65,11 @@ describe('Elements', () => {
6565
{name: 'className', value: 'def'},
6666
];
6767
let element = new ElementNode('div', attrs, [p]);
68-
expect(element.childNodes.length).toBe(1);
69-
let firstChild = element.childNodes[0];
68+
expect(element.childNodes && element.childNodes.length).toBe(1);
69+
let firstChild = element.childNodes ? element.childNodes[0] : null;
7070
// Weird branching to make Flow happy.
7171
if (firstChild instanceof ElementNode) {
72-
expect(firstChild.childNodes.length).toBe(2);
72+
expect(firstChild.childNodes && firstChild.childNodes.length).toBe(2);
7373
} else {
7474
expect(firstChild).toBeAn(ElementNode);
7575
}

yarn.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,9 +2927,10 @@ flat-cache@^1.2.1:
29272927
graceful-fs "^4.1.2"
29282928
write "^0.2.1"
29292929

2930-
2931-
version "0.42.0"
2932-
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.42.0.tgz#05dd754b6b052de7b150f9210e2160746961e3cf"
2930+
flow-bin@^0.92.1:
2931+
version "0.92.1"
2932+
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.92.1.tgz#32c136c07235f30c42dc0549a0790f370fad4070"
2933+
integrity sha512-F5kC5oQOR2FXROAeybJHFqgZP+moKV9fa/53QK4Q4WayTQHdA0KSl48KD1gP0A9mioRLiKUegTva/7I15cX3Iw==
29332934

29342935
flush-write-stream@^1.0.0:
29352936
version "1.1.0"

0 commit comments

Comments
 (0)