Page MenuHomePhabricator

Add minification support for async-await (ES2017)
Closed, ResolvedPublicBUG REPORT

Assigned To
Authored By
Nux
Aug 4 2023, 12:31 AM
Referenced Files
F37165821: obraz.png
Aug 4 2023, 12:31 AM
Tokens
"Barnstar" token, awarded by Novem_Linguae."Barnstar" token, awarded by SD0001.

Description

Steps to replicate the issue (include links if applicable):

What happens?:

This code caused parsing error and multiple gadgets were broken:

$G.saveState = function(state)
{
	console.log('[replylinks]', 'saveState', state);
	localStorage.setItem($G._stateKey, JSON.stringify(state));
}$G.readState = function()
{
	var rawState = localStorage.getItem($G._stateKey);
	var state = JSON.parse(rawState);
	console.log('[replylinks]', 'readState', state);
	return state;
}

Adding semicolons fixed this:
https://pl.wikipedia.org/w/index.php?title=MediaWiki:Gadget-replylinks.js&diff=prev&oldid=70981634

What should have happened instead?:

Minification/obfuscation must produce equivalent code.

Software version (skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Firefox.
Chrome.
Also in VSC.

obraz.png (768×1 px, 113 KB)

Event Timeline

Krinkle triaged this task as Medium priority.
Krinkle moved this task from Inbox to Confirmed Problem on the MediaWiki-ResourceLoader board.
Krinkle moved this task from Inbox, needs triage to Current Sprint on the MediaWiki-Platform-Team board.

@Hokwelum I've copied the revision from before the linked edit at https://pl.wikipedia.org/w/index.php?title=MediaWiki:Gadget-replylinks.js&diff=prev&oldid=70981634, and started a bit on reducing it down. You can use the following to reproduce the problem locally:

var oRepLinks = {};

(function($G){

$G.prepareConfig = async function (userConfig) {
	await userConfig.register();

	const userOptions = [
		'boolAddSignature',
	];
	return userOptions;
},

$G.getNamespaceNames = function(namespaceNumber)
{
	return namespaceNumber;
};

$G.saveState = function(state)
{
	console.log('hello', state);
}
$G.readState = function()
{
	return 42;
}

})(oRepLinks);

oRepLinks.saveState('world');

This code works fine when you run it direclty in the browser console. However, after minifying it with bin/minify js, it becomes broken with a syntax error at }$G.readState = f, which is the bug this task aims to solve.

Change 948986 had a related patch set uploaded (by Hokwelum; author: Hokwelum):

[mediawiki/libs/Minify@master] After minifying some JS code, it returns a syntax error

https://gerrit.wikimedia.org/r/948986

Change 949974 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/libs/Minify@master] [DNM] debug T343499 example.js

https://gerrit.wikimedia.org/r/949974

Change 949974 abandoned by Krinkle:

[mediawiki/libs/Minify@master] [DNM] debug T343499 example.js

Reason:

The main bit of this is now up for review as Ibba284ea1f77201378f265d568c7a53c86215be4

https://gerrit.wikimedia.org/r/949974

Krinkle renamed this task from Invalid minification for some gadgets with requiresES6 to Add minification support for async-await (ES2017).Oct 25 2023, 4:10 PM

Change 948986 merged by jenkins-bot:

[mediawiki/libs/Minify@master] JavaScriptMinifier: Add basic ES2017 async-await syntax support

https://gerrit.wikimedia.org/r/948986