{"id":21186030,"url":"https://github.com/codemodsquad/print-highlighted-ast","last_synced_at":"2026-05-19T00:40:24.090Z","repository":{"id":40783422,"uuid":"253929529","full_name":"codemodsquad/print-highlighted-ast","owner":"codemodsquad","description":"print a babel AST with specific nodes highlighted, for debugging codemods","archived":false,"fork":false,"pushed_at":"2023-01-06T02:56:08.000Z","size":3511,"stargazers_count":1,"open_issues_count":21,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T09:22:28.733Z","etag":null,"topics":["ast","babel","debugging"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codemodsquad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-07T22:47:52.000Z","updated_at":"2021-05-26T07:02:13.000Z","dependencies_parsed_at":"2023-02-05T04:01:47.733Z","dependency_job_id":null,"html_url":"https://github.com/codemodsquad/print-highlighted-ast","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fprint-highlighted-ast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fprint-highlighted-ast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fprint-highlighted-ast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fprint-highlighted-ast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codemodsquad","download_url":"https://codeload.github.com/codemodsquad/print-highlighted-ast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243639556,"owners_count":20323510,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","babel","debugging"],"created_at":"2024-11-20T18:20:50.499Z","updated_at":"2026-05-19T00:40:24.022Z","avatar_url":"https://github.com/codemodsquad.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# print-highlighted-ast\n\n[![CircleCI](https://circleci.com/gh/codemodsquad/print-highlighted-ast.svg?style=svg)](https://circleci.com/gh/codemodsquad/print-highlighted-ast)\n[![Coverage Status](https://codecov.io/gh/codemodsquad/print-highlighted-ast/branch/master/graph/badge.svg)](https://codecov.io/gh/codemodsquad/print-highlighted-ast)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![npm version](https://badge.fury.io/js/print-highlighted-ast.svg)](https://badge.fury.io/js/print-highlighted-ast)\n\nprint a babel AST with specific nodes highlighted, for debugging codemods\n\n# Example\n\n## Script\n\n```ts\nimport printHighlightedAst from 'print-highlighted-ast'\nimport { parse } from '@babel/parser'\nimport traverse, { NodePath } from '@babel/traverse'\nimport chalk from 'chalk'\n\nconst code = `\nconst foo = () =\u003e 2\nconst bar = 500 + 600\n`\nconst ast = parse(code)\nconst highlights: Array\u003c[NodePath\u003cany\u003e, (code: string) =\u003e string]\u003e = []\ntraverse(ast, {\n  NumericLiteral: path =\u003e {\n    highlights.push([path, chalk.bgBlue])\n  },\n})\n\nconsole.log(printHighlightedAst(code, { highlights })\n```\n\n## Output\n\n![Example output](/img/example.png)\n\n# API\n\nYou can pass the source code or a parsed AST as the first argument. If you pass an AST it will be\nconverted to code with `@babel/generator`.\n\nEach element of `highlights` is a tuple of `[0]` path you want to highlight, `[1]` highlighting function.\nYou can pass options to `@babel/parser` and `@babel/generator` as shown below.\n\nThe code will be parsed with `@babel/parser` to determine the source range of the paths you want to\nhighlight. If you're using language extensions like Flow, Typescript, or JSX, you'll need to pass\nthose plugins in `parseOptions`.\n\n```ts\nimport { Node } from '@babel/types'\nimport { NodePath } from '@babel/traverse'\nimport generate from '@babel/generator'\nimport { parse } from '@babel/parser'\n\nfunction printHighlightedAst(\n  codeOrAst: string | Node,\n  {\n    highlights,\n    generateOptions,\n    parseOptions,\n  }: {\n    highlights: Iterable\u003c[NodePath\u003cany\u003e, (code: string) =\u003e string]\u003e\n    generateOptions?: Parameters\u003ctypeof generate\u003e[1]\n    parseOptions?: Parameters\u003ctypeof parse\u003e[1]\n  }\n): string\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemodsquad%2Fprint-highlighted-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemodsquad%2Fprint-highlighted-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemodsquad%2Fprint-highlighted-ast/lists"}