Rollup: Duplicate variable declarations wrongly removed

Created on 12 Jun 2016  ·  3Comments  ·  Source: rollup/rollup

If I import foundation as

import {} from './node_modules/foundation-sites/dist/foundation.js';

only last _createClass helper definition stays, others gets removed. Problem is that every definition of _createClass helper is in their own iffe scope, so I am getting 'undefined' on _createClass helpers calls.

If I import foundation plugins one by one as

import {} from './node_modules/foundation-sites/dist/plugins/foundation.core.js';
import {} from './node_modules/foundation-sites/dist/plugins/foundation.abide.js';
import {} from './node_modules/foundation-sites/dist/plugins/foundation.orbit.js';

it works as expected, _createClass helpers gets namespacing and they are not removed.

rollup 0.31.0, no plugins

t¹ 🐞 bug

Most helpful comment

_Finally_ fixed in 0.35.0

All 3 comments

Minimal reproduction:

// main.js
var a = 1;

console.log(a);

var a = 1;

console.log(a);


// output.js
'use strict';

console.log(a);

var a = 1;

console.log(a);

This is proving surprisingly finicky to fix – I feel a bit of a refactoring coming on – but how does this general solution sound: in a situation like this, we simply drop the var from all but the first declaration, and treat subsequent ones as assignments instead (this is essentially what happens if you run the code).

var a = 1;

console.log(a);

a = 1;

console.log(a);

At the same time we should throw an error if a duplicate declaration is encountered and either the first or the second isn't a function or var declaration (since it's a syntax error to redeclare a let/const/class).

_Finally_ fixed in 0.35.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nanomosfet picture nanomosfet  ·  3Comments

mmacfadden picture mmacfadden  ·  3Comments

good-idea picture good-idea  ·  3Comments

alfonsogarciacaro picture alfonsogarciacaro  ·  3Comments

alendit picture alendit  ·  3Comments