benjamn / benjamn/recast

Parse error using acorn, even though standalone acorn can handle it

Open
#834 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.3k
Forks
363
Avg merge
3d 8h
Merged PRs (30d)
3

Description

Using some new syntax, like object spread but also jsx, recast throws an error while parsing. This is even though I supply acorn as a parser and acorn can handle it on its own.

I have 2 code examples:
**spread:**
```
const a = { foo: 'bar' }
const b = { baz: 'qux' }

const merged = { ...a, ...b }
```

**jsx**
```

Hello

```

Both of these can be parsed if I do:
```
const acorn = require('acorn')
const jsx = require('acorn-jsx')
const acornParser = acorn.Parser.extend(jsx())
acornParser.parse(code)
```

But they fail if I add
```
recast.parse(code, { parser: acornParser })
```
With the alternative setup, _spread_ works but _jsx_ fails again
```
recast.parse(code, {
parser: {
parse (codeString) {
const ast = acornParser.parse(codeString)
return ast
}
}
})
```

I have created a repository to demo this. Clone and run `npm start` to reproduce. https://github.com/TheLudd/recast-bug

The error messages I get are:

**Spread:** `SyntaxError: Unexpected token (4:17)`

**jsx:** `Error: Line 1: Invalid regular expression: missing /`

Contributor guide

No contributing guide indexed for this repository

Research direction

Clone the linked demo repository and run `npm start` to reproduce both failures. Compare direct `acornParser.parse(code)` with the two `recast.parse` configurations shown in the issue, using the spread and JSX examples. Done means both examples parse through recast without the reported errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.