AssemblyScript/assemblyscript

Add AST post-processing (desugaring) stage

MaxGraey opened this issue · 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

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