Skip to content

Commit eb8a4ef

Browse files
committed
Strip propTypes in production
1 parent e43dd2e commit eb8a4ef

13 files changed

+131
-104
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"es2015-loose",
44
"stage-1",
55
"react"
6+
],
7+
"plugins": [
8+
"babel-plugin-dev-expression"
69
]
710
}

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
"rules": {
1717
"prefer-arrow-callback": 2,
1818
"semi": [ 2, "never" ]
19+
},
20+
"globals": {
21+
"__DEV__": true
1922
}
2023
}

modules/BrowserRouter.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ const BrowserRouter = ({ basename, forceRefresh, getUserConfirmation, keyLength,
2626
</BrowserHistory>
2727
)
2828

29-
BrowserRouter.propTypes = {
30-
basename: PropTypes.string,
31-
forceRefresh: PropTypes.bool,
32-
getUserConfirmation: PropTypes.func,
33-
keyLength: PropTypes.number,
34-
children: PropTypes.oneOfType([
35-
PropTypes.func,
36-
PropTypes.node
37-
])
29+
if (__DEV__) {
30+
BrowserRouter.propTypes = {
31+
basename: PropTypes.string,
32+
forceRefresh: PropTypes.bool,
33+
getUserConfirmation: PropTypes.func,
34+
keyLength: PropTypes.number,
35+
children: PropTypes.oneOfType([
36+
PropTypes.func,
37+
PropTypes.node
38+
])
39+
}
3840
}
3941

4042
export default BrowserRouter

modules/HashRouter.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ const HashRouter = ({ basename, getUserConfirmation, hashType, ...props }) => (
2525
</HashHistory>
2626
)
2727

28-
HashRouter.propTypes = {
29-
basename: PropTypes.string,
30-
getUserConfirmation: PropTypes.func,
31-
hashType: PropTypes.string,
32-
children: PropTypes.oneOfType([
33-
PropTypes.func,
34-
PropTypes.node
35-
])
28+
if (__DEV__) {
29+
HashRouter.propTypes = {
30+
basename: PropTypes.string,
31+
getUserConfirmation: PropTypes.func,
32+
hashType: PropTypes.string,
33+
children: PropTypes.oneOfType([
34+
PropTypes.func,
35+
PropTypes.node
36+
])
37+
}
3638
}
3739

3840
export default HashRouter

modules/Link.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,6 @@ import {
55
} from './PropTypes'
66

77
class Link extends React.Component {
8-
static propTypes = {
9-
to: PropTypes.oneOfType([ PropTypes.string, PropTypes.object ]).isRequired,
10-
activeStyle: PropTypes.object,
11-
activeClassName: PropTypes.string,
12-
location: PropTypes.object,
13-
activeOnlyWhenExact: PropTypes.bool,
14-
isActive: PropTypes.func,
15-
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
16-
17-
// props we have to deal with but aren't necessarily
18-
// part of the Link API
19-
style: PropTypes.object,
20-
className: PropTypes.string,
21-
target: PropTypes.string,
22-
onClick: PropTypes.func
23-
}
24-
258
static defaultProps = {
269
activeOnlyWhenExact: false,
2710
className: '',
@@ -121,6 +104,25 @@ class Link extends React.Component {
121104
}
122105
}
123106

107+
if (__DEV__) {
108+
Link.propTypes = {
109+
to: PropTypes.oneOfType([ PropTypes.string, PropTypes.object ]).isRequired,
110+
activeStyle: PropTypes.object,
111+
activeClassName: PropTypes.string,
112+
location: PropTypes.object,
113+
activeOnlyWhenExact: PropTypes.bool,
114+
isActive: PropTypes.func,
115+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
116+
117+
// props we have to deal with but aren't necessarily
118+
// part of the Link API
119+
style: PropTypes.object,
120+
className: PropTypes.string,
121+
target: PropTypes.string,
122+
onClick: PropTypes.func
123+
}
124+
}
125+
124126
// we should probably use LocationUtils.createLocationDescriptor
125127
const createLocationDescriptor = (to) =>
126128
typeof to === 'object' ? to : { pathname: to }

modules/Match.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import matchPattern from './matchPattern'
44
import { LocationSubscriber } from './locationEmission'
55

66
class RegisterMatch extends React.Component {
7-
static propTypes = {
8-
children: PropTypes.node.isRequired,
9-
match: PropTypes.any
10-
}
11-
127
static contextTypes = {
138
match: PropTypes.object,
149
serverRouter: PropTypes.object
@@ -58,17 +53,14 @@ class RegisterMatch extends React.Component {
5853
}
5954
}
6055

61-
class Match extends React.Component {
62-
static propTypes = {
63-
pattern: PropTypes.string,
64-
exactly: PropTypes.bool,
65-
location: PropTypes.object,
66-
67-
children: PropTypes.func,
68-
render: PropTypes.func,
69-
component: PropTypes.func
56+
if (__DEV__) {
57+
RegisterMatch.propTypes = {
58+
children: PropTypes.node.isRequired,
59+
match: PropTypes.any
7060
}
61+
}
7162

63+
class Match extends React.Component {
7264
static defaultProps = {
7365
exactly: false
7466
}
@@ -110,4 +102,16 @@ class Match extends React.Component {
110102
}
111103
}
112104

105+
if (__DEV__) {
106+
Match.propTypes = {
107+
pattern: PropTypes.string,
108+
exactly: PropTypes.bool,
109+
location: PropTypes.object,
110+
111+
children: PropTypes.func,
112+
render: PropTypes.func,
113+
component: PropTypes.func
114+
}
115+
}
116+
113117
export default Match

modules/MatchProvider.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import {
44
} from './PropTypes'
55

66
class MatchProvider extends React.Component {
7-
static propTypes = {
8-
match: PropTypes.any,
9-
children: PropTypes.node
10-
}
11-
127
static childContextTypes = {
138
match: matchContextType.isRequired
149
}
@@ -88,4 +83,11 @@ class MatchProvider extends React.Component {
8883
}
8984
}
9085

86+
if (__DEV__) {
87+
MatchProvider.propTypes = {
88+
match: PropTypes.any,
89+
children: PropTypes.node
90+
}
91+
}
92+
9193
export default MatchProvider

modules/MemoryRouter.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ const MemoryRouter = ({ getUserConfirmation, initialEntries, initialIndex, keyLe
2525
</MemoryHistory>
2626
)
2727

28-
MemoryRouter.propTypes = {
29-
getUserConfirmation: PropTypes.func,
30-
initialEntries: PropTypes.array,
31-
initialIndex: PropTypes.number,
32-
keyLength: PropTypes.number,
33-
children: PropTypes.oneOfType([
34-
PropTypes.func,
35-
PropTypes.node
36-
])
28+
if (__DEV__) {
29+
MemoryRouter.propTypes = {
30+
getUserConfirmation: PropTypes.func,
31+
initialEntries: PropTypes.array,
32+
initialIndex: PropTypes.number,
33+
keyLength: PropTypes.number,
34+
children: PropTypes.oneOfType([
35+
PropTypes.func,
36+
PropTypes.node
37+
])
38+
}
3739
}
3840

3941
export default MemoryRouter

modules/Miss.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,12 @@ import React, { PropTypes } from 'react'
22
import { location as locationType } from './PropTypes'
33

44
class Miss extends React.Component {
5-
static propTypes = {
6-
children: PropTypes.node,
7-
location: locationType,
8-
render: PropTypes.func,
9-
component: PropTypes.func
10-
}
11-
125
static contextTypes = {
136
match: PropTypes.object,
147
location: PropTypes.object,
158
serverRouter: PropTypes.object
169
}
1710

18-
1911
constructor(props, context) {
2012
super(props, context)
2113

@@ -67,4 +59,13 @@ class Miss extends React.Component {
6759
}
6860
}
6961

62+
if (__DEV__) {
63+
Miss.propTypes = {
64+
children: PropTypes.node,
65+
location: locationType,
66+
render: PropTypes.func,
67+
component: PropTypes.func
68+
}
69+
}
70+
7071
export default Miss

modules/Redirect.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ import {
44
} from './PropTypes'
55

66
class Redirect extends React.Component {
7-
static propTypes = {
8-
to: PropTypes.oneOfType([
9-
PropTypes.string,
10-
PropTypes.object
11-
]).isRequired
12-
}
13-
147
static contextTypes = {
158
router: routerContextType,
169
serverRouter: PropTypes.object
@@ -37,4 +30,13 @@ class Redirect extends React.Component {
3730
}
3831
}
3932

33+
if (__DEV__) {
34+
Redirect.propTypes = {
35+
to: PropTypes.oneOfType([
36+
PropTypes.string,
37+
PropTypes.object
38+
]).isRequired
39+
}
40+
}
41+
4042
export default Redirect

modules/ServerRouter.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@ import React, { PropTypes } from 'react'
22
import StaticRouter from './StaticRouter'
33

44
class ServerRouter extends React.Component {
5-
6-
static propTypes = {
7-
context: PropTypes.object.isRequired,
8-
location: PropTypes.string.isRequired,
9-
children: PropTypes.oneOfType([
10-
PropTypes.func,
11-
PropTypes.node
12-
])
13-
}
14-
155
static childContextTypes = {
166
serverRouter: PropTypes.object.isRequired
177
}
@@ -39,4 +29,15 @@ class ServerRouter extends React.Component {
3929
}
4030
}
4131

32+
if (__DEV__) {
33+
ServerRouter.propTypes = {
34+
context: PropTypes.object.isRequired,
35+
location: PropTypes.string.isRequired,
36+
children: PropTypes.oneOfType([
37+
PropTypes.func,
38+
PropTypes.node
39+
])
40+
}
41+
}
42+
4243
export default ServerRouter

modules/StaticRouter.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@ const stringifyQuery = (query) => (
1717
)
1818

1919
class StaticRouter extends React.Component {
20-
static propTypes = {
21-
children: PropTypes.oneOfType([ PropTypes.node, PropTypes.func ]),
22-
23-
action: actionType.isRequired,
24-
location: PropTypes.oneOfType([ PropTypes.object, PropTypes.string ]).isRequired,
25-
26-
onPush: PropTypes.func.isRequired,
27-
onReplace: PropTypes.func.isRequired,
28-
blockTransitions: PropTypes.func,
29-
30-
stringifyQuery: PropTypes.func.isRequired,
31-
parseQueryString: PropTypes.func.isRequired,
32-
createHref: PropTypes.func.isRequired, // TODO: Clarify why this is useful
33-
34-
basename: PropTypes.string // TODO: Feels like we should be able to remove this
35-
}
36-
3720
static defaultProps = {
3821
stringifyQuery,
3922
parseQueryString,
@@ -120,4 +103,23 @@ class StaticRouter extends React.Component {
120103
}
121104
}
122105

106+
if (__DEV__) {
107+
StaticRouter.propTypes = {
108+
children: PropTypes.oneOfType([ PropTypes.node, PropTypes.func ]),
109+
110+
action: actionType.isRequired,
111+
location: PropTypes.oneOfType([ PropTypes.object, PropTypes.string ]).isRequired,
112+
113+
onPush: PropTypes.func.isRequired,
114+
onReplace: PropTypes.func.isRequired,
115+
blockTransitions: PropTypes.func,
116+
117+
stringifyQuery: PropTypes.func.isRequired,
118+
parseQueryString: PropTypes.func.isRequired,
119+
createHref: PropTypes.func.isRequired, // TODO: Clarify why this is useful
120+
121+
basename: PropTypes.string // TODO: Feels like we should be able to remove this
122+
}
123+
}
124+
123125
export default StaticRouter

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"babel-core": "^6.9.1",
4040
"babel-eslint": "^6.0.4",
4141
"babel-loader": "^6.2.4",
42+
"babel-plugin-dev-expression": "^0.2.1",
4243
"babel-preset-es2015": "^6.14.0",
4344
"babel-preset-es2015-loose": "^8.0.0",
4445
"babel-preset-react": "^6.5.0",

0 commit comments

Comments
 (0)