Skip to content

Commit 533c7e7

Browse files
committed
Remove Flow
1 parent ebfea41 commit 533c7e7

9 files changed

Lines changed: 65 additions & 681 deletions

File tree

.babelrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"node": 8
88
}
99
}
10-
],
11-
"@babel/preset-flow"
10+
]
1211
],
1312
"plugins": [
1413
"@babel/plugin-proposal-class-properties",

.eslintrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ root: true
33
parser: "babel-eslint"
44
extends:
55
- "airbnb-base"
6-
- "plugin:flowtype/recommended"
76
- "plugin:jest/recommended"
87
- "prettier"
9-
- "prettier/flowtype"
108

119
plugins:
12-
- "flowtype"
1310
- "jest"
1411

1512
env:
@@ -18,6 +15,7 @@ env:
1815
rules:
1916
one-var: off
2017
prefer-const: off
18+
lines-between-class-members: off
2119
no-use-before-define:
2220
- error
2321
- functions: false

.flowconfig

Lines changed: 0 additions & 7 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules
22
dist
33
coverage
4-
flow-coverage
54
.jest-cache

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,13 @@
4949
"@babel/plugin-proposal-class-properties": "^7.3.0",
5050
"@babel/plugin-proposal-do-expressions": "^7.2.0",
5151
"@babel/preset-env": "^7.3.1",
52-
"@babel/preset-flow": "^7.0.0",
5352
"babel-eslint": "^10.0.1",
5453
"common-tags": "^1.8.0",
5554
"eslint": "^5.12.1",
5655
"eslint-config-airbnb-base": "^13.1.0",
5756
"eslint-config-prettier": "^4.0.0",
58-
"eslint-plugin-flowtype": "^3.2.1",
5957
"eslint-plugin-import": "^2.15.0",
6058
"eslint-plugin-jest": "^22.1.3",
61-
"flow-bin": "^0.91.0",
62-
"flow-coverage-report": "^0.6.1",
6359
"jest": "^24.0.0",
6460
"npm-run-all": "^4.1.5",
6561
"opn-cli": "^4.0.0",

src/index.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
// @flow
21
import { plugin } from 'postcss';
3-
import Visitor, { type Options } from './visitor';
2+
import Visitor from './visitor';
43
import { name } from '../package.json';
54

6-
export default plugin(
7-
name,
8-
(options: Options) => (css: Object, result: Object) => {
9-
const visitor = new Visitor(options);
10-
visitor.result = result;
5+
export default plugin(name, options => (css, result) => {
6+
const visitor = new Visitor(options);
7+
visitor.result = result;
118

12-
visitor.prepend();
9+
visitor.prepend();
1310

14-
css.walkRules(visitor.collect);
11+
css.walkRules(visitor.collect);
1512

16-
visitor.resolveNested();
13+
visitor.resolveNested();
1714

18-
css.walkAtRules('apply', visitor.resolve);
19-
}
20-
);
15+
css.walkAtRules('apply', visitor.resolve);
16+
});

src/utils/index.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
// @flow
2-
3-
export function kebabify(prop: string): string {
4-
const upperToHyphen = (
5-
match: string,
6-
offset: number,
7-
string: string
8-
): string => {
1+
export function kebabify(prop) {
2+
const upperToHyphen = (match, offset, string) => {
93
const addDash = offset && string.charAt(offset - 1) !== '-';
104

115
return (addDash ? '-' : '') + match.toLowerCase();
@@ -14,5 +8,5 @@ export function kebabify(prop: string): string {
148
return prop.replace(/[A-Z]/g, upperToHyphen);
159
}
1610

17-
export const isPlainObject = (arg: any) =>
11+
export const isPlainObject = arg =>
1812
Object.prototype.toString.call(arg) === '[object Object]';

src/visitor.js

Lines changed: 22 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @flow
21
/* eslint-disable no-param-reassign */
32

43
import balanced from 'balanced-match';
@@ -7,54 +6,17 @@ import { kebabify, isPlainObject } from './utils';
76

87
const RE_PROP_SET = /^(--)([\w-]+)(\s*)([:]?)$/;
98

10-
export type Options = {
11-
preserve?: boolean,
12-
sets?: {
13-
[key: string]: {
14-
[key: string]: string,
15-
},
16-
},
17-
};
18-
19-
type Node = Object;
20-
type Decl = Object;
21-
type Result = Object;
22-
23-
type Rule = {
24-
type: string,
25-
selector: string,
26-
selectors: Array<string>,
27-
nodes: Array<Node>,
28-
parent: Rule,
29-
raws: Object,
30-
last: boolean,
31-
warn: (result: Result, text: string, opts?: Object) => void,
32-
clone: () => Rule,
33-
remove: () => void,
34-
append: () => void,
35-
prepend: (children: Node | Array<Node> | Object | string) => void,
36-
insertBefore: (node: Node, add: Node | Array<Node> | Object | string) => void,
37-
replaceWith: (nodes: Array<Node>) => void,
38-
walkDecls: (rule: Decl) => void,
39-
};
40-
41-
type AtRule = {
42-
params: string,
43-
} & Rule;
44-
459
export default class Visitor {
4610
cache = {};
47-
4811
result = {};
12+
options = {};
4913

50-
options: Options = {};
51-
52-
defaults: Options = {
14+
defaults = {
5315
preserve: false,
5416
sets: {},
5517
};
5618

57-
constructor(options: Options) {
19+
constructor(options) {
5820
this.options = {
5921
...this.defaults,
6022
...options,
@@ -68,11 +30,9 @@ export default class Visitor {
6830
prepend = () => {
6931
const { sets } = this.options;
7032

71-
// $FlowFixMe
72-
Object.keys(sets).forEach((setName: string) => {
73-
const newRule: Rule = postcss.rule({ selector: `--${setName}` });
33+
Object.keys(sets).forEach(setName => {
34+
const newRule = postcss.rule({ selector: `--${setName}` });
7435

75-
// $FlowFixMe
7636
const set = sets[setName];
7737

7838
if (typeof set === 'string') {
@@ -94,15 +54,15 @@ export default class Visitor {
9454
/**
9555
* Collect all `:root` declared property sets and save them.
9656
*/
97-
collect = (rule: Rule) => {
57+
collect = rule => {
9858
const matches = RE_PROP_SET.exec(rule.selector);
9959

10060
if (!matches) {
10161
return;
10262
}
10363

104-
const setName: string = matches[2];
105-
const { parent }: Rule = rule;
64+
const setName = matches[2];
65+
const { parent } = rule;
10666

10767
if (parent.selector !== ':root') {
10868
rule.warn(
@@ -122,7 +82,7 @@ export default class Visitor {
12282
// Custom property sets override each other wholly,
12383
// rather than cascading together like colliding style rules do.
12484
// @see: https://tabatkins.github.io/specs/css-apply-rule/#defining
125-
const newRule: Rule = rule.clone();
85+
const newRule = rule.clone();
12686
this.cache[setName] = newRule;
12787

12888
if (!this.options.preserve) {
@@ -139,8 +99,8 @@ export default class Visitor {
13999
* Replace nested `@apply` at-rules declarations.
140100
*/
141101
resolveNested = () => {
142-
Object.keys(this.cache).forEach((rule: string) => {
143-
this.cache[rule].walkAtRules('apply', (atRule: AtRule) => {
102+
Object.keys(this.cache).forEach(rule => {
103+
this.cache[rule].walkAtRules('apply', atRule => {
144104
this.resolve(atRule);
145105

146106
// @TODO honor `preserve` option.
@@ -152,8 +112,8 @@ export default class Visitor {
152112
/**
153113
* Replace `@apply` at-rules declarations with provided custom property set.
154114
*/
155-
resolve = (atRule: AtRule) => {
156-
let ancestor: Rule = atRule.parent;
115+
resolve = atRule => {
116+
let ancestor = atRule.parent;
157117

158118
while (ancestor && ancestor.type !== 'rule') {
159119
ancestor = ancestor.parent;
@@ -173,15 +133,15 @@ export default class Visitor {
173133
return;
174134
}
175135

176-
const param: string = getParamValue(atRule.params);
136+
const param = getParamValue(atRule.params);
177137
const matches = RE_PROP_SET.exec(param);
178138

179139
if (!matches) {
180140
return;
181141
}
182142

183-
const setName: string = matches[2];
184-
const { parent }: Rule = atRule;
143+
const setName = matches[2];
144+
const { parent } = atRule;
185145

186146
if (!(setName in this.cache)) {
187147
atRule.warn(
@@ -208,7 +168,7 @@ export default class Visitor {
208168
/**
209169
* Helper: return whether the rule is a custom property set definition.
210170
*/
211-
function isDefinition(rule: Rule): boolean {
171+
function isDefinition(rule) {
212172
return (
213173
!!rule.selector &&
214174
!!RE_PROP_SET.exec(rule.selector) &&
@@ -220,15 +180,15 @@ function isDefinition(rule: Rule): boolean {
220180
* Helper: allow parens usage in `@apply` AtRule declaration.
221181
* This is for Polymer integration.
222182
*/
223-
function getParamValue(param: string): string {
183+
function getParamValue(param) {
224184
return /^\(/.test(param) ? balanced('(', ')', param).body : param;
225185
}
226186

227187
/**
228188
* Helper: remove excessive declarations indentation.
229189
*/
230-
function cleanIndent(rule: Rule) {
231-
rule.walkDecls((decl: Decl) => {
190+
function cleanIndent(rule) {
191+
rule.walkDecls(decl => {
232192
if (typeof decl.raws.before === 'string') {
233193
decl.raws.before = decl.raws.before.replace(/[^\S\n\r]{2,}/, ' ');
234194
}
@@ -239,7 +199,7 @@ function cleanIndent(rule: Rule) {
239199
* Helper: correctly handle property sets removal and semi-colons.
240200
* @See: postcss/postcss#1014
241201
*/
242-
function safeRemoveRule(rule: Rule) {
202+
function safeRemoveRule(rule) {
243203
if (rule === rule.parent.last && rule.raws.ownSemicolon) {
244204
rule.parent.raws.semicolon = true;
245205
}
@@ -250,7 +210,7 @@ function safeRemoveRule(rule: Rule) {
250210
/**
251211
* Helper: remove immediate preceding comments.
252212
*/
253-
function removeCommentBefore(node: Node) {
213+
function removeCommentBefore(node) {
254214
const previousNode = node.prev();
255215

256216
if (previousNode && previousNode.type === 'comment') {

0 commit comments

Comments
 (0)