From dded04d414f6bdcd60f3120a44d1b04f963942c9 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 5 Oct 2015 12:41:20 -0400 Subject: [PATCH] prevent superfluous semi-colons causing whitespace to collapse after functions declarations --- src/Module.js | 2 ++ .../spacing-after-function-with-semicolon/_config.js | 4 ++++ .../_expected/amd.js | 7 +++++++ .../_expected/cjs.js | 5 +++++ .../_expected/es6.js | 3 +++ .../_expected/iife.js | 7 +++++++ .../_expected/umd.js | 11 +++++++++++ .../spacing-after-function-with-semicolon/main.js | 3 +++ 8 files changed, 42 insertions(+) create mode 100644 test/form/spacing-after-function-with-semicolon/_config.js create mode 100644 test/form/spacing-after-function-with-semicolon/_expected/amd.js create mode 100644 test/form/spacing-after-function-with-semicolon/_expected/cjs.js create mode 100644 test/form/spacing-after-function-with-semicolon/_expected/es6.js create mode 100644 test/form/spacing-after-function-with-semicolon/_expected/iife.js create mode 100644 test/form/spacing-after-function-with-semicolon/_expected/umd.js create mode 100644 test/form/spacing-after-function-with-semicolon/main.js diff --git a/src/Module.js b/src/Module.js index 911d604..57591fc 100644 --- a/src/Module.js +++ b/src/Module.js @@ -436,6 +436,8 @@ export default class Module { let commentIndex = 0; ast.body.forEach( node => { + if ( node.type === 'EmptyStatement' ) return; + // special case - top-level var declarations with multiple declarators // should be split up. Otherwise, we may end up including code we // don't need, just because an unwanted declarator is included diff --git a/test/form/spacing-after-function-with-semicolon/_config.js b/test/form/spacing-after-function-with-semicolon/_config.js new file mode 100644 index 0000000..c26c4da --- /dev/null +++ b/test/form/spacing-after-function-with-semicolon/_config.js @@ -0,0 +1,4 @@ +module.exports = { + solo: true, + description: 'handles superfluous semicolons' +}; diff --git a/test/form/spacing-after-function-with-semicolon/_expected/amd.js b/test/form/spacing-after-function-with-semicolon/_expected/amd.js new file mode 100644 index 0000000..37f42f3 --- /dev/null +++ b/test/form/spacing-after-function-with-semicolon/_expected/amd.js @@ -0,0 +1,7 @@ +define(function () { 'use strict'; + + function x () { return 'x' }; + + assert.equal( x(), 'x' ); + +}); diff --git a/test/form/spacing-after-function-with-semicolon/_expected/cjs.js b/test/form/spacing-after-function-with-semicolon/_expected/cjs.js new file mode 100644 index 0000000..503ea73 --- /dev/null +++ b/test/form/spacing-after-function-with-semicolon/_expected/cjs.js @@ -0,0 +1,5 @@ +'use strict'; + +function x () { return 'x' }; + +assert.equal( x(), 'x' ); diff --git a/test/form/spacing-after-function-with-semicolon/_expected/es6.js b/test/form/spacing-after-function-with-semicolon/_expected/es6.js new file mode 100644 index 0000000..3b3f5e7 --- /dev/null +++ b/test/form/spacing-after-function-with-semicolon/_expected/es6.js @@ -0,0 +1,3 @@ +function x () { return 'x' }; + +assert.equal( x(), 'x' ); diff --git a/test/form/spacing-after-function-with-semicolon/_expected/iife.js b/test/form/spacing-after-function-with-semicolon/_expected/iife.js new file mode 100644 index 0000000..ea1be49 --- /dev/null +++ b/test/form/spacing-after-function-with-semicolon/_expected/iife.js @@ -0,0 +1,7 @@ +(function () { 'use strict'; + + function x () { return 'x' }; + + assert.equal( x(), 'x' ); + +})(); diff --git a/test/form/spacing-after-function-with-semicolon/_expected/umd.js b/test/form/spacing-after-function-with-semicolon/_expected/umd.js new file mode 100644 index 0000000..5c2fdac --- /dev/null +++ b/test/form/spacing-after-function-with-semicolon/_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'; + + function x () { return 'x' }; + + assert.equal( x(), 'x' ); + +})); diff --git a/test/form/spacing-after-function-with-semicolon/main.js b/test/form/spacing-after-function-with-semicolon/main.js new file mode 100644 index 0000000..3b3f5e7 --- /dev/null +++ b/test/form/spacing-after-function-with-semicolon/main.js @@ -0,0 +1,3 @@ +function x () { return 'x' }; + +assert.equal( x(), 'x' );