@sveltejs/acorn-typescript
Acorn plugin that parses TypeScript
Last updated 3 months ago by GitHub Actions .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @sveltejs/acorn-typescript 
SYNC missed versions from official npm registry.

@sveltejs/acorn-typescript

License Chat

This is a plugin for Acorn - a tiny, fast JavaScript parser, written completely in JavaScript.

It was created as an experimental alternative, faster TypeScript parser. It will help you to parse TypeScript using Acorn.

Usage

To get started, import the plugin and use Acorn's extension mechanism to register it. You have to enable options.locations while using @sveltejs/acorn-typescript.

import { Parser } from 'acorn';
import { tsPlugin } from '@sveltejs/acorn-typescript';

const node = 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):

import { Parser } from 'acorn';
import { tsPlugin } from '@sveltejs/acorn-typescript';

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

SUPPORTED

  • Typescript normal syntax
  • Support to parse TypeScript Decorators
  • Support to parse JSX & TSX

CHANGELOG

click

Acknowledgments

We want to thank TyrealHu for his original work on this project. He maintained acorn-typescript until early 2024.

Current Tags

  • 1.0.13                                ...           latest (3 months ago)

13 Versions

  • 1.0.13                                ...           3 months ago
  • 1.0.12                                ...           4 months ago
  • 1.0.11                                ...           5 months ago
  • 1.0.10                                ...           6 months ago
  • 1.0.9                                ...           10 months ago
  • 1.0.8                                ...           a year ago
  • 1.0.7                                ...           a year ago
  • 1.0.6                                ...           a year ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
Downloads
Total 23
Today 0
This Week 0
This Month 4
Last Day 0
Last Week 0
Last Month 19
Dependencies (0)
None
Dev Dependencies (11)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE