Menu

#1990 [js-core] Support of ECMA6 Javascript modules

2.30
open
RBRi
js-core (1)
1
2020-05-17
2018-09-14
Hadrien Sz
No

copy of stackoverflow question:

https://stackoverflow.com/questions/52240645/htmlunit-cannot-process-javascript-module?noredirect=1#comment91433014_52240645

When parsing a complex web page with HTMLUnit, with javascript enabled, it refuses to process type="module" scripts.
Looking at the source code of HtmlScript it looks like scripts of any type other than "text/javascript" || « text/ecmascript » or « application/javascript" || « application/ecmascript" || "application/x-javascript" are rejected
Error is: com.gargoylesoftware.htmlunit.html.HtmlScript isExecutionNeeded WARNING: Script is not JavaScript (type: module, language: ). Skipping execution.
Is there a way to have module scripts also executed ?
Thanks

To this question RBRi suggested :

Please file a bug report for HtmlUnit or even better provide a patch (github.com/HtmlUnit/htmlunit)

Which I'm doing...

Justification (source : https://spring.io/understanding/javascript-modules, 2015)

In JavaScript, the word "modules" refers to small units of independent, reusable code. They are the foundation of many JavaScript design patterns and are critically necessary when building any non-trivial JavaScript-based application.
ECMAScript, the JavaScript standards body, expects to ratify a final specification for modules in ECMAScript version 6 by the end of 2014. ECMAScript 6 modules ("ES6 modules"), however, will likely not be feasible to use in production until 2016 due to the long upgrade cycles of some browsers and operating systems

Complete specification can be found here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

and is discussed here:
https://hacks.mozilla.org/2015/08/es6-in-depth-modules/
http://exploringjs.com/es6/ch_modules.html

additionnal considerations:

(1) it should be considered whether to support only ECMA6 or also previous common module technologies such as Asynchronous Module Definition (AMD), node.js / CommonJS Modules or Universal Module Definition (UMD). All of there could be considered as de facto module standards

(2) maybe this issue / feature should be moved to core-js github community. It looks like support for modules (only AMD probably) is already implemented there but not ported to HTMLUnit

(3) since ECMA6 appeared Oracle developed Nashhorn javascript engine. Is there a plan to support Nashhorn if it provides better ECMA6 support and more frequent updates than Rhino ?

Discussion


Log in to post a comment.