TyrealHu / acorn-typescript

Alternative, TypeScript parser
https://www.npmjs.com/package/acorn-typescript?activeTab=readme
MIT License
145 stars 18 forks source link

"Unexpected token" with optional parameters at arrow functions #28

Closed o-frietsch closed 1 year ago

o-frietsch commented 1 year ago

Consider this test code:

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

const node = acorn.Parser.extend(tsPlugin()).parse(`

const someArrowFunc = (bla: any, hey?: any) => 42;

`, {
  sourceType: 'module',
  ecmaVersion: 'latest',
  locations: true
});
console.log(JSON.stringify(node, null, 2));

It will raise an "Unexpected token" exception because the hey parameter is optional. Removing the ? character immediately makes the exception disappear.

TyrealHu commented 1 year ago

I will check it

TyrealHu commented 1 year ago

This has been fixed at version 1.3.2

o-frietsch commented 1 year ago

Wow. Really great response time!!! Thank you very much!