Skip to content

Commit e7af37b

Browse files
jerryliang64claude
andauthored
fix: handle digits after separator in defaultCamelize (#301)
## Summary - `defaultCamelize` regex `[_-][a-z]` only handled separators followed by letters, leaving separators before digits untouched (e.g. `foo_00.js` → `foo_00` instead of `foo00`) - Extended regex to `[_-][a-z0-9]` so underscores/hyphens before digits are also removed during camelization - Added test fixture `foo_00.js` and assertions covering this edge case across all caseStyle modes ## Test plan - [x] Existing `file_loader.test.js` caseStyle tests pass with new fixture - [x] New test case `should handle separator before digits correctly` verifies `Foo00` is set and `Foo_00` is not - [x] Full test suite passes (the 1 flaky timeout in `load_service.test.js` is a pre-existing parallel race condition) 🤖 Generated with [Claude Code](https://claude.ai/code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved camelization so identifiers with separators (underscores/dashes) followed by digits are transformed correctly (e.g., separator+digits become contiguous capitalized segments). * **Tests** * Added tests verifying correct handling of separator-before-digit cases across multiple naming styles. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
1 parent e8bb315 commit e7af37b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

lib/loader/file_loader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ function defaultCamelize(filepath, caseStyle) {
240240
// FooBar.js > FooBar
241241
// FooBar.js > FooBar
242242
// FooBar.js > fooBar (if lowercaseFirst is true)
243-
property = property.replace(/[_-][a-z]/ig, s => s.substring(1).toUpperCase());
243+
// aaa_00.js > aaa00 (digits after separator should also be handled)
244+
property = property.replace(/[_-][a-z0-9]/ig, s => s.substring(1).toUpperCase());
244245
let first = property[0];
245246
switch (caseStyle) {
246247
case 'lower':
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = {};

test/loader/file_loader.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ describe('test/loader/file_loader.test.js', () => {
265265
assert(target.FooBar2);
266266
assert(target.FooBar3);
267267
assert(target.FooBar4);
268+
assert(target.Foo00);
268269
});
269270

270271
it('should load when caseStyle = camel', () => {
@@ -279,6 +280,7 @@ describe('test/loader/file_loader.test.js', () => {
279280
assert(target.fooBar2);
280281
assert(target.FooBar3);
281282
assert(target.fooBar4);
283+
assert(target.foo00);
282284
});
283285

284286
it('should load when caseStyle = lower', () => {
@@ -293,6 +295,7 @@ describe('test/loader/file_loader.test.js', () => {
293295
assert(target.fooBar2);
294296
assert(target.fooBar3);
295297
assert(target.fooBar4);
298+
assert(target.foo00);
296299
});
297300

298301
it('should load when caseStyle is function', () => {
@@ -312,6 +315,7 @@ describe('test/loader/file_loader.test.js', () => {
312315
assert(target.fooBar2);
313316
assert(target.FooBar3);
314317
assert(target['foo-bar4']);
318+
assert(target.foo00);
315319
});
316320

317321
it('should throw when caseStyle do not return array', () => {
@@ -340,6 +344,20 @@ describe('test/loader/file_loader.test.js', () => {
340344
assert(target.fooBar2);
341345
assert(target.fooBar3);
342346
assert(target.fooBar4);
347+
assert(target.foo00);
348+
});
349+
350+
it('should handle separator before digits correctly', () => {
351+
const target = {};
352+
new FileLoader({
353+
directory: path.join(dirBase, 'camelize'),
354+
target,
355+
caseStyle: 'upper',
356+
}).load();
357+
358+
// foo_00.js should camelize to Foo00, not Foo_00
359+
assert(target.Foo00);
360+
assert(!target.Foo_00);
343361
});
344362
});
345363

0 commit comments

Comments
 (0)