From ad22e33dcd09aa806003c6ff6b9efc9c33b0d830 Mon Sep 17 00:00:00 2001 From: Denis Bardadym Date: Sat, 24 Sep 2016 23:54:11 +0300 Subject: [PATCH] Do not skip non empty block statements --- src/ast/nodes/BlockStatement.js | 10 ++++++++++ test/form/non-empty-block-statement/_config.js | 3 +++ .../form/non-empty-block-statement/_expected/amd.js | 9 +++++++++ .../form/non-empty-block-statement/_expected/cjs.js | 7 +++++++ test/form/non-empty-block-statement/_expected/es.js | 5 +++++ .../non-empty-block-statement/_expected/iife.js | 10 ++++++++++ .../form/non-empty-block-statement/_expected/umd.js | 13 +++++++++++++ test/form/non-empty-block-statement/main.js | 5 +++++ 8 files changed, 62 insertions(+) create mode 100644 test/form/non-empty-block-statement/_config.js create mode 100644 test/form/non-empty-block-statement/_expected/amd.js create mode 100644 test/form/non-empty-block-statement/_expected/cjs.js create mode 100644 test/form/non-empty-block-statement/_expected/es.js create mode 100644 test/form/non-empty-block-statement/_expected/iife.js create mode 100644 test/form/non-empty-block-statement/_expected/umd.js create mode 100644 test/form/non-empty-block-statement/main.js diff --git a/src/ast/nodes/BlockStatement.js b/src/ast/nodes/BlockStatement.js index 78e6e67..d83d321 100644 --- a/src/ast/nodes/BlockStatement.js +++ b/src/ast/nodes/BlockStatement.js @@ -46,4 +46,14 @@ export default class BlockStatement extends Statement { lastNode = node; } } + + render ( code, es ) { + if (this.body.length) { + for ( const node of this.body ) { + node.render( code, es ); + } + } else { + Statement.prototype.render.call(this, code, es); + } + } } diff --git a/test/form/non-empty-block-statement/_config.js b/test/form/non-empty-block-statement/_config.js new file mode 100644 index 0000000..283b0b6 --- /dev/null +++ b/test/form/non-empty-block-statement/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'removes an empty block statement' +}; diff --git a/test/form/non-empty-block-statement/_expected/amd.js b/test/form/non-empty-block-statement/_expected/amd.js new file mode 100644 index 0000000..aaad1ff --- /dev/null +++ b/test/form/non-empty-block-statement/_expected/amd.js @@ -0,0 +1,9 @@ +define(function () { 'use strict'; + + console.log( 1 ); + { + var tmp = 10; + } + console.log( tmp ); + +}); diff --git a/test/form/non-empty-block-statement/_expected/cjs.js b/test/form/non-empty-block-statement/_expected/cjs.js new file mode 100644 index 0000000..ef9e375 --- /dev/null +++ b/test/form/non-empty-block-statement/_expected/cjs.js @@ -0,0 +1,7 @@ +'use strict'; + +console.log( 1 ); +{ + var tmp = 10; +} +console.log( tmp ); diff --git a/test/form/non-empty-block-statement/_expected/es.js b/test/form/non-empty-block-statement/_expected/es.js new file mode 100644 index 0000000..9f19ab6 --- /dev/null +++ b/test/form/non-empty-block-statement/_expected/es.js @@ -0,0 +1,5 @@ +console.log( 1 ); +{ + var tmp = 10; +} +console.log( tmp ); diff --git a/test/form/non-empty-block-statement/_expected/iife.js b/test/form/non-empty-block-statement/_expected/iife.js new file mode 100644 index 0000000..611fa6e --- /dev/null +++ b/test/form/non-empty-block-statement/_expected/iife.js @@ -0,0 +1,10 @@ +(function () { + 'use strict'; + + console.log( 1 ); + { + var tmp = 10; + } + console.log( tmp ); + +}()); diff --git a/test/form/non-empty-block-statement/_expected/umd.js b/test/form/non-empty-block-statement/_expected/umd.js new file mode 100644 index 0000000..9015af2 --- /dev/null +++ b/test/form/non-empty-block-statement/_expected/umd.js @@ -0,0 +1,13 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + (factory()); +}(this, (function () { 'use strict'; + + console.log( 1 ); + { + var tmp = 10; + } + console.log( tmp ); + +}))); diff --git a/test/form/non-empty-block-statement/main.js b/test/form/non-empty-block-statement/main.js new file mode 100644 index 0000000..9f19ab6 --- /dev/null +++ b/test/form/non-empty-block-statement/main.js @@ -0,0 +1,5 @@ +console.log( 1 ); +{ + var tmp = 10; +} +console.log( tmp );