Browse Source

allow empty for loop heads – fixes #919

gh-953
Rich-Harris 8 years ago
parent
commit
eba7a70350
  1. 15
      src/ast/nodes/ForStatement.js
  2. 3
      test/form/for-loop-with-empty-head/_config.js
  3. 7
      test/form/for-loop-with-empty-head/_expected/amd.js
  4. 5
      test/form/for-loop-with-empty-head/_expected/cjs.js
  5. 3
      test/form/for-loop-with-empty-head/_expected/es.js
  6. 8
      test/form/for-loop-with-empty-head/_expected/iife.js
  7. 11
      test/form/for-loop-with-empty-head/_expected/umd.js
  8. 3
      test/form/for-loop-with-empty-head/main.js

15
src/ast/nodes/ForStatement.js

@ -1,15 +1,6 @@
import Statement from './shared/Statement.js';
export default class ForStatement extends Statement {
bind () {
const scope = this.body.scope;
this.init.bind( scope );
this.test.bind( scope );
this.update.bind( scope );
this.body.bind( scope );
}
hasEffects () {
return super.hasEffects( this.body.scope );
}
@ -19,9 +10,9 @@ export default class ForStatement extends Statement {
scope = this.body.scope;
// can't use super, because we need to control the order
this.init.initialise( scope );
this.test.initialise( scope );
this.update.initialise( scope );
if ( this.init ) this.init.initialise( scope );
if ( this.test ) this.test.initialise( scope );
if ( this.update ) this.update.initialise( scope );
this.body.initialise( scope );
}

3
test/form/for-loop-with-empty-head/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'handles for loop with empty head'
};

7
test/form/for-loop-with-empty-head/_expected/amd.js

@ -0,0 +1,7 @@
define(function () { 'use strict';
for ( ; ; ) {
console.log( 42 );
}
});

5
test/form/for-loop-with-empty-head/_expected/cjs.js

@ -0,0 +1,5 @@
'use strict';
for ( ; ; ) {
console.log( 42 );
}

3
test/form/for-loop-with-empty-head/_expected/es.js

@ -0,0 +1,3 @@
for ( ; ; ) {
console.log( 42 );
}

8
test/form/for-loop-with-empty-head/_expected/iife.js

@ -0,0 +1,8 @@
(function () {
'use strict';
for ( ; ; ) {
console.log( 42 );
}
}());

11
test/form/for-loop-with-empty-head/_expected/umd.js

@ -0,0 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';
for ( ; ; ) {
console.log( 42 );
}
})));

3
test/form/for-loop-with-empty-head/main.js

@ -0,0 +1,3 @@
for ( ; ; ) {
console.log( 42 );
}
Loading…
Cancel
Save