Page MenuHomePhabricator

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


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:

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.):

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.

@Hokwelum I've copied the revision from before the linked edit at, and started a bit on reducing it down. You can use the following to reproduce the problem locally:

var oRepLinks = {};


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

	const userOptions = [
	return userOptions;

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

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



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

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

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

Change 949974 abandoned by Krinkle:

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


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

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