TyrealHu / acorn-typescript

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

Syntax error when arrow function parameter is assignment pattern #7

Closed ota-meshi closed 1 year ago

ota-meshi commented 1 year ago

The following code seems to give a syntax error when using acorn-typescript.

a = (x = 42) => {}

The following code is to reproduce.

import * as acorn from "acorn";
import { tsPlugin } from "acorn-typescript";

const acornTs = acorn.Parser.extend(tsPlugin());

const code = "a = (x = 42) => {}";

const options = {
  sourceType: "module",
  ecmaVersion: "latest",
  locations: true,
} as const;

// OK
let node = acorn.Parser.parse(code, options);
console.log(node);

// Error
node = acornTs.parse(code, options);
console.log(node);

Use Versions:

    "acorn": "^8.8.2",
    "acorn-typescript": "^1.2.7",