Browse Source

ignore var inits in dead branches - fixes #1198

gh-786
Rich-Harris 8 years ago
parent
commit
d1d667f9a8
  1. 5
      src/ast/nodes/IfStatement.js
  2. 9
      test/function/vars-with-init-in-dead-branch/_config.js
  3. 4
      test/function/vars-with-init-in-dead-branch/main.js

5
src/ast/nodes/IfStatement.js

@ -17,9 +17,10 @@ function handleVarDeclarations ( node, scope ) {
function visit ( node ) { function visit ( node ) {
if ( node.type === 'VariableDeclaration' && node.kind === 'var' ) { if ( node.type === 'VariableDeclaration' && node.kind === 'var' ) {
node.initialise( scope );
node.declarations.forEach( declarator => { node.declarations.forEach( declarator => {
declarator.init = null;
declarator.initialise( scope );
extractNames( declarator.id ).forEach( name => { extractNames( declarator.id ).forEach( name => {
if ( !~hoistedVars.indexOf( name ) ) hoistedVars.push( name ); if ( !~hoistedVars.indexOf( name ) ) hoistedVars.push( name );
}); });

9
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
test/function/vars-with-init-in-dead-branch/main.js

@ -0,0 +1,4 @@
if ( false ) {
var foo = [];
var bar = foo.concat( 'x' );
}
Loading…
Cancel
Save