Skip to content

Commit

Permalink
Remove documentation about unnecessary workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
d-alleyne committed Sep 6, 2024
1 parent 6dbe159 commit 5c78838
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions projects/js-packages/i18n-check-webpack-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,37 +102,6 @@ Instead put it inside the property:
/>
```

### Conditional function call compaction

When a conditional calls the same function in each branch with only one argument different, Terser will transform it to a single call with the condition inside the argument. For example, either of these
```js
example = flag ? __( 'Flag is set', 'domain' ) : __( 'Flag is not set', 'domain' );
```
```js
if ( flag ) {
example = __( 'Flag is set', 'domain' );
} else {
example = __( 'Flag is not set', 'domain' );
}
```
will become
```js
example = __( flag ? 'Flag is set' : 'Flag is not set', 'domain' );
```
which will result in neither string being detected for translation.

You can fix this by making the calls less similar, for example by adding a dummy argument to one call
```js
example = flag ? __( 'Flag is set', 'domain' ) : __( 'Flag is not set', 'domain', /* dummy arg to avoid bad minification */ 0 );
```
or by specifying an unnecessary context in one call (or a different context in both)
```js
example = flag ? __( 'Flag is set', 'domain' ) : _x( 'Flag is not set', '', 'domain' );
```
```js
example = flag ? _x( 'Flag is set', 'Something', 'domain' ) : _x( 'Flag is not set', 'Something different', 'domain' );
```

### Pruned branches and common strings

In some cases, such as when `process.env.NODE_ENV` is tested or when ES module tree-shaking is done, code paths can be known to be unreachable. For example, only one branch in the following will be kept:
Expand Down

0 comments on commit 5c78838

Please sign in to comment.