@@ -40,13 +40,15 @@ npm install --save-dev babel-plugin-contracts
40
40
Then, in your babel configuration (usually in your ` .babelrc ` file), add ` "contracts" ` to your list of plugins:
41
41
``` json
42
42
{
43
- "plugins" : [" contracts" , {
44
- "env" : {
45
- "production" : {
46
- "strip" : true
43
+ "plugins" : [
44
+ [" contracts" , {
45
+ "env" : {
46
+ "production" : {
47
+ "strip" : true
48
+ }
47
49
}
48
- }
49
- } ]
50
+ }]
51
+ ]
50
52
}
51
53
```
52
54
@@ -165,7 +167,7 @@ The above example configuration will remove all contracts when `NODE_ENV=product
165
167
166
168
``` js
167
169
function addAndSquare (a , b ) {
168
- const result = a + b;
170
+ let result = a + b;
169
171
assert: {
170
172
typeof result === ' number' ;
171
173
! isNaN (result);
@@ -200,6 +202,17 @@ The above example configuration will remove all contracts when `NODE_ENV=product
200
202
201
203
Now if a contract fails, the error object will have a descriptive message.
202
204
205
+ # Migrating from Contractual.
206
+ This plugin uses a very similar syntax to our earlier Design by Contract library, [ contractual] ( https://github.com/codemix/contractual ) .
207
+ If you're migrating your project there are some differences to be aware of:
208
+
209
+ 1 . There is no longer a ` main: ` section. Anything outside of a contract is considered to be part of the normal program code.
210
+ 2 . Contracts containing more than one assertion ** must** be fully wrapped in a block statement (` { ` and ` } ` ), labels no longer act as delimiters.
211
+ 3 . ` __result ` is now called ` it ` in postconditions.
212
+ 4 . Invariants can be specified at the block / scope level, not just at function entry points.
213
+ 5 . No longer creates custom error types.
214
+
215
+
203
216
# License
204
217
205
218
Published by [ codemix] ( http://codemix.com/ ) under a permissive MIT License, see [ LICENSE.md] ( ./LICENSE.md ) .
0 commit comments