-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
prefix for mangle property names #1475
base: master
Are you sure you want to change the base?
Conversation
Previous post #1472 |
To consider this PR we would need |
Could you please remove the [Harmony] prefix in the title if you intend this to be merged to the branch master? |
it("Should add prefix \"__\" for mangle properties (not quoted)", function() | ||
{ | ||
var js = 'a["foo"] = "bar"; a.color = "red"; x = {"bar": 10};'; | ||
var result = Uglify.minify(js, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a formatting issue. Please use spaces instead of tabs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
Also would need documentation in README.md |
Could you please change the |
test/compress/mangle-prefix.js
Outdated
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please only have a single empty line between tests.
test/mocha/minify.js
Outdated
@@ -58,6 +58,46 @@ describe("minify", function() { | |||
assert.strictEqual(result.code, | |||
'a["foo"]="bar",a.a="red",x={"bar":10};'); | |||
}); | |||
|
|||
it("Should add prefix \"__\" for mangle properties (not quoted)", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove \"__\"
from description.
test/mocha/minify.js
Outdated
'a["foo"]="bar",a.__a="red",x={"bar":10};'); | ||
}); | ||
|
||
it("Should add prefix \"__\" for mangle properties (with quoted)", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove \"__\"
from description.
bin/uglifyjs
Outdated
@@ -74,6 +74,7 @@ You need to pass an argument to this option to specify the name that your module | |||
.describe("reserve-domprops", "Make (most?) DOM properties reserved for --mangle-props") | |||
.describe("mangle-props", "Mangle property names (0 - disabled, 1 - mangle all properties, 2 - mangle unquoted properies)") | |||
.describe("mangle-regex", "Only mangle property names matching the regex") | |||
.describe("mangle-prefix", "Prefix of the mangle properties") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename this flag to mangle-props-prefix
in bin/uglifyjs
. The property name in lib/propmangle.js
is fine.
test/mocha/minify.js
Outdated
} | ||
}); | ||
assert.strictEqual(result.code, | ||
'a["foo"]="bar",a.__a="red",x={"bar":10};'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please collapse lines 78 and 79 into one line
test/mocha/minify.js
Outdated
} | ||
}); | ||
assert.strictEqual(result.code, | ||
'a["__a"]="bar",a.__b="red",x={"__c":10};'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please collapse into one line
@dabretin I apologize for not raising this issue earlier - I'm afraid I don't understand the use case of this PR: Why would anyone want to add a prefix to the mangled property name? That just wastes space in the minified output. |
It can enable to restrict access at runtime to properties. |
README.md
Outdated
@@ -150,6 +150,7 @@ The available options are: | |||
notation. You can override these by setting | |||
them explicitly on the command line. | |||
--mangle-regex Only mangle property names matching the regex | |||
--mangle-props-prefix Prefix of the mangle properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more apt description: "Prefix added to the property name after mangling."
Need a command line test in |
bin/uglifyjs
Outdated
@@ -74,6 +74,7 @@ You need to pass an argument to this option to specify the name that your module | |||
.describe("reserve-domprops", "Make (most?) DOM properties reserved for --mangle-props") | |||
.describe("mangle-props", "Mangle property names (0 - disabled, 1 - mangle all properties, 2 - mangle unquoted properies)") | |||
.describe("mangle-regex", "Only mangle property names matching the regex") | |||
.describe("mangle-props-prefix", "Prefix of the mangle properties") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this description match the README.
This PR will not be approved without a command line test for |
@@ -0,0 +1,28 @@ | |||
var Test = function() | |||
{ | |||
this.someVar = 123; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use kick brace style throughout this file:
var Test = function() {
test/input/mangle-prefix/sample.js
Outdated
this.someVar = 123; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use a single empty line between functions.
test/input/mangle-prefix/sample.js
Outdated
this.someVar = 123; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a single empty line between functions throughout the file.
This PR appears to be low risk and now has sufficient tests and documentation. Please squash into a single commit and assign an appropriate commit comment. Thanks. |
I'm not confortable with git so sorry in advance for my (probably stupid) questions... |
I think it's done :) |
If this PR gets in I think it could very well be the last new mangle option. They are getting harder to support and test with each new addition and combination. |
7d1c0a7
to
b468103
Compare
It could be very useful to set profix of mangle names.
It could permit to restrict access (at runtime) to "private" properties/methods on proxified objects.
Sorry for the double post...
I have previously done an error (no default value for
prefix
inmangle_properties
)