Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/as-pect/visitor-as
Visitor utilities for AssemblyScript compiler transforms
https://github.com/as-pect/visitor-as
Last synced: about 1 month ago
JSON representation
Visitor utilities for AssemblyScript compiler transforms
- Host: GitHub
- URL: https://github.com/as-pect/visitor-as
- Owner: as-pect
- License: apache-2.0
- Created: 2020-03-17T01:55:15.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-22T17:53:54.000Z (10 months ago)
- Last Synced: 2024-11-16T09:31:16.795Z (about 1 month ago)
- Language: TypeScript
- Size: 2.01 MB
- Stars: 37
- Watchers: 2
- Forks: 11
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-assemblyscript - as-pect/visitor-as - Tools to build transforms (Packages)
README
# Visitor utilities for AssemblyScript Compiler transformers
## Example
### List Fields
The transformer:
```ts
import {
ClassDeclaration,
FieldDeclaration,
MethodDeclaration,
} from "../../as";
import { ClassDecorator, registerDecorator } from "../decorator";
import { getName } from "../utils";class ListMembers extends ClassDecorator {
visitFieldDeclaration(node: FieldDeclaration): void {
if (!node.name) console.log(getName(node) + "\n");
const name = getName(node);
const _type = getName(node.type!);
this.stdout.write(name + ": " + _type + "\n");
}visitMethodDeclaration(node: MethodDeclaration): void {
const name = getName(node);
if (name == "constructor") {
return;
}
const sig = getName(node.signature);
this.stdout.write(name + ": " + sig + "\n");
}visitClassDeclaration(node: ClassDeclaration): void {
this.visit(node.members);
}get name(): string {
return "list";
}
}export = registerDecorator(new ListMembers());
```assembly/foo.ts:
```ts
@list
class Foo {
a: u8;
b: bool;
i: i32;
}
```And then compile with `--transform` flag:
```
asc assembly/foo.ts --transform ./dist/examples/list --noEmit
```Which prints the following to the console:
```
a: u8
b: bool
i: i32
```