Skip to content

Commit

Permalink
ToggleWithRouterHoc function components fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyyakym committed Oct 15, 2018
1 parent de388bb commit 08fa2dc
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 13 deletions.
14 changes: 14 additions & 0 deletions src/__tests__/data/toggle-with-router-hoc/input/button6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { Tooltip, Icon } from 'antd';

const branchUrl = 'https://github.com/ant-design/ant-design/edit/master/';

export default function EditButton({ title, filename }) {
return (
<Tooltip title={title}>
<a className="edit-button" href={`${branchUrl}${filename}`} target="_blank" rel="noopener noreferrer">
<Icon type="edit" />
</a>
</Tooltip>
);
}
17 changes: 17 additions & 0 deletions src/__tests__/data/toggle-with-router-hoc/input/button7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { Tooltip, Icon } from 'antd';
import { withRouter } from 'react-router';

const branchUrl = 'https://github.com/ant-design/ant-design/edit/master/';

function EditButton({ title, filename }) {
return (
<Tooltip title={title}>
<a className="edit-button" href={`${branchUrl}${filename}`} target="_blank" rel="noopener noreferrer">
<Icon type="edit" />
</a>
</Tooltip>
);
}

export default withRouter(EditButton);
17 changes: 17 additions & 0 deletions src/__tests__/data/toggle-with-router-hoc/output/button6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { Tooltip, Icon } from 'antd';
import { withRouter } from 'react-router';

const branchUrl = 'https://github.com/ant-design/ant-design/edit/master/';

function EditButton({ title, filename }) {
return (
<Tooltip title={title}>
<a className="edit-button" href={`${branchUrl}${filename}`} target="_blank" rel="noopener noreferrer">
<Icon type="edit" />
</a>
</Tooltip>
);
}

export default withRouter(EditButton);
16 changes: 16 additions & 0 deletions src/__tests__/data/toggle-with-router-hoc/output/button7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { Tooltip, Icon } from 'antd';

const branchUrl = 'https://github.com/ant-design/ant-design/edit/master/';

function EditButton({ title, filename }) {
return (
<Tooltip title={title}>
<a className="edit-button" href={`${branchUrl}${filename}`} target="_blank" rel="noopener noreferrer">
<Icon type="edit" />
</a>
</Tooltip>
);
}

export default EditButton;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ConvertToFunctionComponent = require('../refactorings/convert-to-function-
const convertFunctionToArrowComponent = new ConvertFunctionToArrowComponent();
const convertToFunctionComponent = new ConvertToFunctionComponent();

class ConnectRefactoring extends Refactoring {
class FunctionComponentCompatibleRefactoring extends Refactoring {
getTransformations(initialCode) {
if (convertFunctionToArrowComponent.canApply(initialCode)) {
return [
Expand Down Expand Up @@ -54,4 +54,4 @@ class ConnectRefactoring extends Refactoring {
}
}

module.exports = ConnectRefactoring;
module.exports = FunctionComponentCompatibleRefactoring;
4 changes: 2 additions & 2 deletions src/refactorings/connect-map-dispatch-to-props/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ReduxConnectBuilder = require('../../builders/redux-connect-builder');
const ConnectRefactoring = require('../../model/connect-refactoring');
const FunctionComponentCompatibleRefactoring = require('../../model/function-component-compatible-refactoring');

class ConnectMapDispatchToProps extends ConnectRefactoring {
class ConnectMapDispatchToProps extends FunctionComponentCompatibleRefactoring {
constructor() {
super();
this.transformations = [
Expand Down
4 changes: 2 additions & 2 deletions src/refactorings/connect-map-state-to-props/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ReduxConnectBuilder = require('../../builders/redux-connect-builder');
const ConnectRefactoring = require('../../model/connect-refactoring');
const FunctionComponentCompatibleRefactoring = require('../../model/function-component-compatible-refactoring');

class ConnectMapStateToProps extends ConnectRefactoring {
class ConnectMapStateToProps extends FunctionComponentCompatibleRefactoring {
constructor() {
super();
this.transformations = [
Expand Down
4 changes: 2 additions & 2 deletions src/refactorings/connect-merge-props/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ReduxConnectBuilder = require('../../builders/redux-connect-builder');
const ConnectRefactoring = require('../../model/connect-refactoring');
const FunctionComponentCompatibleRefactoring = require('../../model/function-component-compatible-refactoring');

class ConnectMergeProps extends ConnectRefactoring {
class ConnectMergeProps extends FunctionComponentCompatibleRefactoring {
constructor() {
super();
this.transformations = [
Expand Down
4 changes: 2 additions & 2 deletions src/refactorings/connect/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ReduxConnectBuilder = require('../../builders/redux-connect-builder');
const ConnectRefactoring = require('../../model/connect-refactoring');
const FunctionComponentCompatibleRefactoring = require('../../model/function-component-compatible-refactoring');

class Connect extends ConnectRefactoring {
class Connect extends FunctionComponentCompatibleRefactoring {
constructor() {
super();
this.transformations = [
Expand Down
13 changes: 10 additions & 3 deletions src/refactorings/toggle-with-router-hoc/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
const { isIdentifier } = require('@babel/types');
const { Refactoring } = require('../../model');
const FunctionComponentCompatibleRefactoring = require('../../model/function-component-compatible-refactoring');
const parser = require('../../utils/parser');
const ComponentExportDetails = require('../../utils/component-export-details');
const wrapComponent = require('../../transformations/wrap-component');
const unwrapComponent = require('../../transformations/unwrap-component');

class ToggleWithRouterHoc extends Refactoring {
class ToggleWithRouterHoc extends FunctionComponentCompatibleRefactoring {
constructor() {
super();
this.transformations = [
this.toggleWithRouterHoc.bind(this)
];
}

canApply() {
return true;
}

refactor(code, ast = parser.parse(code)) {
toggleWithRouterHoc(code, ast = parser.parse(code)) {
const details = new ComponentExportDetails(ast).getDetails();
const { outermostHocPath } = details;
let isWrapped = false;
Expand Down

0 comments on commit 08fa2dc

Please sign in to comment.