UNPKG

1.08 kBJavaScriptView Raw
1var test = require('tape')
2var transform = require('../')
3
4test('update()', function (t) {
5 var source = `
6 var a = 0
7 a += 10
8 `
9
10 var result = transform(source, function (node) {
11 if (node.type === 'Literal') node.update(String(node.value + 10))
12 })
13
14 t.is(result.toString(), `
15 var a = 10
16 a += 20
17 `)
18 t.is(
19 JSON.stringify(result.map),
20 '{"version":3,"file":null,"sources":["input.js"],"sourcesContent":["\\n var a = 0\\n a += 10\\n "],"names":[],"mappings":"AAAA;YACY,EAAC;SACJ,EAAE;"}'
21 )
22 t.end()
23})
24
25test('append/prepend()', function (t) {
26 var source = `
27 var a = 'hello'
28 `
29
30 var result = transform(source, function (node) {
31 if (node.type === 'Literal') node.prepend('beep(').append(').boop')
32 })
33
34 t.is(result.toString(), `
35 var a = beep('hello').boop
36 `)
37 t.is(
38 JSON.stringify(result.map),
39 '{"version":3,"file":null,"sources":["input.js"],"sourcesContent":["\\n var a = \'hello\'\\n "],"names":[],"mappings":"AAAA;iBACY,aAAO;"}'
40 )
41 t.end()
42})
43
44test('input sourcemap', function (t) {
45 t.end()
46})