New Ways of Working with AST
This is what you need to iterate over objects searching for a property with a key.

returning to the root and the source.
Better to have been blind and deaf
from the beginning!
Dwelling in one’s true abode,
unconcerned with and without -
The river flows tranquilly on
and the flowers are red
© Zen Ten Bulls
Hi folks! New day, new article 😄!
Get the property
If you want to iterate over objects searching for a property with a key, operator.getProperty() is what you need.
Let’s suppose you have an object:
{
"test": "npm test"
}
Here is how you can remove property with a name test
:
import {operate} from 'putout';
const {getProperty} = operate;const testPath = getProperty(path, 'test');
testPath.remove();
Get ExportDefaultDeclaration
When you need to get export default
operator.getExportDefault() will help you out!
import {operate} from 'putout';
const {getExportDefault} = operate;const exportPath = getExportDefault(path);
exportPath.remove();
How it’s related to plugins?
The thing is two new rules added to @putout/plugin-madrun
that improves using madly comfortable script runner 🏎madrun
.
Both of them using methods described earlier to convert .madrun.js code like this:
export default {
'test': () => [env, 'npm test'],
'test:only': () => 'npm test',
'coverage': async () => [env, await run('test')],
'coverage:only': async () => [env, await cutEnv('test:only')],
};
To:
export default {
'test': () => [env, 'npm test'],
'test:only': () => 'npm test',
'coverage': async () => [env, await cutEnv('test')],
'coverage:only': async () => [env, await run('test:only')],
};
cutEnv() clears any env variables already passed to script, so it can be overridden with a new one like it was with a test.
It’s not needed when env doesn’t pass, like with test:only.
That’s all for today! Have a nice transforms🦉!
More content at plainenglish.io. Sign up for our free weekly newsletter. Get exclusive access to writing opportunities and advice in our community Discord.