Page MenuHomePhabricator

Add support for regexp u flag for user-space javaScript
Closed, DuplicatePublic

Description

when I try to ad a Regexp like

/๐Ÿ˜Š/u,

it results with this Error in Chrome 51:
JavaScript parse error: Parse error: Unexpected token; token } expected in file 'User:Boshomi/global.js' on line 56

(firefox 47 also fails, with same error)

The sticky flag (y) also fails

Event Timeline

I can not see a chrome bug. Chrome 51 and Firefox 47 works in the same way, there is no difference between.

when I write this into the console:
var t="bla ๐Ÿ˜Š๐Ÿ˜Š foo"; var find=/๐Ÿ˜Š{2}/u; var mend=" โ˜ป"; t=t.replace( find, mend ); t

it results in "bla โ˜ป foo" โœ“

var t="bla ๐Ÿ˜Š๐Ÿ˜Š foo"; var find=/๐Ÿ˜Š{2}/g; var mend=" โ˜ป"; t=t.replace( find, mend ); t

it results in "bla ๐Ÿ˜Š๐Ÿ˜Š foo" โœ“

so the Browser console works as expected. (Chrome and Firefox)

Here my userscript enviroment:
'User:Boshomi/global.js' is executed by
https://de.wikipedia.org/w/index.php?title=Benutzer:Boshomi/ARreplace.js&action=edit <line 163: t=t.replace( to.find, to.mend ); >
(hint ARreplace.js dependences on TMg/Autoformatter.js here activated with Fliegelflagel.js)

when I uncomment the object marked with Phabricator Task, ARreplace.js

  • code-editor show a warning "Expected '}' to match '{' from line 56 and instead saw 'u' " and
  • ARreplace crashes (does not show the Button)

when I change the flag form u to g ARreplace.js works, but no unicode-Replacement (as expected).

It is possible that the mediawiki codeeditor causes the issue.

A link to the specific revision that contained the error would have been nice. I assume we are talking about https://meta.wikimedia.org/w/index.php?title=User:Boshomi/global.js&diff=prev&oldid=15730253 and the following edits.

There is no /u flag in the current ES5 specification, but in ES6, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Browser_compatibility and the links provided there. So I assume this ticket is about ES6 support in the MediaWiki source code editor you can use when editing titles that end with .css or .js.

@Boshomi, can you please clarify where this error message appears? Only in the source code editor while editing this .js page, or is this an actual runtime error when you try to use your script? The later would indeed mean this is a MediaWiki-ResourceLoader issue.

  • Test with Autoformatter.js

Add
<code>
var autoFormatReplacements = [

[/๐Ÿ˜Š{2}/u, " โ˜ป"] // test u flag

];
</code>
in line 49 in Benutzer:Boshomi/common.js
Waring in codeEditor:
<code>

Expected ']' to match '[' from line 51 and instead saw 'u' missing semicolon{F4235786}

<code>
The warning appears after changing flag form g to u
Syntax highlighter show differnt colors (look at the picture)

Screenshot_20160704_183147.png (112ร—683 px, 16 KB)

The error is also present in the console (picture )

In contrast to ARreplace.js Autoformatter.js show the Button (swipe), and and other functions also works, but not the user Replacement.

Screenshot_20160704_185528.png (843ร—1 px, 187 KB)

Screenshot error message in global.ja for ARreplace.js-Replacemante variable:

Screenshot_20160704_190051.png (315ร—926 px, 46 KB)

Error with change in global.js:

Screenshot_20160704_190858.png (397ร—1 px, 88 KB)

Description: not any user-script is loaded. (no extra buttons, no extra links in left panel, ...). And a new error with global.js is present. So there is an difference if the Replacement is defined in an array or in an array of objects.

hth