UNPKG

ember-codemod-add-component-signatures

Version:
20 lines (19 loc) 840 B
import { AST } from '@codemod-utils/ast-javascript'; export function updateConstructor(file, options) { const traverse = AST.traverse(true); const { data } = options; const ast = traverse(file, { visitClassMethod(path) { if (path.node.kind !== 'constructor' || path.node.params.length !== 2) { return false; } const args = path.node.params[1]; if (args.type !== 'Identifier') { return false; } args.typeAnnotation = AST.builders.tsTypeAnnotation(AST.builders.tsIndexedAccessType(AST.builders.tsTypeReference(AST.builders.identifier(`${data.entity.pascalizedName}Signature`)), AST.builders.tsLiteralType(AST.builders.stringLiteral('Args')))); return false; }, }); return AST.print(ast); }