How to use the acorn-walk.findNodeAt function in acorn-walk

To help you get started, we’ve selected a few acorn-walk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stdlib-js / stdlib / lib / node_modules / @stdlib / _tools / eslint / rules / doctest-marker / lib / main.js View on Github external
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`)';
github microsoft / vscode-azure-blockchain-ethereum / src / helpers / truffleConfig.ts View on Github external
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;
      }
    }
  }
github endorphinjs / endorphin / packages / template-parser / src / walk.ts View on Github external
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);
}
github microsoft / vscode-azure-blockchain-ethereum / src / debugAdapter / configurationReader.ts View on Github external
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();
      }
    }
github microsoft / vscode-azure-blockchain-ethereum / src / helpers / truffleConfig.ts View on Github external
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;
  }
github microsoft / vscode-azure-blockchain-ethereum / src / helpers / truffleConfig.ts View on Github external
public isHdWalletProviderDeclared(): boolean {
      try {
        const moduleExports = walk.findNodeAt(this.ast, null, null, isHdWalletProviderDeclaration);
        return !!moduleExports;
      } catch (error) {
        Telemetry.sendException(error);
      }
      return false;
    }
  }
github publiclab / leaflet-environmental-layers / node_modules / acorn-node / walk.js View on Github external
function findNodeAt (node, start, end, test, baseVisitor, state) {
  return walk.findNodeAt(node, start, end, test, baseVisitor || base, state)
}
github peterqliu / threebox / node_modules / acorn-node / walk.js View on Github external
function findNodeAt (node, start, end, test, baseVisitor, state) {
  return walk.findNodeAt(node, start, end, test, baseVisitor || base, state)
}
github microsoft / vscode-azure-blockchain-ethereum / src / debugAdapter / configurationReader.ts View on Github external
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;
      }
    }
  }