diff --git a/src/__tests__/data/toggle-with-router-hoc/input/button6.js b/src/__tests__/data/toggle-with-router-hoc/input/button6.js
new file mode 100644
index 0000000..01d4817
--- /dev/null
+++ b/src/__tests__/data/toggle-with-router-hoc/input/button6.js
@@ -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 (
+
+
+
+
+
+ );
+}
diff --git a/src/__tests__/data/toggle-with-router-hoc/input/button7.js b/src/__tests__/data/toggle-with-router-hoc/input/button7.js
new file mode 100644
index 0000000..98488e1
--- /dev/null
+++ b/src/__tests__/data/toggle-with-router-hoc/input/button7.js
@@ -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 (
+
+
+
+
+
+ );
+}
+
+export default withRouter(EditButton);
diff --git a/src/__tests__/data/toggle-with-router-hoc/output/button6.js b/src/__tests__/data/toggle-with-router-hoc/output/button6.js
new file mode 100644
index 0000000..98488e1
--- /dev/null
+++ b/src/__tests__/data/toggle-with-router-hoc/output/button6.js
@@ -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 (
+
+
+
+
+
+ );
+}
+
+export default withRouter(EditButton);
diff --git a/src/__tests__/data/toggle-with-router-hoc/output/button7.js b/src/__tests__/data/toggle-with-router-hoc/output/button7.js
new file mode 100644
index 0000000..d638d57
--- /dev/null
+++ b/src/__tests__/data/toggle-with-router-hoc/output/button7.js
@@ -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 (
+
+
+
+
+
+ );
+}
+
+export default EditButton;
diff --git a/src/model/connect-refactoring.js b/src/model/function-component-compatible-refactoring.js
similarity index 94%
rename from src/model/connect-refactoring.js
rename to src/model/function-component-compatible-refactoring.js
index 6a2c6d3..ab3b83d 100644
--- a/src/model/connect-refactoring.js
+++ b/src/model/function-component-compatible-refactoring.js
@@ -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 [
@@ -54,4 +54,4 @@ class ConnectRefactoring extends Refactoring {
}
}
-module.exports = ConnectRefactoring;
+module.exports = FunctionComponentCompatibleRefactoring;
diff --git a/src/refactorings/connect-map-dispatch-to-props/index.js b/src/refactorings/connect-map-dispatch-to-props/index.js
index 4848809..39015ba 100644
--- a/src/refactorings/connect-map-dispatch-to-props/index.js
+++ b/src/refactorings/connect-map-dispatch-to-props/index.js
@@ -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 = [
diff --git a/src/refactorings/connect-map-state-to-props/index.js b/src/refactorings/connect-map-state-to-props/index.js
index ab01f28..aedb628 100644
--- a/src/refactorings/connect-map-state-to-props/index.js
+++ b/src/refactorings/connect-map-state-to-props/index.js
@@ -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 = [
diff --git a/src/refactorings/connect-merge-props/index.js b/src/refactorings/connect-merge-props/index.js
index e9d6bde..2be8afc 100644
--- a/src/refactorings/connect-merge-props/index.js
+++ b/src/refactorings/connect-merge-props/index.js
@@ -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 = [
diff --git a/src/refactorings/connect/index.js b/src/refactorings/connect/index.js
index 763b067..f7bd6b2 100644
--- a/src/refactorings/connect/index.js
+++ b/src/refactorings/connect/index.js
@@ -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 = [
diff --git a/src/refactorings/toggle-with-router-hoc/index.js b/src/refactorings/toggle-with-router-hoc/index.js
index f972d2f..f9279e5 100644
--- a/src/refactorings/toggle-with-router-hoc/index.js
+++ b/src/refactorings/toggle-with-router-hoc/index.js
@@ -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;