fabrix-app / fabrix

Strongly Typed Modern Web Application Framework for Node.js and Browsers
Other
107 stars 5 forks source link

bug(): catch spools declarations that are not classes #33

Open scott-wyatt opened 5 years ago

scott-wyatt commented 5 years ago

Attached is a possible script implementation to check if a spool is actually a class. This helps pure JS users more than TS users, but, since it all runs in JavaScript at the end of the day, it makes sense to do an explicit check.

export default fn => {
  if (typeof fn != "function") {
    return false
  }

  let proxy = new Proxy(fn, {
    construct: () => fn,
  })

  try {
    new proxy
  } catch {
    return false
  }

  return true
}

Additionally, with babel constructing things down to es5 for browsers, it would be helpful to detect if the spool is es5 or es6 already.