From b53e0e1e957d569053037b17d150e3c296013118 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 6 Jan 2022 22:33:34 +0800 Subject: [PATCH] fix(napi-derive): BigInt in TypeScript should be bigint --- crates/backend/src/typegen.rs | 16 ++++++++-------- .../__test__/get-napi-version.spec.ts | 2 +- examples/napi/__test__/typegen.spec.ts.md | 16 ++++++++-------- examples/napi/__test__/typegen.spec.ts.snap | Bin 2284 -> 2283 bytes examples/napi/index.d.ts | 16 ++++++++-------- tsconfig.json | 2 +- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/crates/backend/src/typegen.rs b/crates/backend/src/typegen.rs index b17907a6..123f6dc9 100644 --- a/crates/backend/src/typegen.rs +++ b/crates/backend/src/typegen.rs @@ -115,14 +115,14 @@ static KNOWN_TYPES: Lazy> = Lazy::new(|| { ("u8", "number"), ("u16", "number"), ("u32", "number"), - ("u64", "BigInt"), - ("i64n", "BigInt"), - ("u128", "BigInt"), - ("i128", "BigInt"), - ("usize", "BigInt"), - ("isize", "BigInt"), - ("JsBigInt", "BigInt"), - ("BigInt", "BigInt"), + ("u64", "bigint"), + ("i64n", "bigint"), + ("u128", "bigint"), + ("i128", "bigint"), + ("usize", "bigint"), + ("isize", "bigint"), + ("JsBigInt", "bigint"), + ("BigInt", "bigint"), ("JsBoolean", "boolean"), ("bool", "boolean"), ("JsString", "string"), diff --git a/examples/napi-compat-mode/__test__/get-napi-version.spec.ts b/examples/napi-compat-mode/__test__/get-napi-version.spec.ts index 62fa68b8..c623c437 100644 --- a/examples/napi-compat-mode/__test__/get-napi-version.spec.ts +++ b/examples/napi-compat-mode/__test__/get-napi-version.spec.ts @@ -5,5 +5,5 @@ const bindings = require('../index.node') test('should get napi version', (t) => { const napiVersion = bindings.getNapiVersion() t.true(typeof napiVersion === 'number') - t.is(`${napiVersion}`, process.versions.napi) + t.is(`${napiVersion}`, process.versions.napi!) }) diff --git a/examples/napi/__test__/typegen.spec.ts.md b/examples/napi/__test__/typegen.spec.ts.md index 25d3615b..ec3e0649 100644 --- a/examples/napi/__test__/typegen.spec.ts.md +++ b/examples/napi/__test__/typegen.spec.ts.md @@ -27,9 +27,9 @@ Generated by [AVA](https://avajs.dev). export function sumNums(nums: Array): number␊ export function readFileAsync(path: string): Promise␊ export function asyncMultiTwo(arg: number): Promise␊ - export function bigintAdd(a: BigInt, b: BigInt): BigInt␊ - export function createBigInt(): BigInt␊ - export function createBigIntI64(): BigInt␊ + export function bigintAdd(a: bigint, b: bigint): bigint␊ + export function createBigInt(): bigint␊ + export function createBigIntI64(): bigint␊ export function getCwd(callback: (arg0: string) => void): void␊ /** napi = { version = 2, features = ["serde-json"] } */␊ export function readFile(callback: (arg0: Error | undefined, arg1?: string | undefined | null) => void): void␊ @@ -69,7 +69,7 @@ Generated by [AVA](https://avajs.dev). export function getExternal(external: ExternalObject): number␊ export function mutateExternal(external: ExternalObject, newVal: number): void␊ export function tsRename(a: { foo: number }): string[]␊ - export function xxh64Alias(input: Buffer): BigInt␊ + export function xxh64Alias(input: Buffer): bigint␊ export function getMapping(): Record␊ export function sumMapping(nums: Record): number␊ export function mapOption(val?: number | undefined | null): number | undefined | null␊ @@ -207,19 +207,19 @@ Generated by [AVA](https://avajs.dev). }␊ export namespace xxh3 {␊ export const ALIGNMENT: number␊ - export function xxh3_64(input: Buffer): BigInt␊ + export function xxh3_64(input: Buffer): bigint␊ /** xxh128 function */␊ - export function xxh128(input: Buffer): BigInt␊ + export function xxh128(input: Buffer): bigint␊ /** Xxh3 class */␊ export class Xxh3 {␊ constructor()␊ /** update */␊ update(input: Buffer): void␊ - digest(): BigInt␊ + digest(): bigint␊ }␊ }␊ export namespace xxh2 {␊ export function xxh2Plus(a: number, b: number): number␊ - export function xxh3Xxh64Alias(input: Buffer): BigInt␊ + export function xxh3Xxh64Alias(input: Buffer): bigint␊ }␊ ` diff --git a/examples/napi/__test__/typegen.spec.ts.snap b/examples/napi/__test__/typegen.spec.ts.snap index a929b2b0f48e25edcd535fc0e7a1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ts b/examples/napi/index.d.ts index 31d68233..d6e712b8 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.ts @@ -17,9 +17,9 @@ export function getNums(): Array export function sumNums(nums: Array): number export function readFileAsync(path: string): Promise export function asyncMultiTwo(arg: number): Promise -export function bigintAdd(a: BigInt, b: BigInt): BigInt -export function createBigInt(): BigInt -export function createBigIntI64(): BigInt +export function bigintAdd(a: bigint, b: bigint): bigint +export function createBigInt(): bigint +export function createBigIntI64(): bigint export function getCwd(callback: (arg0: string) => void): void /** napi = { version = 2, features = ["serde-json"] } */ export function readFile(callback: (arg0: Error | undefined, arg1?: string | undefined | null) => void): void @@ -59,7 +59,7 @@ export function createExternalString(content: string): ExternalObject export function getExternal(external: ExternalObject): number export function mutateExternal(external: ExternalObject, newVal: number): void export function tsRename(a: { foo: number }): string[] -export function xxh64Alias(input: Buffer): BigInt +export function xxh64Alias(input: Buffer): bigint export function getMapping(): Record export function sumMapping(nums: Record): number export function mapOption(val?: number | undefined | null): number | undefined | null @@ -197,18 +197,18 @@ export class JsClassForEither { } export namespace xxh3 { export const ALIGNMENT: number - export function xxh3_64(input: Buffer): BigInt + export function xxh3_64(input: Buffer): bigint /** xxh128 function */ - export function xxh128(input: Buffer): BigInt + export function xxh128(input: Buffer): bigint /** Xxh3 class */ export class Xxh3 { constructor() /** update */ update(input: Buffer): void - digest(): BigInt + digest(): bigint } } export namespace xxh2 { export function xxh2Plus(a: number, b: number): number - export function xxh3Xxh64Alias(input: Buffer): BigInt + export function xxh3Xxh64Alias(input: Buffer): bigint } diff --git a/tsconfig.json b/tsconfig.json index 5de32776..16988746 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,5 +27,5 @@ "lib": ["dom", "DOM.Iterable", "ES2019", "ES2020", "esnext"] }, "include": ["."], - "exclude": ["node_modules", "bench", "cli/scripts", "scripts", "examples"] + "exclude": ["node_modules", "bench", "cli/scripts", "scripts"] }