Skip to content

Commit

Permalink
Merge pull request #1204 from rollup/gh-1198
Browse files Browse the repository at this point in the history
ignore var inits in dead branches
  • Loading branch information
Rich-Harris committed Dec 30, 2016
2 parents 11a2830 + d1d667f commit 38bb9d9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ast/nodes/IfStatement.js
Expand Up @@ -17,9 +17,10 @@ function handleVarDeclarations ( node, scope ) {

function visit ( node ) {
if ( node.type === 'VariableDeclaration' && node.kind === 'var' ) {
node.initialise( scope );

node.declarations.forEach( declarator => {
declarator.init = null;
declarator.initialise( scope );

extractNames( declarator.id ).forEach( name => {
if ( !~hoistedVars.indexOf( name ) ) hoistedVars.push( name );
});
Expand Down
9 changes: 9 additions & 0 deletions test/function/vars-with-init-in-dead-branch/_config.js
@@ -0,0 +1,9 @@
module.exports = {
description: 'handles vars with init in dead branch (#1198)',
warnings: [
{
code: 'EMPTY_BUNDLE',
message: 'Generated an empty bundle'
}
]
};
4 changes: 4 additions & 0 deletions test/function/vars-with-init-in-dead-branch/main.js
@@ -0,0 +1,4 @@
if ( false ) {
var foo = [];
var bar = foo.concat( 'x' );
}

0 comments on commit 38bb9d9

Please sign in to comment.