1egoman / debundle

:card_file_box: A javascript debundler. Takes a Browserify or Webpack bundle and recreates the initial, pre-bundled source.
https://www.npmjs.com/package/debundle
706 stars 145 forks source link

If a bundle is minified, debundle will replace identifiers globally not following scoping rules. #2

Closed 1egoman closed 7 years ago

1egoman commented 7 years ago

Given a bundle that contains this module:

function(a, b, c) { 
  a.foo = 1; // Used as expected
  {
    // A different scope!
    let a = 5;
    a = 6;
  };
}

This project will replace globally in the whole file all occurrences of the symbol a, even in cases where the symbol is overwritten in a nested lexical context.

The above code will be transformed into:

function(module, exports, require) { 
  module.foo = 1; // Transformed as expected
  {
   // BAD! Should have kept those identifiers as `a`!
    let module = 5;
    module = 6;
  };
}
1egoman commented 7 years ago

Fixed by: