facebook / facebook/jscodeshift

templates evaluate at global scope, breaks statement`return;`

Open
#42 9 comments 0 reactions 0 assignees View on GitHub
discussion improvement
Dominant language
JavaScript
Stars
10k
Forks
498
PR merge metrics
No merged PRs in 30d

Description

Return statements can only be added inside a function but templates are evaluated by babel at the global scope so babel throws on

```
statement`return;`
```

Example: http://felix-kling.de/esprima_ast_explorer/#/1lLYuPcGmT

This also happens for `break;` statements as well.

@fkling had an idea of always evaluating templates within a function but that could break things like `import` that can only be added at the global scope. Not sure what the way forward is here but i find the templating extremely valuable so it would be great to find a solution!

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.