Skip to content

Commit

Permalink
[Chore] Babel 7: Upgrade Dependency and AST related Changes
Browse files Browse the repository at this point in the history
Refactored constant expressions and memoize PropType to Flow mapping.
Update React-Utils from react-codemod repo.

Minor Version Upgrade against #5

Signed-off-by: Progyan Bhattacharya <[email protected]>
  • Loading branch information
Progyan-APAC authored and 0xTheProDev committed Nov 26, 2019
1 parent dfcaf65 commit 109d276
Show file tree
Hide file tree
Showing 31 changed files with 5,676 additions and 3,628 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
'prettier',
],
rules: {
'comma-dangle': ['error', 'always-multiline'],
"comma-dangle": [1, 'only-multiline'],
'import/order': ['error', {
'groups': ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
}],
Expand Down
106 changes: 103 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,104 @@
node_modules
coverage
# Logs
logs
*.log
npm-debug.log*
.DS_Store
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
56 changes: 18 additions & 38 deletions __tests__/__snapshots__/proptypes-to-flow-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`React.PropTypes to flow add empty PropTypes (no constructor) 1`] = `
"
/* @flow */
// @flow
import React from 'react';
import { View } from 'react-native';
Expand All @@ -22,7 +22,7 @@ exports[`React.PropTypes to flow add empty PropTypes (no constructor) 1`] = `
exports[`React.PropTypes to flow adds empty PropTypes (constructor) 1`] = `
"
/* @flow */
// @flow
import { Component } from 'react';
import { View } from 'react-native';
import PureRenderMixin from 'react-addons-pure-render-mixin';
Expand Down Expand Up @@ -77,7 +77,7 @@ exports[`React.PropTypes to flow adds type annotation to \`prop\` parameter in c
exports[`React.PropTypes to flow does not touch files with flow Props already declared 1`] = `
"
/* @flow */
// @flow
import React from 'react';
export type Props = {
Expand Down Expand Up @@ -113,7 +113,7 @@ exports[`React.PropTypes to flow does not touch non React classes 1`] = `
exports[`React.PropTypes to flow handles block comments 1`] = `
"
/* @flow */
// @flow
import React from 'react';
type Props = {
Expand All @@ -130,7 +130,7 @@ exports[`React.PropTypes to flow handles block comments 1`] = `
exports[`React.PropTypes to flow handles functional components with expression body 1`] = `
"
/* @flow */
// @flow
import React from 'react';
export type Props = { hello: string };
const MyComponent = (props: Props) => {
Expand All @@ -143,7 +143,7 @@ exports[`React.PropTypes to flow handles functional components with expression b
exports[`React.PropTypes to flow handles presence of defaultProps 1`] = `
"
/* @flow */
// @flow
import React from 'react';
type Props = {
Expand All @@ -164,7 +164,7 @@ exports[`React.PropTypes to flow handles presence of defaultProps 1`] = `
exports[`React.PropTypes to flow preserves comments 1`] = `
"
/* @flow */
// @flow
import React from 'react';
export type Props = {
Expand Down Expand Up @@ -217,7 +217,7 @@ exports[`React.PropTypes to flow preserves comments 1`] = `
exports[`React.PropTypes to flow removes react's 16 PropTypes import 1`] = `
"
/* @flow */
// @flow
import React from 'react';
export type Props = {
Expand All @@ -237,7 +237,7 @@ exports[`React.PropTypes to flow removes react's 16 PropTypes import 1`] = `
exports[`React.PropTypes to flow removes react's 16 destructured PropTypes import 1`] = `
"
/* @flow */
// @flow
import React from 'react';
export type Props = { optionalArray?: Array<any> };
Expand All @@ -253,7 +253,7 @@ exports[`React.PropTypes to flow removes react's 16 destructured PropTypes impor
exports[`React.PropTypes to flow transforms PropTypes that are a class property 1`] = `
"
/* @flow */
// @flow
import React from 'react';
type Props = {
Expand Down Expand Up @@ -288,30 +288,10 @@ exports[`React.PropTypes to flow transforms PropTypes that are a class property
exports[`React.PropTypes to flow transforms PropTypes that are defined outside of class definition 1`] = `
"
/* @flow */
// @flow
import React from 'react';
type Props = {
optionalArray?: Array<any>,
optionalBool?: boolean,
optionalFunc?: Function,
optionalNumber?: number,
optionalObject?: Object,
optionalString?: string,
optionalNode?: number | string | React.Element | Array<any>,
optionalElement?: React.Element,
optionalMessage?: Message,
optionalEnum?: 'News' | 'Photos',
optionalUnion?: string | number | Message,
optionalArrayOf?: Array<number>,
optionalObjectOf?: Object<number>,
optionalObjectWithShape?: {
color?: string,
fontSize?: number,
},
requiredFunc: Function,
requiredAny: any,
};
type Props = {};
export default class Test extends React.Component<Props> {
componentDidMount() {
Expand All @@ -322,7 +302,7 @@ exports[`React.PropTypes to flow transforms PropTypes that are defined outside o
exports[`React.PropTypes to flow transforms optional PropTypes prefixed with \`React\` 1`] = `
"
/* @flow */
// @flow
import React from 'react';
export type Props = {
Expand Down Expand Up @@ -352,7 +332,7 @@ exports[`React.PropTypes to flow transforms optional PropTypes prefixed with \`R
exports[`React.PropTypes to flow transforms optional PropTypes with no \`React\` prefix 1`] = `
"
/* @flow */
// @flow
import React from 'react';
export type Props = {
Expand Down Expand Up @@ -387,7 +367,7 @@ exports[`React.PropTypes to flow transforms optional PropTypes with no \`React\`
exports[`React.PropTypes to flow transforms required PropTypes prefixed with \`React\` 1`] = `
"
/* @flow */
// @flow
/* eslint */
import React from 'react';
Expand Down Expand Up @@ -434,7 +414,7 @@ exports[`React.PropTypes to flow transforms required PropTypes prefixed with \`R
exports[`React.PropTypes to flow transforms required PropTypes with no \`React\` prefix 1`] = `
"
/* @flow */
// @flow
import React from 'react';
export type Props = {
Expand Down Expand Up @@ -469,11 +449,11 @@ exports[`React.PropTypes to flow transforms required PropTypes with no \`React\`
exports[`React.PropTypes to flow transforms something that just looks like React class 1`] = `
"
/* @flow */
// @flow
import React from 'react';
import PureComponent from '../PureComponent';
type Props = { optionalArray?: Array<any> };
type Props = {};
class Test extends PureComponent<Props> {
render() {
Expand Down
11 changes: 6 additions & 5 deletions __tests__/proptypes-to-flow-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-env jest */
const jscodeshift = require('jscodeshift');
import { withParser } from 'jscodeshift';
import transform from '../src';

const transform = require('../src/index').default;
const jscodeshift = withParser('babylon');

const transformString = (source, path = 'test.js') => {
return transform({ path, source }, { jscodeshift }, {});
const transformString = source => {
return transform({ source }, { jscodeshift });
};

describe('React.PropTypes to flow', () => {
Expand Down Expand Up @@ -532,7 +533,7 @@ describe('React.PropTypes to flow', () => {

it('does not touch files with flow Props already declared', () => {
const input = `
/* @flow */
// @flow
import React from 'react';
export type Props = {
Expand Down
13 changes: 13 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: '10',
},
},
],
'@babel/preset-flow',
],
};
Loading

0 comments on commit 109d276

Please sign in to comment.