There is 1 update, 2 comments.
 
 
XWiki Platform / cid:jira-generated-image-avatar-43fc7400-f571-45d1-bdfa-a78b4bb6234b XWIKI-23379 Open

Issues with Google Closure Compiler and modern JavaScript

 
View issue   ยท   Add comment
 

1 update

 
cid:jira-generated-image-avatar-31035f2e-de0e-4a0e-9bc1-42cc5c6bb0cf Changes by Ralf on 24/Jul/25 15:45
 
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, v16.10.8 and v15.10.16 - everywhere there's this issue.
 
 

2 comments

 
cid:jira-generated-image-avatar-31035f2e-de0e-4a0e-9bc1-42cc5c6bb0cf Ralf on 24/Jul/25 15:53
 

Hello Thomas Mortagne,

I've tested with XWiki v17.0.5, 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"):

class Demo {
  #greeting = 'Hello!';

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

new Demo().sayHello(); 

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]

 

 
cid:jira-generated-image-avatar-31035f2e-de0e-4a0e-9bc1-42cc5c6bb0cf Ralf on 24/Jul/25 15:54
 
Hello [~tmortagne],

I've tested with XWiki v17.0.5, 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]}}