Skip to content

bug: Parse error when using typed template function #329

Open
@SimonSimCity

Description

@SimonSimCity

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-typescript

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

I see a parsing error in my editor (zed), but can't say much more than that. It seems that the problem is a result of the typed template function, but any line I change or remove seems to have an influence on the outcome.

Steps To Reproduce/Bad Parse Tree

export class TRPCError extends Error {
  constructor(opts: { message?: string; code: string }) {
    super(opts.code);
  }
}
let sql: <T = unknown>(
  sqlFragments: TemplateStringsArray,
  ...parameters: unknown[]
) => T[];
const fn = (...args: unknown[]) => args;

export default {
  abc: () => {
    fn(() => [fn(sql<never[]>`'[]'`)]);
  },
  cde: fn(async ({ ctx, input }) => {
    new TRPCError({
      code: "NOT_FOUND",
      message: `The company was not found.`,
    });

    await Promise.resolve(fn([fn([{}]), fn((oc: unknown) => oc)]));
  }),
};

export const foo = `No id found.`;

Try to parse this code. Remove the line message: ``The company was not found.``, and try again. The result, I guess, should be almost the same as when having the line in place 😊

Expected Behavior/Parse Tree

Should return the same as with the deleted line, I guess.

Repro

export class TRPCError extends Error {
  constructor(opts: { message?: string; code: string }) {
    super(opts.code);
  }
}
let sql: <T = unknown>(
  sqlFragments: TemplateStringsArray,
  ...parameters: unknown[]
) => T[];
const fn = (...args: unknown[]) => args;

export default {
  abc: () => {
    fn(() => [fn(sql<never[]>`'[]'`)]);
  },
  cde: fn(async ({ ctx, input }) => {
    new TRPCError({
      code: "NOT_FOUND",
    });

    await Promise.resolve(fn([fn([{}]), fn((oc: unknown) => oc)]));
  }),
};

export const foo = `No id found.`;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions