Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

visitor-as

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

visitor-as

A generic visitor framework for AssemblyScript

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
464
decreased by-60.91%
Maintainers
1
Weekly downloads
 
Created
Source

Visitor utilities for AssemblyScript Compiler transformers

Example

List Fields

The transformer:

import {
  ClassDeclaration,
  FieldDeclaration,
  MethodDeclaration,
} from "../../as";
import { ClassDecorator, registerDecorator } from "../decorator";
import { toString } from "../utils";

class ListMembers extends ClassDecorator {
  visitFieldDeclaration(node: FieldDeclaration): void {
    if (!node.name) console.log(toString(node) + "\n");
    const name = toString(node.name);
    const _type = toString(node.type!);
    this.stdout.write(name + ": " + _type + "\n");
  }

  visitMethodDeclaration(node: MethodDeclaration): void {
    const name = toString(node.name);
    if (name == "constructor") {
      return;
    }
    const sig = toString(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:

@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

FAQs

Package last updated on 08 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc