Skip to content
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

Add babel-plugin-dev expression #2107

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"plugins": ["dev-expression"],
"stage": 1,
"env": {
"development": {
"sourceMap": "inline"
}
}
}
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ plugins:

ecmaFeatures:
jsx: true

globals:
__DEV__: true

5 changes: 1 addition & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ module.exports = function(config) {
extensions: [ '.js', '.jsx' ],
paths: [ './node_modules', './src' ],
transform: [
['babelify', {
stage: 1,
sourceMap: 'inline'
}],
'babelify',
'browserify-istanbul'
]
},
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"scripts": {
"test": "npm run test-base -- --single-run",
"test-watch": "npm run test-base -- --auto-watch",
"test-base": "./node_modules/.bin/karma start",
"test-base": "BABEL_ENV=development ./node_modules/.bin/karma start",
"prebuild": "rimraf lib",
"lint": "gulp eslint",
"build": "babel --stage 1 ./src --out-dir ./lib",
"build": "babel ./src --out-dir ./lib",
"prepublish": "npm run build"
},
"keywords": [
Expand Down Expand Up @@ -49,6 +49,7 @@
"babel-core": "^5.8.21",
"babel-eslint": "^4.1.3",
"babel-loader": "^5.3.2",
"babel-plugin-dev-expression": "^0.1.0",
"babel-runtime": "^5.8.25",
"babelify": "^6.1.3",
"browserify-istanbul": "^0.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/app-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const AppBar = React.createClass({
},

