There is 1 update, 1 comment.
 
 
XWiki Platform / cid:jira-generated-image-avatar-bc6551b6-3cc4-43f3-9d50-021f04ffa8a4 XWIKI-23379 Open

Issues with Google Closure Compiler and modern JavaScript

 
View issue   ยท   Add comment
 

1 update

 
cid:jira-generated-image-avatar-d89ab5d8-30d9-46c9-8007-687ceb0dda8e Changes by Ralf on 19/Jan/26 16:53
 
Description: It seems that XWiki uses the Google Closure Compiler to minify JavaScript.

Also, it seems that Google Closure Compiler does not support modern JavaScript syntax completely (please have a look on the "no"s at the bottom of this page: [Link|https://github.com/google/closure-compiler/wiki/Supported-features]). 

At least, if I use a JavaScript class with private member (=> "private" means, the name of the member starts with "#"), the Google Closure Compiler seems to have problems with that and logs error messages like the following (here the privat member was called #getLocale):
{code:java}
2025-07-14 05:39:44,591 [qtp107456312-42 - http://localhost:8080/xwiki/bin/jsx/xwiki-tools/WebHome?language=en&docVersion=59.4] ERROR c.x.x.w.s.JsExtension          - Error at line [50], column [11]: [Parse error. 'identifier' expected]
Jul 14, 2025 5:40:15 AM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: xwiki:xwiki-tools.WebHome:50:11: ERROR - [JSC_PARSE_ERROR] Parse error. 'identifier' expected
  50|       this.#getLocale = getLocale;
                 ^

Jul 14, 2025 5:40:15 AM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 1 error(s), 0 warning(s) {code}
If my interpretations are wrong, please let me know.
Otherwise, is there anything I can do against those errors (except for refraining from using modern JavaScript features)?

Maybe, a solution could be that XWiki will use some other tool to minify JavaScript (for example "terser" or whatever).

Thank you very much.

[Edit] Tested with XWiki v17.
0. 5 .0 , v16.10.8 and v15.10.16 - everywhere there's this issue.
 
 

1 comment

 
cid:jira-generated-image-avatar-d89ab5d8-30d9-46c9-8007-687ceb0dda8e Ralf on 19/Jan/26 16:53
 
Hello [~tmortagne],

I've tested with XWiki v17.
0. 5 .0 , v16.10.8 and v15.10.16 - everywhere I got these Goolge Closure Compiler issues.

To reproduce:

Open a XWiki page of your choice and add the following JavaScript snippet as JavaScriptExtension (Configuration"Use this extension" => "On this page or on demand", "Caching policy" => "Long"):
{code:java}
class Demo {
  #greeting = 'Hello!';

  sayHello() {
    alert(this.#greeting);
  }
}

new Demo().sayHello(); {code}
Now "Save & View" the page.
In the logs you'll find error messages like the following:

{{-------------}}
{{XWiki v17.5.0}}
{{-------------}}

{{SEVERE: xwiki:Main.WebHome:2:2: ERROR - [JSC_PARSE_ERROR] Parse error. '}' expected}}
{{  2|   #greeting = 'Hello!';}}
{{       ^}}

{{Jul 24, 2025 3:42:14 PM com.google.javascript.jscomp.LoggerErrorManager printSummary}}
{{WARNING: 1 error(s), 0 warning(s)}}
{{2025-07-24 15:42:14,934 [qtp107456312-38 - http://localhost:8080/xwiki/bin/jsx/Main/WebHome?language=en&docVersion=5.1] ERROR c.x.x.w.s.JsExtension          - Error at line [2], column [2]: [Parse error. '}' expected]}}

{{--------------}}
{{XWiki v16.10.8}}
{{--------------}}

{{Jul 24, 2025 3:35:29 PM com.google.javascript.jscomp.LoggerErrorManager println}}
{{SEVERE: xwiki:Main.WebHome:2:2: ERROR - [JSC_PARSE_ERROR] Parse error. '}' expected}}
{{  2|   #greeting = 'Hello!';}}
{{       ^}}

{{Jul 24, 2025 3:35:29 PM com.google.javascript.jscomp.LoggerErrorManager printSummary}}
{{WARNING: 1 error(s), 0 warning(s)}}
{{2025-07-24 15:35:29,983 [qtp1627428162-161 - http://localhost:8080/xwiki/bin/jsx/Main/WebHome?language=de&docVersion=6.1] ERROR c.x.x.w.s.JsExtension          - Error at line [2], column [2]: [Parse error. '}' expected]}}


{{---------------}}
{{XWiki v15.10.16}}
{{---------------}}

{{SEVERE: xwiki:Main.WebHome:2:2: ERROR - [JSC_PARSE_ERROR] Parse error. '}' expected}}
{{  2|   #greeting = 'Hello!';}}
{{       ^}}

{{Jul 24, 2025 3:39:34 PM com.google.javascript.jscomp.LoggerErrorManager printSummary}}
{{WARNING: 1 error(s), 0 warning(s)}}
{{2025-07-24 15:39:34,232 [qtp1682463303-150 - http://localhost:8080/xwiki/bin/jsx/Main/WebHome?language=en&docVersion=75.1] ERROR c.x.x.w.s.JsExtension          - Error at line [2], column [2]: [Parse error. '}' expected]}}