Skip to content

Commit

Permalink
Sanitize shortened internal export names (#2768)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Mar 24, 2019
1 parent dec4d83 commit 9cbb73e
Show file tree
Hide file tree
Showing 18 changed files with 3,104 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/Chunk.ts
Expand Up @@ -34,6 +34,7 @@ import relativeId from './utils/relativeId';
import renderChunk from './utils/renderChunk';
import { RenderOptions } from './utils/renderHelpers';
import { makeUnique, renderNamePattern } from './utils/renderNamePattern';
import { RESERVED_NAMES } from './utils/reservedNames';
import { sanitizeFileName } from './utils/sanitizeFileName';
import { timeEnd, timeStart } from './utils/timers';
import { MISSING_EXPORT_SHIM_VARIABLE } from './utils/variableNames';
Expand Down Expand Up @@ -248,12 +249,14 @@ export default class Chunk {
const exportedVariables = Array.from(this.exports);
if (mangle) {
for (const variable of exportedVariables) {
safeExportName = toBase64(++i);
// skip past leading number identifiers
if (safeExportName.charCodeAt(0) === 49 /* '1' */) {
i += 9 * 64 ** (safeExportName.length - 1);
safeExportName = toBase64(i);
}
do {
safeExportName = toBase64(++i);
// skip past leading number identifiers
if (safeExportName.charCodeAt(0) === 49 /* '1' */) {
i += 9 * 64 ** (safeExportName.length - 1);
safeExportName = toBase64(i);
}
} while (RESERVED_NAMES[safeExportName]);
this.exportNames[safeExportName] = variable;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/reservedNames.ts
Expand Up @@ -4,7 +4,7 @@ export interface NameCollection {
[name: string]: true;
}

const RESERVED_NAMES: NameCollection = Object.assign(Object.create(null), {
export const RESERVED_NAMES: NameCollection = Object.assign(Object.create(null), {
await: true,
break: true,
case: true,
Expand Down
@@ -0,0 +1,6 @@
module.exports = {
description: 'make sure internal exports are sanitized',
options: {
input: ['main.js']
}
};

0 comments on commit 9cbb73e

Please sign in to comment.