dsherret / ts-morph

TypeScript Compiler API wrapper for static analysis and programmatic code changes.

Home Page:https://ts-morph.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to build version 22 due to Memoize errors

ajvincent opened this issue · comments

Describe the bug

Version: 22.0.0

I've been unable to build ts-morph in my fork of this repository, which is up to date. Memoize.ts is landing at throw new Error("Not implemented.").

To Reproduce

npm run setup

Expected behavior

ts-morph builds.

Additional details

After I encountered the throw statement, I modified Memoize locally as follows, trying to understand why it's failing:

/** Decorator for memoizing the result of a method. */
export function Memoize(target: (...args: any[]) => void) {
  /*
  if (target instanceof Function) {
    return getNewFunction(target);
  } else {
    throw new Error("Not implemented: type = " + typeof target);
  }
  */
  if (!(typeof target === "function"))
    console.log("memoize: ", arguments);
  return;
}

I was expecting, per the decorators proposal, two arguments: the value and a DecoratorContext. Instead, I got three:

memoize:  [Arguments] {
  "0": {},
  "1": "getTsSymbol",
  "2": {
    value: [Function: getTsSymbol],
    writable: true,
    enumerable: false,
    configurable: true
  }
}

That appears to be the old decorators implementation for a method on a class instance. I know what property descriptors look like, but I'm very surprised to see them in TypeScript 5.x decorators. TS5.0 should've gone to the new decorators pattern already. (That's why I started using decorators in my projects to begin with.)

I'm willing to help fix, and/or provide details of my runtime environment to assist. But I'd really like to understand why the stage 3 decorators proposal isn't in play here.

Node: 18.20
OS: Fedora Linux 39
shell: /bin/bash

I did not, and that indeed was the bustage. Apologies for the spam.