Build crashes with "undefined is not an object (evaluating 'node.kind')" when using custom plugin · Issue #1619 · TypeScriptToLua/TypeScriptToLua · GitHub
Skip to content

Build crashes with "undefined is not an object (evaluating 'node.kind')" when using custom plugin #1619

Open

Description

@jamesWalker55

Apologies for opening an issue again, turns out it wasn't a user error.

Since 1.29.0, using a custom plugin will cause building to fail with this error:

429 |     expression.operand = operand;  
430 |     expression.operator = operator;
431 |     return expression;
432 | }
433 | function isBinaryExpression(node) {
434 |     return node.kind === SyntaxKind.BinaryExpression;
                 ^
TypeError: undefined is not an object (evaluating 'node.kind')
      at isBinaryExpression (D:\Programming\reaper-scripting-5\lib\reaper-api\node_modules\typescript-to-lua\dist\LuaAST.js:434:12)
      at needsParenthesis (D:\Programming\reaper-scripting-5\lib\reaper-api\node_modules\typescript-to-lua\dist\LuaPrinter.js:543:17)
      at printExpressionInParenthesesIfNeeded (D:\Programming\reaper-scripting-5\lib\reaper-api\node_modules\typescript-to-lua\dist\LuaPrinter.js:538:21) 
      at printTableIndexExpression (D:\Programming\reaper-scripting-5\lib\reaper-api\node_modules\typescript-to-lua\dist\LuaPrinter.js:578:26)
      at map (1:11)
      at printVariableDeclarationStatement (D:\Programming\reaper-scripting-5\lib\reaper-api\node_modules\typescript-to-lua\dist\LuaPrinter.js:286:68)    
      at printStatement (D:\Programming\reaper-scripting-5\lib\reaper-api\node_modules\typescript-to-lua\dist\LuaPrinter.js:213:31)
      at printStatementArray (D:\Programming\reaper-scripting-5\lib\reaper-api\node_modules\typescript-to-lua\dist\LuaPrinter.js:200:31)
      at printFile (D:\Programming\reaper-scripting-5\lib\reaper-api\node_modules\typescript-to-lua\dist\LuaPrinter.js:155:35)
      at printFile (D:\Programming\reaper-scripting-5\lib\reaper-api\dist\plugins\importFixPlugin.js:21:34)
      at print (D:\Programming\reaper-scripting-5\lib\reaper-api\node_modules\typescript-to-lua\dist\LuaPrinter.js:95:37)
      at processSourceFile (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript-to-lua\dist\transpilation\transpile.js:66:33)  
      at <anonymous> (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript-to-lua\dist\transpilation\transformers.js:13:9)      
      at transformSourceFileOrBundle (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:94907:49)
      at transformation (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:118154:14)
      at transformRoot (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:118177:71)
      at transformNodes (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:118162:56)
      at emitJsFileOrBundle (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:118707:24)
      at emitSourceFileOrBundle (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:118665:5)
      at forEachEmittedFile (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:118429:24)
      at emitFiles (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:118647:3)
      at <anonymous> (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:125759:13)
      at runWithCancellationToken (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:50507:16)
      at emitWorker (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:125757:37)
      at <anonymous> (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:125728:13)
      at runWithCancellationToken (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:125838:14)
      at emit (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript\lib\typescript.js:125727:20)
      at getProgramTranspileResult (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript-to-lua\dist\transpilation\transpile.js:100:37)
      at emit (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript-to-lua\dist\transpilation\transpiler.js:27:100)
      at performCompilation (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript-to-lua\dist\tstl.js:90:86)
      at executeCommandLine (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript-to-lua\dist\tstl.js:61:13)
      at <anonymous> (D:\Programming\reaper-scripting-5\fx-modulation-helper\node_modules\typescript-to-lua\dist\tstl.js:176:1

The following no-op plugin that does nothing will trigger the error:

import * as ts from "typescript";
import * as tstl from "typescript-to-lua";

class CustomPrinter extends tstl.LuaPrinter {}

/** @type {tstl.Plugin} */
const plugin = {
  /**
   * @param {ts.Program} program
   * @param {tstl.EmitHost} emitHost
   * @param {string} fileName
   * @param {tstl.File} file
   * @returns
   */
  printer: (program, emitHost, fileName, file) =>
    new CustomPrinter(emitHost, program, fileName).print(file),
};

export default plugin;

My tsconfig.json:

{
  "$schema": "https://raw.githubusercontent.com/TypeScriptToLua/TypeScriptToLua/master/tsconfig-schema.json",
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["ESNext"],
    "moduleResolution": "Node",
    "types": ["lua-types/5.4"],
    // output settings
    "declaration": true,
    "rootDir": "src",
    "outDir": "dist",
    "checkJs": true,
    // === google gts config ===
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "forceConsistentCasingInFileNames": true,
    "noEmitOnError": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "pretty": true,
    // === google gts config ===
    "strict": true
  },
  "tstl": {
    "luaPlugins": [{ "name": "./plugins/importFixPlugin.js" }],
    "luaTarget": "5.4",
    "luaLibImport": "require-minimal",
    "noImplicitGlobalVariables": true
  }
}

Activity

  1. Perryvw commented on Feb 16, 2025

    @Perryvw
    Member

    I cannot reproduce this with the plugin and config you gave. Do you have a minimal TS file that reproduces the error?

    Do you have any other plugins or transformers being executed on your code? The error looks familiar to me, but usually these always happen in combination with some transformer or plugins creating synthetic code.

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