@@ -4395,7 +4395,7 @@ merge(Compressor.prototype, {
|
|||||||
var prop = self.property;
|
var prop = self.property;
|
||||||
if (prop instanceof AST_String && compressor.option("properties")) {
|
if (prop instanceof AST_String && compressor.option("properties")) {
|
||||||
prop = prop.getValue();
|
prop = prop.getValue();
|
||||||
if (RESERVED_WORDS(prop) ? !compressor.option("ie8") : is_identifier_string(prop)) {
|
if (is_identifier_string(prop)) {
|
||||||
return make_node(AST_Dot, self, {
|
return make_node(AST_Dot, self, {
|
||||||
expression : self.expression,
|
expression : self.expression,
|
||||||
property : prop
|
property : prop
|
||||||
@@ -4432,19 +4432,10 @@ merge(Compressor.prototype, {
|
|||||||
if (def) {
|
if (def) {
|
||||||
return def.optimize(compressor);
|
return def.optimize(compressor);
|
||||||
}
|
}
|
||||||
var prop = self.property;
|
|
||||||
if (RESERVED_WORDS(prop) && compressor.option("ie8")) {
|
|
||||||
return make_node(AST_Sub, self, {
|
|
||||||
expression : self.expression,
|
|
||||||
property : make_node(AST_String, self, {
|
|
||||||
value: prop
|
|
||||||
})
|
|
||||||
}).optimize(compressor);
|
|
||||||
}
|
|
||||||
if (compressor.option("unsafe") && self.expression instanceof AST_Object) {
|
if (compressor.option("unsafe") && self.expression instanceof AST_Object) {
|
||||||
var values = self.expression.properties;
|
var values = self.expression.properties;
|
||||||
for (var i = values.length; --i >= 0;) {
|
for (var i = values.length; --i >= 0;) {
|
||||||
if (values[i].key === prop) {
|
if (values[i].key === self.property) {
|
||||||
var value = values[i].value;
|
var value = values[i].value;
|
||||||
if (value instanceof AST_Function ? !value.contains_this() : !value.has_side_effects(compressor)) {
|
if (value instanceof AST_Function ? !value.contains_this() : !value.has_side_effects(compressor)) {
|
||||||
var obj = self.expression.clone();
|
var obj = self.expression.clone();
|
||||||
|
|||||||
@@ -1146,15 +1146,23 @@ function OutputStream(options) {
|
|||||||
DEFPRINT(AST_Dot, function(self, output){
|
DEFPRINT(AST_Dot, function(self, output){
|
||||||
var expr = self.expression;
|
var expr = self.expression;
|
||||||
expr.print(output);
|
expr.print(output);
|
||||||
if (expr instanceof AST_Number && expr.getValue() >= 0) {
|
var prop = self.property;
|
||||||
if (!/[xa-f.)]/i.test(output.last())) {
|
if (output.option("ie8") && RESERVED_WORDS(prop)) {
|
||||||
output.print(".");
|
output.print("[");
|
||||||
|
output.add_mapping(self.end);
|
||||||
|
output.print_string(prop);
|
||||||
|
output.print("]");
|
||||||
|
} else {
|
||||||
|
if (expr instanceof AST_Number && expr.getValue() >= 0) {
|
||||||
|
if (!/[xa-f.)]/i.test(output.last())) {
|
||||||
|
output.print(".");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
output.print(".");
|
||||||
|
// the name after dot would be mapped about here.
|
||||||
|
output.add_mapping(self.end);
|
||||||
|
output.print_name(prop);
|
||||||
}
|
}
|
||||||
output.print(".");
|
|
||||||
// the name after dot would be mapped about here.
|
|
||||||
output.add_mapping(self.end);
|
|
||||||
output.print_name(self.property);
|
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Sub, function(self, output){
|
DEFPRINT(AST_Sub, function(self, output){
|
||||||
self.expression.print(output);
|
self.expression.print(output);
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ keep_properties: {
|
|||||||
dot_properties: {
|
dot_properties: {
|
||||||
options = {
|
options = {
|
||||||
properties: true,
|
properties: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
ie8: true,
|
ie8: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
a["foo"] = "bar";
|
a["foo"] = "bar";
|
||||||
a["if"] = "if";
|
a["if"] = "if";
|
||||||
@@ -36,8 +38,10 @@ dot_properties: {
|
|||||||
dot_properties_es5: {
|
dot_properties_es5: {
|
||||||
options = {
|
options = {
|
||||||
properties: true,
|
properties: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
ie8: false,
|
ie8: false,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
a["foo"] = "bar";
|
a["foo"] = "bar";
|
||||||
a["if"] = "if";
|
a["if"] = "if";
|
||||||
|
|||||||
@@ -2,16 +2,17 @@ var Uglify = require('../../');
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|
||||||
describe("let", function() {
|
describe("let", function() {
|
||||||
it("Should not produce reserved keywords as variable name in mangle", function(done) {
|
this.timeout(30000);
|
||||||
this.timeout(10000);
|
it("Should not produce reserved keywords as variable name in mangle", function() {
|
||||||
|
|
||||||
// Produce a lot of variables in a function and run it through mangle.
|
// Produce a lot of variables in a function and run it through mangle.
|
||||||
var s = '"dddddeeeeelllllooooottttt"; function foo() {';
|
var s = '"dddddeeeeelllllooooottttt"; function foo() {';
|
||||||
for (var i = 0; i < 18000; i++) {
|
for (var i = 0; i < 18000; i++) {
|
||||||
s += "var v" + i + "=0;";
|
s += "var v" + i + "=0;";
|
||||||
}
|
}
|
||||||
s += '}';
|
s += '}';
|
||||||
var result = Uglify.minify(s, {compress: false});
|
var result = Uglify.minify(s, {
|
||||||
|
compress: false
|
||||||
|
}).code;
|
||||||
|
|
||||||
// Verify that select keywords and reserved keywords not produced
|
// Verify that select keywords and reserved keywords not produced
|
||||||
[
|
[
|
||||||
@@ -19,7 +20,7 @@ describe("let", function() {
|
|||||||
"let",
|
"let",
|
||||||
"var",
|
"var",
|
||||||
].forEach(function(name) {
|
].forEach(function(name) {
|
||||||
assert.strictEqual(result.code.indexOf("var " + name + "="), -1);
|
assert.strictEqual(result.indexOf("var " + name + "="), -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Verify that the variable names that appeared immediately before
|
// Verify that the variable names that appeared immediately before
|
||||||
@@ -30,9 +31,27 @@ describe("let", function() {
|
|||||||
"eet", "fet",
|
"eet", "fet",
|
||||||
"rar", "oar",
|
"rar", "oar",
|
||||||
].forEach(function(name) {
|
].forEach(function(name) {
|
||||||
assert.ok(result.code.indexOf("var " + name + "=") >= 0);
|
assert.notStrictEqual(result.indexOf("var " + name + "="), -1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Should quote mangled properties that are reserved keywords", function() {
|
||||||
|
var s = '"rrrrrnnnnniiiiiaaaaa";';
|
||||||
|
for (var i = 0; i < 18000; i++) {
|
||||||
|
s += "v.b" + i + ";";
|
||||||
|
}
|
||||||
|
var result = Uglify.minify(s, {
|
||||||
|
compress: false,
|
||||||
|
ie8: true,
|
||||||
|
mangle: {
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
}).code;
|
||||||
|
[
|
||||||
|
"in",
|
||||||
|
"var",
|
||||||
|
].forEach(function(name) {
|
||||||
|
assert.notStrictEqual(result.indexOf(name), -1);
|
||||||
|
assert.notStrictEqual(result.indexOf('v["' + name + '"]'), -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user