Skip to content

maybe attribute eq/neq could be more type infered? #84

@ssddi456

Description

@ssddi456

function equal (obj: any, value: any, type: TSQueryAttributeOperatorType): boolean {
switch (type) {
case 'regexp': return typeof obj === 'string' && (value as RegExp).test(obj);
case 'literal': return `${value}` === `${obj}`;
case 'type': return value === typeof obj;
}
}
function notEqual (obj: any, value: any, type: TSQueryAttributeOperatorType): boolean {
switch (type) {
case 'regexp': return typeof obj === 'string' && !(value as RegExp).test(obj);
case 'literal': return `${value}` !== `${obj}`;
case 'type': return value !== typeof obj;
}
}

unlike esquery they dont have any type info, tsquery could be more type infered, for example, with code

const routeMap = [{}]

we could do somethings like:

VariableDeclaration[name.name="routeMap"][initializer=type(ArrayLiteralExpression)]

which is more accurate than some thing

VariableDeclaration[name.name="routeMap"]):has(ArrayLiteralExpression)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions