@@ -80,6 +80,93 @@ describe("parse()", () => {
80
80
assert . deepStrictEqual ( tester . getRaw ( ast ) , allPiecesJson ) ;
81
81
} ) ;
82
82
83
+ it ( "should output the same value for program.start, end and range when there is a leading/trailing comments" , ( ) => {
84
+ const ast = espree . parse ( "/* foo */ bar /* baz */" , {
85
+ range : true
86
+ } ) ;
87
+
88
+ assert . strictEqual ( ast . start , ast . range [ 0 ] ) ;
89
+ assert . strictEqual ( ast . end , ast . range [ 1 ] ) ;
90
+ } ) ;
91
+
92
+ it ( "should output the same value for program.start, end and range and loc when there is a leading comments with range and loc true" , ( ) => {
93
+ const ast = espree . parse ( "/* foo */ bar" , {
94
+ range : true ,
95
+ loc : true
96
+ } ) ;
97
+
98
+ assert . strictEqual ( ast . start , ast . range [ 0 ] ) ;
99
+ assert . strictEqual ( ast . end , ast . range [ 1 ] ) ;
100
+ assert . strictEqual ( ast . start , ast . loc . start . column ) ;
101
+ assert . strictEqual ( ast . end , ast . loc . end . column ) ;
102
+ } ) ;
103
+
104
+ it ( "should output the same value for program.start, end and loc when there is a leading comments with loc" , ( ) => {
105
+ const ast = espree . parse ( "/* foo */ bar" , {
106
+ loc : true
107
+ } ) ;
108
+
109
+ assert . strictEqual ( ast . start , ast . loc . start . column ) ;
110
+ assert . strictEqual ( ast . end , ast . loc . end . column ) ;
111
+ } ) ;
112
+
113
+ it ( "should output the same value for program.start, end and range when there is a trailing comments" , ( ) => {
114
+ const ast = espree . parse ( " bar /* foo */" , {
115
+ range : true
116
+ } ) ;
117
+
118
+ assert . strictEqual ( ast . start , ast . range [ 0 ] ) ;
119
+ assert . strictEqual ( ast . end , ast . range [ 1 ] ) ;
120
+ } ) ;
121
+
122
+ it ( "should output the same value for range and start and end in templateElement with range" , ( ) => {
123
+ const ast = espree . parse ( "`foo ${bar}`;" , {
124
+ ecmaVersion : 6 ,
125
+ range : true
126
+ } ) ;
127
+
128
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 0 ] . start , ast . body [ 0 ] . expression . quasis [ 0 ] . range [ 0 ] ) ;
129
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 0 ] . end , ast . body [ 0 ] . expression . quasis [ 0 ] . range [ 1 ] ) ;
130
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 1 ] . start , ast . body [ 0 ] . expression . quasis [ 1 ] . range [ 0 ] ) ;
131
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 1 ] . end , ast . body [ 0 ] . expression . quasis [ 1 ] . range [ 1 ] ) ;
132
+ } ) ;
133
+
134
+ it ( "should output the same value for loc and start and end in templateElement with loc" , ( ) => {
135
+ const ast = espree . parse ( "`foo ${bar}`;" , {
136
+ ecmaVersion : 6 ,
137
+ loc : true
138
+ } ) ;
139
+
140
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 0 ] . start , ast . body [ 0 ] . expression . quasis [ 0 ] . loc . start . column ) ;
141
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 0 ] . end , ast . body [ 0 ] . expression . quasis [ 0 ] . loc . end . column ) ;
142
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 1 ] . start , ast . body [ 0 ] . expression . quasis [ 1 ] . loc . start . column ) ;
143
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 1 ] . end , ast . body [ 0 ] . expression . quasis [ 1 ] . loc . end . column ) ;
144
+ } ) ;
145
+
146
+ it ( "should output the same value for loc, range and start and end in templateElement with loc and range" , ( ) => {
147
+ const ast = espree . parse ( "`foo ${bar}`;" , {
148
+ ecmaVersion : 6 ,
149
+ loc : true ,
150
+ range : true
151
+ } ) ;
152
+
153
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 0 ] . start , ast . body [ 0 ] . expression . quasis [ 0 ] . loc . start . column ) ;
154
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 0 ] . end , ast . body [ 0 ] . expression . quasis [ 0 ] . loc . end . column ) ;
155
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 1 ] . start , ast . body [ 0 ] . expression . quasis [ 1 ] . range [ 0 ] ) ;
156
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 1 ] . end , ast . body [ 0 ] . expression . quasis [ 1 ] . range [ 1 ] ) ;
157
+ } ) ;
158
+
159
+ it ( "should output the same value for loc, range and start and end in templateElement" , ( ) => {
160
+ const ast = espree . parse ( "`foo ${bar}`;" , {
161
+ ecmaVersion : 6
162
+ } ) ;
163
+
164
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 0 ] . start , 0 ) ;
165
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 0 ] . end , 7 ) ;
166
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 1 ] . start , 10 ) ;
167
+ assert . strictEqual ( ast . body [ 0 ] . expression . quasis [ 1 ] . end , 12 ) ;
168
+ } ) ;
169
+
83
170
it ( "should reset lastToken on each parse" , ( ) => {
84
171
espree . parse ( "var foo = bar;" ) ;
85
172
const ast = espree . parse ( "//foo" , {
0 commit comments