Skip to content

Commit

Permalink
fix(instrumenter): don't mutate generics (#2530)
Browse files Browse the repository at this point in the history
Don't mutate `TSTypeParameterInstantiation` like `React.useState<true>()`
  • Loading branch information
nicojs committed Oct 7, 2020
1 parent 6a3a993 commit ed42e3c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/instrumenter/src/util/syntax-helpers.ts
Expand Up @@ -175,6 +175,7 @@ const tsTypeAnnotationNodeTypes: ReadonlyArray<types.Node['type']> = Object.free
'TSModuleDeclaration',
'TSEnumDeclaration',
'TSDeclareFunction',
'TSTypeParameterInstantiation',
]);

const flowTypeAnnotationNodeTypes: ReadonlyArray<types.Node['type']> = Object.freeze([
Expand Down
Expand Up @@ -124,6 +124,12 @@ describe('babel-transformer', () => {
expectMutateNotCalledWith((t) => t.isVariableDeclaration());
expectMutateNotCalledWith((t) => t.isStringLiteral());
});

it('should skip generic parameters', () => {
const ast = createTSAst({ rawContent: 'React.useState<string | false>()' });
transformBabel(ast, mutantCollectorMock, context);
expectMutateNotCalledWith((t) => t.isTSTypeParameterInstantiation());
});
});

it('should skip import declarations', () => {
Expand Down
Expand Up @@ -2,3 +2,5 @@ export declare const globalNamespace = "globalNamespace";
declare function foo(): 'foo';
declare module 'express' {
}

React.useState<false>();
Expand Up @@ -3,5 +3,6 @@
exports[`instrumenter integration type declarations should not produce mutants for a TS declaration file 1`] = `
"export declare const globalNamespace = \\"globalNamespace\\";
declare function foo(): 'foo';
declare module 'express' {}"
declare module 'express' {}
React.useState<false>();"
`;

0 comments on commit ed42e3c

Please sign in to comment.