Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function checkComment( comment, ast, offset ) {
var matches;
var node;
var prev;
var type;
matches = comment.value.match( RE_ANNOTATION );
if ( matches ) {
offset += 1 + comment.loc.start.column;
prev = walk.findNodeAt( ast, null, comment.start-offset );
type = matches[ 1 ];
if ( !prev ) {
// Handle case when comment refers to node on the same line:
if ( walk.findNodeAt( ast, null, comment.start-1 ) ) {
return null;
}
return 'Encountered an orphaned return annotation without a preceding node';
}
node = prev.node;
switch ( type ) {
case 'returns':
if (
node.type !== 'VariableDeclaration' &&
( node.type !== 'ExpressionStatement' || node.expression.type !== 'AssignmentExpression' )
) {
return 'Only include `// returns` after variable declarations or assignment expressions (use `=>` after `console.log`)';
function getModuleExportsObjectExpression(ast: ESTree.Node): ESTree.ObjectExpression | void {
const moduleExports: IFound = walk.findNodeAt(ast, null, null, isModuleExportsExpression);
if (moduleExports && moduleExports.node.type === 'ExpressionStatement') {
const rightExpression = (moduleExports.node.expression as ESTree.AssignmentExpression).right;
if (rightExpression.type === 'ObjectExpression') {
return rightExpression;
}
}
}
export function findNodeAt(node: Ast.Node,
start?: number | null,
end?: number | null,
test?: string | AstTestFn | null,
baseVisitor = base, state?: T):
{ node: Node, state: T } {
return acornWalk.findNodeAt(node, start, end, test, baseVisitor, state);
}
public importPackage(variableName: string, packageName: string): void {
const packageRequired: IFound = walk.findNodeAt(this.ast, null, null, isVarDeclaration(variableName));
if (!packageRequired) {
const declaration = generateVariableDeclaration(variableName, 'require', packageName);
(this.ast as ESTree.Program).body.unshift(declaration);
this.writeAST();
}
}
options.from = from.value.value;
}
const skipDryRun = findProperty(node, 'skipDryRun');
if (skipDryRun && skipDryRun.value.type === 'Literal' && typeof skipDryRun.value.value === 'boolean') {
options.skipDryRun = skipDryRun.value.value;
}
const timeoutBlocks = findProperty(node, 'timeoutBlocks');
if (timeoutBlocks && timeoutBlocks.value.type === 'Literal' && typeof timeoutBlocks.value.value === 'number') {
options.timeoutBlocks = timeoutBlocks.value.value;
}
const provider = findProperty(node, 'provider');
if (provider && provider.value.type === 'FunctionExpression') {
const hdWalletProvider: IFound = walk.findNodeAt(provider, null, null, isHDWalletProvider);
if (hdWalletProvider && hdWalletProvider.node.type === 'NewExpression') {
options.provider = astToHDWalletProvider(hdWalletProvider.node);
}
}
if (provider && provider.value.type === 'NewExpression') {
options.provider = astToHDWalletProvider(provider.value);
}
return options;
}
public isHdWalletProviderDeclared(): boolean {
try {
const moduleExports = walk.findNodeAt(this.ast, null, null, isHdWalletProviderDeclaration);
return !!moduleExports;
} catch (error) {
Telemetry.sendException(error);
}
return false;
}
}
function findNodeAt (node, start, end, test, baseVisitor, state) {
return walk.findNodeAt(node, start, end, test, baseVisitor || base, state)
}
function findNodeAt (node, start, end, test, baseVisitor, state) {
return walk.findNodeAt(node, start, end, test, baseVisitor || base, state)
}
function getModuleExportsObjectExpression(ast: ESTree.Node): ESTree.ObjectExpression | void {
const moduleExports: IFound = walk.findNodeAt(ast, null, null, isModuleExportsExpression);
if (moduleExports && moduleExports.node.type === 'ExpressionStatement') {
const rightExpression = (moduleExports.node.expression as ESTree.AssignmentExpression).right;
if (rightExpression.type === 'ObjectExpression') {
return rightExpression;
}
}
}