https://github.com/knightedcodemonkey/reparse
Multiple SWC parsings with correct spans.
https://github.com/knightedcodemonkey/reparse
ast commonjs esmodule parser swc
Last synced: 22 days ago
JSON representation
Multiple SWC parsings with correct spans.
- Host: GitHub
- URL: https://github.com/knightedcodemonkey/reparse
- Owner: knightedcodemonkey
- License: mit
- Created: 2024-06-01T14:06:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-18T03:19:07.000Z (over 1 year ago)
- Last Synced: 2025-09-22T10:27:23.477Z (5 months ago)
- Topics: ast, commonjs, esmodule, parser, swc
- Language: TypeScript
- Homepage:
- Size: 87.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [`@knighted/reparse`](https://www.npmjs.com/package/@knighted/reparse)

[](https://codecov.io/gh/knightedcodemonkey/reparse)
[](https://www.npmjs.com/package/@knighted/reparse)
Multiple SWC parsings of the same file with correct spans.
Provides a workaround for [swc/1366](https://github.com/swc-project/swc/issues/1366).
## Requirements
- Node >= 20.11.0
- `@swc/core` >= 1.5.24 as peer dependency
## Example
There are four exports `reparse`, `reparseFile`, `reparseSync` and `reparseFileSync`.
```js
import { reparse } from '@knighted/reparse'
import assert from 'node:assert/strict'
const ast1 = await reparse('const foo = "bar"')
const ast2 = await reparse('const foo = "bar"')
assert.equal(ast1.span.start, ast2.span.start)
assert.equal(ast1.span.end, ast2.span.end)
```
Sync file example:
```js
import { reparseFileSync } from '@knighted/reparse'
const ast0 = reparseFileSync('./file.ts')
const ast1 = reparseFileSync('./file.ts')
console.log(ast0.span.start === ast1.span.start) // true
```