Skip to content

Refactor the target structure #129

Open
@dstallenberg

Description

@dstallenberg
Contributor

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
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @dstallenberg

        Issue actions

          Refactor the target structure · Issue #129 · syntest-framework/syntest-javascript