Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: camel case match #632

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Plugin.js
Original file line number Diff line number Diff line change
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) || [];
Wxh16144 marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import _QRCode from "antd/lib/qr-code";
switch (_QRCode) {
case _QRCode:
console.log('foo');
default:
console.log('bar');
}
Loading