Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

acorn-typescript

TyrealHu1.7mMIT1.4.13TypeScript support: included

Alternative, TypeScript parser

readme

acorn-typescript

npm versionCoverage Status

This is 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 script into typeScript AST.

Usage

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

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).

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
    acorn.parse(input, {
      sourceType: 'module',
      ecmaVersion: 'latest',
      // here
      locations: true
    })

SUPPORTED

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

CHANGELOG

click

RoadMap

  • support import-assertions

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.4.13 (2024-01-03)

✨ Features

1.4.12 (2023-12-05)

🐛 Bug Fixes

  • 🐛the scope flag between type value and ident (da26d27)

1.4.11 (2023-11-10)

🐛 Bug Fixes

  • 🐛parse tagged template expression with type (575ab8c)

1.4.10 (2023-10-20)

🐛 Bug Fixes

  • 🐛bugs of left relational and right relational (de5984c)

1.4.9 (2023-10-18)

♻️ Code Refactoring

  • 🌟set jsx options to true, while its empty (77e26cd)

1.4.8 (2023-10-09)

🐛 Bug Fixes

  • 🐛 parse import specifier with keyword (91a27a9)

1.4.7 (2023-09-21)

🐛 Bug Fixes

  • 🐛 JSX token parse in ! > ! case (a519fab)

1.4.6 (2023-09-20)

✨ Features

  • 🚀 support import assertions and type check (e6d286d)

1.4.5 (2023-09-06)

🐛 Bug Fixes

  • 🐛checkLValInnerPattern in TSParameterProperty (6de3ebd)

1.4.4 (2023-08-30)

🐛 Bug Fixes

  • 🐛bugs of TSTypeCastExpression (22be8a3)

1.4.3 (2023-08-25)

🐛 Bug Fixes

  • 🐛 optional class property & class method generic types & arrow function generic type (998969a)

1.4.2 (2023-08-24)

🐛 Bug Fixes

  • 🐛modifier params in class method (5a06b09)

1.4.1 (2023-07-26)

🐛 Bug Fixes

  • 🐛bugs in parseExprList (399f38e)

1.4.0 (2023-07-03)

✨ Features

  • 🚀rewrite some methonds in acorn 8.9.0 (8666259)

1.3.7 (2023-06-14)

✨ Features

  • 🚀add locations validating in static method (e707b64)

1.3.6 (2023-06-08)

🐛 Bug Fixes

  • 🐛error dependencies in index.d.ts (0a04e07)

1.3.5 (2023-06-06)

♻️ Code Refactoring

  • position checkLValSimple in function (038e588)

1.3.4 (2023-06-06)

🐛 Bug Fixes

  • 🐛duplicate name in dts (d608373)

1.3.3 (2023-06-02)

🐛 Bug Fixes

  • 🐛condition expression dont throw error (1779760)

1.3.2 (2023-06-01)

🐛 Bug Fixes

  • 🐛arrow function with optinal param (163f0cf)

1.3.1 (2023-05-31)

♻️ Code Refactoring

  • allow comma at the end of generics (3e0bf3d)
  • allow comma at the end of generics (fa1b6cf)

1.3.0 (2023-05-31)

🐛 Bug Fixes

  • parse generics with trailing comma (028d787)

1.2.10 (2023-05-29)

♻️ Code Refactoring

  • async arrow function with one param (2cd5a29)

🐛 Bug Fixes

  • async in for of without decl (c73f2f0)

1.2.9 (2023-05-29)

🐛 Bug Fixes

  • eatContextual and reduce keywords (d280912)
  • syntax error in async arrow function with one param (d13794e)
  • syntax error in catch redeclared var statement captured (cd6f0de)
  • syntax error in escaped keyword property (2c11ea9)
  • syntax error in identifier named as in export and import declarations (ad797e8)
  • to raise error in escaped static method (0c3f381)
  • to raise error in multiple constructors (20ab1bd)

1.2.8 (2023-05-26)

🐛 Bug Fixes

  • syntax error in async generator function (94c3cfa)
  • syntax error in export default anonymous class (af10901)
  • syntax error in for-in without decl (c544039)
  • syntax error in static async methods (eba80f4)
  • syntax error in static getter/setter (e8fb775)
  • syntax error when arrow function parameter is assignment pattern (7f84e5c)

1.2.7 (2023-05-25)

♻️ Code Refactoring

1.2.6 (2023-05-25)

✨ Features

1.2.5 (2023-05-25)

🐛 Bug Fixes

