TrySound / rollup-plugin-uglify

Rollup plugin to minify generated bundle
MIT License
260 stars 42 forks source link

Name collision #50

Closed snooopcatt closed 6 years ago

snooopcatt commented 6 years ago

Hello. We have a name collision when uglifying rolled up code. This a snippet, causing problems:

let { cellElement, row, record, value } = renderData,
    html                                = '',
    gridMeta                            = record.instanceMeta(renderData.grid),
    cls                                 = '';

cellElement.className = 'b-grid-cell ' + me.internalCellCls;

if (me.originalRenderer) {
    let rendererHtml = me.originalRenderer(renderData);
    value = rendererHtml === false ? cellElement.innerHTML : rendererHtml;
}

if (gridMeta.parentFor >= 0) {
    row.addCls && row.addCls('b-tree-parent-row');
    cellElement.classList.add('b-tree-parent-cell');
}

It gets uglified to (I took liberty to add some spaces for readability):

let{cellElement:r,row:n,record:o,value:i}=e,s="",a=o.instanceMeta(e.grid),l=""; // first n
if(
  r.className="b-grid-cell "+t.internalCellCls,
  t.originalRenderer) {
    let n=t.originalRenderer(e);i=!1===n?r.innerHTML:n // second n
  }

if(a.parentFor>=0){n.addCls&&n.addCls("b-tree-parent-row"),r.classList.add("b-tree-parent-cell")

If you look closely, there are 2 n variables declared. While this is allowed with let, it causes troubles when this code gets processed by javascript-obfuscator, which replaces let with var.

Can you please look into that and maybe avoid such possible collisions?

TrySound commented 6 years ago

First of all this plugin is a thin wrapper around uglifyjs project which doesn't add any functionality.

From what you described the output of uglify is correct and the problem is introduced actually by your obfuscator. I would suggest to drop it. Business requirements are not competent here.

Or as a workaround just transpile your code with babel before uglifying, so uglify could mangle names according es5 behaviour.