Skip to content

Commit

Permalink
Revert "Revert "fix: camel case match (#632)" (#634)"
Browse files Browse the repository at this point in the history
This reverts commit 33b05c9.
  • Loading branch information
zombieJ committed Jul 26, 2023
1 parent 33b05c9 commit 8f7f9a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Plugin.js
Expand Up @@ -2,8 +2,11 @@ import { join } from 'path';
import { addSideEffect, addDefault, addNamed } from '@babel/helper-module-imports';

function transCamel(_str, symbol) {
const str = _str[0].toLowerCase() + _str.substr(1);
return str.replace(/([A-Z])/g, $1 => `${symbol}${$1.toLowerCase()}`);
// e.g. QRCode
// First match: QR
// Second match: Code
const cells = _str.match(/([A-Z]+(?=[A-Z]))|([A-Z]?[^A-Z]+)/g) || [];
return cells.map(c => c.toLowerCase()).join(symbol);
}

function winPath(path) {
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/qr-code/actual.js
@@ -0,0 +1,8 @@
import { QRCode } from 'antd';

switch(QRCode){
case QRCode:
console.log('foo');
default:
console.log('bar')
}
7 changes: 7 additions & 0 deletions test/fixtures/qr-code/expected.js
@@ -0,0 +1,7 @@
import _QRCode from "antd/lib/qr-code";
switch (_QRCode) {
case _QRCode:
console.log('foo');
default:
console.log('bar');
}

0 comments on commit 8f7f9a6

Please sign in to comment.