benjamn / benjamn/recast

useTabs option works only partially

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

Description

When running the following code:

``` js
var recast = require('recast');

var ast = recast.parse(
'while (true) {\n' +
'\tx;\n' +
'}'
, {useTabs: true});

// Add one line inside WHILE loop
ast.program.body[0].body.body.push({
'type': 'ExpressionStatement',
'expression': {
'type': 'Identifier',
'name': 'y'
}
});

console.log(recast.print(ast, {useTabs: true}).code.replace(/\t/g, ""));
```

I'd expect to get:

```
while (true) {
x;
y;
}
```

But instead Recast gives me:

```
while (true) {
x;
y;
}
```

NOTE: There are no docs to tell me whether I should pass `useTabs` option to `recast.parse()` or `recast.print()`, it seems that it's only needed for the latter, but just in case I'm passing it to both.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the provided JavaScript reproduction and compare the output from recast.parse and recast.print with useTabs enabled. Trace how indentation is preserved for existing lines versus newly inserted nodes; done means both x and y use tabs, matching the expected output, and the option behavior is documented.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.