list of names that are not o be assigned to vars during mangle/propmangle. added javascript reserved words as default. This fixes current issue that in some constalations uglify-js mangles properties to js reserved words e.g. if
66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
/**
|
|
* Created by anatd on 2/9/2017.
|
|
*/
|
|
var assert = require("assert");
|
|
var uglify = require("../../");
|
|
|
|
describe("verify that the mangled names are legal", function () {
|
|
it("Should not mangle properties to names in the illegal_mangled_names param", function () {
|
|
var js = 'a["foo"] = "bar"; a.color = "red"; x = {"bar": 10};';
|
|
var result = uglify.minify(js, {
|
|
fromString: true,
|
|
compress: {
|
|
properties: false
|
|
},
|
|
mangleProperties: {
|
|
ignore_quoted: true,
|
|
illegal_mangled_names: ["a"]
|
|
},
|
|
output: {
|
|
keep_quoted_props: true,
|
|
quote_style: 3
|
|
}
|
|
});
|
|
assert.strictEqual(result.code,
|
|
'a["foo"]="bar",a.b="red",x={"bar":10};');
|
|
});
|
|
it("Should not mangle names to names in the illegal_mangled_names param", function () {
|
|
var js = 'var a; a["foo"] = "bar"; a.color = "red"; x = {"bar": 10};';
|
|
var result = uglify.minify(js, {
|
|
fromString: true,
|
|
compress: {
|
|
properties: false
|
|
},
|
|
mangleProperties: {
|
|
ignore_quoted: true
|
|
},
|
|
mangle: {toplevel: true, illegal_mangled_names: ["r", "a"]},
|
|
output: {
|
|
keep_quoted_props: true,
|
|
quote_style: 3
|
|
}
|
|
});
|
|
assert.strictEqual(result.code,
|
|
'var b;b["foo"]="bar",b.a="red",x={"bar":10};');
|
|
});
|
|
it("Should not fail without illegal_mangled_names param", function () {
|
|
var js = 'var b; b["foo"] = "bar"; b.color = "red"; x = {"bar": 10};';
|
|
var result = uglify.minify(js, {
|
|
fromString: true,
|
|
compress: {
|
|
properties: false
|
|
},
|
|
mangleProperties: {
|
|
ignore_quoted: true
|
|
},
|
|
mangle: {toplevel: true},
|
|
output: {
|
|
keep_quoted_props: true,
|
|
quote_style: 3
|
|
}
|
|
});
|
|
assert.strictEqual(result.code,
|
|
'var a;a["foo"]="bar",a.a="red",x={"bar":10};');
|
|
});
|
|
});
|