Skip to content

Commit 8ee7d51

Browse files
committed
fix: Only add an analysis for block:scope if it's not explicitly there.
1 parent f69c457 commit 8ee7d51

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

packages/@css-blocks/glimmer/src/ElementAnalyzer.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export class ElementAnalyzer<TemplateType extends keyof TemplateTypes> {
120120
return this._analyze(node, atRootElement, AnalysisMode.REWRITE);
121121
}
122122

123-
analyzeForRewrite(node: AnalyzableNode, atRootElement: boolean): AttrRewriteMap {
124-
return this._analyze(node, atRootElement, AnalysisMode.ANALYZE_AND_REWRITE);
123+
analyzeForRewrite(node: AnalyzableNode, atRootElement: boolean, forbidNonBlockAttributes = false): AttrRewriteMap {
124+
return this._analyze(node, atRootElement, AnalysisMode.ANALYZE_AND_REWRITE, forbidNonBlockAttributes);
125125
}
126126

127127
private debugAnalysis(node: AnalyzableNode, atRootElement: boolean, element: TemplateElement) {
@@ -249,21 +249,24 @@ export class ElementAnalyzer<TemplateType extends keyof TemplateTypes> {
249249

250250
const attrRewrites = {};
251251
let element = attrRewrites["class"] = this.newElement(node, mode);
252-
253-
// The root element gets the block"s root class automatically.
254-
if (atRootElement) {
255-
element.addStaticClass(this.block.rootClass);
256-
}
252+
let explicitScope = false;
257253

258254
// Find the class or scope attribute and process it
259255
for (let analyzableAttr of this.eachAnalyzedAttribute(node, forbidNonBlockAttributes)) {
260256
if (analyzableAttr.type === "class") {
261257
this.processClass(analyzableAttr.namespace, analyzableAttr.property, element, mode);
262258
} else if (analyzableAttr.type === "scope") {
259+
explicitScope = analyzableAttr.namespace === DEFAULT_BLOCK_NS;
263260
this.processScope(analyzableAttr.namespace, analyzableAttr.property, element, mode);
264261
}
265262
}
266263

264+
// The root element gets the block"s root class automatically.
265+
if (atRootElement && !explicitScope) {
266+
// TODO: Deprecate this.
267+
element.addStaticClass(this.block.rootClass);
268+
}
269+
267270
// validate that html elements aren't using the class attribute.
268271
if (isElementNode(node)) {
269272
for (let attribute of node.attributes) {

0 commit comments

Comments
 (0)