@@ -129,4 +129,145 @@ mod test {
129129 " ,
130130 ) ;
131131 }
132+
133+ #[ test]
134+ #[ ignore]
135+ fn test_collapsing ( ) {
136+ // Basic collapsing
137+ test ( "var a;var b;" , "var a,b;" ) ;
138+
139+ // With initial values
140+ test ( "var a = 1;var b = 1;" , "var a=1,b=1;" ) ;
141+
142+ // Already collapsed
143+ test_same ( "var a, b;" ) ;
144+
145+ // Already collapsed with values
146+ test_same ( "var a = 1, b = 1;" ) ;
147+
148+ // Some already collapsed
149+ test ( "var a;var b, c;var d;" , "var a,b,c,d;" ) ;
150+
151+ // Some already collapsed with values
152+ test ( "var a = 1;var b = 2, c = 3;var d = 4;" , "var a=1,b=2,c=3,d=4;" ) ;
153+
154+ test (
155+ "var x = 2; foo(x); x = 3; x = 1; var y = 2; var z = 4; x = 5" ,
156+ "var x = 2; foo(x); x = 3; x = 1; var y = 2, z = 4; x = 5" ,
157+ ) ;
158+ }
159+
160+ #[ test]
161+ fn test_issue820 ( ) {
162+ // Don't redeclare function parameters, this is incompatible with
163+ // strict mode.
164+ test_same ( "function f(a){ var b=1; a=2; var c; }" ) ;
165+ }
166+
167+ #[ test]
168+ fn test_if_else_var_declarations ( ) {
169+ test_same ( "if (x) var a = 1; else var b = 2;" ) ;
170+ }
171+
172+ #[ test]
173+ fn test_aggressive_redeclaration_in_for ( ) {
174+ test_same ( "for(var x = 1; x = 2; x = 3) {x = 4}" ) ;
175+ test_same ( "for(var x = 1; y = 2; z = 3) {var a = 4}" ) ;
176+ test_same ( "var x; for(x = 1; x = 2; z = 3) {x = 4}" ) ;
177+ }
178+
179+ #[ test]
180+ #[ ignore]
181+ fn test_issue397 ( ) {
182+ test_same ( "var x; x = 5; var z = 7;" ) ;
183+ test ( "var x; var y = 3; x = 5;" , "var x, y = 3; x = 5;" ) ;
184+ test ( "var a = 1; var x; var y = 3; x = 5;" , "var a = 1, x, y = 3; x = 5;" ) ;
185+ test ( "var x; var y = 3; x = 5; var z = 7;" , "var x, y = 3; x = 5; var z = 7;" ) ;
186+ }
187+
188+ #[ test]
189+ fn test_arguments_assignment ( ) {
190+ test_same ( "function f() {arguments = 1;}" ) ;
191+ }
192+
193+ // ES6 Tests
194+ #[ test]
195+ #[ ignore]
196+ fn test_collapsing_let_const ( ) {
197+ // Basic collapsing
198+ test ( "let a;let b;" , "let a,b;" ) ;
199+
200+ // With initial values
201+ test ( "const a = 1;const b = 1;" , "const a=1,b=1;" ) ;
202+
203+ // Already collapsed
204+ test_same ( "let a, b;" ) ;
205+
206+ // Already collapsed with values
207+ test_same ( "let a = 1, b = 1;" ) ;
208+
209+ // Some already collapsed
210+ test ( "let a;let b, c;let d;" , "let a,b,c,d;" ) ;
211+
212+ // Some already collapsed with values
213+ test ( "let a = 1;let b = 2, c = 3;let d = 4;" , "let a=1,b=2,c=3,d=4;" ) ;
214+
215+ // Different variable types
216+ test_same ( "let a = 1; const b = 2;" ) ;
217+ }
218+
219+ #[ test]
220+ fn test_if_else_var_declarations_let ( ) {
221+ test_same ( "if (x) { let a = 1; } else { let b = 2; }" ) ;
222+ }
223+
224+ #[ test]
225+ fn test_aggressive_redeclaration_of_let_in_for ( ) {
226+ test_same ( "for(let x = 1; x = 2; x = 3) {x = 4}" ) ;
227+ test_same ( "for(let x = 1; y = 2; z = 3) {let a = 4}" ) ;
228+ test_same ( "let x; for(x = 1; x = 2; z = 3) {x = 4}" ) ;
229+ }
230+
231+ #[ test]
232+ #[ ignore]
233+ fn test_redeclaration_let_in_function ( ) {
234+ test (
235+ "function f() { let x = 1; let y = 2; let z = 3; x + y + z; }" ,
236+ "function f() { let x = 1, y = 2, z = 3; x + y + z; } " ,
237+ ) ;
238+
239+ // recognize local scope version of x
240+ test (
241+ "var x = 1; function f() { let x = 1; let y = 2; x + y; }" ,
242+ "var x = 1; function f() { let x = 1, y = 2; x + y } " ,
243+ ) ;
244+
245+ // do not redeclare function parameters
246+ // incompatible with strict mode
247+ test_same ( "function f(x) { let y = 3; x = 4; x + y; }" ) ;
248+ }
249+
250+ #[ test]
251+ #[ ignore]
252+ fn test_arrow_function ( ) {
253+ test ( "() => {let x = 1; let y = 2; x + y; }" , "() => {let x = 1, y = 2; x + y; }" ) ;
254+
255+ // do not redeclare function parameters
256+ // incompatible with strict mode
257+ test_same ( "(x) => {x = 4; let y = 2; x + y; }" ) ;
258+ }
259+
260+ #[ test]
261+ fn test_uncollapsable_declarations ( ) {
262+ test_same ( "let x = 1; var y = 2; const z = 3" ) ;
263+ test_same ( "let x = 1; var y = 2; let z = 3;" ) ;
264+ }
265+
266+ #[ test]
267+ #[ ignore]
268+ fn test_mixed_declaration_types ( ) {
269+ // lets, vars, const declarations consecutive
270+ test ( "let x = 1; let z = 3; var y = 2;" , "let x = 1, z = 3; var y = 2;" ) ;
271+ test ( "let x = 1; let y = 2; var z = 3; var a = 4;" , "let x = 1, y = 2; var z = 3, a = 4" ) ;
272+ }
132273}
0 commit comments