# acorn-typescript

> Alternative, TypeScript parser

Latest version **1.4.13** (published 2024-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install acorn-typescript
pnpm add acorn-typescript
yarn add acorn-typescript
bun add acorn-typescript
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.13 |
| Published | 2024-01-03 |
| First published | 2023-01-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 519.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 154 |
| Author | tyrealhu |
| Maintainers | tyrealhu |

## Links

- npm: https://www.npmjs.com/package/acorn-typescript
- Repository: https://github.com/TyrealHu/acorn-typescript
- Homepage: https://github.com/TyrealHu/acorn-typescript#readme
- Issues: https://github.com/TyrealHu/acorn-typescript/issues
- npm.io page: https://npm.io/package/acorn-typescript

## Recent versions

- 1.4.13 (latest) — 2024-01-03
- 1.4.12 — 2023-12-05
- 1.4.11 — 2023-11-10
- 1.4.10 — 2023-10-20
- 1.4.9 — 2023-10-18
- 1.4.8 — 2023-10-09
- 1.4.7 — 2023-09-21
- 1.4.6 — 2023-09-20
- 1.4.5 — 2023-09-06
- 1.4.4 — 2023-08-30
- 1.4.3 — 2023-08-25
- 1.4.2 — 2023-08-24
- 1.4.1 — 2023-07-26
- 1.4.0 — 2023-07-03
- 1.3.7 — 2023-06-14
- … 35 more at https://npm.io/package/acorn-typescript/versions

## README

# acorn-typescript
[![npm version](https://img.shields.io/npm/v/acorn-typescript.svg?style=flat)](https://www.npmjs.com/package/acorn-typescript)[![Coverage Status](https://codecov.io/gh/TyrealHu/acorn-typescript/branch/master/graph/badge.svg)](https://codecov.io/gh/TyrealHu/acorn-typescript)
---

This is plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript.

It was created as an experimental alternative, faster [TypeScript](https://www.typescriptlang.org/) parser. It will help you to parse
typescript script into typeScript AST.

## Usage

Requiring this module provides you with an Acorn plugin that you can use like this:

```typescript
import * as acorn from 'acorn'
import tsPlugin from 'acorn-typescript'

/*
*
* */
const node = acorn.Parser.extend(tsPlugin()).parse(`
const a = 1
type A = number
export {
  a,
  type A as B
}
`, {
  sourceType: 'module',
  ecmaVersion: 'latest',
  locations: true
})
```

If you want to enable parsing within a TypeScript ambient context, where certain syntax have different rules (like .d.ts files and inside [declare module blocks](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)).
```typescript
import * as acorn from 'acorn'
import tsPlugin from 'acorn-typescript'

/*
*
* */
const node = acorn.Parser.extend(tsPlugin({ dts: true })).parse(`
const a = 1
type A = number
export {
  a,
  type A as B
}
`, {
  sourceType: 'module',
  ecmaVersion: 'latest',
  locations: true
})
```

## Notice
- You have to enable options.locations while using acorn-typescript
```ts
acorn.parse(input, {
    sourceType: 'module',
    ecmaVersion: 'latest',
    // here
    locations: true
  })
```

## SUPPORTED
- Typescript normal syntax
- Support to parse TypeScript [Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)
- Support to parse JSX & TSX

## CHANGELOG

[click](./CHANGELOG.md)

## RoadMap
- support import-assertions

## License
[MIT](https://couto.mit-license.org/)

---
_Source: https://npm.io/package/acorn-typescript · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
