Workbench User Guide : Managing and Deploying Applications : How You Can Compile Applications and Components : How You Can Transpile JavaScript Modules from Your 4GL Components and Applications
 
Share this page          
How You Can Transpile JavaScript Modules from Your 4GL Components and Applications
The -js flag (see Parameters for the CompileApp Utility) converts 4GL modules (applications consisting of userclasses and procedures) into JavaScript modules. When followed by a valid file pathname, the flag instructs the CompileApp utility to create the JavaScript modules at the specified pathname.
Install OpenROAD ECMA Script Runtime
The generated ECMAScript has a runtime dependency on the OpenROAD ECMAScript runtime, this is available separately from https://esd.actian.com/product/OpenROAD/6.2/Source_Code.
Download the source code, unzip, and consult the installation instructions in README.md.
What CompileApp -js Transpiles
The JavaScript module created will contain the JavaScript equivalent of the original OpenROAD 4GL. The JavaScript will contain JavaScript code blocks for each module that is compiled by the 4GL compiler. If CompileApp with the -js option is used without the -c (component) option, all modules within the application will be transpiled (compiled and translated) into JavaScript. The ‑js flag implicitly forces 4GL modules to be recompiled, thus you need not specify -f (forcecompile). If the 4GL code cannot be successfully compiled for a component, no JavaScript will be generated for it.
Viewing Transpilation Errors
You can view any 4GL compiler errors and warnings by specifying the -e (errors) and -w (treat warnings as errors) flags. If transpiling a module generates transpilation errors, those errors will also be viewable using the -e (errors) flag. Any errors and the 4GL source code that generated them will be written to the Trace log file.
Transpiling Entire Applications
When transpiling 4GL modules for an entire application, JavaScript statements that include modules from OpenROAD included applications will also be generated (in addition to the implicit core.plb equivalent, core.js). If the transpiled application contains a starting component, a call to that component will be added to the JavaScript module at the end. The generated JavaScript will also contain the definitions needed to export procedures and methods so that they may be used in other modules, for example a web page.
JavaScript Transpiling Restrictions
Currently, some restrictions apply to what 4GL statements can be transpiled into JavaScript.
Valid 4GL Statements That Can Be Transpiled
Method invocations
4GL procedure calls
Assignment statements
OpenROAD numeric types below are mapped to ECMAScript Number type, which means math and string conversions follow ECMAScript rules.
float4, float8, integer1, integer2, integer4, integer8*, tinyint, smallint, integer, bigint*
Note:  *JavaScript can safely represent integers in the range −9,007,199,254,740,992 < i < 9,007,199,254,740,992. Beyond this range, there is no guarantee that a value is correctly represented.
Variable declarations for scalar and userclass types, except for:
DECIMAL (and aliases such as DEC and NUMERIC), DATE, INGRESDATE, and MONEY data types are currently unsupported
OpenROAD system classes are unsupported
If, for, and while statements
Accessing attributes within OpenROAD arrays of user classes
Inserting, modifying, and deleting array objects.
Return statements
Arithmetic operations (+, -, /, and *)
String operations (+ for concatenation)
IS NULL predicate
Arithmetic and string expressions
UserClass methods and attributes (setting and getting values)
Some OpenROAD system constants:
hc_doublequote, hc_quote, hc_space, hc_formfeed, hc_newline, and hc_tab
er_ok, er_fail, er_outofrange, er_rownotfound, er_keynotfound, and er_nameexists
4GL That the JavaScript Transpiler Does Not Support
OpenROAD system classes (for example, EntryField, StringObject, IntegerObject)
Variable data types DATE, DEC, DECIMAL, INGRESDATE, NUMERIC, and MONEY
OpenROAD system variables (for example, CurEventScope, CurFrame, CurSession, IIDBMSError)
Exception: All CurFrame, CurProcedure, and CurMethod 4GL ProcExec references are converted to CurExec. CurExec has one JavaScript method Trace(), which has a single parameter named 'text'.
UserEvents
UserClassObject Initialize() sections
ENDLOOP and CONTINUE labels
3GL procedure calls
SQL statements (DDL and DML)
Database procedure calls
NOT NULL datatype declarations (all JavaScript variables are nullable)
User interface (UI) activations (for example, ON CLICK)
EXEC 4GL statements
Call System statement
CallFrame, OpenFrame, and GotoFrame statements
CASE statement
MESSAGE, SLEEP, RESUME, and PROMPT statements
OpenROAD system constants related to user interface (UI) and database (for example, CC_SYS_BTNFACE and DS_CONNECTED)
Dynamic expressions
Using variables for procedure and method names (for example, a = objectref.:varmeth())
Using BYREF() on callproc statement for local variables
LIKE, BETWEEN, ANY, ALL, and EXISTS SQL predicates
External class library
Global constants
Global variables