From 835ff7cb409cdea45206e321bc9a48da10d1eb43 Mon Sep 17 00:00:00 2001 From: Bilal Akbar Date: Tue, 18 Nov 2025 14:03:55 +0500 Subject: [PATCH] prevent double underscores in snake case mapper when using underscores before digits --- lib/utils/identifierMapping.js | 2 +- tests/unit/utils.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/utils/identifierMapping.js b/lib/utils/identifierMapping.js index dfa2164c9..4deb464a4 100644 --- a/lib/utils/identifierMapping.js +++ b/lib/utils/identifierMapping.js @@ -51,7 +51,7 @@ function snakeCase( // If underScoreBeforeDigits is true then, well, insert an underscore // before digits :). Only the first digit gets an underscore if // there are multiple. - if (underscoreBeforeDigits && isDigit(char) && !isDigit(prevChar)) { + if (underscoreBeforeDigits && isDigit(char) && !isDigit(prevChar) && prevChar !== '_') { out += '_' + char; continue; } diff --git a/tests/unit/utils.js b/tests/unit/utils.js index b0fb68864..4a6e661ac 100644 --- a/tests/unit/utils.js +++ b/tests/unit/utils.js @@ -135,6 +135,7 @@ describe('utils', () => { testUnderscoreBeforeNumbers('fööBäR', 'föö_bä_r'); testUnderscoreBeforeNumbers('foo1bar2', 'foo_1bar_2'); + testUnderscoreBeforeNumbers('foo_1bar_2', 'foo_1bar_2', 'foo1bar2'); testUnderscoreBeforeNumbers('Foo', 'foo', 'foo'); testUnderscoreBeforeNumbers('FooBar', 'foo_bar', 'fooBar'); testUnderscoreBeforeNumbers('märkäLänttiÄäliö', 'märkä_läntti_ääliö');