benjamn / benjamn/recast

Extra parents when replacing an IIFE wrappedInParens

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

Description

While attempting to create a transformer to remove IIFEs from a code base I started to run into issues when the IIFE used the parens-outside/`(function() {}())` style and only contained a single `ExpressionStatement`.

reproduction script: https://gist.github.com/spalger/b544122e7df96e8335ed975945931fe0
expected: all of the examples should produce the same output:
actual:

``` js

console.log('foo');
(console.log('bar'));

console.log('foo');
console.log('bar');

console.log('foo');
console.log('bar');

```

I've been debugging for a while now and can't seem to wrap my head around where this is happening. Given that [it's mentioned in this comment](http://github.com/benjamn/recast/blob/9d351c27cb981ebd65189b113c9a2aa87bbc560c/lib/patcher.js#L493) I imagine the patcher is responsible for this behavior, but that's as far as I've gotten

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reproduction script in the linked gist and inspect lib/patcher.js around the referenced comment at line 493. Compare the output for the parens-outside IIFE containing one ExpressionStatement with the other examples; done means all examples produce the same output without the extra parentheses.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
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.