Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize shortened internal export names #2768

Merged
merged 1 commit into from Mar 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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']
}
};