@putout/operate
Advanced tools
Comparing version 6.6.0 to 6.7.0
@@ -12,2 +12,3 @@ 'use strict'; | ||
const {extract} = require('./extract'); | ||
const {compute} = require('./compute'); | ||
@@ -19,2 +20,3 @@ const {assign} = Object; | ||
module.exports.extract = extract; | ||
module.exports.compute = compute; | ||
module.exports.replaceWith = replaceWith; | ||
@@ -21,0 +23,0 @@ |
{ | ||
"name": "@putout/operate", | ||
"version": "6.6.0", | ||
"version": "6.7.0", | ||
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
@@ -5,0 +5,0 @@ "description": "operate on ast", |
@@ -105,4 +105,35 @@ # Operate [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL] | ||
## `compute(path)` | ||
Computes value of expression: | ||
For `code` like this: | ||
```js | ||
const bodies = { | ||
function: `typeof __a === 'function'`, | ||
}; | ||
module.exports.replace = () => ({ | ||
[bodies.function]: 'isFn(__a)', | ||
}); | ||
``` | ||
You can compute value of `bodies.function`: | ||
```js | ||
const {parse, operator} = require('putout'); | ||
const {traverse, compute} = operator; | ||
traverse({ | ||
'__a.__b': (path) => { | ||
const [computed, value] = compute(path); | ||
// returns | ||
[true, "typeof __a === 'function'"]; | ||
}, | ||
}); | ||
``` | ||
## License | ||
MIT |
11348
7
179
139