{"id":15504470,"url":"https://github.com/kwonoj/woodpile","last_synced_at":"2025-06-12T12:33:28.547Z","repository":{"id":184310078,"uuid":"670677011","full_name":"kwonoj/woodpile","owner":"kwonoj","description":"SWC AST visitor in Javascript","archived":false,"fork":false,"pushed_at":"2024-07-03T07:45:10.000Z","size":52,"stargazers_count":70,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-19T18:30:21.923Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","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/kwonoj.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-25T15:23:22.000Z","updated_at":"2024-10-04T23:17:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"e020f964-7e1d-483e-b4cf-408905a2cea0","html_url":"https://github.com/kwonoj/woodpile","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"76f32348f4bc1f28274582bd145681ec6998a96a"},"previous_names":["kwonoj/woodpile"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/kwonoj/woodpile","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwonoj%2Fwoodpile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwonoj%2Fwoodpile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwonoj%2Fwoodpile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwonoj%2Fwoodpile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kwonoj","download_url":"https://codeload.github.com/kwonoj/woodpile/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwonoj%2Fwoodpile/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259465321,"owners_count":22862076,"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":"2024-10-02T09:18:14.298Z","updated_at":"2025-06-12T12:33:28.405Z","avatar_url":"https://github.com/kwonoj.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Woodpile\n\nWoodpile is a utility library to traverse [SWC](https://github.com/swc-project/swc) ASTs in Javascript. It is a thin interop layer to the SWC's rust implementation of its visitor macro, attempt to provide consistent, synchronized mechanism to traverse ASTs in Javascript as well. This package could be useful for ducktyping, or prototyping SWC plugin in Javascript as its interface aims to provide similar experience as SWC's visitor macro.\n\nFor those reason, this package aims correctness over performance. There are inevitable costs to exchange data between Javascript to Rust, and vice versa. If you want to achieve peak performace, you should use SWC's visitor macro directly.\n\n\n### Usage\n\n`visit` is a main interface to traverse AST.\n\nCurrently, `visit` accepts an object with visitor properties have corresponding callbacks to traverse. `visit` property's callback will be called with corresponding node.\n\n```ts\nconst { visit } = require('woodpile');\nconst { parseSync } = require('@swc/core');\n\nconst ast = parseSync('console.log(\"Hello, World!\")');\n\nvisit(ast, {\n    visit: {\n        // Callbacks with visit${NodeName} will be called recursively for the node\n        visitProgram: (node, self) =\u003e {\n            console.log('visitProgram', node);\n        },\n        visitExpr: (node) =\u003e {\n            console.log('visitExpr', node);\n        }\n    },\n});\n```\n\nIt is possible to return node in each callback which attempts to replace given node. The return value of `visit` will reflect updated AST. Note it won't replace input ast similar to `visit_mut` in swc's visitor. However, it doesn't check if the returned node is valid or not but will hard fail if the returned node is not valid.\n\n```ts\nconst updatedNode = visit(ast, {\n    visit: {\n        visitProgram: (node, self) =\u003e {\n            const updatedNode = {\n              ...node\n            };\n            return updatedNode;\n        },\n    },\n});\n```\n\nCallback also passes `self` as a second parameter. This is a context to the visitor object itself.\n\nThere is also `visitWithPath` property. This visitor's callback will supply `path` to the current node. This is useful to determin what kind of parent nodes are there from existing node. The parent nodes passed into path is not a full AST node, but a subset of the nodes indicates its types.\n\n```ts\nvisit(ast, {\n    visitWithPath: {\n        visitExpr: (node, path, self) =\u003e {\n        },\n    }\n})\n```\n\nThere are also another utility function `compat`, attempts to provide conversion to the estree-compatble AST from SWC. Note this is the _closest attempt_ to generate compatible AST, likely will have some differences.\n\n```ts\nconst { compat } = require('woodpile');\nconst { parseSync } = require('@swc/core');\n\nconst ast = parseSync('console.log(\"Hello, World!\")');\n\nconst compat_ast = compat(ast, {\n  source: \"\" // optional, original source code to the input ast\n  flavor: \"babel\" | \"acorn\" // optional, default to babel\n})\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwonoj%2Fwoodpile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkwonoj%2Fwoodpile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwonoj%2Fwoodpile/lists"}