groovy-to-js
Groovy to JS simply tries to convert a Groovy code to JavaScript code.
Features
- Check types to call methods (subtract, add, multiply, etc.) on arrays
- Supports [number].times { ... }
- Supports simple closures
- Supports ranges ([number]..[number], [identifier]..[number], etc.)
- Supports triple quotes (simple & double) strings
Roadmap
- Test on advanced code
- Provide more functions to dictionnary
Not supported
- Class definitions
- array[index < 0]
Using Groovy-To-JS
;;
Using the converter
// Import lib; ; ;console.logjs;// Gives: /* var arr = [1, 2, 3]; arr = subtract(arr, 1); var map = { a: 0, b: [1, 2, 3] }; map.a = map.b.length */
Giving a scope to check types
Converting a groovy script would require to know the base scope.
Given this scope:
;
And this groovy script
;
Would return:
`return myObject.member - 1;`;
The problem is, member
is an array, so the output should be:
`return subtract(myObject.member, 1);
To prevent this, just build a base scope, that's all!
Example:
// Import scope; ; ; ;console.logjs;// Gives: /* return subtract(myObject.member, 1); */
Requiring groovy functions
These are called augmentations that you can import like:
; ;;; console.logaugmentations.subtracta, b; // [1, 3]console.logaugmentations.subtracta, c; // [1, 3] console.logaugmentations.adda, b; // [1, 2, 3, 2];console.logaugmentations.adda, c; // [1, 2, 3, 2]; console.logaugmentations.multiplya, b; // [1, 2, 3, 1, 2, 3];console.logaugmentations.multiplya, c; // [1, 2, 3, 1, 2, 3]; console.logaugmentations.range2, 5; // [2, 3, 4, 5] augmentations.times3,; // 3 -> 3 -> 3