Skip to content

Commit

Permalink
preserve semicolon if var decl is body of for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Aug 11, 2017
1 parent 11508c4 commit c63782e
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/ast/nodes/VariableDeclaration.js
Expand Up @@ -95,10 +95,10 @@ export default class VariableDeclaration extends Node {
} else {
// always include a semi-colon (https://github.com/rollup/rollup/pull/1013),
// unless it's a var declaration in a loop head
const needsSemicolon = !forStatement.test( this.parent.type );
const needsSemicolon = !forStatement.test( this.parent.type ) || this === this.parent.body;

if ( this.end > c ) {
code.overwrite( c, this.end, needsSemicolon ? ';' : '\n' );
code.overwrite( c, this.end, needsSemicolon ? ';' : '' );
} else if ( needsSemicolon ) {
this.insertSemicolon( code );
}
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions test/form/for-loop-body-var-declaration/_expected/amd.js
@@ -0,0 +1,5 @@
define(function () { 'use strict';

for(var x=1;x<2;x++)var d=x|0;console.log(d);

});
3 changes: 3 additions & 0 deletions test/form/for-loop-body-var-declaration/_expected/cjs.js
@@ -0,0 +1,3 @@
'use strict';

for(var x=1;x<2;x++)var d=x|0;console.log(d);
File renamed without changes.
6 changes: 6 additions & 0 deletions test/form/for-loop-body-var-declaration/_expected/iife.js
@@ -0,0 +1,6 @@
(function () {
'use strict';

for(var x=1;x<2;x++)var d=x|0;console.log(d);

}());
Expand Up @@ -4,7 +4,6 @@
(factory());
}(this, (function () { 'use strict';

for(var x=1;x<2;x++)var d=x|0
console.log(d);
for(var x=1;x<2;x++)var d=x|0;console.log(d);

})));
1 change: 1 addition & 0 deletions test/form/for-loop-body-var-declaration/main.js
@@ -0,0 +1 @@
for(var x=1;x<2;x++)var d=x|0;console.log(d);
6 changes: 0 additions & 6 deletions test/form/line-wrap/_expected/amd.js

This file was deleted.

4 changes: 0 additions & 4 deletions test/form/line-wrap/_expected/cjs.js

This file was deleted.

2 changes: 0 additions & 2 deletions test/form/line-wrap/_expected/es.js

This file was deleted.

7 changes: 0 additions & 7 deletions test/form/line-wrap/_expected/iife.js

This file was deleted.

0 comments on commit c63782e

Please sign in to comment.