Closed NatoBoram closed 3 weeks ago
This file is autogenerated by napi-rs. Would you like to submit a ticket there? Thanks
Also this can be fixed by https://github.com/microsoft/TypeScript/issues/52669
I tried to dig a bit more and simply adding --no-const-enum
seems to be enough. I tested the generated code in my node_modules
and it works. We can even do console.log(Lang)
to see the full object.
crates/napi/index.d.ts | 2 +-
crates/napi/package.json | 6 +++---
crates/napi/tsconfig.json | 1 +
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/crates/napi/index.d.ts b/crates/napi/index.d.ts
index 9749e14c..f1ffc4bb 100644
--- a/crates/napi/index.d.ts
+++ b/crates/napi/index.d.ts
@@ -39,7 +39,7 @@ export interface FindConfig {
*/
languageGlobs?: Array<string>
}
-export const enum Lang {
+export enum Lang {
Html = 'Html',
JavaScript = 'JavaScript',
Tsx = 'Tsx',
diff --git a/crates/napi/package.json b/crates/napi/package.json
index 976b0108..4ee2ae40 100644
--- a/crates/napi/package.json
+++ b/crates/napi/package.json
@@ -41,8 +41,8 @@
},
"scripts": {
"artifacts": "napi artifacts",
- "build": "napi build --platform --release",
- "build:debug": "napi build --platform",
+ "build": "napi build --no-const-enum --platform --release",
+ "build:debug": "napi build --no-const-enum --platform",
"prepublishOnly": "napi prepublish -t npm --skip-gh-release",
"test": "ava",
"version": "napi version"
@@ -67,4 +67,4 @@
"TS_NODE_PROJECT": "./tsconfig.json"
}
}
-}
\ No newline at end of file
+}
diff --git a/crates/napi/tsconfig.json b/crates/napi/tsconfig.json
index 969d7b3d..0bf07256 100644
--- a/crates/napi/tsconfig.json
+++ b/crates/napi/tsconfig.json
@@ -4,6 +4,7 @@
"strict": true,
"moduleResolution": "node",
"module": "CommonJS",
+ "verbatimModuleSyntax": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"esModuleInterop": true,
@NatoBoram This looks good! Would you like to submit a pull request?
I'd love to!
I have also updated the bug report pull request with a pnpm patch
to show that the pipeline passes with this change
Please read the FAQ for the bug you encountered.
β― Playground Link
https://github.com/NatoBoram/bug-report-ast-grep/pull/4/files
π» Code
π Actual behavior
π Expected behavior
Building should be successful
Additional information about the issue
It can be worked around by re-declaring a new language map and using this instead of the fake enum.
In the auto-generated code, this can be fixed by dropping the
const enum
and using atype
instead.https://github.com/ast-grep/ast-grep/blob/c28558a2605e131fc1226c70314a9fa8bded3081/crates/napi/index.d.ts#L42-L68
I'd want to make a PR, but the file is auto-generated and I don't know Rust.