Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AST post-processing (desugaring) stage #2141

Open
MaxGraey opened this issue Nov 13, 2021 · 2 comments
Open

Add AST post-processing (desugaring) stage #2141

MaxGraey opened this issue Nov 13, 2021 · 2 comments

Comments

@MaxGraey
Copy link
Member

MaxGraey commented Nov 13, 2021

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 MaxGraey pinned this issue Nov 13, 2021
@MaxGraey
Copy link
Member Author

MaxGraey commented Nov 28, 2021

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
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant