Skip to content
Permalink
Browse files
Merge branch 'base64-deshadow'
  • Loading branch information
lukastaegert committed May 15, 2018
2 parents 14dbe39 + 7c34a20 commit f837dd000cd0efbcb07fe5cc2f67c77810f0c8d0
Showing 18 changed files with 95 additions and 5 deletions.
@@ -6,6 +6,7 @@
* Do not emit empty chunks when code-splitting or empty files when preserving modules ([#2128](https://github.com/rollup/rollup/pull/2128))
* Support `import.meta.url` ([#2164](https://github.com/rollup/rollup/pull/2164))
* Add `esm` format alias ([#2102](https://github.com/rollup/rollup/pull/2102))
* Use alphanumeric base64 characters when deconflicting variables ([#2188](https://github.com/rollup/rollup/pull/2188))
* Improve handling of external modules imported as both default and named imports ([#2136](https://github.com/rollup/rollup/pull/2136))
* Properly deconflict named imports from other chunks ([#2177](https://github.com/rollup/rollup/pull/2177))
* Fix an issue with namespaces containing reexports ([#2157](https://github.com/rollup/rollup/pull/2157))
@@ -22,6 +22,7 @@ import sha256 from 'hash.js/lib/hash/sha/256';
import { jsExts } from './utils/relativeId';
import ExternalVariable from './ast/variables/ExternalVariable';
import { GlobalsOption, OutputOptions, RawSourceMap } from './rollup/types';
import { toBase64 } from './utils/base64';

export interface ModuleDeclarations {
exports: ChunkExports;
@@ -365,11 +366,11 @@ export default class Chunk {
const exportedVariables = Array.from(this.exports.keys());
if (mangle) {
for (const variable of exportedVariables) {
safeExportName = (++i).toString(36);
safeExportName = toBase64(++i);
// skip past leading number identifiers
if (safeExportName.charCodeAt(0) === 49 /* '1' */) {
i += 9 * 36 ** (safeExportName.length - 1);
safeExportName = i.toString(36);
i += 9 * 64 ** (safeExportName.length - 1);
safeExportName = toBase64(i);
}
this.exportNames[safeExportName] = variable;
}
@@ -451,7 +452,7 @@ export default class Chunk {
function getSafeName(name: string): string {
let safeName = name;
while (used[safeName]) {
safeName = `${name}$${used[name]++}`;
safeName = `${name}$${toBase64(used[name]++)}`;
}
used[safeName] = 1;
return safeName;
@@ -10,6 +10,7 @@ import ArgumentsVariable from '../variables/ArgumentsVariable';
import Variable from '../variables/Variable';
import { ExpressionEntity } from '../nodes/shared/Expression';
import ExternalVariable from '../variables/ExternalVariable';
import { toBase64 } from '../../utils/base64';

export default class Scope {
parent: Scope | void;
@@ -95,7 +96,7 @@ export default class Scope {
let deshadowed,
i = 1;
do {
deshadowed = `${name}$$${i++}`;
deshadowed = `${name}$$${toBase64(i++)}`;
} while (names.has(deshadowed));

declaration.setSafeName(deshadowed);
@@ -0,0 +1,11 @@
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_';

export function toBase64(num: number) {
let outStr = '';
do {
const curDigit = num % 64;
num = Math.floor(num / 64);
outStr = chars[curDigit] + outStr;
} while (num !== 0);
return outStr;
}
@@ -0,0 +1,3 @@
module.exports = {
description: 'base64 deshadowing indices'
};
@@ -0,0 +1,37 @@
var name = 5;

var name$1 = 5;

var name$2 = 5;

var name$3 = 5;

var name$4 = 5;

var name$5 = 5;

var name$6 = 5;

var name$7 = 5;

var name$8 = 5;

var name$9 = 5;

var name$a = 5;

console.log(name);
console.log(name$1);
console.log(name$2);
console.log(name$3);
console.log(name$4);
console.log(name$5);
console.log(name$6);
console.log(name$7);
console.log(name$8);
console.log(name$9);
console.log(name$a);

var name$b = 'name';

export { name$b as name };
@@ -0,0 +1 @@
export var name = 5;
@@ -0,0 +1 @@
export var name = 5;
@@ -0,0 +1 @@
export var name = 5;
@@ -0,0 +1 @@
export var name = 5;
@@ -0,0 +1 @@
export var name = 5;
@@ -0,0 +1 @@
export var name = 5;
@@ -0,0 +1 @@
export var name = 5;
@@ -0,0 +1 @@
export var name = 5;
@@ -0,0 +1 @@
export var name = 5;
@@ -0,0 +1 @@
export var name = 5;
@@ -0,0 +1 @@
export var name = 5;
@@ -0,0 +1,25 @@
import { name as a } from './dep1.js';
import { name as b } from './dep2.js';
import { name as c } from './dep3.js';
import { name as d } from './dep4.js';
import { name as e } from './dep5.js';
import { name as f } from './dep6.js';
import { name as g } from './dep7.js';
import { name as h } from './dep8.js';
import { name as i } from './dep9.js';
import { name as j } from './dep10.js';
import { name as k } from './dep11.js';

console.log(a);
console.log(b);
console.log(c);
console.log(d);
console.log(e);
console.log(f);
console.log(g);
console.log(h);
console.log(i);
console.log(j);
console.log(k);

export var name = 'name';

0 comments on commit f837dd0

Please sign in to comment.