ScriptUtils
ceramic.ScriptUtils (Class)
Utilities for converting JavaScript/TypeScript syntax to HScript.
Provides transpilation of common JS/TS idioms to make scripts more familiar to web developers while maintaining HScript compatibility.
Supported conversions:
- Arrow functions:
() => expr
→function() expr
- Arrow functions:
=>
→->
- For-of loops:
for (x of array)
→for (x in array)
- Const declarations:
const
→var
- Template literals:
`text`
→"text"
- Infinite loop protection in while loops
Static Members
Converts JavaScript/TypeScript-like code to HScript.
Performs multiple transformation passes:
- Clean code (arrow functions, comments, template literals)
- Convert for-of loops to for-in
- Replace const with var
- Add infinite loop protection to while loops
Name | Type | Description |
---|---|---|
code |
String | Source code with JS/TS syntax |
Returns | Description |
---|---|
String | Equivalent HScript code |
Private Members
Matches word characters at start of string
Matches word after non-word character
Matches string literals (single, double, or template)
Matches for-of/for-in loop declarations
Matches while loop start
Matches no-argument arrow function
First pass: Cleans and converts basic JS/TS syntax.
Handles:
- Arrow function conversion
- Comment preservation
- Template literal conversion
- Regex literal handling
Name | Type | Description |
---|---|---|
code |
String | Raw JS/TS code |
Returns | Description |
---|---|
String | Cleaned code with basic conversions |
Throws a parsing error.
Name | Type | Description |
---|---|---|
error |
Dynamic | Error message |
i |
Int | Character position where error occurred |
code |
String | Full source code |