From 472880a4c0722633b15d82359ffd4ecfec027827 Mon Sep 17 00:00:00 2001 From: Sophie Yang Date: Mon, 22 Jan 2024 13:32:00 -0800 Subject: [PATCH] Use a more accurate heuristic for identifying ES6 classes (#49) --- src/manager.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/manager.ts b/src/manager.ts index b6d5ddd..6b04769 100644 --- a/src/manager.ts +++ b/src/manager.ts @@ -92,7 +92,7 @@ export class Manager extends ManagerBase implements IWidgetManager { // The ES6 classes cannot be subclassed via Backbone's extend that some // code uses, so if the export looks like a class use swizzle to make it // extensible. - if (value.prototype) { + if (isES6Class(value)) { value = swizzle(value); } module[key] = value; @@ -107,7 +107,7 @@ export class Manager extends ManagerBase implements IWidgetManager { // The ES6 classes cannot be subclassed via Backbone's extend that some // code uses, so if the export looks like a class use swizzle to make it // extensible. - if (value.prototype) { + if (isES6Class(value)) { value = swizzle(value); } module[key] = value; @@ -248,6 +248,10 @@ export class Manager extends ManagerBase implements IWidgetManager { } } +function isES6Class(value: unknown): boolean { + return typeof value === 'function' && value.toString().startsWith('class '); +} + class ClassicComm implements IClassicComm { constructor(private readonly id: string, private readonly comm: IComm) {} get target_name() {