Add AST post-processing (desugaring) stage
MaxGraey opened this issue · 2 comments
MaxGraey commented
This extra stage run immediately after AST creation and process following tasks:
Desugaring for top-level non-exported to host, non-mutable (const)FunctionExpressiontoFunctionDeclarationwith preserving order.- Destructive assignment desugaring
- Spread syntax desugaring
- Variadic function desugaring
- String enum desugaring (?)
- Processing for custom (user-space) decorators
MaxGraey commented
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) == 0x65rewrite:
= new Array
= new Array(?<T>)();
= new Array(?<T>)(0);to
: T[] = [];
: T[] = [];
: T[] = [];MaxGraey commented
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