Skip to content

Commit

Permalink
feat: add switch and switchCase treatment (#520)
Browse files Browse the repository at this point in the history
* feat: add switch and switchCase treatment

* feat: add processing to entry array

* test: adjustment unit test
  • Loading branch information
ProfBramble authored Oct 10, 2020
1 parent 4a89311 commit 917e8dc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ export default class Plugin {
this.buildExpressionHandler(node, ['callee', 'arguments'], path, state);
}

SwitchStatement(path, state) {
const { node } = path;
this.buildExpressionHandler(node, ['discriminant'], path, state);
}

SwitchCase(path, state) {
const { node } = path;
this.buildExpressionHandler(node, ['test'], path, state);
}

ClassDeclaration(path, state) {
const { node } = path;
this.buildExpressionHandler(node, ['superClass'], path, state);
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export default function ({ types }) {
'BinaryExpression',
'NewExpression',
'ClassDeclaration',
'SwitchStatement',
'SwitchCase',
];

const ret = {
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/switch/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Select } from 'antd';

switch(Select){
case Select:
console.log('foo');
default:
console.log('bar')
}
13 changes: 13 additions & 0 deletions test/fixtures/switch/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

var _select = _interopRequireDefault(require("antd/lib/select"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

switch (_select.default) {
case _select.default:
console.log('foo');

default:
console.log('bar');
}

0 comments on commit 917e8dc

Please sign in to comment.