{"id":29189377,"url":"https://github.com/coderaiser/swc-to-babel","last_synced_at":"2025-07-01T23:07:23.693Z","repository":{"id":50310279,"uuid":"455886047","full_name":"coderaiser/swc-to-babel","owner":"coderaiser","description":"convert SWC to Babel AST","archived":false,"fork":false,"pushed_at":"2025-03-30T17:52:13.000Z","size":363,"stargazers_count":58,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-29T07:05:44.988Z","etag":null,"topics":[],"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/coderaiser.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","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}},"created_at":"2022-02-05T14:04:30.000Z","updated_at":"2025-04-22T07:51:20.000Z","dependencies_parsed_at":"2022-08-29T15:51:58.310Z","dependency_job_id":"7869f272-b65c-481f-bec0-a51fe127335a","html_url":"https://github.com/coderaiser/swc-to-babel","commit_stats":{"total_commits":105,"total_committers":6,"mean_commits":17.5,"dds":0.1523809523809524,"last_synced_commit":"bb759c0bf81897b659a16fcbfb0961b16e538341"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"purl":"pkg:github/coderaiser/swc-to-babel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderaiser%2Fswc-to-babel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderaiser%2Fswc-to-babel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderaiser%2Fswc-to-babel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderaiser%2Fswc-to-babel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderaiser","download_url":"https://codeload.github.com/coderaiser/swc-to-babel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderaiser%2Fswc-to-babel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262559916,"owners_count":23328619,"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-07-01T23:07:22.982Z","updated_at":"2025-07-01T23:07:23.662Z","avatar_url":"https://github.com/coderaiser.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SWC-to-babel [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/swc-to-babel.svg?style=flat\u0026longCache=true\n[BuildStatusURL]: https://github.com/coderaiser/swc-to-babel/actions?query=workflow%3A%22Node+CI%22 \"Build Status\"\n[BuildStatusIMGURL]: https://github.com/coderaiser/swc-to-babel/workflows/Node%20CI/badge.svg\n[NPMURL]: https://npmjs.org/package/swc-to-babel \"npm\"\n[BuildStatusURL]: https://travis-ci.org/coderaiser/swc-to-babel \"Build Status\"\n[CoverageURL]: https://coveralls.io/github/coderaiser/swc-to-babel?branch=master\n[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/swc-to-babel/badge.svg?branch=master\u0026service=github\n\nConvert [`SWC`](https://swc.rs/) `JavaScript AST` to [`Babel AST`](https://github.com/babel/babel/blob/main/packages/babel-parser/ast/spec.md).\n\nTo use `SWC` parser with `babel` tools like:\n\n- [`@babel/traverse`](https://babeljs.io/docs/en/babel-traverse)\n- [`@babel/types`](https://babeljs.io/docs/en/babel-types)\n- etc...\n\nThe thing is [`@babel/parser`](https://babeljs.io/docs/en/babel-parser) has a a little differences with `swc` standard:\n\n- `File` node exists;\n- `Program` instead of `Module`;\n- `loc` with `line` and `column` instead of `span`;\n- `StringLiteral` has no `kind` an `hasEscape`;\n- [`Identifier`](https://github.com/coderaiser/putout/blob/master/docs/the-book-of-ast.md#identifier) has no `optional` and uses `name` instead of `value`;\n- `BlockStatement` has `body` instead of `stmts`;\n- `VariableDeclarator` has no `optional` and `definite`;\n- `CallExpression` has no `typeArguments`, `spread` and `expression` properties in `arguments`;\n- `TemplateElement` has `value` field with `raw` and `cooked`;\n- TypeScript ast nodes has prefix `TS` instead of `Ts`;\n- `ExportNamedDeclaration` instead of `ExportDeclaration`;\n- `ExportDefaultDeclaration` instead of `ExportDefaultExpression`;\n- `VariableDeclaration` has no `declare` field;\n- Has no `ParenthesisExpression`;\n- `ClassDeclaration` and `ClassExpression` uses `id` instead of `identifier`, has `ClassBody`;\n- `ClassMethod` uses `static` instead of `isStatic`;\n- [`MemberExpression`](https://github.com/coderaiser/putout/blob/master/docs/the-book-of-ast.md#memberexpression) has `computed` property instead of `Computed` node in `property` field;\n- `NewExpression` has no untyped node with a `spread` property in `arguments`, always has `arguments` field, instead of `null` when absent;\n- `ArrayExpression` has no untyped node with a `spread` property in `elements`;\n- `Function` has no `typeParameters`;\n- `TSTypeReference` has no `typeParams` field;\n- `TSTypeOperator` has `operator` instead of `op`;\n- `TSTypeParameter` has a field `name` which is `string` instead of `Identifier`;\n- `FunctionDeclaration` instead of `FunctionExpression` with `identifier` field;\n- `ImportDeclaration` has `importKind` instead of `typeOnly` and `attributes` fields;\n- `ObjectProperty` instead of `KeyValueProperty`, `KeyValuePatternProperty` and `AssignmentPatternProperty`;\n- `ExportNamedDeclaration` has `exportKind`, `specifiers` fields;\n- `ExportSpecifier` has `local` which is never `null` instead of `orig`;\n- `ExportDefaultDeclaration` has `declaration` instead of `decl`;\n- `TSAnyKeyword` instead of `TSKeywordType`;\n- `TSAsExpression` instead of `TsConstAssertion`;\n- `ObjectMethod` with `kind: get` instead of `GetterProperty`;\n- `ObjectMethod` with `kind: set` instead of `SetterProperty`;\n- `TSMappedType` `typeParameter.constraint`, instead of `typeParameter`;\n- etc...\n\n`swc-to-babel` aims to smooth this differences.\n\n## Install\n\n```\nnpm i swc-to-babel\n```\n\n### Example\n\n```js\nimport swc from '@swc/core';\nimport toBabel from 'swc-to-babel';\nimport traverse from 'babel/traverse';\n\nconst ast = toBabel(swc.parseSync(`\n    const f = ({a}) =\u003e a;\n`));\n\ntraverse({\n    ObjectProperty(path) {\n        console.log(path.value.name);\n        // output\n        'a';\n    },\n});\n```\n\n## API reference\n\n```ts\n/**\n * Convert an SWC ast to a babel ast\n * @param ast {Module} SWC ast\n * @param {string} [src=\"\"] Source code\n * @returns {ParseResult\u003cFile\u003e} Babel ast\n */\nexport default function toBabel(ast: Module, src?: string): ParseResult\u003cFile\u003e;\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderaiser%2Fswc-to-babel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderaiser%2Fswc-to-babel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderaiser%2Fswc-to-babel/lists"}