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

Issue trying to use keep_fargs and keep_fnames #579

Open
castortech opened this issue May 15, 2024 · 0 comments
Open

Issue trying to use keep_fargs and keep_fnames #579

castortech opened this issue May 15, 2024 · 0 comments

Comments

@castortech
Copy link

I first used Uglify with simply compress and mangle true, but got into an issue with the arguments field being used after the function argument variable was reused and changed.

Original config:

		uglify: {
			options: {
				compress: true,
				mangle: true,
				sourceMap: true,
				sourceMapIncludeSources: true,
			},
			target: {
				src: '<%= paths.src.js %>',
				dest: '<%= paths.dest.jsMin %>'
			}
		},

Original code:

		_dropAction: function(event) {
			event.preventDefault();
			// check acceptable file type
			const fileItems = event.originalEvent.dataTransfer.items;
			if (fileItems != null) {
				for (let fileItem of fileItems) {
					if (!this.checkType(fileItem.type)) {
						this.showError_('File type is not allowed: ' + fileItem.type);
						return;
					}
				}
			}
			exWidget._dropAction.apply(this, arguments);
		},

Original result:

_dropAction: function (A) {
    A.preventDefault();
    A = A.originalEvent.dataTransfer.items;
    if (null != A)
        for (var e of A)
            if (!this.checkType(e.type))
                return void this.showError_("File type is not allowed: " + e.type);
    t._dropAction.apply(this, arguments)
}

Then I tried to change it at the compress level and the file was somewhat different, but the problematic code was unchanged. I then added keep_fargs to mangle and I got very different results. Now the function argument wasn't replaced but it was still re-using the variable
Config:

		uglify: {
			options: {
				compress: { "keep_fargs" : "true" },
				mangle: { "keep_fargs" : "true" },
				sourceMap: true,
				sourceMapIncludeSources: true,
			},
			target: {
				src: '<%= paths.src.js %>',
				dest: '<%= paths.dest.jsMin %>'
			}
		},

Here is that output where we can see that event is being re-assigned on the 3rd line to some items. Finally at the end of the function, arguments is being passed with now incorrect content:

_dropAction: function(event) {
            event.preventDefault();
            event = event.originalEvent.dataTransfer.items;
            if (null != event)
                for (var A of event)
                    if (!this.checkType(A.type))
                        return void this.showError_("File type is not allowed: " + A.type);
            e._dropAction.apply(this, arguments)
        },

Finally after perusing on Github I tried the following config:

		uglify: {
			options: {
				compress: {
					keep_fargs : true
				},
				mangle: { 
					keep_fargs : true
				},
				sourceMap: true,
				sourceMapIncludeSources: true,
			},
			target: {
				src: '<%= paths.src.js %>',
				dest: '<%= paths.dest.jsMin %>'
			}
		},

and now nothing is compressed or mangled at all.

So I'm very confused and even wondering if the 2nd result is a bug with UglifyJS or not, or I am totally misconfiguring this thing.

Thanks

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

No branches or pull requests

1 participant