@putout/engine-runner
Advanced tools
Comparing version 13.1.0 to 13.2.0
@@ -13,2 +13,3 @@ 'use strict'; | ||
upStore, | ||
upListStore, | ||
} = require('./store'); | ||
@@ -43,2 +44,3 @@ | ||
listStore, | ||
uplist, | ||
} = getStore(plugin, { | ||
@@ -59,2 +61,3 @@ fix, | ||
upstore, | ||
uplist, | ||
generate, | ||
@@ -96,2 +99,3 @@ options, | ||
const placesStore = listStore(); | ||
const uplist = upListStore(); | ||
@@ -128,4 +132,5 @@ const push = (path) => { | ||
upstore, | ||
uplist, | ||
}; | ||
} | ||
@@ -9,2 +9,4 @@ 'use strict'; | ||
const toArray = (a) => Array.from(a); | ||
module.exports.listStore = (list = []) => { | ||
@@ -31,2 +33,5 @@ const fn = (...args) => { | ||
module.exports.mapStore = createStore({ | ||
get(map) { | ||
return values(map); | ||
}, | ||
set(map, name, data) { | ||
@@ -38,2 +43,5 @@ map[name] = data; | ||
module.exports.upStore = createStore({ | ||
get(map) { | ||
return values(map); | ||
}, | ||
set(map, name, data) { | ||
@@ -45,7 +53,17 @@ map[name] = map[name] || {}; | ||
function createStore({set}) { | ||
module.exports.upListStore = createStore({ | ||
get(map) { | ||
return values(map).map(toArray); | ||
}, | ||
set(map, name, data) { | ||
map[name] = map[name] || new Set(); | ||
map[name].add(data); | ||
}, | ||
}); | ||
function createStore({set, get}) { | ||
return (map = {}) => { | ||
const fn = (...args) => { | ||
if (!args.length) | ||
return values(map); | ||
return get(map); | ||
@@ -52,0 +70,0 @@ const [name, data] = args; |
{ | ||
"name": "@putout/engine-runner", | ||
"version": "13.1.0", | ||
"version": "13.2.0", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", |
@@ -242,2 +242,3 @@ # @putout/engine-runner [![NPM version][NPMIMGURL]][NPMURL] | ||
- ✅`upstore`; | ||
- ✅`uplist`; | ||
@@ -344,2 +345,39 @@ Let's talk about each of them. | ||
### `uplist` | ||
When you need to update named arrays: | ||
```js | ||
module.exports.traverse = ({uplist, push}) => ({ | ||
'const __object = __a.__b': (fullPath) => { | ||
const {__a, __b} = getTemplateValues(fullPath, 'const __object = __a.__b'); | ||
const path = fullPath.get('declarations.0.init'); | ||
const {uid} = path.scope; | ||
if (isIdentifier(__a) || isCallExpression(__a)) { | ||
const {code} = generate(__a); | ||
const id = `${uid}-${code}`; | ||
return uplist(id, path); | ||
} | ||
}, | ||
'Program': { | ||
exit: () => { | ||
for (const items of uplist()) { | ||
if (items.length < 2) | ||
continue; | ||
const index = items.length - 1; | ||
const path = items[index]; | ||
push({ | ||
path, | ||
items, | ||
}); | ||
} | ||
}, | ||
}, | ||
}); | ||
``` | ||
## Logs | ||
@@ -346,0 +384,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32045
743
394