From 3b615cbdda454cb61ac1d0f5b8baf13313dd0f28 Mon Sep 17 00:00:00 2001 From: "Congcong Cai (EE-CN-42)" Date: Wed, 27 Jul 2022 14:16:25 +0800 Subject: [PATCH 1/2] fix: fix endless recursion during dts generation --- src/bindings/tsd.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bindings/tsd.ts b/src/bindings/tsd.ts index 59b3362954..c34aacac94 100644 --- a/src/bindings/tsd.ts +++ b/src/bindings/tsd.ts @@ -302,17 +302,21 @@ export class TSDBuilder extends ExportsWalker { sb.push(mode == Mode.EXPORT ? "" : ""); } } else { - if (this.isPlainObject(clazz)) { + let isPlainObject = this.isPlainObject(clazz); + if (isPlainObject) { typeName = "__Record" + clazz.id.toString(); sb.push(typeName); sb.push(mode == Mode.EXPORT ? "" : ""); - this.deferredTypings.push(this.makeRecordType(clazz, mode)); } else { typeName = "__Internref" + clazz.id.toString(); sb.push(typeName); - this.deferredTypings.push(this.makeInternrefType(clazz)); } seenObjectTypes.set(clazz, typeName); + if (isPlainObject) { + this.deferredTypings.push(this.makeRecordType(clazz, mode)); + } else { + this.deferredTypings.push(this.makeInternrefType(clazz)); + } } } if (type.is(TypeFlags.NULLABLE)) { From c8810dd8baca83a3c2e605e89090c871aa409e9e Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 28 Jul 2022 17:10:48 +0800 Subject: [PATCH 2/2] change format --- src/bindings/tsd.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/bindings/tsd.ts b/src/bindings/tsd.ts index c34aacac94..fc5c8a2e6b 100644 --- a/src/bindings/tsd.ts +++ b/src/bindings/tsd.ts @@ -302,17 +302,12 @@ export class TSDBuilder extends ExportsWalker { sb.push(mode == Mode.EXPORT ? "" : ""); } } else { - let isPlainObject = this.isPlainObject(clazz); - if (isPlainObject) { - typeName = "__Record" + clazz.id.toString(); - sb.push(typeName); - sb.push(mode == Mode.EXPORT ? "" : ""); - } else { - typeName = "__Internref" + clazz.id.toString(); - sb.push(typeName); - } + let isPlain = this.isPlainObject(clazz); + typeName = `${isPlain ? "__Record" : "__Internref"}${clazz.id}`; + sb.push(typeName); seenObjectTypes.set(clazz, typeName); - if (isPlainObject) { + if (isPlain) { + sb.push(mode == Mode.EXPORT ? "" : ""); this.deferredTypings.push(this.makeRecordType(clazz, mode)); } else { this.deferredTypings.push(this.makeInternrefType(clazz));