Skip to content

Refactor the target structure #129

Description

@dstallenberg

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions