fix code review

pull/6322/head
tanhauhau 4 years ago
parent cca87e41c8
commit ad5d19bcfc

@ -234,6 +234,10 @@ export default {
code: 'css-invalid-global-selector', code: 'css-invalid-global-selector',
message: ':global(...) must contain a single selector' message: ':global(...) must contain a single selector'
}, },
css_invalid_global_selector_position: {
code: 'css-invalid-global-selector-position',
message: ':global(...) which not at the start of selector sequence should not contain type or universal selector'
},
css_invalid_selector: (selector: string) => ({ css_invalid_selector: (selector: string) => ({
code: 'css-invalid-selector', code: 'css-invalid-selector',
message: `Invalid selector "${selector}"` message: `Invalid selector "${selector}"`

@ -130,8 +130,6 @@ export default class Selector {
} }
validate(component: Component) { validate(component: Component) {
this.blocks.some((block) => block.validateGlobalCompoundSelector(component));
let start = 0; let start = 0;
let end = this.blocks.length; let end = this.blocks.length;
@ -150,6 +148,7 @@ export default class Selector {
} }
this.validate_global_with_multiple_selectors(component); this.validate_global_with_multiple_selectors(component);
this.validate_global_compound_selector(component);
this.validate_invalid_combinator_without_selector(component); this.validate_invalid_combinator_without_selector(component);
} }
@ -181,6 +180,23 @@ export default class Selector {
} }
} }
validate_global_compound_selector(component: Component) {
for (const block of this.blocks) {
for (let index = 0; index < block.selectors.length; index++) {
const selector = block.selectors[index];
if (selector.type === 'PseudoClassSelector' &&
selector.name === 'global' &&
index !== 0 &&
selector.children &&
selector.children.length > 0 &&
!/[.:#]/.test(selector.children[0].value)
) {
component.error(selector, compiler_errors.css_invalid_global_selector_position);
}
}
}
}
get_amount_class_specificity_increased() { get_amount_class_specificity_increased() {
let count = 0; let count = 0;
for (const block of this.blocks) { for (const block of this.blocks) {
@ -640,24 +656,6 @@ class Block {
this.selectors.every((selector) => selector.type === 'PseudoClassSelector' || selector.type === 'PseudoElementSelector') this.selectors.every((selector) => selector.type === 'PseudoClassSelector' || selector.type === 'PseudoElementSelector')
); );
} }
validateGlobalCompoundSelector(component: Component) {
this.selectors.some((selector, index) => {
if (selector.type === 'PseudoClassSelector' &&
selector.name === 'global' &&
index !== 0 &&
selector.children &&
selector.children.length > 0 &&
selector.children[0].value[0] !== '.'
) {
component.error(selector, {
code: 'css-invalid-global',
message: ':global(...) which not at the start of selector sequence should not contain type or universal selector'
});
return false;
}
});
}
} }
function group_selectors(selector: CssNode) { function group_selectors(selector: CssNode) {

@ -1,5 +1,5 @@
[{ [{
"code": "css-invalid-global", "code": "css-invalid-global-selector-position",
"message": ":global(...) which not at the start of selector sequence should not contain type or universal selector", "message": ":global(...) which not at the start of selector sequence should not contain type or universal selector",
"start": { "start": {
"line": 2, "line": 2,

@ -2,4 +2,5 @@
.foo:global(div) { .foo:global(div) {
color: red; color: red;
} }
</style> </style>
Loading…
Cancel
Save