Skip to content

Commit b824bef

Browse files
committed
fix: keep exception js emit syntax-valid
1 parent 97804a2 commit b824bef

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

packages/compiler/src/codegen.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,9 +3219,13 @@ class Codegen {
32193219
// in strict mode. Manually copy each descriptor field via
32203220
// `Object.defineProperty` to override the built-in.
32213221
this.write(` const descriptor = type.native(${JSON.stringify(node.name)}, (v) => `)
3222-
this.write(`v != null && typeof v === "object" && (v as { name?: unknown }).name === ${JSON.stringify(node.name)})\n`)
3222+
this.write(this.tsMode
3223+
? `v != null && typeof v === "object" && (v as { name?: unknown }).name === ${JSON.stringify(node.name)})\n`
3224+
: `v != null && typeof v === "object" && v.name === ${JSON.stringify(node.name)})\n`)
32233225
this.write(` for (const k of Object.keys(descriptor)) {\n`)
3224-
this.write(` Object.defineProperty(factory, k, { value: (descriptor as unknown as Record<string, unknown>)[k], writable: true, configurable: true, enumerable: true })\n`)
3226+
this.write(this.tsMode
3227+
? ` Object.defineProperty(factory, k, { value: (descriptor as unknown as Record<string, unknown>)[k], writable: true, configurable: true, enumerable: true })\n`
3228+
: ` Object.defineProperty(factory, k, { value: descriptor[k], writable: true, configurable: true, enumerable: true })\n`)
32253229
this.write(` }\n`)
32263230
this.write(this.tsMode
32273231
? ` return factory as typeof factory & __tu_TypeDescriptor\n`

0 commit comments

Comments
 (0)