facebook / facebook/jscodeshift

template.statements breaks TypeScript namespaces

Open
#327 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
10k
Forks
498
PR merge metrics
No merged PRs in 30d

Description

[AST Explorer](https://astexplorer.net/#/gist/fb1d90bd9d97857af8a7acbc7649dcc3/b81b9bd246ca9a13d7fa2b0e6f1287d42718bae3)

**Input**
```ts
interface Foo { foo: string; }
interface Bar { bar: string; }
```

**Transformation**
```js
export default function transformer(file, api) {
const j = api.jscodeshift.withParser('ts');

return j(file.source)
.find('Program')
.replaceWith( p => j.template.statement`namespace Z { ${p.node.body} }`)
.toSource();
}
```

**Output**
```ts
namespace Z interface Foo { foo: string; }
interface Bar { bar: string; }
```

**Expected**
```ts
namespace Z {
interface Foo { foo: string; }
interface Bar { bar: string; }
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.