-
Notifications
You must be signed in to change notification settings - Fork 61
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
PropTypes not always removed from stateless function components #66
Comments
I have tried reproducing your example with no luck. npm babel-plugin-transform-runtime@6.15.0 babel-preset-es2015@6.18.0 babel-preset-react@6.16.0 babel-preset-stage-1@6.16.0 babel-core@6.13.2 babel-runtime@6.11.6 How is this source code transpiled? |
Via webpack@1.3.2 and babel-loader@6.2.7. The full list of compilation dependencies is quite large. |
I'm clueless here 😕 . It could be linked to a conflict with another Babel plugin. |
We're not using
|
Thanks for the compiled code, that was quite useful! Here is a simple reproduction test case: const Foo11 = () => (
true && <div />
);
Foo11.propTypes = {
foo: React.PropTypes.string
}; That's embarrassing. Oh cool, that's a piece of |
Nice, thanks for tracking down the issue! |
…lement We are traversing the return statement deep down. I still expect some case not behing catched by this approach. But I would rather not take them into account for now. Fix #66.
…lement We are traversing the return statement deep down. I still expect some case not being caught by this approach. But I would rather not take them into account for now. Closes #66.
…lement We are traversing the return statement deep down. I still expect some case not being caught by this approach. But I would rather not take them into account for now. Closes #66.
Hi, I'm also having an issue with getting this working with stateless function components. Original code: const { createElement, PropTypes } = require('react');
const el = createElement;
const Foo = ({ bar }) => {
return el('span', null, bar);
};
Foo.propTypes = {
bar: PropTypes.string,
};
module.exports = Foo; Compiled code: const{createElement,PropTypes}=require('react'),el=createElement,Foo=({bar:a})=>{return el('span',null,a)};Foo.propTypes={bar:PropTypes.string},module.exports=Foo; Does it require If I create a class component, it works just fine, e.g.: const { createElement, PropTypes, PureComponent } = require('react');
const el = createElement;
class Foo extends PureComponent {
render() {
return el('span', null, this.props.bar);
}
}
Foo.propTypes = {
bar: PropTypes.string,
};
module.exports = Foo; Becomes: const{createElement,PropTypes,PureComponent}=require('react'),el=createElement;class Foo extends PureComponent{render(){return el('span',null,this.props.bar)}}module.exports=Foo; |
@mkretschek Without looking at what's actually going on, my best guess would be that we don't resolve the |
Thanks for the fast reply. : ) Unfortunately, I'm getting the same result with |
@mkretschek The issue comes from here. We look for the |
We have a file containing several stateless function components, and one of those components is not having its PropTypes removed. I can't see why, since you have test cases for similar situations. This is what the file roughly looks like:
There are the babel dependencies
The text was updated successfully, but these errors were encountered: