babel: using passPerPreset breaks class properties with babel 6.7 (T7274)

Issue originally made by Chirag (chirag04)

Bug information

  • Babel version: 6.7
  • Node version: 5.6.0
  • npm version: 3.6.0

Input code

{
  "passPerPreset": true,
  "presets": [
    "react-native"
  ],
}
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */

import React, {
  AppRegistry,
  Component,
  StyleSheet,
  Text,
  View
} from 'react-native';

class Name extends Component {
  renderName = () => {
    const { name } = this.props;
    return <Text>{name}</Text>
  };

  render() {
    return this.renderName();
  }
};

class aproject extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Name name={'chirag'} />
        <Text style={styles.instructions}>
          To get started, edit index.ios.js
        </Text>
        <Text style={styles.instructions}>
          Press Cmd+R to reload,{'\n'}
          Cmd+D or shake for dev menu
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('aproject', () => aproject);

Description

Doing a fresh install of react-native and adding .babelrc with passPerPresets breaks class properties. I get error like undefined is not an object evaluating this.props.name.

I can confirm with works fine with babel 6.6.

PS: This is my first issue on babel repo and i’m not sure what the general guidelines are for posting an issue.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (5 by maintainers)

Commits related to this issue

Most upvoted comments

BTW, for those of us hitting this issue because of Relay, it’s actually not necessary to use passPerPreset for the Relay plugin.

@yutin1987 it’s just a warning not an error