Skip to content

Commit ae56e9f

Browse files
author
Robert Jackson
committed
Update README for predicate prefix changes with assert.
1 parent ed02f75 commit ae56e9f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ The plugin takes 5 types options: `envFlags`, `features`, `debugTools`, `externa
1717
},
1818
// @required
1919
debugTools: {
20-
source: 'debug-tools'
20+
source: 'debug-tools',
21+
// @optional
22+
assertPredicateIndex: 0
2123
},
2224
// @optional
2325
features: {
@@ -94,6 +96,11 @@ Expands into:
9496

9597
## `assert` macro expansion
9698

99+
The `assert` macro can expand in a more intelligent way with the correct
100+
configuration. When `babel-plugin-debug-macros` is provided with the
101+
`assertPredicateIndex` the predicate is injected in front of the assertion
102+
in order to avoid costly assertion message generation when not needed.
103+
97104
```javascript
98105
import { assert } from 'debug-tools';
99106

@@ -102,10 +109,15 @@ assert((() => {
102109
})(), 'You bad!');
103110
```
104111

105-
Expands into:
112+
With the `debugTools: { assertPredicateIndex: 0 }` configuration the following expansion is done:
106113

107-
```javascript
114+
```js
115+
(true && !((() => { return 1 === 1;})()) && console.assert(false, 'this is a warning'));
116+
```
117+
118+
When `assertPredicateIndex` is not specified, the following expansion is done:
108119

120+
```javascript
109121
(true && console.assert((() => { return 1 === 1;})(), 'this is a warning'));
110122
```
111123

0 commit comments

Comments
 (0)