Skip to content

Commit ca13f28

Browse files
Cleanup
1 parent 4deaa00 commit ca13f28

8 files changed

Lines changed: 20 additions & 57 deletions

File tree

TODO.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
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.
22

3-
4-
- [ ] 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`).
5-
6-
- [ ] After implementing re-read all the stuff dcode and Max have been explaining and try to better understand it
7-
8-
- [ ] Need to add a transform hook for valdiating after parse but before compiliation.
9-
10-
- [ ] Need to add a test case for having a transform validate decorators.
11-
123
NOTES:
134
- 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.
145
- 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.
156

167
- "Transformer" refers the to transformers in /tests/transform
178

189
- 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.
19-
- 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.
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.

cli/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ export abstract class Transform {
273273
/** Lists all files in a directory. */
274274
listFiles(dirname: string, baseDir: string): (string[] | null) | Promise<string[] | null>;
275275

276+
/** Called after program initialization, before WASM compilation. Transformers should use
277+
* this hook to perform custom validation of AST constructs such as parameter decorators
278+
* and emit their own diagnostics. Decorators remain in the AST unchanged. */
279+
beforeCompile?(program: Program): void | Promise<void>;
280+
276281
/** Called when parsing is complete, before a program is instantiated from the AST. */
277282
afterParse?(parser: Parser): void | Promise<void>;
278283

src/compiler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,8 @@ export class Compiler extends DiagnosticEmitter {
536536

537537
// initialize lookup maps, built-ins, imports, exports, etc.
538538
this.program.initialize();
539-
539+
540+
540541
// Binaryen treats all function references as being leaked to the outside world when
541542
// the module isn't marked as closed-world (see WebAssembly/binaryen#7135). Therefore,
542543
// we should mark the module as closed-world when we're definitely sure it is.

src/program.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,6 @@ export class Program extends DiagnosticEmitter {
462462
nextSignatureId: i32 = 0;
463463
/** An indicator if the program has been initialized. */
464464
initialized: bool = false;
465-
/** Indicates whether the one-shot post-transform parameter decorator validation has run. */
466-
parameterDecoratorsValidated: bool = false;
467465

468466
// Lookup maps
469467

tests/compiler/parameter-decorators.json

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/compiler/parameter-decorators.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/transform/cjs/remove-parameter-decorators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Example transform proving that preserved parameter decorators can be stripped
2-
// during afterInitialize before compilation rejects them.
2+
// during afterInitialize, since the compiler otherwise ignores them.
33
console.log("CommonJS parameter decorator removal transform loaded");
44

55
exports.afterInitialize = (program) => {

tests/transform/remove-parameter-decorators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Example transform proving that preserved parameter decorators can be stripped
2-
// during afterInitialize before compilation rejects them.
2+
// during afterInitialize, since the compiler otherwise ignores them.
33
console.log("Parameter decorator removal transform loaded");
44

55
import type { Program } from "assemblyscript";

0 commit comments

Comments
 (0)