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

[Feature]: Replace TSTypeReference inside NewExpression #657

Open
1 task
trivikr opened this issue Oct 26, 2023 · 2 comments · May be fixed by #658
Open
1 task

[Feature]: Replace TSTypeReference inside NewExpression #657

trivikr opened this issue Oct 26, 2023 · 2 comments · May be fixed by #658
Labels
enhancement New feature or request p3 This is a minor priority issue

Comments

@trivikr
Copy link
Member

trivikr commented Oct 26, 2023

Self-service

  • I'd be willing to implement this feature

Problem

Codemod does not transform TSTypeReference inside NewExpression

Example input:

import AWS from "aws-sdk";
const arr = new Array<AWS.CloudFormation.StackResourceSummary>();

Returned output:

const arr = new Array<AWS.CloudFormation.StackResourceSummary>();

Solution

Replace TSTypeReference inside NewExpression

import { StackResourceSummary } from "@aws-sdk/client-cloudformation";
const arr = new Array<StackResourceSummary>();

Alternatives

N/A

Additional context

No response

@trivikr trivikr added the enhancement New feature or request label Oct 26, 2023
@trivikr trivikr linked a pull request Oct 26, 2023 that will close this issue
@trivikr
Copy link
Member Author

trivikr commented Oct 26, 2023

This happens as jscodeshift does nor detect TSQualifiedName inside NewExpression, like the following:

const arr = new Array<AWS.CloudFormation.StackResourceSummary>();

But it detects TSQualifiedName in types as follows:

const arr: AWS.CloudFormation.StackResourceSummary = new Array();

@trivikr
Copy link
Member Author

trivikr commented Oct 26, 2023

This appears to be a bug in JSCodeShift, as the following log clearly shows there's a TSQualifiedName for example input.

Log:

console.log(source.find(j.NewExpression).nodes()[0].typeParameters.params[0].typeName.left);

Output:

Node {
  type: 'TSQualifiedName',
  start: 50,
  end: 68,
  loc: SourceLocation {
    start: Position { line: 3, column: 22, index: 50, token: 11 },
    end: Position { line: 3, column: 40, index: 68, token: 14 },
    filename: undefined,
    identifierName: undefined,
    lines: Lines {
      infos: [Array],
      mappings: [],
      cachedSourceMap: null,
      cachedTabWidth: 2,
      length: 3,
      name: null
    },
    tokens: [
      [Token], [Token], [Token],
      [Token], [Token], [Token],
      [Token], [Token], [Token],
      [Token], [Token], [Token],
      [Token], [Token], [Token],
      [Token], [Token], [Token],
      [Token], [Token], [Token]
    ],
    indent: 0
  },
  left: Node {
    type: 'Identifier',
    start: 50,
    end: 53,
    loc: SourceLocation {
      start: [Position],
      end: [Position],
      filename: undefined,
      identifierName: 'AWS',
      lines: [Lines],
      tokens: [Array],
      indent: 0
    },
    name: 'AWS'
  },
  right: Node {
    type: 'Identifier',
    start: 54,
    end: 68,
    loc: SourceLocation {
      start: [Position],
      end: [Position],
      filename: undefined,
      identifierName: 'CloudFormation',
      lines: [Lines],
      tokens: [Array],
      indent: 0
    },
    name: 'CloudFormation'
  }
}

@trivikr trivikr added the p3 This is a minor priority issue label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p3 This is a minor priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant