1 | var test = require('tape')
|
2 | var transformAst = require('../')
|
3 |
|
4 | test('walk() method', function testfn (t) {
|
5 | t.plan(1)
|
6 |
|
7 | var count = 0
|
8 | var result = transformAst(testfn.toString(), function (node) {
|
9 | count++
|
10 | node.walked = true
|
11 | })
|
12 |
|
13 | var check = 0
|
14 | result.walk(function (node) {
|
15 | check += node.walked ? 1 : 0
|
16 | })
|
17 |
|
18 | t.is(count, check)
|
19 |
|
20 | t.end()
|
21 | })
|
22 |
|
23 | test('no callback on parse', function (t) {
|
24 | t.plan(1)
|
25 |
|
26 | var result = transformAst(`
|
27 | module.exports = function a () { return 10 }
|
28 | `)
|
29 |
|
30 | result.walk(function (node) {
|
31 | if (node.type === 'Program') {
|
32 | node.edit.prepend('(function (module, exports) {')
|
33 | node.edit.append('})(xyz, xyz.exports)')
|
34 | }
|
35 | })
|
36 |
|
37 | t.is(result.toString(), `(function (module, exports) {
|
38 | module.exports = function a () { return 10 }
|
39 | })(xyz, xyz.exports)`)
|
40 | t.end()
|
41 | })
|