Comparing version 5.0.0-next.204 to 5.0.0-next.205
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "5.0.0-next.204", | ||
"version": "5.0.0-next.205", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "types": "./types/index.d.ts", |
@@ -7,3 +7,2 @@ /** @import { ComponentAnalysis } from '../../types.js' */ | ||
import { is_keyframes_node } from '../../css.js'; | ||
import { merge } from '../../visitors.js'; | ||
@@ -54,3 +53,3 @@ /** | ||
/** @type {CssVisitors} */ | ||
const analysis_visitors = { | ||
const css_visitors = { | ||
Atrule(node, context) { | ||
@@ -62,2 +61,4 @@ if (is_keyframes_node(node)) { | ||
} | ||
context.next(); | ||
}, | ||
@@ -67,2 +68,49 @@ ComplexSelector(node, context) { | ||
{ | ||
const global = node.children.find(is_global); | ||
if (global) { | ||
const idx = node.children.indexOf(global); | ||
if (global.selectors[0].args !== null && idx !== 0 && idx !== node.children.length - 1) { | ||
// ensure `:global(...)` is not used in the middle of a selector (but multiple `global(...)` in sequence are ok) | ||
for (let i = idx + 1; i < node.children.length; i++) { | ||
if (!is_global(node.children[i])) { | ||
e.css_global_invalid_placement(global.selectors[0]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// ensure `:global(...)` do not lead to invalid css after `:global()` is removed | ||
for (const relative_selector of node.children) { | ||
for (let i = 0; i < relative_selector.selectors.length; i++) { | ||
const selector = relative_selector.selectors[i]; | ||
if (selector.type === 'PseudoClassSelector' && selector.name === 'global') { | ||
const child = selector.args?.children[0].children[0]; | ||
// ensure `:global(element)` to be at the first position in a compound selector | ||
if (child?.selectors[0].type === 'TypeSelector' && i !== 0) { | ||
e.css_global_invalid_selector_list(selector); | ||
} | ||
// ensure `:global(.class)` is not followed by a type selector, eg: `:global(.class)element` | ||
if (relative_selector.selectors[i + 1]?.type === 'TypeSelector') { | ||
e.css_type_selector_invalid_placement(relative_selector.selectors[i + 1]); | ||
} | ||
// ensure `:global(...)`contains a single selector | ||
// (standalone :global() with multiple selectors is OK) | ||
if ( | ||
selector.args !== null && | ||
selector.args.children.length > 1 && | ||
(node.children.length > 1 || relative_selector.selectors.length > 1) | ||
) { | ||
e.css_global_invalid_selector(selector); | ||
} | ||
} | ||
} | ||
} | ||
node.metadata.rule = context.state.rule; | ||
@@ -126,18 +174,2 @@ | ||
context.next({ | ||
...context.state, | ||
rule: node | ||
}); | ||
node.metadata.has_local_selectors = node.prelude.children.some((selector) => { | ||
return selector.children.some( | ||
({ metadata }) => !metadata.is_global && !metadata.is_global_like | ||
); | ||
}); | ||
} | ||
}; | ||
/** @type {CssVisitors} */ | ||
const validation_visitors = { | ||
Rule(node, context) { | ||
if (node.metadata.is_global_block) { | ||
@@ -182,51 +214,12 @@ if (node.prelude.children.length > 1) { | ||
context.next(); | ||
}, | ||
ComplexSelector(node) { | ||
{ | ||
const global = node.children.find(is_global); | ||
context.next({ | ||
...context.state, | ||
rule: node | ||
}); | ||
if (global) { | ||
const idx = node.children.indexOf(global); | ||
if (global.selectors[0].args !== null && idx !== 0 && idx !== node.children.length - 1) { | ||
// ensure `:global(...)` is not used in the middle of a selector (but multiple `global(...)` in sequence are ok) | ||
for (let i = idx + 1; i < node.children.length; i++) { | ||
if (!is_global(node.children[i])) { | ||
e.css_global_invalid_placement(global.selectors[0]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// ensure `:global(...)` do not lead to invalid css after `:global()` is removed | ||
for (const relative_selector of node.children) { | ||
for (let i = 0; i < relative_selector.selectors.length; i++) { | ||
const selector = relative_selector.selectors[i]; | ||
if (selector.type === 'PseudoClassSelector' && selector.name === 'global') { | ||
const child = selector.args?.children[0].children[0]; | ||
// ensure `:global(element)` to be at the first position in a compound selector | ||
if (child?.selectors[0].type === 'TypeSelector' && i !== 0) { | ||
e.css_global_invalid_selector_list(selector); | ||
} | ||
// ensure `:global(.class)` is not followed by a type selector, eg: `:global(.class)element` | ||
if (relative_selector.selectors[i + 1]?.type === 'TypeSelector') { | ||
e.css_type_selector_invalid_placement(relative_selector.selectors[i + 1]); | ||
} | ||
// ensure `:global(...)`contains a single selector | ||
// (standalone :global() with multiple selectors is OK) | ||
if ( | ||
selector.args !== null && | ||
selector.args.children.length > 1 && | ||
(node.children.length > 1 || relative_selector.selectors.length > 1) | ||
) { | ||
e.css_global_invalid_selector(selector); | ||
} | ||
} | ||
} | ||
} | ||
node.metadata.has_local_selectors = node.prelude.children.some((selector) => { | ||
return selector.children.some( | ||
({ metadata }) => !metadata.is_global && !metadata.is_global_like | ||
); | ||
}); | ||
}, | ||
@@ -236,2 +229,3 @@ NestingSelector(node, context) { | ||
const parent_rule = rule.metadata.parent_rule; | ||
if (!parent_rule) { | ||
@@ -248,7 +242,7 @@ e.css_nesting_selector_invalid_placement(node); | ||
} | ||
context.next(); | ||
} | ||
}; | ||
const css_visitors = merge(analysis_visitors, validation_visitors); | ||
/** | ||
@@ -255,0 +249,0 @@ * @param {Css.StyleSheet} stylesheet |
@@ -9,3 +9,3 @@ // generated during release, do not modify | ||
*/ | ||
export const VERSION = '5.0.0-next.204'; | ||
export const VERSION = '5.0.0-next.205'; | ||
export const PUBLIC_VERSION = '5'; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2182491
298
48309