New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unused production code #18
Conversation
checkPropTypes.js
Outdated
var warning = require('fbjs/lib/warning'); | ||
|
||
var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret'); | ||
|
||
var invariant = emptyFunction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call this invariantInDevOnly
. This is not how we usually use invariant
so it might be very confusing.
Can you show the build output after? |
Sure! I'll give that a try today and let you know.
@gaearon bellow is the (prettified) minified output from Diff--- prop-types.min.master.js 2017-04-11 09:26:03.000000000 -0500
+++ prop-types.min.js 2017-04-11 09:25:55.000000000 -0500
@@ -1,18 +1,12 @@
-!(function(f) {
- if ("object" == typeof exports && "undefined" != typeof module)
- module.exports = f();
- else if ("function" == typeof define && define.amd)
- define([], f);
+! function (f) {
+ if ("object" == typeof exports && "undefined" != typeof module) module.exports = f();
+ else if ("function" == typeof define && define.amd) define([], f);
else {
var g;
- (g = "undefined" != typeof window
- ? window
- : "undefined" != typeof global
- ? global
- : "undefined" != typeof self ? self : this), (g.PropTypes = f());
+ g = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this, g.PropTypes = f()
}
-})(function() {
- return (function e(t, n, r) {
+}(function () {
+ return function e(t, n, r) {
function s(o, u) {
if (!n[o]) {
if (!t[o]) {
@@ -20,172 +14,108 @@
if (!u && a) return a(o, !0);
if (i) return i(o, !0);
var f = new Error("Cannot find module '" + o + "'");
- throw ((f.code = "MODULE_NOT_FOUND"), f);
+ throw f.code = "MODULE_NOT_FOUND", f
}
- var l = (n[o] = { exports: {} });
- t[o][0].call(
- l.exports,
- function(e) {
+ var l = n[o] = {
+ exports: {}
+ };
+ t[o][0].call(l.exports, function (e) {
var n = t[o][1][e];
- return s(n ? n : e);
- },
- l,
- l.exports,
- e,
- t,
- n,
- r
- );
- }
- return n[o].exports;
- }
- for (
- var i = "function" == typeof require && require, o = 0;
- o < r.length;
- o++
- ) s(r[o]);
- return s;
- })(
- {
- 1: [
- function(require, module) {
- "use strict";
- function checkPropTypes(
- typeSpecs,
- values,
- location,
- componentName,
- getStack
- ) {}
- require(6), require(7), require(4);
- module.exports = checkPropTypes;
- },
- { 4: 4, 6: 6, 7: 7 }
- ],
- 2: [
- function(require, module) {
- "use strict";
- var checkPropTypes = (require(5), require(7), require(4), require(1));
- module.exports = function(isValidElement) {
- function PropTypeError(message) {
- (this.message = message), (this.stack = "");
- }
- var ReactPropTypes,
- productionTypeChecker = ("function" == typeof Symbol &&
- Symbol.iterator, function() {
- throw new Error(
- "React.PropTypes type checking code is stripped in production."
- );
+ return s(n ? n : e)
+ }, l, l.exports, e, t, n, r)
+ }
+ return n[o].exports
+ }
+ for (var i = "function" == typeof require && require, o = 0; o < r.length; o++) s(r[o]);
+ return s
+ }({
+ 1: [function (require, module) {
+ "use strict";
+
+ function checkPropTypes() {}
+ require(5), require(6), require(4);
+ module.exports = checkPropTypes
+ }, {
+ 4: 4,
+ 5: 5,
+ 6: 6
+ }],
+ 2: [function (require, module) {
+ "use strict";
+ var checkPropTypes = (require(5), require(6), require(4), require(1));
+ module.exports = function () {
+ function r(e) {
+ this.message = e, this.stack = ""
+ }
+ var o, t = ("function" == typeof Symbol && Symbol.iterator, function () {
+ throw new Error("prop-types type checking code is stripped in production.")
});
- productionTypeChecker.isRequired = productionTypeChecker;
- var getProductionTypeChecker = function() {
- return productionTypeChecker;
+ t.isRequired = t;
+ var n = function () {
+ return t
};
- return (ReactPropTypes = {
- array: productionTypeChecker,
- bool: productionTypeChecker,
- func: productionTypeChecker,
- number: productionTypeChecker,
- object: productionTypeChecker,
- string: productionTypeChecker,
- symbol: productionTypeChecker,
- any: productionTypeChecker,
- arrayOf: getProductionTypeChecker,
- element: productionTypeChecker,
- instanceOf: getProductionTypeChecker,
- node: productionTypeChecker,
- objectOf: getProductionTypeChecker,
- oneOf: getProductionTypeChecker,
- oneOfType: getProductionTypeChecker,
- shape: getProductionTypeChecker
- }), (PropTypeError.prototype = Error.prototype), (ReactPropTypes.checkPropTypes = checkPropTypes), (ReactPropTypes.PropTypes = ReactPropTypes), ReactPropTypes;
- };
- },
- { 1: 1, 4: 4, 5: 5, 7: 7 }
- ],
- 3: [
- function(require, module) {
- function isValidElement(object) {
- return "object" == typeof object &&
- null !== object &&
- object.$$typeof === REACT_ELEMENT_TYPE;
+ return o = {
+ array: t,
+ bool: t,
+ func: t,
+ number: t,
+ object: t,
+ string: t,
+ symbol: t,
+ any: t,
+ arrayOf: n,
+ element: t,
+ instanceOf: n,
+ node: t,
+ objectOf: n,
+ oneOf: n,
+ oneOfType: n,
+ shape: n
+ }, r.prototype = Error.prototype, o.checkPropTypes = checkPropTypes, o.PropTypes = o, o
+ }
+ }, {
+ 1: 1,
+ 4: 4,
+ 5: 5,
+ 6: 6
+ }],
+ 3: [function (require, module) {
+ function isValidElement(e) {
+ return "object" == typeof e && null !== e && e.$$typeof === REACT_ELEMENT_TYPE
}
var factory = require(2),
- REACT_ELEMENT_TYPE = ("function" == typeof Symbol &&
- Symbol["for"] &&
- Symbol["for"]("react.element")) ||
- 60103;
- module.exports = factory(isValidElement);
- },
- { 2: 2 }
- ],
- 4: [
- function(require, module) {
+ REACT_ELEMENT_TYPE = "function" == typeof Symbol && Symbol["for"] && Symbol["for"]("react.element") || 60103;
+ module.exports = factory(isValidElement)
+ }, {
+ 2: 2
+ }],
+ 4: [function (require, module) {
"use strict";
var ReactPropTypesSecret = "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";
- module.exports = ReactPropTypesSecret;
- },
- {}
- ],
- 5: [
- function(require, module) {
+ module.exports = ReactPropTypesSecret
+ }, {}],
+ 5: [function (require, module) {
"use strict";
+
function makeEmptyFunction(arg) {
- return function() {
- return arg;
- };
+ return function () {
+ return arg
}
- var emptyFunction = function() {};
- (emptyFunction.thatReturns = makeEmptyFunction), (emptyFunction.thatReturnsFalse = makeEmptyFunction(
- !1
- )), (emptyFunction.thatReturnsTrue = makeEmptyFunction(
- !0
- )), (emptyFunction.thatReturnsNull = makeEmptyFunction(
- null
- )), (emptyFunction.thatReturnsThis = function() {
- return this;
- }), (emptyFunction.thatReturnsArgument = function(arg) {
- return arg;
- }), (module.exports = emptyFunction);
- },
- {}
- ],
- 6: [
- function(require, module) {
- "use strict";
- function invariant(condition, format, a, b, c, d, e, f) {
- if ((validateFormat(format), !condition)) {
- var error;
- if (void 0 === format)
- error = new Error(
- "Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings."
- );
- else {
- var args = [a, b, c, d, e, f], argIndex = 0;
- (error = new Error(
- format.replace(/%s/g, function() {
- return args[argIndex++];
- })
- )), (error.name = "Invariant Violation");
- }
- throw ((error.framesToPop = 1), error);
- }
- }
- var validateFormat = function() {};
- module.exports = invariant;
- },
- {}
- ],
- 7: [
- function(require, module) {
- "use strict";
- var emptyFunction = require(5), warning = emptyFunction;
- module.exports = warning;
- },
- { 5: 5 }
- ]
- },
- {},
- [3]
- )(3);
+ }
+ var emptyFunction = function () {};
+ emptyFunction.thatReturns = makeEmptyFunction, emptyFunction.thatReturnsFalse = makeEmptyFunction(!1), emptyFunction.thatReturnsTrue = makeEmptyFunction(!0), emptyFunction.thatReturnsNull = makeEmptyFunction(null), emptyFunction.thatReturnsThis = function () {
+ return this
+ }, emptyFunction.thatReturnsArgument = function (arg) {
+ return arg
+ }, module.exports = emptyFunction
+ }, {}],
+ 6: [function (require, module) {
+ "use strict";
+ var emptyFunction = require(5),
+ warning = emptyFunction;
+ module.exports = warning
+ }, {
+ 5: 5
+ }]
+ }, {}, [3])(3)
}); prop-types.min.js on master!(function(f) {
if ("object" == typeof exports && "undefined" != typeof module)
module.exports = f();
else if ("function" == typeof define && define.amd)
define([], f);
else {
var g;
(g = "undefined" != typeof window
? window
: "undefined" != typeof global
? global
: "undefined" != typeof self ? self : this), (g.PropTypes = f());
}
})(function() {
return (function e(t, n, r) {
function s(o, u) {
if (!n[o]) {
if (!t[o]) {
var a = "function" == typeof require && require;
if (!u && a) return a(o, !0);
if (i) return i(o, !0);
var f = new Error("Cannot find module '" + o + "'");
throw ((f.code = "MODULE_NOT_FOUND"), f);
}
var l = (n[o] = { exports: {} });
t[o][0].call(
l.exports,
function(e) {
var n = t[o][1][e];
return s(n ? n : e);
},
l,
l.exports,
e,
t,
n,
r
);
}
return n[o].exports;
}
for (
var i = "function" == typeof require && require, o = 0;
o < r.length;
o++
) s(r[o]);
return s;
})(
{
1: [
function(require, module) {
"use strict";
function checkPropTypes(
typeSpecs,
values,
location,
componentName,
getStack
) {}
require(6), require(7), require(4);
module.exports = checkPropTypes;
},
{ 4: 4, 6: 6, 7: 7 }
],
2: [
function(require, module) {
"use strict";
var checkPropTypes = (require(5), require(7), require(4), require(1));
module.exports = function(isValidElement) {
function PropTypeError(message) {
(this.message = message), (this.stack = "");
}
var ReactPropTypes,
productionTypeChecker = ("function" == typeof Symbol &&
Symbol.iterator, function() {
throw new Error(
"React.PropTypes type checking code is stripped in production."
);
});
productionTypeChecker.isRequired = productionTypeChecker;
var getProductionTypeChecker = function() {
return productionTypeChecker;
};
return (ReactPropTypes = {
array: productionTypeChecker,
bool: productionTypeChecker,
func: productionTypeChecker,
number: productionTypeChecker,
object: productionTypeChecker,
string: productionTypeChecker,
symbol: productionTypeChecker,
any: productionTypeChecker,
arrayOf: getProductionTypeChecker,
element: productionTypeChecker,
instanceOf: getProductionTypeChecker,
node: productionTypeChecker,
objectOf: getProductionTypeChecker,
oneOf: getProductionTypeChecker,
oneOfType: getProductionTypeChecker,
shape: getProductionTypeChecker
}), (PropTypeError.prototype = Error.prototype), (ReactPropTypes.checkPropTypes = checkPropTypes), (ReactPropTypes.PropTypes = ReactPropTypes), ReactPropTypes;
};
},
{ 1: 1, 4: 4, 5: 5, 7: 7 }
],
3: [
function(require, module) {
function isValidElement(object) {
return "object" == typeof object &&
null !== object &&
object.$$typeof === REACT_ELEMENT_TYPE;
}
var factory = require(2),
REACT_ELEMENT_TYPE = ("function" == typeof Symbol &&
Symbol["for"] &&
Symbol["for"]("react.element")) ||
60103;
module.exports = factory(isValidElement);
},
{ 2: 2 }
],
4: [
function(require, module) {
"use strict";
var ReactPropTypesSecret = "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";
module.exports = ReactPropTypesSecret;
},
{}
],
5: [
function(require, module) {
"use strict";
function makeEmptyFunction(arg) {
return function() {
return arg;
};
}
var emptyFunction = function() {};
(emptyFunction.thatReturns = makeEmptyFunction), (emptyFunction.thatReturnsFalse = makeEmptyFunction(
!1
)), (emptyFunction.thatReturnsTrue = makeEmptyFunction(
!0
)), (emptyFunction.thatReturnsNull = makeEmptyFunction(
null
)), (emptyFunction.thatReturnsThis = function() {
return this;
}), (emptyFunction.thatReturnsArgument = function(arg) {
return arg;
}), (module.exports = emptyFunction);
},
{}
],
6: [
function(require, module) {
"use strict";
function invariant(condition, format, a, b, c, d, e, f) {
if ((validateFormat(format), !condition)) {
var error;
if (void 0 === format)
error = new Error(
"Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings."
);
else {
var args = [a, b, c, d, e, f], argIndex = 0;
(error = new Error(
format.replace(/%s/g, function() {
return args[argIndex++];
})
)), (error.name = "Invariant Violation");
}
throw ((error.framesToPop = 1), error);
}
}
var validateFormat = function() {};
module.exports = invariant;
},
{}
],
7: [
function(require, module) {
"use strict";
var emptyFunction = require(5), warning = emptyFunction;
module.exports = warning;
},
{ 5: 5 }
]
},
{},
[3]
)(3);
}); prop-types.min.js with these changes! function (f) {
if ("object" == typeof exports && "undefined" != typeof module) module.exports = f();
else if ("function" == typeof define && define.amd) define([], f);
else {
var g;
g = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this, g.PropTypes = f()
}
}(function () {
return function e(t, n, r) {
function s(o, u) {
if (!n[o]) {
if (!t[o]) {
var a = "function" == typeof require && require;
if (!u && a) return a(o, !0);
if (i) return i(o, !0);
var f = new Error("Cannot find module '" + o + "'");
throw f.code = "MODULE_NOT_FOUND", f
}
var l = n[o] = {
exports: {}
};
t[o][0].call(l.exports, function (e) {
var n = t[o][1][e];
return s(n ? n : e)
}, l, l.exports, e, t, n, r)
}
return n[o].exports
}
for (var i = "function" == typeof require && require, o = 0; o < r.length; o++) s(r[o]);
return s
}({
1: [function (require, module) {
"use strict";
function checkPropTypes() {}
require(5), require(6), require(4);
module.exports = checkPropTypes
}, {
4: 4,
5: 5,
6: 6
}],
2: [function (require, module) {
"use strict";
var checkPropTypes = (require(5), require(6), require(4), require(1));
module.exports = function () {
function r(e) {
this.message = e, this.stack = ""
}
var o, t = ("function" == typeof Symbol && Symbol.iterator, function () {
throw new Error("prop-types type checking code is stripped in production.")
});
t.isRequired = t;
var n = function () {
return t
};
return o = {
array: t,
bool: t,
func: t,
number: t,
object: t,
string: t,
symbol: t,
any: t,
arrayOf: n,
element: t,
instanceOf: n,
node: t,
objectOf: n,
oneOf: n,
oneOfType: n,
shape: n
}, r.prototype = Error.prototype, o.checkPropTypes = checkPropTypes, o.PropTypes = o, o
}
}, {
1: 1,
4: 4,
5: 5,
6: 6
}],
3: [function (require, module) {
function isValidElement(e) {
return "object" == typeof e && null !== e && e.$$typeof === REACT_ELEMENT_TYPE
}
var factory = require(2),
REACT_ELEMENT_TYPE = "function" == typeof Symbol && Symbol["for"] && Symbol["for"]("react.element") || 60103;
module.exports = factory(isValidElement)
}, {
2: 2
}],
4: [function (require, module) {
"use strict";
var ReactPropTypesSecret = "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";
module.exports = ReactPropTypesSecret
}, {}],
5: [function (require, module) {
"use strict";
function makeEmptyFunction(arg) {
return function () {
return arg
}
}
var emptyFunction = function () {};
emptyFunction.thatReturns = makeEmptyFunction, emptyFunction.thatReturnsFalse = makeEmptyFunction(!1), emptyFunction.thatReturnsTrue = makeEmptyFunction(!0), emptyFunction.thatReturnsNull = makeEmptyFunction(null), emptyFunction.thatReturnsThis = function () {
return this
}, emptyFunction.thatReturnsArgument = function (arg) {
return arg
}, module.exports = emptyFunction
}, {}],
6: [function (require, module) {
"use strict";
var emptyFunction = require(5),
warning = emptyFunction;
module.exports = warning
}, {
5: 5
}]
}, {}, [3])(3)
}); |
Thanks for the PR! Since there was a larger issue I changed how we bundle |
Resolves #16
fbjs/lib/invariant
in DEV, otherwise useemptyFunction
. This mirrors whatwarning
does internallyuglifyify
to remove the conditionalinvariant
requirebundle-collapser