@sveltejs/acorn-typescript
Acorn plugin that parses TypeScript
Last updated 2 months ago by GitHub Actions .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm 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.9                                ...           latest (2 months ago)

9 Versions

  • 1.0.9                                ...           2 months ago
  • 1.0.8                                ...           4 months ago
  • 1.0.7                                ...           5 months ago
  • 1.0.6                                ...           7 months ago
  • 1.0.5                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (11)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |