Visitor plugin not called for decorator node · Issue #1626 · TypeScriptToLua/TypeScriptToLua · GitHub
Skip to content

Visitor plugin not called for decorator node #1626

Open

Description

@takegine
// plugin.ts
import * as ts from "typescript";
import * as tstl from "typescript-to-lua";

console.log("Plugin is being loaded!");
const plugin: tstl.Plugin = {
    visitors: {
        [ts.SyntaxKind.Decorator]: (node, context) : tstl.Node[] => {
            console.log("Found decorator:", node.getText()); // Didn't see it in the console
            return context.superTransformNode(node);
        }
    },
};

export default plugin;
//tsconfig.json

    "tstl":{
        "luaTarget": "JIT",
        "sourceMapTraceback":true,
        
        "luaPlugins": [
            { "name": "./plugin.ts" }
        ]
    },
    "compilerOptions": {
        
        "experimentalDecorators": true,
    }
const declareModifier = (
    type: LuaModifierType | LuaModifierMotionType,
    name?: string,
) => (modifier: new () => Partial<CDOTA_Modifier_Lua>) => {};


@declareModifier(LuaModifierType.LUA_MODIFIER_MOTION_NONE)
class modifier_npc_recycle implements Partial<CDOTA_Modifier_Lua> {

    static OnCreated(params: object): void {
        print(111)
    }
    static CheckState(): Partial<Record<modifierstate, boolean>> {
        return {
            // [modifierstate.MODIFIER_STATE_INVISIBLE]: true,
            // [modifierstate.MODIFIER_STATE_NO_HEALTH_BAR]: true,
            // [modifierstate.MODIFIER_STATE_NO_UNIT_COLLISION]: true,
            // [modifierstate.MODIFIER_STATE_INVULNERABLE]: true,
        };
    }
}

Image

Activity

  1. changed the title [-]plugin error with[/-] [+]Visitor plugin not called for decorator node[/+] on Mar 26, 2025
  2. Perryvw commented on Mar 26, 2025

    @Perryvw
    Member

    Current tstl implementation does not directly visit decorators, instead, decorators are handled as part of the class visitor. I will have a think about if we want to make some kind of change here, but for now you can get the decorators like this:

    const plugin: tstl.Plugin = {
      visitors: {
        [ts.SyntaxKind.ClassDeclaration]: (node, context) => {
          if (ts.canHaveDecorators(node)) {
            const decorators = ts.getDecorators(node) ?? [];
              for (const decorator of decorators) {
                console.log("Found decorator:", decorator.getText());
              }
          }
          return context.superTransformStatements(node);
        }
      },
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions