1
- import test from 'tape'
2
- import { parse as acornParse } from 'acorn'
3
- import recast from 'recast'
4
- import { visit } from 'estree-util-visit'
5
- import { attachComments } from './index.js'
6
-
7
1
/**
8
2
* @typedef {import('estree').BaseNode } EstreeNode
9
3
* @typedef {import('estree').Program } EstreeProgram
10
4
* @typedef {import('estree').Comment } EstreeComment
11
5
*/
12
6
13
- test ( 'estree-attach-comments (recast)' , ( t ) => {
14
- t . equal (
7
+ import assert from 'node:assert/strict'
8
+ import test from 'node:test'
9
+ import { parse as acornParse } from 'acorn'
10
+ import recast from 'recast'
11
+ import { visit } from 'estree-util-visit'
12
+ import { attachComments } from './index.js'
13
+
14
+ test ( 'estree-attach-comments (recast)' , ( ) => {
15
+ assert . equal (
15
16
recast . print ( attachComments ( ...parse ( '' ) ) ) . code ,
16
17
'' ,
17
18
'should support an empty document'
18
19
)
19
20
20
- t . equal (
21
+ assert . equal (
21
22
recast . print ( attachComments ( ...parse ( 'a + 1' ) ) ) . code ,
22
23
'a + 1;' ,
23
24
'should support no comments'
24
25
)
25
26
26
- t . equal (
27
+ assert . equal (
27
28
recast . print ( attachComments ( ...parse ( '/* ! */' ) ) ) . code ,
28
29
'/* ! */\n' ,
29
30
'should support a single block comment'
30
31
)
31
32
32
- t . equal (
33
+ assert . equal (
33
34
recast . print ( attachComments ( ...parse ( '// !' ) ) ) . code ,
34
35
'// !\n' ,
35
36
'should support a single line comment'
36
37
)
37
38
38
- t . equal (
39
+ assert . equal (
39
40
recast . print (
40
41
attachComments ( ...parse ( '/* 1 */ function a (/* 2 */b) { return b + 1 }' ) )
41
42
) . code ,
42
43
'/* 1 */\nfunction a(\n /* 2 */\n b\n) {\n return b + 1;\n}' ,
43
44
'should support some comments'
44
45
)
45
46
46
- t . equal (
47
+ assert . equal (
47
48
recast . print (
48
49
attachComments (
49
50
...parse (
@@ -58,15 +59,15 @@ test('estree-attach-comments (recast)', (t) => {
58
59
// Recast parses `4` as “dangling”:
59
60
// <https://github.com/benjamn/recast/blob/dd7c5ec/lib/comments.ts#L255-L256>
60
61
// But apprently doesn’t serialize it?
61
- t . equal (
62
+ assert . equal (
62
63
recast . print (
63
64
attachComments ( ...parse ( '/* 1 */ a /* 2 */ = /* 3 */ { /* 4 */ }' ) )
64
65
) . code ,
65
66
'/* 1 */\na = /* 2 */\n/* 3 */\n{};' ,
66
67
'should support some more comments'
67
68
)
68
69
69
- t . equal (
70
+ assert . equal (
70
71
recast . print (
71
72
attachComments (
72
73
...parse (
@@ -90,7 +91,7 @@ test('estree-attach-comments (recast)', (t) => {
90
91
91
92
removePositions ( tree )
92
93
93
- t . equal (
94
+ assert . equal (
94
95
recast . print ( attachComments ( tree , comments ) ) . code ,
95
96
'a + 1;' ,
96
97
'should not fail on a tree w/o positional info'
@@ -104,7 +105,7 @@ test('estree-attach-comments (recast)', (t) => {
104
105
onComment : comments
105
106
} )
106
107
107
- t . equal (
108
+ assert . equal (
108
109
recast . print ( attachComments ( tree ) ) . code ,
109
110
'1 + 1;' ,
110
111
'should not fail w/o comments'
@@ -121,7 +122,7 @@ test('estree-attach-comments (recast)', (t) => {
121
122
122
123
removePositions ( comments )
123
124
124
- t . equal (
125
+ assert . equal (
125
126
recast . print ( attachComments ( tree , comments ) ) . code ,
126
127
'a + 1;' ,
127
128
'should not fail on comments w/o positional info'
@@ -138,7 +139,7 @@ test('estree-attach-comments (recast)', (t) => {
138
139
139
140
removePositions ( tree )
140
141
141
- t . equal (
142
+ assert . equal (
142
143
recast . print ( attachComments ( tree , comments ) ) . code ,
143
144
'/* 1 */\na + /* 2 */\n/* 3 */\n1;' ,
144
145
'should use `range`s'
@@ -155,13 +156,11 @@ test('estree-attach-comments (recast)', (t) => {
155
156
156
157
removePositions ( tree )
157
158
158
- t . equal (
159
+ assert . equal (
159
160
recast . print ( attachComments ( tree , comments ) ) . code ,
160
161
'/* 1 */\na + /* 2 */\n/* 3 */\n1;' ,
161
162
'should use `loc`s'
162
163
)
163
-
164
- t . end ( )
165
164
} )
166
165
167
166
/**
0 commit comments