Skip to content

Commit feb3422

Browse files
committed
Merge branch 'master' of github.com:codemix/babel-plugin-contracts
2 parents e64415d + f37d44c commit feb3422

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

README.md

+20-7
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ npm install --save-dev babel-plugin-contracts
4040
Then, in your babel configuration (usually in your `.babelrc` file), add `"contracts"` to your list of plugins:
4141
```json
4242
{
43-
"plugins": ["contracts", {
44-
"env": {
45-
"production": {
46-
"strip": true
43+
"plugins": [
44+
["contracts", {
45+
"env": {
46+
"production": {
47+
"strip": true
48+
}
4749
}
48-
}
49-
}]
50+
}]
51+
]
5052
}
5153
```
5254

@@ -165,7 +167,7 @@ The above example configuration will remove all contracts when `NODE_ENV=product
165167

166168
```js
167169
function addAndSquare (a, b) {
168-
const result = a + b;
170+
let result = a + b;
169171
assert: {
170172
typeof result === 'number';
171173
!isNaN(result);
@@ -200,6 +202,17 @@ The above example configuration will remove all contracts when `NODE_ENV=product
200202

201203
Now if a contract fails, the error object will have a descriptive message.
202204

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+
203216
# License
204217

205218
Published by [codemix](http://codemix.com/) under a permissive MIT License, see [LICENSE.md](./LICENSE.md).

0 commit comments

Comments
 (0)