Skip to content

Commit a8b0ae2

Browse files
committed
fix(diagnostics): ignoring dynamic selectors from dignostics collection until a proper way to handle them is identified
1 parent 423cc6c commit a8b0ae2

7 files changed

Lines changed: 36 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.9.4]
2+
3+
- Dynamic References to selectors is not considered for diagnostics - Partially fixes [#86](https://github.com/Viijay-Kr/react-ts-css/issues/86)
4+
15
## [1.9.3]
26

37
- Disabling References and Code lens due to performance issue
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.sm {
2+
font-size: small;
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import styles from "./DynamicClasses.module.scss";
2+
3+
export const DynamicClasses = ({ size }: { size: "sm" | "md" | "lg" }) => {
4+
return <div className={styles[size]}></div>;
5+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-ts-css",
33
"displayName": "React CSS modules",
44
"description": "React CSS modules - VS code extension for CSS modules support in React projects written in typescript.Supports Definitions, Hover , Completion Providers and Diagnostics",
5-
"version": "1.9.3",
5+
"version": "1.9.4",
66
"author": "Viijay-Kr",
77
"publisher": "viijay-kr",
88
"homepage": "https://github.com/Viijay-Kr/react-ts-css/blob/main/README.md",

src/parser/v2/ts.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const isCssModuleDeclaration = (value: string) => {
1919
type Accessor = {
2020
property: StringLiteral | Identifier;
2121
object: Identifier; // Should always be one of sourceIdentfiers
22+
isDynamic?: boolean;
2223
};
2324
export type ParserResult = {
2425
/** A list of default export identifier of a css module */
@@ -72,6 +73,12 @@ export const parseTypescript = (
7273
accessors.push({
7374
property: path.node.property,
7475
object: path.node.object,
76+
isDynamic:
77+
isIdentifier(path.node.property) &&
78+
content.charAt(
79+
// @ts-expect-error
80+
(path.node.property.loc?.start.index! as number) - 1
81+
) === "[",
7582
});
7683
}
7784
}

src/providers/ts/diagnostics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class SelectorRelatedDiagnostics extends Diagnostics {
102102
renameSelector() {}
103103
runDiagnostics() {
104104
for (const accessor of this.parsedResult?.style_accessors ?? []) {
105-
const { property, object } = accessor;
105+
const { property, object, isDynamic } = accessor;
106106
const style_reference = this.parsedResult?.style_references.get(
107107
object.name
108108
);
@@ -119,6 +119,7 @@ export class SelectorRelatedDiagnostics extends Diagnostics {
119119
return "";
120120
})();
121121
if (
122+
!isDynamic &&
122123
selector !== "" &&
123124
selectors &&
124125
!selectors.has(selector) &&

src/test/suite/extension.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,20 @@ suite("Extension Test Suite", async () => {
343343
const diagnostics = await StorageInstance.bootStrap();
344344
assert.equal(diagnostics?.length, 2);
345345
});
346+
347+
test("should not provide dignostics for dynamic slectors", async () => {
348+
const DynamicClasses = Uri.file(
349+
path.join(
350+
__dirname,
351+
examplesLocation,
352+
"react-app/src/test/DynamicClasses/DynamicClasses.tsx"
353+
)
354+
);
355+
const document = await workspace.openTextDocument(DynamicClasses);
356+
await window.showTextDocument(document);
357+
const diagnostics = await StorageInstance.bootStrap();
358+
assert.equal(diagnostics?.length, 0);
359+
});
346360
});
347361
});
348362

0 commit comments

Comments
 (0)