Skip to content

Commit 8afae0c

Browse files
authored
Merge pull request #111 from willofindie/fix/issue-110
fix: `node.nodes` can be empty for some rules
2 parents 74ee93b + d82198a commit 8afae0c

File tree

7 files changed

+55
-7
lines changed

7 files changed

+55
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

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

812
## [2.6.3](https://github.com/willofindie/vscode-cssvar/compare/v2.6.2...v2.6.3) - 2023-07-02
913
### Fixes

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ Please find details for CSS colors [here in MDN Docs](https://developer.mozilla.
119119

120120
<br><br><br><br>
121121

122-
<h3 align="center">Phoenisx Sponsors</h3>
122+
<!-- <h3 align="center">Phoenisx Sponsors</h3>
123123
124124
<p align="center">
125125
<a href="./img/sponsors.png">
126126
<img src='./img/sponsors.png'/>
127127
</a>
128-
</p>
128+
</p> -->
129129

130130

131131

examples/css-imports/local.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
@import url("https://unpkg.com/[email protected]/orange.min.css");
22
@import url(./nested.css);
33

4+
@layer x01, x02;
5+
@layer x01 {
6+
.test {
7+
--test-x01: green;
8+
}
9+
}
10+
@layer x02 {
11+
.test {
12+
--test-x01: red;
13+
}
14+
}
15+
416
:root {
517
--gap-sm: 0.25rem;
618
--gap-md: 0.5rem;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"typescript"
2121
],
2222
"description": "Intellisense support for CSS Variables",
23-
"version": "2.6.3",
23+
"version": "2.6.4",
2424
"publisher": "phoenisx",
2525
"license": "MIT",
2626
"homepage": "https://github.com/willofindie/vscode-cssvar",

src/parser.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export function getVariableDeclarations(
192192
if (isNodeType<Rule>(node, SUPPORTED_CSS_RULE_TYPES[0])) {
193193
// For proper theming, following filter condition should be improved
194194
const [theme] = config.themes.filter(theme => node.selector.match(theme));
195-
if (!config.excludeThemedVariables || !theme) {
195+
if (node.nodes && (!config.excludeThemedVariables || !theme)) {
196196
for (const _node of node.nodes) {
197197
const decls = getVariableDeclarations(config, _node, {
198198
...options,
@@ -208,9 +208,11 @@ export function getVariableDeclarations(
208208
isNodeType<AtRule>(node, SUPPORTED_CSS_RULE_TYPES[2]) &&
209209
SUPPORTED_EVALUATING_ATRULES.has(node.name)
210210
) {
211-
for (const _node of node.nodes) {
212-
const decls = getVariableDeclarations(config, _node, options);
213-
declarations = declarations.concat(decls);
211+
if (node.nodes) {
212+
for (const _node of node.nodes) {
213+
const decls = getVariableDeclarations(config, _node, options);
214+
declarations = declarations.concat(decls);
215+
}
214216
}
215217
}
216218

src/test/at-rules.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@layer x01, x02;
2+
@layer x02 {
3+
.test {
4+
color: firebrick;
5+
}
6+
}
7+
@layer x01 {
8+
.test {
9+
color: limegreen;
10+
}
11+
}
12+
13+
:root {
14+
--red100: #f00;
15+
--red500: #f24455;
16+
}

src/test/parser.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { fetchAndCacheAsset } from "../remote-paths";
1111
const MODIFIED_DATE = new Date("2021-04-12T08:58:58.676Z");
1212
const DUMMY_FILE = path.resolve("src", "test", "touch.css");
1313
const RENAMED_FILE = path.resolve("src", "test", "renamed.css");
14+
const AT_RULES_CSS = path.resolve("src", "test", "at-rules.css");
1415
const BROKEN_FILE = path.resolve("src", "test", "broken.css");
1516
const IMPORT_BASE = path.resolve("src", "test", "css-imports");
1617
const IMPORT_CSS_FILE = path.resolve(IMPORT_BASE, "import.css");
@@ -153,6 +154,19 @@ describe("Test Parser", () => {
153154
await parseFiles(updatedConfig);
154155
expect(fetchAndCacheAsset).toHaveBeenCalledTimes(0);
155156
});
157+
158+
it("Should parse at-rules", async () => {
159+
// Updated config should contain the latest renamed file name.
160+
const updatedConfig: ConfigRecord = {
161+
[CACHE.activeRootPath]: {
162+
...EXTENSION_CONFIG[CACHE.activeRootPath],
163+
files: [getLocalCSSVarLocation(AT_RULES_CSS)],
164+
},
165+
};
166+
CACHE.config = updatedConfig;
167+
const [_, errorPaths] = await parseFiles(updatedConfig);
168+
expect(errorPaths.length).toBe(0);
169+
});
156170
});
157171

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

0 commit comments

Comments
 (0)