componentDidMount() {
if (process.env.NODE_ENV !== 'production') {
if (__DEV__) {
if (this.props.iconElementLeft && this.props.iconClassNameLeft) {
console.warn(
'Properties iconClassNameLeft and iconElementLeft cannot be simultaneously ' +
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/date-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const DatePicker = React.createClass({
},

setDate(d) {
if (process.env.NODE_ENV !== 'production' && this._isControlled()) {
if (__DEV__ && this._isControlled()) {
console.error('Cannot call DatePicker.setDate when value or valueLink is defined as a property.');
}
this.setState({
Expand Down
35 changes: 15 additions & 20 deletions src/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Overlay = require('./overlay');
const Paper = require('./paper');
const DefaultRawTheme = require('./styles/raw-themes/light-raw-theme');
const ThemeManager = require('./styles/theme-manager');
const warning = (process.env.NODE_ENV !== 'production') ? require('warning') : function(){};
const warning = require('warning');

const ReactTransitionGroup = require('react-addons-transition-group');

Expand Down Expand Up @@ -136,7 +136,7 @@ let Dialog = React.createClass({
},

getInitialState() {
if (process.env.NODE_ENV !== 'production') this._testDeprecations();
if (__DEV__) this._testDeprecations();

let open = this.props.isOpen;

Expand All @@ -155,7 +155,7 @@ let Dialog = React.createClass({
let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
this.setState({muiTheme: newMuiTheme});

if (process.env.NODE_ENV !== 'production') this._testDeprecations();
if (__DEV__) this._testDeprecations();

if (nextProps.isOpen !== this.props.isOpen) {
if (nextProps.isOpen && !this.state.open)
Expand Down Expand Up @@ -283,19 +283,17 @@ let Dialog = React.createClass({
},

_testDeprecations() {
if (process.env.NODE_ENV !== 'production') {
warning(!this.props.hasOwnProperty('openImmediately'),
'openImmediately has been deprecated in favor of defaultIsOpen');
warning(!this.props.hasOwnProperty('openImmediately'),
'openImmediately has been deprecated in favor of defaultIsOpen');

warning(!this.props.hasOwnProperty('onShow'),
'onShow will be removed in favor of explicitly setting isOpen');
warning(!this.props.hasOwnProperty('onShow'),
'onShow will be removed in favor of explicitly setting isOpen');

warning(!this.props.hasOwnProperty('onDismiss'),
'onDismiss will be removed in favor of explicitly setting isOpen and can be replaced by onRequestClose');
warning(!this.props.hasOwnProperty('onDismiss'),
'onDismiss will be removed in favor of explicitly setting isOpen and can be replaced by onRequestClose');

warning(!this.props.hasOwnProperty('modal'),
'modal will be removed in favor of explicitly setting isOpen and onRequestClose');
}
warning(!this.props.hasOwnProperty('modal'),
'modal will be removed in favor of explicitly setting isOpen and onRequestClose');
},

_getAction(actionJSON, key) {
Expand Down Expand Up @@ -399,8 +397,7 @@ let Dialog = React.createClass({
},

show() {
if (process.env.NODE_ENV !== 'production')
warning(false, 'show has been deprecated in favor of explicitly setting the isOpen property.');
warning(false, 'show has been deprecated in favor of explicitly setting the isOpen property.');

this._show();
},
Expand All @@ -415,8 +412,7 @@ let Dialog = React.createClass({
},

dismiss() {
if (process.env.NODE_ENV !== 'production')
warning(false, 'dismiss has been deprecated in favor of explicitly setting the isOpen property.');
warning(false, 'dismiss has been deprecated in favor of explicitly setting the isOpen property.');

this._dismiss();
},
Expand All @@ -434,9 +430,8 @@ let Dialog = React.createClass({
},

_requestClose(buttonClicked) {
if (process.env.NODE_ENV !== 'production')
warning(!this.props.hasOwnProperty('modal'),
'modal will be removed in favor of explicitly setting isOpen and onRequestClose');
warning(!this.props.hasOwnProperty('modal'),
'modal will be removed in favor of explicitly setting isOpen and onRequestClose');

if (!buttonClicked && this.props.modal) return;

Expand Down
2 changes: 1 addition & 1 deletion src/drop-down-icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const DropDownIcon = React.createClass({

componentDidMount() {
// This component can be deprecated once ./menu/menu has been deprecated.
// if (process.env.NODE_ENV !== 'production') {
// if (__DEV__) {
// console.warn('DropDownIcon has been deprecated. Use IconMenu instead.');
// }
},
Expand Down
4 changes: 2 additions & 2 deletions src/drop-down-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const DropDownMenu = React.createClass({
let selectedIndex = this._isControlled() ? null : this.state.selectedIndex;
let displayValue = "";
if (selectedIndex) {
if (process.env.NODE_ENV !== 'production') {
if (__DEV__) {
console.assert(!!this.props.menuItems[selectedIndex], 'SelectedIndex of ' + selectedIndex + ' does not exist in menuItems.');
}
}
Expand Down Expand Up @@ -270,7 +270,7 @@ const DropDownMenu = React.createClass({
_setSelectedIndex(props) {
let selectedIndex = props.selectedIndex;

if (process.env.NODE_ENV !== 'production' && selectedIndex < 0) {
if (__DEV__ && selectedIndex < 0) {
console.warn('Cannot set selectedIndex to a negative index.', selectedIndex);
}

Expand Down
2 changes: 1 addition & 1 deletion src/enhanced-switch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ const EnhancedSwitch = React.createClass({
this.props.onParentShouldUpdate(newSwitchedValue);
ReactDOM.findDOMNode(this.refs.checkbox).checked = newSwitchedValue;
}
else if (process.env.NODE_ENV !== 'production') {
else if (__DEV__) {
let message = 'Cannot call set method while checked is defined as a property.';
console.error(message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/floating-action-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const FloatingActionButton = React.createClass({
},

componentDidMount() {
if (process.env.NODE_ENV !== 'production') {
if (__DEV__) {
if (this.props.iconClassName && this.props.children) {
let warning = 'You have set both an iconClassName and a child icon. ' +
'It is recommended you use only one method when adding ' +
Expand Down
2 changes: 1 addition & 1 deletion src/radio-button-group.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const RadioButtonGroup = React.createClass({
if (this.state.numberCheckedRadioButtons === 0) {
this.setState({selected: newSelection});
}
else if (process.env.NODE_ENV !== 'production') {
else if (__DEV__) {
let message = "Cannot select a different radio button while another radio button " +
"has the 'checked' property set to true.";
console.error(message);
Expand Down
2 changes: 1 addition & 1 deletion src/tabs/tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const Tabs = React.createClass({

let tabs = React.Children.map(children, (tab, index) => {
if (tab.type.displayName === "Tab") {
if (!tab.props.value && tabValue && process.env.NODE_ENV !== 'production') {
if (!tab.props.value && tabValue && __DEV__) {
console.error('Tabs value prop has been passed, but Tab ' + index +
' does not have a value prop. Needs value if Tabs is going' +
' to be a controlled component.');
Expand Down
4 changes: 2 additions & 2 deletions src/text-field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ const TextField = React.createClass({
},

setErrorText(newErrorText) {
if (process.env.NODE_ENV !== 'production' && this.props.hasOwnProperty('errorText')) {
if (__DEV__ && this.props.hasOwnProperty('errorText')) {
console.error('Cannot call TextField.setErrorText when errorText is defined as a property.');
}
else if (this.isMounted()) {
Expand All @@ -401,7 +401,7 @@ const TextField = React.createClass({
},

setValue(newValue) {
if (process.env.NODE_ENV !== 'production' && this._isControlled()) {
if (__DEV__ && this._isControlled()) {
console.error('Cannot call TextField.setValue when value or valueLink is defined as a property.');
}
else if (this.isMounted()) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/date-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const monthLongList = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'];

function DateTimeFormat(locale, options) {
if (process.env.NODE_ENV !== 'production' && locale !== 'en-US') {
if (__DEV__ && locale !== 'en-US') {
console.warn('Wrong usage of DateTimeFormat. The ' + locale +' locale is not supported.');
}

Expand All @@ -25,7 +25,7 @@ function DateTimeFormat(locale, options) {

output = monthLongList[date.getMonth()];
output += ' ' + date.getFullYear();
} else if (process.env.NODE_ENV !== 'production') {
} else if (__DEV__) {
console.warn('Wrong usage of DateTimeFormat');
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
// This function ensures that `style` supports both ltr and rtl directions by checking
// `styleConstants` in `muiTheme` and replacing attribute keys if necessary.
ensureDirection(muiTheme, style) {
if (process.env.NODE_ENV !== 'production') {
if (__DEV__) {
if (style.didFlip) {
console.warn(new Error('You\'re calling `ensureDirection` on the same style object twice.'));
}
Expand Down