benjamn / benjamn/recast

Bug: ExportDeclaration `declaration` missing `loc` property

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

Description

When traversing literals in the following code, I noticed that the `loc` property is not present in export declarations:

```javascript
const a = "blah"; // loc: { ... }
export default "blah"; // loc: null
```

After stepping through, I find that `loc` has been intentionally set to `null` here: https://github.com/benjamn/recast/blob/82386fbacea3743d22c3766195e4513f7ba5f6d4/lib/util.js#L186-L188

History suggests that this was introduced to satisfy a decorator use-case: https://github.com/benjamn/recast/commit/537a5ac5ed1708d94e6ad5d3d57e63444c1a78a4

This unfortunately comes at the expense of tracking the movement of the literal with source-maps.

I'm not familiar enough with the decorator use-case to know if/how this could be selectively turned off to satisfy both requirements. Any help appreciated, thanks!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at lib/util.js lines 186-188 and review the linked decorator-related commit to understand why ExportDeclaration loc is set to null. Determine how source-map tracking for export literals could be preserved without breaking that decorator use-case, then verify the resulting traversal behavior.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.