11/**
22 * @typedef {import('./types.js').Rule } Rule
3+ * @typedef {import('./types.js').RuleSet } RuleSet
34 * @typedef {import('./types.js').RulePseudo } RulePseudo
45 * @typedef {import('./types.js').RulePseudoSelector } RulePseudoSelector
56 * @typedef {import('./types.js').Parent } Parent
6- * @typedef {import('./types.js').Selector } Selector
77 * @typedef {import('./types.js').Selectors } Selectors
88 * @typedef {import('./types.js').SelectState } SelectState
9+ * @typedef {import('./types.js').Root } Root
910 * @typedef {import('./types.js').Element } Element
1011 * @typedef {import('./types.js').ElementChild } ElementChild
1112 */
@@ -103,8 +104,7 @@ export function pseudo(query, element, index, parent, state) {
103104 * @returns {boolean }
104105 */
105106function matches ( query , element , _ , parent , state ) {
106- const shallow = state . shallow
107- const one = state . one
107+ const { shallow, one} = state
108108
109109 state . shallow = false
110110 state . one = true
@@ -344,7 +344,6 @@ function lang(query, _1, _2, _3, state) {
344344 return (
345345 state . language !== '' &&
346346 state . language !== undefined &&
347- state . language !== undefined &&
348347 // @ts -expect-error never `selectors`.
349348 extendedFilter ( state . language , commas ( query . value ) ) . length > 0
350349 )
@@ -540,16 +539,15 @@ function assertDeep(state, query) {
540539 * @returns {boolean }
541540 */
542541function has ( query , element , _1 , _2 , state ) {
543- const shallow = state . shallow
544- const one = state . one
545- const scopeElements = state . scopeElements
546- const value = appendScope ( query . value )
542+ /** @type {Root } */
543+ const fragment = { type : 'root' , children : element . children }
544+ const { shallow, one, scopeElements} = state
547545
548546 state . shallow = false
549547 state . one = true
550548 state . scopeElements = [ element ]
551549
552- const result = any ( value , element , state ) . length > 0
550+ const result = any ( query . value , fragment , state ) . length > 0
553551
554552 state . shallow = shallow
555553 state . one = one
@@ -558,36 +556,6 @@ function has(query, element, _1, _2, state) {
558556 return result
559557}
560558
561- /**
562- * @param {Selector } value
563- * @returns {Selectors }
564- */
565- function appendScope ( value ) {
566- /** @type {Selectors } */
567- const selector =
568- value . type === 'ruleSet' ? { type : 'selectors' , selectors : [ value ] } : value
569- let index = - 1
570-
571- while ( ++ index < selector . selectors . length ) {
572- const rule = selector . selectors [ index ] . rule
573- rule . nestingOperator = null
574-
575- if (
576- ! rule . pseudos ||
577- rule . pseudos . length !== 1 ||
578- rule . pseudos [ 0 ] . name !== 'scope'
579- ) {
580- selector . selectors [ index ] = {
581- type : 'ruleSet' ,
582- // @ts -expect-error pseudos are fine w/ just a name!
583- rule : { type : 'rule' , rule, pseudos : [ { name : 'scope' } ] }
584- }
585- }
586- }
587-
588- return selector
589- }
590-
591559/**
592560 * @param {RulePseudo } query
593561 * @returns {(value: number) => boolean }
0 commit comments