How to use the ts-morph.SyntaxKind.CallExpression function in ts-morph

To help you get started, we’ve selected a few ts-morph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github anoaland / anoa-cli / src / services / theme / builders / connect-theme / index.ts View on Github external
viewFile: SourceFile,
    propsName: string
  ): boolean {
    const hoc = `AppStyle.withTheme`
    const identifier = viewVar.getFirstChild(
      c =>
        c.getKind() === SyntaxKind.CallExpression && c.getText().startsWith(hoc)
    )

    let callExp: CallExpression
    if (identifier) {
      if (identifier.getText().startsWith(hoc)) {
        return false
      }

      callExp = identifier.getFirstChildByKind(SyntaxKind.CallExpression)
    }

    if (!callExp) {
      const arrowFn = viewVar.getInitializer() as ArrowFunction // viewVar.getFirstDescendantByKind(SyntaxKind.ArrowFunction)
      if (arrowFn.getParameters) {
        ReactUtils.setFunctionPropsParams(arrowFn, propsName)
      }
      viewVar.replaceWithText(
        `${viewVar.getName()} = ${hoc}(${arrowFn.getText()})`
      )

      this.updateImports(viewFile, propsName)
      return true
    }

    return false
github anoaland / anoa-cli / src / core / libs / react-view.ts View on Github external
this.sourceFile,
      this.name,
      props.name
    )

    const identifier = viewVar.getFirstChild(
      c =>
        c.getKind() === SyntaxKind.CallExpression && c.getText().startsWith(key)
    )

    let callExp: CallExpression
    if (identifier) {
      // if (identifier.getText().startsWith(hoc)) {
      //   return false
      // }
      callExp = identifier.getFirstChildByKind(SyntaxKind.CallExpression)
    }

    if (!callExp) {
      const fn = viewVar.getInitializer() as ArrowFunction
      if (fn.getParameters) {
        react.setFunctionPropsParams(fn, props.name)
      }
      viewVar.replaceWithText(
        `${viewVar.getName()} = ${statement}(${fn.getText()})`
      )
    } else {
      if (force) {
        callExp.replaceWithText(statement)
      } else {
        return false
      }
github anoaland / anoa-cli / src / services / theme / builders / connect-theme / index.ts View on Github external
c =>
        c.getKind() === SyntaxKind.CallExpression && c.getText().startsWith(hoc)
    )
github anoaland / anoa-cli / src / services / core / redux-utils.ts View on Github external
static setAppStoreHoc(
    viewVar: VariableDeclaration,
    propsName: string,
    typeArgs: string[],
    statesMap: NameValue[],
    actionsMap: NameValue[]
  ) {
    let callExp: CallExpression
    const identifier = viewVar.getChildAtIndex(2)
    if (
      identifier &&
      identifier.getKind() === SyntaxKind.CallExpression &&
      identifier.getText().startsWith('AppStore.withStore')
    ) {
      callExp = identifier.getFirstChildByKind(SyntaxKind.CallExpression)
    }

    let connectionArgs: string[]
    ;({ connectionArgs, typeArgs } = ReduxUtils.resolveConnectionArgs(
      callExp,
      statesMap,
      actionsMap,
      typeArgs
    ))

    const connectionArgsStr = `AppStore.withStore<${typeArgs.join(
      ','
    )}>(${connectionArgs.join(',')})`

    if (callExp) {
      callExp.replaceWithText(connectionArgsStr)
github anoaland / anoa-cli / src / core / tools / react.ts View on Github external
.map(s => {
        const ce = s.getFirstDescendantByKind(SyntaxKind.CallExpression)
        if (ce && ce.getText().startsWith('useState(')) {
          return ce
        }
        return undefined
      })
      .filter(ce => !!ce)
github anoaland / anoa-cli / src / services / core / redux-utils.ts View on Github external
static setAppStoreHoc(
    viewVar: VariableDeclaration,
    propsName: string,
    typeArgs: string[],
    statesMap: NameValue[],
    actionsMap: NameValue[]
  ) {
    let callExp: CallExpression
    const identifier = viewVar.getChildAtIndex(2)
    if (
      identifier &&
      identifier.getKind() === SyntaxKind.CallExpression &&
      identifier.getText().startsWith('AppStore.withStore')
    ) {
      callExp = identifier.getFirstChildByKind(SyntaxKind.CallExpression)
    }

    let connectionArgs: string[]
    ;({ connectionArgs, typeArgs } = ReduxUtils.resolveConnectionArgs(
      callExp,
      statesMap,
      actionsMap,
      typeArgs
    ))

    const connectionArgsStr = `AppStore.withStore<${typeArgs.join(
      ','
    )}>(${connectionArgs.join(',')})`
github gregjacobs / js-to-ts-converter / src / converter / add-optionals-to-function-params.ts View on Github external
				.map( ( node: Node ) => node.getFirstAncestorByKind( SyntaxKind.CallExpression ) )
				.filter( ( node ): node is CallExpression => !!node );
github anoaland / anoa-cli / src / generators / nav / navigator-generator.ts View on Github external
private attachToArrowFunction(name: string, screenFile: SourceFile): boolean {
    const vd = screenFile.getVariableDeclaration(name)
    if (!vd) {
      return false
    }

    let arrowFn = vd.getInitializerIfKind(SyntaxKind.ArrowFunction)
    if (!arrowFn) {
      const callExp = vd.getInitializerIfKind(SyntaxKind.CallExpression)
      if (!callExp) {
        return false
      }

      arrowFn = callExp.getFirstChildByKind(SyntaxKind.ArrowFunction)
    }

    if (!arrowFn) {
      return false
    }

    this.setFunctionBody(arrowFn)
    return true
  }
github anoaland / anoa-cli / src / core / libs / react-view.ts View on Github external
getFunction() {
    let fn = this.sourceFile.getFunction(this.name)
    if (!fn) {
      const varDec = this.sourceFile.getVariableDeclaration(this.name)
      if (!varDec) {
        return undefined
      }

      const initializer = varDec.getInitializerIfKind(SyntaxKind.CallExpression)
      if (!initializer) {
        return undefined
      }

      const args = initializer.getArguments()
      if (!args.length) {
        return undefined
      }

      fn = this.sourceFile.getFunction(args[0].getText())
    }
    return fn
  }