Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Unhandled SyntaxKind: Unknown (regression?) #54

Closed
vfsfitvnm opened this issue Apr 10, 2023 · 1 comment
Closed

[BUG] Unhandled SyntaxKind: Unknown (regression?) #54

vfsfitvnm opened this issue Apr 10, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@vfsfitvnm
Copy link

Hi again.

Describe the bug
When using version 2.2.1 (with either ts-patch@3.0.0-beta2 or ttsc@0.3.1), I get that cryptic error when I use a certain macro ($$readFile for instance) in certain scenarios.

Code to reproduce
Apparently, we cannot use $$readFile in a namespace...

// ❌ error.ts
import { $$readFile } from "ts-macros";

namespace Foo {
  $$readFile!("src/index.ts");
}

or in a object literal AND in a class...

// ❌ error.ts
import { $$readFile } from "ts-macros";

const Foo = {
  a: $$readFile!("src/index.ts"),
};

class Bar {
  foo() {
    $$readFile!("src/index.ts");
  }
}

but we can use $$ts inside a namespace...

// ✅ fine.ts
import { $$ts } from "ts-macros";

namespace Foo {
  $$ts!(";");
}

or $$readFile in a object literal...

// ✅ fine.ts
import { $$readFile } from "ts-macros";

const Foo = {
  a: $$readFile!("src/index.ts"),
};

or $$readFile in a class...

// ✅ fine.ts
import { $$readFile } from "ts-macros";

class Bar {
  foo() {
    $$readFile!("src/index.ts");
  }
}

Expected behavior

Additional context
Doesn't occur in 2.1.0. Not sure if this is related to ts-patch or typescript=^5.

@GoogleFeud
Copy link
Owner

Thanks for the bug report! There's indeed a bug regarding namespace members (your first example), and also a $$readFile bug that returns a raw string instead of a string literal if the file is being read more than once (second example).

Will be fixed in the next patch!

@GoogleFeud GoogleFeud added the bug Something isn't working label Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants