assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

Add AST post-processing (desugaring) stage

Open MaxGraey opened this issue 2 years ago • 2 comments

This extra stage run immediately after AST creation and process following tasks:

  • ~~Desugaring for top-level non-exported to host, non-mutable (const) FunctionExpression to FunctionDeclaration with preserving order.~~
  • Destructive assignment desugaring
  • Spread syntax desugaring
  • Variadic function desugaring
  • String enum desugaring (?)
  • Processing for custom (user-space) decorators

MaxGraey avatar Nov 13 '21 10:11 MaxGraey

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[] = [];

MaxGraey avatar Nov 28 '21 21:11 MaxGraey

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

MaxGraey avatar Nov 29 '21 17:11 MaxGraey