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

Fix a collision with exported variables with short names #1072

Merged
merged 2 commits into from Sep 22, 2021
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
9 changes: 5 additions & 4 deletions lib/scope.js
Expand Up @@ -781,6 +781,8 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
}

const mangled_names = this.mangled_names = new Set();
unmangleable_names = new Set();

if (options.cache) {
this.globals.forEach(collect);
if (options.cache.props) {
Expand Down Expand Up @@ -833,7 +835,6 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
this.walk(tw);

if (options.keep_fnames || options.keep_classnames) {
unmangleable_names = new Set();
// Collect a set of short names which are unmangleable,
// for use in avoiding collisions in next_mangled.
to_mangle.forEach(def => {
Expand All @@ -849,9 +850,9 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
unmangleable_names = null;

function collect(symbol) {
const should_mangle = !options.reserved.has(symbol.name)
&& !(symbol.export & MASK_EXPORT_DONT_MANGLE);
if (should_mangle) {
if (symbol.export & MASK_EXPORT_DONT_MANGLE) {
unmangleable_names.add(symbol.name);
} else if (!options.reserved.has(symbol.name)) {
to_mangle.push(symbol);
}
}
Expand Down
31 changes: 31 additions & 0 deletions test/compress/export.js
Expand Up @@ -921,3 +921,34 @@ issue_333_toplevel: {
export { _setToString };
}
}

export_object_property_mangle: {
module = true
options = {
reduce_vars: false,
}
mangle = true
input: {
const n = null;
export const o = { o: n };
}
expect: {
const n = null;
export const o = {o: n};
}
}

export_object_property_mangle_2: {
module = true
mangle = true
input: {
const n = null;
const o = { o: n };
export { o };
}
expect: {
const o = null;
const n = {o: o};
export {n as o};
}
}