Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the target structure #129

Open
dstallenberg opened this issue Apr 23, 2023 · 0 comments
Open

Refactor the target structure #129

dstallenberg opened this issue Apr 23, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@dstallenberg
Copy link
Contributor

dstallenberg commented Apr 23, 2023

Currently, we have a target structure where we differentiate between classes, methods, functions, objects, and object functions.
This requires that during the collection of the targets, we keep track of what kind of sub-target we are currently in.
This can be pretty challenging, especially when properties are dynamically added, as in the following example:

class a {
  methodOne() {
    this.methodTwo = () => {...}
  }
}

Or:

const a = {}
a.methodOne = () => {...}

Or:

const a = {
  b: class {}
}
a.b.methodOne = () => {...}

These example show that it is difficult to keep track of what is a class and what is an object during the target discover.
Now since javascript internally uses object for classes anyway we can convert our entire targeting structure to be as follows:

interface Target {
  filePath: string;
  name: string;
  subTargets: SubTarget[];
}

type SubTarget = (ObjectTarget | FunctionTarget) & {
  name: string;
  renamedTo: string;
  default: boolean;
  module: boolean;
}

interface ObjectTarget {
  id: string
  subTargets: SubTarget[]
}

interface FunctionTarget {
  id: string

  visibility: VisibilityType

  functionType: "constructor" | "method" | "get" | "set" | "function"
  isStatic: boolean
  isAsync: boolean
}

@dstallenberg dstallenberg added the enhancement New feature or request label Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant