{"id":24111244,"url":"https://github.com/sveltejs/esrap","last_synced_at":"2025-05-16T12:01:49.772Z","repository":{"id":195283203,"uuid":"692591137","full_name":"sveltejs/esrap","owner":"sveltejs","description":"Parse in reverse","archived":false,"fork":false,"pushed_at":"2025-04-02T21:47:59.000Z","size":712,"stargazers_count":66,"open_issues_count":4,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-11T09:16:27.454Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/sveltejs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2023-09-17T00:37:36.000Z","updated_at":"2025-04-20T18:32:23.000Z","dependencies_parsed_at":"2024-01-13T17:10:55.297Z","dependency_job_id":"0800cf74-a707-4fe2-b90d-1386de648a6f","html_url":"https://github.com/sveltejs/esrap","commit_stats":null,"previous_names":["rich-harris/esrap","sveltejs/esrap"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveltejs%2Fesrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveltejs%2Fesrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveltejs%2Fesrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveltejs%2Fesrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sveltejs","download_url":"https://codeload.github.com/sveltejs/esrap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527071,"owners_count":22085917,"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":[],"created_at":"2025-01-11T02:20:42.381Z","updated_at":"2025-05-16T12:01:49.686Z","avatar_url":"https://github.com/sveltejs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esrap\n\nParse in reverse. AST goes in, code comes out.\n\n## Usage\n\n```js\nimport { print } from 'esrap';\n\nconst { code, map } = print({\n  type: 'Program',\n  body: [\n    {\n      type: 'ExpressionStatement',\n      expression: {\n        callee: {\n          type: 'Identifier',\n          name: 'alert'\n        },\n        arguments: [\n          {\n            type: 'Literal',\n            value: 'hello world!'\n          }\n        ]\n      }\n    }\n  ]\n});\n\nconsole.log(code); // alert('hello world!');\n```\n\nIf the nodes of the input AST have `loc` properties (e.g. the AST was generated with [`acorn`](https://github.com/acornjs/acorn/tree/master/acorn/#interface) with the `locations` option set), sourcemap mappings will be created.\n\n## Options\n\nYou can pass the following options:\n\n```js\nconst { code, map } = print(ast, {\n  // Populate the `sources` field of the resulting sourcemap\n  // (note that the AST is assumed to come from a single file)\n  sourceMapSource: 'input.js',\n\n  // Populate the `sourcesContent` field of the resulting sourcemap\n  sourceMapContent: fs.readFileSync('input.js', 'utf-8'),\n\n  // Whether to encode the `mappings` field of the resulting sourcemap\n  // as a VLQ string, rather than an unencoded array. Defaults to `true`\n  sourceMapEncodeMappings: false,\n\n  // String to use for indentation — defaults to '\\t'\n  indent: '  ',\n\n  // Whether to wrap strings in single or double quotes — defaults to 'single'.\n  // This only applies to string literals with no `raw` value, which generally\n  // means the AST node was generated programmatically, rather than parsed\n  // from an original source\n  quotes: 'single'\n});\n```\n\n## TypeScript\n\n`esrap` can also print TypeScript nodes, assuming they match the ESTree-like [`@typescript-eslint/types`](https://www.npmjs.com/package/@typescript-eslint/types).\n\n## Why not just use Prettier?\n\nBecause it's ginormous.\n\n## Developing\n\nThis repo uses [pnpm](https://pnpm.io). Once it's installed, do `pnpm install` to install dependencies, and `pnpm test` to run the tests.\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsveltejs%2Fesrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsveltejs%2Fesrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsveltejs%2Fesrap/lists"}