Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
continue;
}
if (isAssignmentPattern(node)) {
traverseAssign(paramPath);
continue;
}
if (isObjectPattern(node)) {
processObj(paramPath.get('properties'));
continue;
}
}
// ArrowFunction only
if (isIdentifier(body))
use(path, body.name);
addParams({
path,
params,
});
},
...jsx(use),
}
for (const paramPath of paramsPaths) {
const {node} = paramPath;
if (isIdentifier(node)) {
declare(paramPath, node.name);
continue;
}
if (isAssignmentPattern(node)) {
traverseAssign(paramPath);
continue;
}
if (isObjectPattern(node)) {
processObj(paramPath.get('properties'));
continue;
}
}
// ArrowFunction only
if (isIdentifier(body))
use(path, body.name);
addParams({
path,
params,
});
},
...jsx(use),
if (id) {
declare(path, node.id.name);
if (!parentPath.isBlock() && !parentPath.isProgram())
use(path, node.id.name);
}
for (const paramPath of paramsPaths) {
const {node} = paramPath;
if (isIdentifier(node)) {
declare(paramPath, node.name);
continue;
}
if (isAssignmentPattern(node)) {
traverseAssign(paramPath);
continue;
}
if (isObjectPattern(node)) {
processObj(paramPath.get('properties'));
continue;
}
}
// ArrowFunction only
if (isIdentifier(body))
use(path, body.name);
addParams({
path,
'use strict';
const test = require('supertape');
const mockRequire = require('mock-require');
const {Identifier} = require('putout').types;
const {reRequire} = mockRequire;
const stub = require('@cloudcmd/stub');
const {assign} = Object;
test('putout: run-plugins: template: log', (t) => {
const namespace = stub();
assign(namespace, {
enabled: true,
});
const debug = stub().returns(namespace);
mockRequire('debug', debug);
'use strict';
const {
isStringLiteral,
stringLiteral,
identifier,
callExpression,
arrayExpression,
} = require('putout').types;
module.exports.report = ({name}) => {
return `"run" should be called in script: "${name}"`;
};
module.exports.traverse = ({push}) => {
return {
ArrowFunctionExpression(path) {
const {body} = path.node;
if (!isStringLiteral(body))
return;
const {value} = body;
if (!/^(redrun|npm run)/.test(value))
test('putout: run-plugins: template: log: object', (t) => {
const namespace = stub();
assign(namespace, {
enabled: true,
});
const debug = stub().returns(namespace);
mockRequire('debug', debug);
const log = reRequire('./log');
log(Identifier('hello'), Identifier('world'));
const expected = `Identifier: "hello" = Identifier: "world"`;
t.ok(namespace.calledWith(expected));
t.end();
});
module.exports.fix = ({path, value}) => {
const [line, arg] = value.split(' -- ');
const scripts = getScripts(line);
const strs = [];
for (const script of scripts) {
strs.push(stringLiteral(script));
}
const runArgs = getRunArgs(strs, arg);
path.node.body = callExpression(identifier('run'), runArgs);
};
module.exports.fix = ({path, value}) => {
const [line, arg] = value.split(' -- ');
const scripts = getScripts(line);
const strs = [];
for (const script of scripts) {
strs.push(stringLiteral(script));
}
const runArgs = getRunArgs(strs, arg);
path.node.body = callExpression(identifier('run'), runArgs);
};
UnaryExpression(path) {
const {argument} = path.node;
if (isIdentifier(argument))
use(path, argument.name);
},
SwitchStatement(path) {
const {node} = path;
if (isIdentifier(node.discriminant))
use(path, node.discriminant.name);
for (const {test} of node.cases) {
if (isIdentifier(test))
use(path, test.name);
}
},