Skip to content

knightedcodemonkey/reparse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

66d4da1 · Jun 18, 2024

History

6 Commits
Jun 18, 2024
Jun 18, 2024
Jun 18, 2024
Jun 1, 2024
Jun 1, 2024
Jun 18, 2024
Jun 1, 2024
Jun 3, 2024
Jun 18, 2024
Jun 18, 2024
Jun 1, 2024
Jun 1, 2024

Repository files navigation

CI codecov NPM version

Multiple SWC parsings of the same file with correct spans.

Provides a workaround for swc/1366.

Requirements

  • Node >= 20.11.0
  • @swc/core >= 1.5.24 as peer dependency

Example

There are four exports reparse, reparseFile, reparseSync and reparseFileSync.

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:

import { reparseFileSync } from '@knighted/reparse'

const ast0 = reparseFileSync('./file.ts')
const ast1 = reparseFileSync('./file.ts')

console.log(ast0.span.start === ast1.span.start) // true