Skip to content

Commit

Permalink
Merge pull request #47 from vordgi/ncm-44
Browse files Browse the repository at this point in the history
ncm-44 fix reservednames logic
  • Loading branch information
vordgi authored Jan 19, 2024
2 parents fb9bdd9 + 2756174 commit a252f7c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-classnames-minifier",
"version": "2.2.3",
"version": "2.2.4",
"description": "Library for configuring style modules to generate compressed classes",
"main": "dist/withClassnamesMinifier.js",
"types": "dist/withClassnamesMinifier.d.ts",
Expand Down
13 changes: 8 additions & 5 deletions src/lib/converters/ConverterMinified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class ConverterMinified implements ConverterBase {
const cachedMatchings = classnames.reduce<{[orig: string]: string}>((acc, cur) => {
const [origClass, newClass] = cur.split('=');
acc[origClass] = newClass;
usedClassNames.push(newClass);
if (!usedClassNames.includes(newClass)) {
usedClassNames.push(newClass);
}
return acc;
}, {});
dirtyСache[resourcePath] = {
Expand Down Expand Up @@ -118,16 +120,17 @@ class ConverterMinified implements ConverterBase {
return currentClassname;
}

getTargetClassName() {
getTargetClassName(origName: string) {
let targetClassName: string;
if (this.freeClasses.length) {
targetClassName = this.freeClasses.shift() as string;
} else {
targetClassName = this.generateClassName();
}

while (this.reservedNames.includes(targetClassName)) {
targetClassName = this.getTargetClassName();
if (this.reservedNames.includes(targetClassName)) {
targetClassName = this.getTargetClassName(origName);
this.lastIndex += 1;
}

return targetClassName;
Expand All @@ -141,7 +144,7 @@ class ConverterMinified implements ConverterBase {

if (currentCache.matchings[origName]) return currentCache.matchings[origName];

let targetClassName = this.getTargetClassName();
let targetClassName = this.getTargetClassName(origName);
currentCache.matchings[origName] = targetClassName;
currentCache.type = 'updated';
this.lastIndex += 1;
Expand Down

0 comments on commit a252f7c

Please sign in to comment.