{"id":15207055,"url":"https://github.com/babel/acorn-to-esprima","last_synced_at":"2025-10-02T23:35:38.381Z","repository":{"id":57172647,"uuid":"38904837","full_name":"babel/acorn-to-esprima","owner":"babel","description":"(unmaintained) Converts acorn tokens to esprima tokens","archived":true,"fork":false,"pushed_at":"2016-07-13T23:39:37.000Z","size":24,"stargazers_count":33,"open_issues_count":1,"forks_count":11,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-10-30T02:31:59.739Z","etag":null,"topics":["unmaintained"],"latest_commit_sha":null,"homepage":"","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/babel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["babel"],"open_collective":"babel","custom":"https://gitcoin.co/grants/2906/babel-compiler-for-next-generation-javascript"}},"created_at":"2015-07-10T22:28:08.000Z","updated_at":"2024-02-02T03:02:09.000Z","dependencies_parsed_at":"2022-08-24T14:41:01.236Z","dependency_job_id":null,"html_url":"https://github.com/babel/acorn-to-esprima","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Facorn-to-esprima","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Facorn-to-esprima/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Facorn-to-esprima/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Facorn-to-esprima/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/babel","download_url":"https://codeload.github.com/babel/acorn-to-esprima/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235051546,"owners_count":18928183,"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":["unmaintained"],"created_at":"2024-09-28T06:20:41.428Z","updated_at":"2025-10-02T23:35:33.100Z","avatar_url":"https://github.com/babel.png","language":"JavaScript","funding_links":["https://github.com/sponsors/babel","https://opencollective.com/babel","https://gitcoin.co/grants/2906/babel-compiler-for-next-generation-javascript"],"categories":[],"sub_categories":[],"readme":"# acorn-to-esprima\n\nSome functions to help transform an acorn/babel ast to esprima format.\n\nPrimarily for use in [babel-eslint](https://github.com/babel/babel-eslint), [babel-jscs](https://github.com/jscs-dev/babel-jscs), and [ast explorer](https://github.com/fkling/esprima_ast_explorer)\n\n**There are no dependencies** (the methods were changed to pass in dependencies instead)\n\nThe current functions exposed are:\n\n- `function attachComments(ast, comments, tokens)`\n  - This modifies the comments passed in.\n- `function toTokens(tokens, tt)`\n  - `tt` is `require(\"babel-core\").acorn.tokTypes`\n  - Converts template string tokens (`convertTemplateType`)\n  - filters out comment tokens\n  - runs `toToken` over each token\n- `function toToken(token, tt)`\n  - Sets `token.type`, `token.range`, and `token.value`\n- `function toAST(ast, traverse)`\n  - `traverse` is `require(\"babel-core\").traverse;`\n  - traverses over the ast and makes any necessary changes (usually es6+)\n- `function convertComments(comments)`\n  - Modifies `comment.type`\n\nHow to use:\n\nCheck out the parse method of https://github.com/babel/babel-eslint/blob/master/index.js\n```js\n// example\nexports.parse = function (code) {\n  var comments = opts.onComment = [];\n  var tokens = opts.onToken = [];\n\n  var ast;\n  try {\n    ast = parse(code, {\n        locations: true,\n        ranges: true\n    });\n  } catch (err) { throw err; }\n\n  tokens.pop();\n  ast.tokens = acornToEsprima.toTokens(tokens, tt);\n\n  acornToEsprima.convertComments(comments);\n  ast.comments = comments;\n  acornToEsprima.attachComments(ast, comments, ast.tokens);\n\n  acornToEsprima.toAST(ast, traverse);\n\n  return ast;\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabel%2Facorn-to-esprima","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbabel%2Facorn-to-esprima","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabel%2Facorn-to-esprima/lists"}