Comments (4)
So with from 'types'
we detect that it looks like an import from 'node_modules', and decide not to import the type, so it behaves like the import doesn't exist (you'd get the same output if you removed the type import).
If that's changed to from './types'
, which looks like an import of your own source files (presumably also compiled by this plugin), then you get this:
import React from "react";
const X = props => React.createElement("div", null);
X.propTypes = {
aa: function() {
return (typeof bpfrpt_proptype_MyType === "function"
? bpfrpt_proptype_MyType.isRequired
? bpfrpt_proptype_MyType.isRequired
: bpfrpt_proptype_MyType
: PropTypes.shape(bpfrpt_proptype_MyType).isRequired
).apply(this, arguments);
}
};
export default X;
import { bpfrpt_proptype_MyType } from "./types";
import PropTypes from "prop-types";
The reason for the relative vs package import rule is the webpack will error if you try to import something that doesn't exist from an ESM. We had to add it when we started supporting the output you see above, with the import/export syntax being generated.
Your longer output examples are with the import/export syntax we generate being run through the official 'babel-plugin-transform-es2015-modules-commonjs' transform, which is why you get the require/exports.
You can get the plugin to produce require/exports code by enabling the 'deadCode' option, e.g. if you didn't want it to ever eliminate the code, it'd be:
"plugins": [["flow-react-proptypes", { "deadCode": "false" }]]
Hope that clarifies things a bit. Going to close this for now, but if you have ideas on improvements, please share.
from babel-plugin-flow-react-proptypes.
Thanks for the info!
from babel-plugin-flow-react-proptypes.
@brigand would you consider a PR that adds an option (default to current behavior) around https://github.com/brigand/babel-plugin-flow-react-proptypes/blob/master/src/index.js#L629 to bypass the relative path regex / requirement?
We use a flat, haste-like module resolver, where filenames are guaranteed unique. Even in a webpack system, I think the current regex solution could potentially result in confusing behavior if aliases are used.
from babel-plugin-flow-react-proptypes.
@ndreckshage yeah, and option for that seems reasonable. There's no way we can really detect that automatically that I know of.
from babel-plugin-flow-react-proptypes.
Related Issues (20)
- PropTypes are not added to class components with intersected type parameters HOT 2
- Not working when module.name_mapper is used HOT 1
- transforming recompose context props. HOT 1
- Types imported with `import *` (import star) are treated as values, causing runtime error HOT 4
- Add support for $ReadOnlyArray HOT 2
- Error when union types HOT 1
- Perform escape analysis on imported types HOT 3
- Fails to check "Objects as maps"
- Identifier 'PropTypes' has already been declared HOT 2
- Example form README is not transpiled correctly HOT 2
- plugin errors when parsing "empty" types HOT 2
- Undefined variable in output when input file contains two classes using same prop types HOT 4
- Using built-in generics in a generic type fails
- Add support for recursive data types
- aria-{name} and data-{name} props do not work HOT 1
- Issue when using with rollup imports HOT 2
- Support `React.ElementConfig`
- support webpack5
- Suppression only works for the very first directive (which might not be user-controllable)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-plugin-flow-react-proptypes.