Skip to content

Commit

Permalink
Use a more accurate heuristic for identifying ES6 classes (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
syangabq authored Jan 22, 2024
1 parent 664b13d commit 472880a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 472880a

Please sign in to comment.