4e8510cf81b171ba20c55dc50699a7af8cb44824.svn-base
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'
var test = require('tape')
var redeyed = require('..')
var esprima = require('esprima')
test('redeyed result does not have esprima ast by default', function(t) {
var code = '// a comment\nvar a = 3;'
var conf = { Keyword: { _default: '_:-' } }
var ast = esprima.parse(code, { tokens: true, comment: true, range: true, loc: true, tolerant: true })
var tokens = ast.tokens
var comments = ast.comments
var result = redeyed(code, conf)
t.equal(typeof result.ast, 'undefined', 'ast')
t.deepEquals(result.tokens, tokens, 'tokens')
t.deepEquals(result.comments, comments, 'comments')
t.notEquals(result.code, undefined, 'code')
t.end()
})
test('redeyed result has esprima ast, tokens, comments and splits and transformed code', function(t) {
var code = '// a comment\nvar a = 3;'
var conf = { Keyword: { _default: '_:-' } }
var ast = esprima.parse(code, { tokens: true, comment: true, range: true, loc: true, tolerant: true })
var tokens = ast.tokens
var comments = ast.comments
var result = redeyed(code, conf, { buildAst: true })
t.deepEquals(result.ast, ast, 'ast')
t.deepEquals(result.tokens, tokens, 'tokens')
t.deepEquals(result.comments, comments, 'comments')
t.notEquals(result.code, undefined, 'code')
t.end()
})
test('redeyed result - { nojoin } has esprima ast, tokens, comments and splits but no transformed code', function(t) {
var code = '// a comment\nvar a = 3;'
var conf = { Keyword: { _default: '_:-' } }
var ast = esprima.parse(code, { tokens: true, comment: true, range: true, loc: true, tolerant: true })
var tokens = ast.tokens
var comments = ast.comments
var result = redeyed(code, conf, { nojoin: true, buildAst: true })
t.deepEquals(result.ast, ast, 'ast')
t.deepEquals(result.tokens, tokens, 'tokens')
t.deepEquals(result.comments, comments, 'comments')
t.equals(result.code, undefined, 'code')
t.end()
})