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

Minified variables are not being used in JavaScript [varName]: value object syntax #593

Open
Mike-Logit opened this issue Mar 1, 2023 · 0 comments
Labels

Comments

@Mike-Logit
Copy link

Mike-Logit commented Mar 1, 2023

Describe the bug
The un-minified code looks like the following:

function initializePage(getTotalCostUrl, tokenHeaderName, tokenValue) {	
	function sendTotalCostRequest() {
		var payload = createTotalCostRequestPayload();

		$.ajax({
			url: getTotalCostUrl,
			headers: { [tokenHeaderName]: tokenValue },
			type: "POST",
			dataType: "json",
			contentType: "application/json; charset=utf-8",
			success: onTotalCostRetrieved,
			data: JSON.stringify(payload)
		});
	}

	// other code omitted
}

And when minified using BundlerMinifier the output is this:

function initializePage(h, ut, ft) {
	function yi() {
		var n = st();
		
		$.ajax({
			url: h,
			headers: {
				[tokenHeaderName]: ft
			},
			type: "POST",
			dataType: "json",
			contentType: "application/json; charset=utf-8",
			success: fi,
			data: JSON.stringify(n)
		})
	}

	// other code omitted
}	

The bug in question is this line: [tokenHeaderName]: ft. As you can see the tokenHeaderName is passed into the initializePage function and the minifier will change this variable to ut but it will not replace this reference to it on this line.

When unminified, this code is supposed to add a new property to the new JavaScript object where the property name is the string value assigned to the variable. So if tokenHeaderName has the string value of "RequestToken" then the object would have a RequestToken field.

However, instead tokenHeaderName is undefined because the minifier renamed the variable.

Expected behavior
The [tokenHeaderName]: tokenValue syntax in Javascript should also be minified to use the minified variable name.

So in the example given, this should have been minified to output: [ut]: ft

@Mike-Logit Mike-Logit added the bug label Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant