refactor: eliminate 4 as any casts in extraction.ts
- Added 'contain' field to FastExtractedElement.style interface, removing (s as any).contain property smuggling (line 682) - Replaced (assertion as any) duck-typing in getSelectorsFromAssertion with instanceof FluentRelation/FluentQuantifier/FluentAssertion checks - Replaced (assertion as any) duck-typing in buildFluentLabel with same instanceof pattern - Structural baseline ratcheted: asAny 101→98, nullishZero 62→61
This commit is contained in:
@@ -404,6 +404,7 @@ export async function extractWorldFastGeometry(
|
||||
overflowY: string
|
||||
visibility: string
|
||||
pointerEvents: string
|
||||
contain: string
|
||||
opacity: number
|
||||
zIndex: string
|
||||
lineHeight: number
|
||||
@@ -679,7 +680,7 @@ export async function extractWorldFastGeometry(
|
||||
zIndexKind.push(s.zIndex === 'auto' ? 0 : 1)
|
||||
zIndexValue.push(s.zIndex === 'auto' ? 0 : Number.parseInt(s.zIndex, 10) || 0)
|
||||
opacity.push(s.opacity)
|
||||
const csContain = (s as any).contain
|
||||
const csContain = s.contain
|
||||
let flags = 0
|
||||
if (typeof csContain === 'string') {
|
||||
for (const part of csContain.split(/\s+/)) {
|
||||
@@ -1451,34 +1452,33 @@ export function compileCanonicalClauseToFormula(clause: CanonicalClauseDescripto
|
||||
|
||||
export function getSelectorsFromAssertion(assertion: FluentRelation | FluentAssertion | FluentQuantifier): string[] {
|
||||
const selectors = new Set<string>()
|
||||
const rel = assertion as any
|
||||
if (rel.assertion?.getSubject) {
|
||||
selectors.add(rel.assertion.getSubject())
|
||||
}
|
||||
if (rel.referenceSelector) {
|
||||
selectors.add(rel.referenceSelector)
|
||||
}
|
||||
// Extract selectors from compound relation parts (.and / .or chaining)
|
||||
const compoundRel = assertion as FluentRelation
|
||||
if (compoundRel.isCompound) {
|
||||
for (const part of compoundRel.compoundParts) {
|
||||
if (part.referenceSelector) {
|
||||
selectors.add(part.referenceSelector)
|
||||
|
||||
if (assertion instanceof FluentRelation) {
|
||||
selectors.add(assertion.assertion.getSubject())
|
||||
if (assertion.referenceSelector) {
|
||||
selectors.add(assertion.referenceSelector)
|
||||
}
|
||||
if (assertion.isCompound) {
|
||||
for (const part of assertion.compoundParts) {
|
||||
if (part.referenceSelector) {
|
||||
selectors.add(part.referenceSelector)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(rel.bindings)) {
|
||||
for (const b of rel.bindings) {
|
||||
if (b?.selector) selectors.add(b.selector)
|
||||
// Extract reference selectors from assertions inside FluentQuantifier bindings
|
||||
if (typeof b?.getAssertions === 'function') {
|
||||
for (const assertion of b.getAssertions()) {
|
||||
if (assertion?.reference?.value) {
|
||||
selectors.add(assertion.reference.value)
|
||||
} else if (assertion instanceof FluentQuantifier) {
|
||||
for (const b of assertion.bindings) {
|
||||
if (b.selector) selectors.add(b.selector)
|
||||
if (typeof b.getAssertions === 'function') {
|
||||
for (const inner of b.getAssertions()) {
|
||||
if (inner?.reference?.value) {
|
||||
selectors.add(inner.reference.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// FluentAssertion
|
||||
selectors.add(assertion.getSubject())
|
||||
}
|
||||
return Array.from(selectors)
|
||||
}
|
||||
@@ -1518,21 +1518,17 @@ export function getSelectorsFromFormula(formula: FormulaNode): string[] {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export function buildFluentLabel(assertion: FluentRelation | FluentAssertion | FluentQuantifier): string {
|
||||
const rel = assertion as any
|
||||
|
||||
// FluentQuantifier
|
||||
if (rel.bindings && Array.isArray(rel.bindings)) {
|
||||
const firstBinding = rel.bindings[0]
|
||||
if (assertion instanceof FluentQuantifier) {
|
||||
const firstBinding = assertion.bindings[0]
|
||||
const selector = firstBinding?.selector || 'unknown'
|
||||
return `quantified assertion over '${selector}'`
|
||||
}
|
||||
|
||||
// FluentRelation
|
||||
if (rel.relation && rel.assertion?.getSubject) {
|
||||
const subject = rel.assertion.getSubject()
|
||||
const ref = rel.referenceSelector || ''
|
||||
const opts = rel.options || {}
|
||||
const parts: string[] = [`'${subject}' ${rel.relation}`]
|
||||
if (assertion instanceof FluentRelation) {
|
||||
const subject = assertion.assertion.getSubject()
|
||||
const ref = assertion.referenceSelector || ''
|
||||
const opts = assertion.options || {}
|
||||
const parts: string[] = [`'${subject}' ${assertion.relation}`]
|
||||
if (ref) parts.push(`'${ref}'`)
|
||||
if (opts.minGap !== undefined) parts.push(`gap ${opts.minGap}px`)
|
||||
if (opts.maxGap !== undefined) parts.push(`maxGap ${opts.maxGap}px`)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"asAny": 101,
|
||||
"asAny": 98,
|
||||
"emptyCatch": 17,
|
||||
"nullishZero": 62
|
||||
"nullishZero": 61
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user