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

prefix for mangle property names #1475

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

dabretin
Copy link

@dabretin dabretin commented Feb 8, 2017

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 in mangle_properties)

@dabretin
Copy link
Author

dabretin commented Feb 8, 2017

Previous post #1472

@kzc
Copy link
Contributor

kzc commented Feb 8, 2017

Could you please close #1472 if this PR replaces it?

To consider this PR we would need bin/uglifyjs and minify() tests in test/mocha/, as well as tests in test/compress/.

@kzc
Copy link
Contributor

kzc commented Feb 8, 2017

Could you please remove the [Harmony] prefix in the title if you intend this to be merged to the branch master?

@dabretin dabretin changed the title [Harmony] - prefix for mangle property names prefix for mangle property names Feb 8, 2017
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, {
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@kzc
Copy link
Contributor

kzc commented Feb 8, 2017

Also would need documentation in README.md

@kzc
Copy link
Contributor

kzc commented Feb 8, 2017

Could you please change the bin/uglifyjs flag name to mangle-props-prefix?

}
}


Copy link
Contributor

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.

@@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove \"__\" from description.

'a["foo"]="bar",a.__a="red",x={"bar":10};');
});

it("Should add prefix \"__\" for mangle properties (with quoted)", function() {
Copy link
Contributor

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")
Copy link
Contributor

@kzc kzc Feb 8, 2017

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.

}
});
assert.strictEqual(result.code,
'a["foo"]="bar",a.__a="red",x={"bar":10};');
Copy link
Contributor

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

}
});
assert.strictEqual(result.code,
'a["__a"]="bar",a.__b="red",x={"__c":10};');
Copy link
Contributor

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

@kzc
Copy link
Contributor

kzc commented Feb 8, 2017

@dabretin I apologize for not raising this issue earlier - I'm afraid I don't understand the use case of this PR:

#1472 (comment)

Why would anyone want to add a prefix to the mangled property name? That just wastes space in the minified output.

@dabretin
Copy link
Author

dabretin commented Feb 8, 2017

It can enable to restrict access at runtime to properties.
After mangle, it's not possible to detect the "private" orientation of a property. The only possibility seems to be a prefix of the obfuscated 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
Copy link
Contributor

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."

@kzc
Copy link
Contributor

kzc commented Feb 8, 2017

Need a command line test in test/mocha/ to test the new bin/uglifyjs flag. See test/mocha/cli.js for an example.

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")
Copy link
Contributor

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.

@kzc
Copy link
Contributor

kzc commented Feb 8, 2017

This PR will not be approved without a command line test for bin/uglifyjs.

example: https://github.com/mishoo/UglifyJS2/blob/1eaa211e0932105439d98d4f03a981f157f0a77c/test/mocha/cli.js#L93-L102

@@ -0,0 +1,28 @@
var Test = function()
{
this.someVar = 123;
Copy link
Contributor

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() {

this.someVar = 123;
};


Copy link
Contributor

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.

this.someVar = 123;
};


Copy link
Contributor

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.

@kzc
Copy link
Contributor

kzc commented Feb 9, 2017

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.

@dabretin
Copy link
Author

dabretin commented Feb 9, 2017

I'm not confortable with git so sorry in advance for my (probably stupid) questions...
Is the last comment for me ?
If it is...how can I do that ?

@dabretin
Copy link
Author

dabretin commented Feb 9, 2017

I think it's done :)

@kzc
Copy link
Contributor

kzc commented Feb 9, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants