esquery icon indicating copy to clipboard operation
esquery copied to clipboard

How to match import with given specifier (ie. match on list of nodes)

Open kristianmandrup opened this issue 9 years ago • 1 comments

I'm trying to use grasp with squery which I think uses esquery under the hood? How do I match an import with a given specifier:

I can't do import-dec[specifiers=x] since specifiers is a list of nodes, such as import {x, y z} from 'v'

const find = 'import-dec[specifiers=x] ~ class-dec[id=#CoolGang]'
const replace = `class {{.id}} {{.body}}`

const replacer = grasp.replace('squery', find, replace)

kristianmandrup avatar Dec 05 '16 16:12 kristianmandrup

Been trying a nested selector like this:

const find = `(import-dec[specifiers=(id=#x)], class-dec[id=#CoolGang])`
const replace = `class {{.id}} {{.body}}`

const replacer = grasp.replace('squery', find, replace)

Still to no avail.

kristianmandrup avatar Dec 05 '16 16:12 kristianmandrup