Skip to content

Commit b25acdd

Browse files
fix: class names defined after comments were not being recognized
1 parent 2cd605b commit b25acdd

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/libs/classNameCache.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { DEBOUNCE_TIMER, SUPPORTED_MODULES } from "../config";
1111
import isPositionInComment from "../utils/isPositionInComment";
1212
import CssModuleDependencyCache from "./cssModuleDependencyCache";
1313
import CheckDocument from "./checkDocument";
14+
import { sanitizeCssInput } from "../utils/sanitizeCssInput";
1415

1516
/**
1617
* A utility class to extract and cache class names from CSS Module files.
@@ -221,7 +222,8 @@ export default class ClassNameCache {
221222
}
222223

223224
const content = document.getText();
224-
const root = safeParser(content);
225+
const sanitizedContent = sanitizeCssInput(content);
226+
const root = safeParser(sanitizedContent);
225227
const classNames = new ClassNameDataMap();
226228
const rules: Parameters<Parameters<(typeof root)["walkRules"]>[0]>[0][] =
227229
[];

src/utils/sanitizeCssInput.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function sanitizeCssInput(css: string): string {
2+
// Replace all lines that start with `//` with an empty string
3+
return css.replace(/^\s*\/\/.*$/gm, "\n");
4+
}

0 commit comments

Comments
 (0)