Skip to content

Commit

Permalink
Merge pull request #111 from willofindie/fix/issue-110
Browse files Browse the repository at this point in the history
 fix: `node.nodes` can be empty for some rules
  • Loading branch information
phoenisx authored Oct 12, 2023
2 parents 74ee93b + d82198a commit 8afae0c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.6.4](https://github.com/willofindie/vscode-cssvar/compare/v2.6.3...2.6.4) - 2023-10-12
### Fixes
- #110(https://github.com/willofindie/vscode-cssvar/issues/110) Failed to parse CSS variable with @layer declaration


## [2.6.3](https://github.com/willofindie/vscode-cssvar/compare/v2.6.2...v2.6.3) - 2023-07-02
### Fixes
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ Please find details for CSS colors [here in MDN Docs](https://developer.mozilla.

<br><br><br><br>

<h3 align="center">Phoenisx Sponsors</h3>
<!-- <h3 align="center">Phoenisx Sponsors</h3>
<p align="center">
<a href="./img/sponsors.png">
<img src='./img/sponsors.png'/>
</a>
</p>
</p> -->



Expand Down
12 changes: 12 additions & 0 deletions examples/css-imports/local.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
@import url("https://unpkg.com/[email protected]/orange.min.css");
@import url(./nested.css);

@layer x01, x02;
@layer x01 {
.test {
--test-x01: green;
}
}
@layer x02 {
.test {
--test-x01: red;
}
}

:root {
--gap-sm: 0.25rem;
--gap-md: 0.5rem;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"typescript"
],
"description": "Intellisense support for CSS Variables",
"version": "2.6.3",
"version": "2.6.4",
"publisher": "phoenisx",
"license": "MIT",
"homepage": "https://github.com/willofindie/vscode-cssvar",
Expand Down
10 changes: 6 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function getVariableDeclarations(
if (isNodeType<Rule>(node, SUPPORTED_CSS_RULE_TYPES[0])) {
// For proper theming, following filter condition should be improved
const [theme] = config.themes.filter(theme => node.selector.match(theme));
if (!config.excludeThemedVariables || !theme) {
if (node.nodes && (!config.excludeThemedVariables || !theme)) {
for (const _node of node.nodes) {
const decls = getVariableDeclarations(config, _node, {
...options,
Expand All @@ -208,9 +208,11 @@ export function getVariableDeclarations(
isNodeType<AtRule>(node, SUPPORTED_CSS_RULE_TYPES[2]) &&
SUPPORTED_EVALUATING_ATRULES.has(node.name)
) {
for (const _node of node.nodes) {
const decls = getVariableDeclarations(config, _node, options);
declarations = declarations.concat(decls);
if (node.nodes) {
for (const _node of node.nodes) {
const decls = getVariableDeclarations(config, _node, options);
declarations = declarations.concat(decls);
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/test/at-rules.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@layer x01, x02;
@layer x02 {
.test {
color: firebrick;
}
}
@layer x01 {
.test {
color: limegreen;
}
}

:root {
--red100: #f00;
--red500: #f24455;
}
14 changes: 14 additions & 0 deletions src/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { fetchAndCacheAsset } from "../remote-paths";
const MODIFIED_DATE = new Date("2021-04-12T08:58:58.676Z");
const DUMMY_FILE = path.resolve("src", "test", "touch.css");
const RENAMED_FILE = path.resolve("src", "test", "renamed.css");
const AT_RULES_CSS = path.resolve("src", "test", "at-rules.css");
const BROKEN_FILE = path.resolve("src", "test", "broken.css");
const IMPORT_BASE = path.resolve("src", "test", "css-imports");
const IMPORT_CSS_FILE = path.resolve(IMPORT_BASE, "import.css");
Expand Down Expand Up @@ -153,6 +154,19 @@ describe("Test Parser", () => {
await parseFiles(updatedConfig);
expect(fetchAndCacheAsset).toHaveBeenCalledTimes(0);
});

it("Should parse at-rules", async () => {
// Updated config should contain the latest renamed file name.
const updatedConfig: ConfigRecord = {
[CACHE.activeRootPath]: {
...EXTENSION_CONFIG[CACHE.activeRootPath],
files: [getLocalCSSVarLocation(AT_RULES_CSS)],
},
};
CACHE.config = updatedConfig;
const [_, errorPaths] = await parseFiles(updatedConfig);
expect(errorPaths.length).toBe(0);
});
});

describe("parseFiles handle improper CSS Files", () => {
Expand Down

0 comments on commit 8afae0c

Please sign in to comment.