-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ResetNext identifier only when reuse is true Fix tests - add keepClassName Reuse vars as default I dont know why it works - #326 Extract tracker to a separate file, Add topLevel Option
- Loading branch information
Showing
8 changed files
with
1,803 additions
and
221 deletions.
There are no files selected for viewing
1,210 changes: 1,210 additions & 0 deletions
1,210
packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-reuse-test.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"use strict"; | ||
|
||
const CHARSET = ("abcdefghijklmnopqrstuvwxyz" + | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ$_").split(""); | ||
|
||
module.exports = class Charset { | ||
constructor(shouldConsider) { | ||
this.shouldConsider = shouldConsider; | ||
this.chars = CHARSET.slice(); | ||
this.frequency = {}; | ||
this.chars.forEach((c) => { this.frequency[c] = 0; }); | ||
this.finalized = false; | ||
} | ||
|
||
consider(str) { | ||
if (!this.shouldConsider) { | ||
return; | ||
} | ||
|
||
str.split("").forEach((c) => { | ||
if (this.frequency[c] != null) { | ||
this.frequency[c]++; | ||
} | ||
}); | ||
} | ||
|
||
sort() { | ||
if (this.shouldConsider) { | ||
this.chars = this.chars.sort( | ||
(a, b) => this.frequency[b] - this.frequency[a] | ||
); | ||
} | ||
|
||
this.finalized = true; | ||
} | ||
|
||
getIdentifier(num) { | ||
if (!this.finalized) { | ||
throw new Error("Should sort first"); | ||
} | ||
|
||
let ret = ""; | ||
num++; | ||
do { | ||
num--; | ||
ret += this.chars[num % this.chars.length]; | ||
num = Math.floor(num / this.chars.length); | ||
} while (num > 0); | ||
return ret; | ||
} | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/babel-plugin-minify-mangle-names/src/counted-set.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Set that counts | ||
module.exports = class CountedSet { | ||
constructor() { | ||
// because you can't simply extend Builtins yet | ||
this.map = new Map; | ||
} | ||
keys() { | ||
return [...this.map.keys()]; | ||
} | ||
has(value) { | ||
return this.map.has(value); | ||
} | ||
add(value) { | ||
if (!this.has(value)) { | ||
this.map.set(value, 0); | ||
} | ||
this.map.set(value, this.map.get(value) + 1); | ||
} | ||
delete(value) { | ||
if (!this.has(value)) return; | ||
const count = this.map.get(value); | ||
if (count <= 1) { | ||
this.map.delete(value); | ||
} else { | ||
this.map.set(value, count - 1); | ||
} | ||
} | ||
}; |
Oops, something went wrong.