Closed kristianmandrup closed 7 years ago
Very difficult to see how to read/understand how to use docs to select AST nodes for replacement...
Been trying:
class-dec#hello, [class-dec=#hello]' and [class-dec='hello'] ...
class-dec#hello
[class-dec=#hello]'
[class-dec='hello']
Then tried equery
const find = 'class Model { $body }' const replace = 'class Control { {{body}} }'
Error processing selector 'class Model { $body }'
help syntax grasp --help syntax is not been much help when you don't understand the basic operations
grasp --help syntax
class-dec (ClassDeclaration) id, superClass, body
Why can't I do this!?
const find = 'class[id=#Model]' const replace = 'class Control {{.body}}' const replacer = grasp.replace('squery', find, replace)
How do I use this in a concrete example!?
import test from 'ava' import grasp from 'grasp' const find = 'class-dec#Model' const replace = 'Control' let code = `export default class Model { constructor() { } display(x) { console.log(x) } }` let expResult = `export default class Control { constructor() { } display(x) { console.log(x) } }` const replacer = grasp.replace('squery', find, replace) let result = replacer(code) const log = console.log test('replace class name', t => { log('result', result) t.is(result, expResult) })
Took me all day, but now I finally got it working here
Very difficult to see how to read/understand how to use docs to select AST nodes for replacement...
Been trying:
class-dec#hello
,[class-dec=#hello]'
and[class-dec='hello']
...Then tried equery
Error processing selector 'class Model { $body }'
help syntax
grasp --help syntax
is not been much help when you don't understand the basic operationsclass-dec (ClassDeclaration) id, superClass, body
Why can't I do this!?
How do I use this in a concrete example!?