{"id":18256007,"url":"https://github.com/ull-esit-pl/compact-js-ast","last_synced_at":"2026-02-11T07:02:00.068Z","repository":{"id":118542993,"uuid":"610362003","full_name":"ULL-ESIT-PL/compact-js-ast","owner":"ULL-ESIT-PL","description":"Outputs a compact string representation of the espree AST of an input program.","archived":false,"fork":false,"pushed_at":"2024-08-11T09:10:03.000Z","size":79,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-13T03:10:03.077Z","etag":null,"topics":["ast","babel","espree","estree"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/compact-js-ast","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ULL-ESIT-PL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-06T16:10:11.000Z","updated_at":"2024-08-11T09:10:06.000Z","dependencies_parsed_at":"2024-08-11T10:26:05.515Z","dependency_job_id":"e06fa17b-4769-4d67-87fe-00afa4f081c1","html_url":"https://github.com/ULL-ESIT-PL/compact-js-ast","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ULL-ESIT-PL%2Fcompact-js-ast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ULL-ESIT-PL%2Fcompact-js-ast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ULL-ESIT-PL%2Fcompact-js-ast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ULL-ESIT-PL%2Fcompact-js-ast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ULL-ESIT-PL","download_url":"https://codeload.github.com/ULL-ESIT-PL/compact-js-ast/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223151215,"owners_count":17096067,"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","espree","estree"],"created_at":"2024-11-05T10:19:24.457Z","updated_at":"2026-02-11T07:01:55.032Z","avatar_url":"https://github.com/ULL-ESIT-PL.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Synopsis\n\nOutputs a compact string representation of the espree AST of an input program. It provides an executable `compast` that can be used to output \na summarized version of the AST of a given JavaScript program. The output can be in YML or JSON format. The program can be given as a file or as a string in the command line.\n\n```\n$ compast -h                    \nUsage: compast [options] [filename]\n\nConverts a JS program into a JSON or YML AST format\n\nArguments:\n  filename                    file with the original code\n\nOptions:\n  -V, --version               output the version number\n  -o, --output \u003cfilename\u003e     file name of the json output program\n  -p, --program \u003cJS program\u003e  JS program is given in the command line\n  -jw --whites \u003cstring\u003e       string '  ' Specifies the number of whites for formatting the object (default: \"  \")\n  -e --hide \u003cfieldnames...\u003e   List of AST fields to omit (default: [])\n  -f --hideFile \u003cfileName\u003e    File with a line per AST fields to omit\n  -j --json                   output in JSON format (default is YML\n  -n --no-parse               do not parse the code, assume the input is already an AST in json format\n  -b --babel                  parse the code with babel (default is espree)\n  -a --all                    output all fields\n  -l --location               omit only location fields\n  -h, --help                  display help for command\n```\n\n## Install\n\n```\nnpm i -g compact-js-ast\n```\n\n\n## Examples\n\nHere is an example of the YML output of the AST for the program `a.b(4)`:\n\n```yml\n$ compast -p 'a.b(4)'           \ntype: \"Program\"\nbody:\n  - type: \"ExpressionStatement\"\n    expression:\n      type: \"CallExpression\"\n      callee:\n        type: \"MemberExpression\"\n        object:\n          type: \"Identifier\"\n          name: \"a\"\n        property:\n          type: \"Identifier\"\n          name: \"b\"\n      arguments:\n        - type: \"Literal\"\n          value: 4\n```\n\n```\n$ compast -jp 'a.b(4)'\n```\n```json\n{\n  \"type\": \"Program\",\n  \"body\": [\n    {\n      \"type\": \"ExpressionStatement\",\n      \"expression\": {\n        \"type\": \"CallExpression\",\n        \"callee\": {\n          \"type\": \"MemberExpression\",\n          \"object\": {\n            \"type\": \"Identifier\",\n            \"name\": \"a\"\n          },\n          \"property\": {\n            \"type\": \"Identifier\",\n            \"name\": \"b\"\n          }\n        },\n        \"arguments\": [\n          {\n            \"type\": \"Literal\",\n            \"value\": 4\n          }\n        ]\n      }\n    }\n  ]\n}\n```\nSame, but removing `names`s and `value`s:\n\n```yml\n$ compast -e name value -p 'a.b(4)' \ntype: \"Program\"\nbody:\n  - type: \"ExpressionStatement\"\n    expression:\n      type: \"CallExpression\"\n      callee:\n        type: \"MemberExpression\"\n        object:\n          type: \"Identifier\"\n        property:\n          type: \"Identifier\"\n      arguments:\n        - type: \"Literal\"\n```\n\nUsing babel:\n\n`➜  nicolo-howto-talk git:(main) compast -blp 'a?.[0]' | yq '.program.body[0]'`\n```json\n{\n  \"type\": \"ExpressionStatement\",\n  \"expression\": {\n    \"type\": \"OptionalMemberExpression\",\n    \"object\": {\n      \"type\": \"Identifier\",\n      \"name\": \"a\"\n    },\n    \"computed\": true,\n    \"property\": {\n      \"type\": \"NumericLiteral\",\n      \"extra\": {\n        \"rawValue\": 0,\n        \"raw\": \"0\"\n      },\n      \"value\": 0\n    },\n    \"optional\": true\n  }\n}\n```\n\n## See also\n\n- [astexplorer.net](https://astexplorer.net/) is a web-based tool for exploring the AST of a JavaScript program. It provides a visual representation of the AST and allows to explore the different nodes and their properties.\n- [jq](https://stedolan.github.io/jq/) is a lightweight and flexible command-line JSON processor. It can be used to filter and transform the output of `compast` to obtain a more compact representation of the AST.\n- [yq](https://github.com/mikefarah/yq) is a YAML version of jq\n- [jless](https://www.npmjs.com/package/less) is a command-line JSON viewer that can be used to visualize the output of `compast` in a more readable format.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Full-esit-pl%2Fcompact-js-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Full-esit-pl%2Fcompact-js-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Full-esit-pl%2Fcompact-js-ast/lists"}