Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add % commands #1

@azz

Description

@azz

Say we want to match:

foo({ bar, baz })
foo({})

and not

foo(bar);
foo();
foo("bar");

Currently this isn't possible without running ast-grep many times.

V8 exposes custom functions through a "natives syntax", we could re-use this syntax to provide pattern matching:

  • %type:* - match any statement/expression/annotation.
  • %type:Identifier, %type:LogicalExpression, etc: Only match one AST type.
  • %type:ClassMethod,static:true: Only show ClassMethods where are static.

So to match the above, we would issue:

ast-grep 'foo(%type:ObjectExpression)'

This would possibly require that all patterns must have a space after % if it is used as an actual binary expression, but that will be uncommon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions