{"version":3,"file":"create-transformer.mjs","names":[],"sources":["../../../src/codemods/lib/create-transformer.ts"],"sourcesContent":["// Copied from https://github.com/vercel/ai/blob/main/packages/codemod/src/codemods/lib/create-transformer.ts\n// License: Apache-2.0\n\nimport type { FileInfo, API, JSCodeshift, Collection } from 'jscodeshift';\n\ntype TransformerFunction = (\n  fileInfo: FileInfo,\n  api: API,\n  options: Record<string, unknown>,\n  context: TransformContext,\n) => void;\n\nexport interface TransformContext {\n  /**\n   * The jscodeshift API object.\n   */\n  j: JSCodeshift;\n\n  /**\n   * The root collection of the AST.\n   */\n  root: Collection<any>;\n\n  /**\n   * Codemods should set this to true if they make any changes to the AST.\n   */\n  hasChanges: boolean;\n\n  /**\n   * Codemods can append messages to this array to report information to the user.\n   */\n  messages: string[];\n}\n\nexport function createTransformer(transformFn: TransformerFunction) {\n  // Note the return type of this function is explicitly designed to conform to\n  // the signature expected by jscodeshift. For more see\n  // https://github.com/facebook/jscodeshift\n  return function transformer(fileInfo: FileInfo, api: API, options: Record<string, unknown>) {\n    const j = api.jscodeshift;\n    const root = j(fileInfo.source);\n    const context: TransformContext = {\n      j,\n      root,\n      hasChanges: false,\n      messages: [],\n    };\n\n    // Execute the transformation\n    transformFn(fileInfo, api, options, context);\n\n    // Report any messages\n    context.messages.forEach(message => api.report(message));\n\n    // Return the transformed source code if changes were made\n    return context.hasChanges ? root.toSource({ quote: 'single' }) : null;\n  };\n}\n"],"mappings":";AAkCA,SAAgB,kBAAkB,aAAkC;CAIlE,OAAO,SAAS,YAAY,UAAoB,KAAU,SAAkC;EAC1F,MAAM,IAAI,IAAI;EACd,MAAM,OAAO,EAAE,SAAS,MAAM;EAC9B,MAAM,UAA4B;GAChC;GACA;GACA,YAAY;GACZ,UAAU,CAAC;EACb;EAGA,YAAY,UAAU,KAAK,SAAS,OAAO;EAG3C,QAAQ,SAAS,SAAQ,YAAW,IAAI,OAAO,OAAO,CAAC;EAGvD,OAAO,QAAQ,aAAa,KAAK,SAAS,EAAE,OAAO,SAAS,CAAC,IAAI;CACnE;AACF"}