Skip to content

Commit 12a0f32

Browse files
committed
fix: A state cannot be named 'scope'.
The attribute 'scope' is selected by :scope.
1 parent bfa8150 commit 12a0f32

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

packages/@css-blocks/core/src/BlockParser/features/construct-block.ts

+6
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ function assertBlockObject(configuration: Configuration, block: Block, sel: Comp
287287
range(configuration, block.stylesheet, file, rule, n),
288288
);
289289
}
290+
if (n.attribute === "scope") {
291+
throw new errors.InvalidBlockSyntax(
292+
`A state cannot be named 'scope'.`,
293+
range(configuration, block.stylesheet, file, rule, n),
294+
);
295+
}
290296
if (!found) {
291297
throw new errors.InvalidBlockSyntax(
292298
`States without an explicit :scope or class selector are not supported: ${rule.selector}`,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// import { assert } from "chai";
2+
import { suite, test } from "mocha-typescript";
3+
4+
import { assertError } from "../util/assertError";
5+
import { BEMProcessor } from "../util/BEMProcessor";
6+
import { MockImportRegistry } from "../util/MockImportRegistry";
7+
8+
const { InvalidBlockSyntax } = require("../util/postcss-helper");
9+
10+
@suite("Block Attributes")
11+
export class BlockAttributesTest extends BEMProcessor {
12+
13+
@test "An attribute cannot be named 'scope'"() {
14+
let imports = new MockImportRegistry();
15+
16+
let filename = "foo/bar/test-block.css";
17+
let inputCSS = `:scope[scope] { color: red; }`;
18+
19+
return assertError(
20+
InvalidBlockSyntax,
21+
`A state cannot be named 'scope'. (foo/bar/test-block.css:1:7)`,
22+
this.process(filename, inputCSS, {importer: imports.importer()}));
23+
}
24+
}

0 commit comments

Comments
 (0)