1.2.4 (2023-05-18)

🐛 Bug Fixes

  • bugs of exports (ca33992)
  • support import default in commonjs tsc (bb69884)

1.2.3 (2023-05-18)

🐛 Bug Fixes

  • support import default in commonjs tsc (bf219cf)

1.2.2 (2023-05-18)

🐛 Bug Fixes

  • use export instead of export default (8984560)

1.2.1 (2023-05-18)

✨ Features

  • 🚀 support parse accessor modifier (ac1e54b)

1.2.0 (2023-04-03)

✨ Features

  • 🚀 support parse jsx and tsx (0e5974c)

1.1.2 (2023-03-23)

🐛 Bug Fixes

  • 🐛the bugs of isContextual (fcf13f3)

1.1.1 (2023-03-23)

🐛 Bug Fixes

  • 🐛 throw error while parsing for...of (26495a5)

1.1.0 (2023-03-22)

✨ Features

  • 🚀 support parse typescript decorators (01e0ef8)

1.0.13 (2023-03-08)

✨ Features

  • 🚀 add acornTypeScript in runtime (26414f5)
  • 🚀 get acornJsx from Parser (bd3dd82)

1.0.12 (2023-03-06)

✨ Features

  • 🚀add acornTypeScript to export some methods and tokenTypes (a113a0e)

1.0.11 (2023-03-02)

🐛 Bug Fixes

  • 🐛parse definite assignment (710773b)

1.0.10 (2023-03-01)

🐛 Bug Fixes

  • parse async arrow in subscript (f9beb65)

1.0.9 (2023-02-28)

🐛 Bug Fixes

  • 🐛 return type location and expr and distinguish arrow function parse (ffbc4ee)

✨ Features

  • 🚀 unit test of express arrow function and expression with paren (e77b2e9)

1.0.8 (2023-02-23)

✨ Features

  • 🚀add outer kind variable to help parse import or export (65bd2ad)

🐛 Bug Fixes

  • 🐛 check comma while parse binding list & methods abstract (ccc7866)
  • 🐛 check the position number while raise error (55dd763)

1.0.7 (2023-02-20)

✨ Features

  • 🚀acorn middleware class and delete ts-ignore (7d05f36)

1.0.6 (2023-02-15)

✨ Features

1.0.5 (2023-01-12)

✨ Features

  • tyreal: only export cjs and esm, minimum the pkg (1c46756)

1.0.4 (2023-01-11)

✨ Features

  • tyreal: package desc and change test file (5ca6959)

1.0.3 (2023-01-11)

✨ Features

1.0.2 (2023-01-11)

✨ Features

1.0.1 (2023-01-11)

✨ Features

1.0.0 (2023-01-11)

🐛 Bug Fixes

✨ Features

  • 🚀complete parseMaybeDecoratorArguments and ts class (b5eb8c8)
  • 🚀support ts parse default import (93de410)
  • add import and export type as (8a27090)
  • complete parse middleware (dfb76ab)
  • origin export (5a4cefa)
  • parseArrayLiker (c40fb84)
  • parseClassId (76f1459)
  • parseImport (d2eab00)
  • parseNew (9f55c7d)
  • parseSubscript (1d55b72)
  • parseVarId (7c21967)
  • reportReservedArrowTypeParam, next parseMaybeAssign (037b675)
  • support declare and export/import type (a745431)
  • tyreal: 'let contextual is false (bf9e593)
  • tyreal: add jest and bundler (d0212b7)
  • tyreal: add ts jest (96459f0)
  • tyreal: class method, and normal property (fbf22ec)
  • tyreal: class modifiers (23510de)
  • tyreal: class support abstract and add unit test (5b7b9b5)
  • tyreal: export test (9889601)
  • tyreal: finish import normal test (146e0d6)
  • tyreal: finish no parameters function test (647032e)
  • tyreal: finish the development of export unit test (e71b85e)
  • tyreal: function with paramaters (59814c5)
  • tyreal: generate snapshot (abe8198)
  • tyrealhu: WIP parseClassElement (369c2c7)
  • tyreal: import type ut (5cf8686)
  • tyreal: interface and type unit test (b010bca)
  • tyreal: remove ignore file (a3ea153)
  • tyreal: snapshot map structure (0ee2778)
  • tyreal: support class static (ac450e4)
  • tyreal: type identifier and export type unit test (6ac96da)
  • tyreal: variables test (35bf1a9)
  • tyreal: write one test and fix parameters of typescript parser (cdbbd6c)