From eba7a70350ac22973421eb7a45a9187ad3d264c2 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 10 Sep 2016 19:20:53 -0400 Subject: [PATCH] =?UTF-8?q?allow=20empty=20for=20loop=20heads=20=E2=80=93?= =?UTF-8?q?=20fixes=20#919?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ast/nodes/ForStatement.js | 15 +++------------ test/form/for-loop-with-empty-head/_config.js | 3 +++ .../for-loop-with-empty-head/_expected/amd.js | 7 +++++++ .../for-loop-with-empty-head/_expected/cjs.js | 5 +++++ .../form/for-loop-with-empty-head/_expected/es.js | 3 +++ .../for-loop-with-empty-head/_expected/iife.js | 8 ++++++++ .../for-loop-with-empty-head/_expected/umd.js | 11 +++++++++++ test/form/for-loop-with-empty-head/main.js | 3 +++ 8 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 test/form/for-loop-with-empty-head/_config.js create mode 100644 test/form/for-loop-with-empty-head/_expected/amd.js create mode 100644 test/form/for-loop-with-empty-head/_expected/cjs.js create mode 100644 test/form/for-loop-with-empty-head/_expected/es.js create mode 100644 test/form/for-loop-with-empty-head/_expected/iife.js create mode 100644 test/form/for-loop-with-empty-head/_expected/umd.js create mode 100644 test/form/for-loop-with-empty-head/main.js diff --git a/src/ast/nodes/ForStatement.js b/src/ast/nodes/ForStatement.js index bd5a57f..1d61b02 100644 --- a/src/ast/nodes/ForStatement.js +++ b/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 ); } diff --git a/test/form/for-loop-with-empty-head/_config.js b/test/form/for-loop-with-empty-head/_config.js new file mode 100644 index 0000000..3fc4a67 --- /dev/null +++ b/test/form/for-loop-with-empty-head/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'handles for loop with empty head' +}; diff --git a/test/form/for-loop-with-empty-head/_expected/amd.js b/test/form/for-loop-with-empty-head/_expected/amd.js new file mode 100644 index 0000000..a07e3e0 --- /dev/null +++ b/test/form/for-loop-with-empty-head/_expected/amd.js @@ -0,0 +1,7 @@ +define(function () { 'use strict'; + + for ( ; ; ) { + console.log( 42 ); + } + +}); \ No newline at end of file diff --git a/test/form/for-loop-with-empty-head/_expected/cjs.js b/test/form/for-loop-with-empty-head/_expected/cjs.js new file mode 100644 index 0000000..f94dff7 --- /dev/null +++ b/test/form/for-loop-with-empty-head/_expected/cjs.js @@ -0,0 +1,5 @@ +'use strict'; + +for ( ; ; ) { + console.log( 42 ); +} \ No newline at end of file diff --git a/test/form/for-loop-with-empty-head/_expected/es.js b/test/form/for-loop-with-empty-head/_expected/es.js new file mode 100644 index 0000000..1690f25 --- /dev/null +++ b/test/form/for-loop-with-empty-head/_expected/es.js @@ -0,0 +1,3 @@ +for ( ; ; ) { + console.log( 42 ); +} \ No newline at end of file diff --git a/test/form/for-loop-with-empty-head/_expected/iife.js b/test/form/for-loop-with-empty-head/_expected/iife.js new file mode 100644 index 0000000..2217234 --- /dev/null +++ b/test/form/for-loop-with-empty-head/_expected/iife.js @@ -0,0 +1,8 @@ +(function () { + 'use strict'; + + for ( ; ; ) { + console.log( 42 ); + } + +}()); \ No newline at end of file diff --git a/test/form/for-loop-with-empty-head/_expected/umd.js b/test/form/for-loop-with-empty-head/_expected/umd.js new file mode 100644 index 0000000..3e90731 --- /dev/null +++ b/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 ); + } + +}))); \ No newline at end of file diff --git a/test/form/for-loop-with-empty-head/main.js b/test/form/for-loop-with-empty-head/main.js new file mode 100644 index 0000000..5e492f8 --- /dev/null +++ b/test/form/for-loop-with-empty-head/main.js @@ -0,0 +1,3 @@ +for ( ; ; ) { + console.log( 42 ); +}