1 | var test = require('tape')
|
2 | var transform = require('../')
|
3 |
|
4 | test('getSource()', function (t) {
|
5 | t.plan(2)
|
6 | var source = `
|
7 | import something from 'somewhere'
|
8 |
|
9 | something.whatever()
|
10 | `
|
11 |
|
12 | transform(source, { sourceType: 'module' }, function (node) {
|
13 | if (node.type === 'ImportDeclaration') {
|
14 | t.is(node.getSource(), "import something from 'somewhere'")
|
15 | t.is(node.source.value, 'somewhere')
|
16 | }
|
17 | })
|
18 |
|
19 | t.end()
|
20 | })
|
21 |
|
22 | test('keys that are both functions and objects', function (t) {
|
23 | t.plan(3)
|
24 |
|
25 | var source = `
|
26 | for (;; xyz) {} // update.name === "xyz"
|
27 | for (;; xyz(1, 2)) {} // update.arguments === [1, 2]
|
28 | `
|
29 |
|
30 | t.doesNotThrow(function () {
|
31 | transform(source, function (node) {
|
32 | if (node.type === 'ForStatement' && node.update.type === 'Identifier') {
|
33 | t.is(node.update.name, 'xyz')
|
34 | }
|
35 | if (node.type === 'ForStatement' && node.update.type === 'CallExpression') {
|
36 | t.is(node.update.arguments.length, 2)
|
37 | }
|
38 | })
|
39 | })
|
40 |
|
41 | t.end()
|
42 | })
|