You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: parse and preserve parameter decorators in AST
Adds support for decorator syntax on function parameters (e.g.
`@decorator value: i32`). Decorators are parsed and stored in
`ParameterNode.decorators` and `FunctionTypeNode.explicitThisDecorators`,
making them available to transformer plugins without affecting compilation.
- Parser: parses leading parameter decorators into AST; emits TS1206
only for misplaced decorators (e.g. `value @Deco: i32`)
- AST: new `decorators` field on ParameterNode, `explicitThisDecorators`
on FunctionTypeNode, `decoratedFunctionTypes` index on Source
- Serialization: inline parameter decorator serialization in extra/ast.ts
- Transform API: new `beforeCompile(program)` hook in cli/index.d.ts for
transformer-owned validation after program init, before WASM compilation
- Tests: parser round-trip, compiler clean-compile, parser error cases,
and transform example that reads parameter decorators via afterInitialize
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Working document of notes/tasks for trying to figure out how to correctly add decorators to AssemblyScript. Will be delete once the PR is complete.
2
+
3
+
NOTES:
4
+
- AST can be extended without breaking changes, this is perfectly fine and anything that is added will just be ignored by the compiler but at least transformer plugins can then make use of it. No need to validate and throw errors unless it is an AST parse error.
5
+
- Need to add a transformer hook so transformers can add their own validation. This way AssemblyScript can delegate validation to transformers instead of having to handle it internally, which doesn't make sense because AS shouldn't be in charge of worring about that in the first place.
6
+
7
+
- "Transformer" refers the to transformers in /tests/transform
8
+
9
+
- Rather than have a method validate the decorators, they should just be part of the AST. Once the AST can directly handle the decorators then validating decorators syntax will happen automatically. This also means we need actual AST nodes in ast.ts for the different parts of decorators rather than just inlining the decorators.
10
+
- Correction to the above. The method validation was only 1 part of the problem, the compiler of assemblyscript is for outputting WASM binaries not validating valid AST syntax. The compiler.ts will not need to be touched AT ALL for this PR.
11
+
12
+
TODO:
13
+
<!--
14
+
- [ ] Ask claude to explain how the AssemblyScript parser works and try to add a garbage throwaway feature myself manually for learning purposes (eg. `mut` keyword for syntax like `mut myVariable = 10`).
15
+
16
+
- [ ] After implementing re-read all the stuff dcode and Max have been explaining and try to better understand it -->
17
+
18
+
-[ ] Need to add a transform hook for valdiating after parse but before compiliation.
19
+
20
+
-[ ] Need to add a test case for having a transform validate decorators.
0 commit comments