assemblyscript
assemblyscript copied to clipboard
Add AST post-processing (desugaring) stage
This extra stage run immediately after AST creation and process following tasks:
- ~~Desugaring for top-level non-exported to host, non-mutable (const)
FunctionExpression
toFunctionDeclaration
with preserving order.~~ - Destructive assignment desugaring
- Spread syntax desugaring
- Variadic function desugaring
- String enum desugaring (?)
- Processing for custom (user-space) decorators
Another good candidate for simple rewriting is string operations:
const a = "a".charCodeAt(0);
to
const a = 0x61;
and
str.charAt(i) == 'e'
to
str.charCodeAt(i) == 0x65
rewrite:
= new Array
= new Array(?<T>)();
= new Array(?<T>)(0);
to
: T[] = [];
: T[] = [];
: T[] = [];
Interesting paper about AST rule rewriting with partial parsing: TWEAST: A Simple and Effective Technique to Implement Concrete-Syntax AST Rewriting Using Partial Parsing.pdf