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

fix mutation of Array constructor call for TypeScript #1903

Merged
merged 7 commits into from
Dec 1, 2019

Conversation

brodycj
Copy link

@brodycj brodycj commented Nov 29, 2019

with testing

resolves #1902

@bartekleon
Copy link
Member

Looks good at first glance, but I think there might be a small mistake or a way to make this code shorter:

} else if (node.kind === ts.SyntaxKind.CallExpression) {
      if (node.expression.kind === ts.SyntaxKind.Identifier && node.expression.getFullText(sourceFile).trim() === 'Array') {
        if (node.arguments && node.arguments.length) {
          return [{ node, replacement: 'Array()' }];
        } else {
          return [{ node, replacement: 'Array([])' }];
        }
      } else {
        return [];
      }
    } else {
      if (node.expression.getFullText(sourceFile).trim() === 'Array') {
        if (node.arguments && node.arguments.length) {
          return [{ node, replacement: 'new Array()' }];
        } else {
          return [{ node, replacement: 'new Array([])' }];
        }
      } else {
        return [];
      }
    }

This part looks fishy / strange. Especially that you are calling node.expression.getFullText(sourceFile).trim() === 'Array' in two places

@brodycj
Copy link
Author

brodycj commented Nov 29, 2019

I pushed some changes to make the code shorter, and add another test case to hopefully ensure we do not make another mistake. I hope this is good to go soon, it is now blocking updates needed on PR #1898.

@bartekleon
Copy link
Member

Now it looks much cleaner :D

@bartekleon
Copy link
Member

bartekleon commented Nov 29, 2019

@nicojs, @simondel if you could take a look / merge it :)

@simondel simondel merged commit aecd944 into stryker-mutator:master Dec 1, 2019
@brodycj brodycj deleted the array-call-missing-new branch December 2, 2019 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mutator of Array constructor without new missing for TypeScript
3 participants