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..92803d7 --- /dev/null +++ b/test/form/non-empty-block-statement/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'do not remove non 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 );