Wikimedia Developer Support

Problem to use classes in JavaScript

Hi!

I have problem to use classes in a gadget. This message show to me in the console::

JavaScript parse error: Parse error: Missing ; before statement in file 'MediaWiki:Gadget-fastbuttons.js/core.js' on line 25

The script can be acessed here.

My question is: we cannot use class in gadgets? That’s weird, because the editor doesn’t show any error before save, but the parser do…

JavaScript is executed by your browser. What browser are you using, including the version?

My browser is Firefox 77.0. But the proble isn’t the browser, because the script runs normaly through console. The problem is when it is executed by the ResourceLoader (as a gadget).

ResourceLoader validates code against the EMCAScript 5 standard to prevent users from receiving broken JavaScript. Classes were introduced in ES6, which is not yet supported (https://phabricator.wikimedia.org/T75714). This fact doesn’t seem to be well documented, so I filed https://phabricator.wikimedia.org/T255075 so that someone with more knowledge on the topic can improve the documentation.

1 Like

Yep, there is no documentation about the support. The solution there i figure out (in T75714) was write the code with ES6 and use babel to transpile to a ES5 version.

Thnks for you help!